classFileStream.hpp revision 2073
325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A *
325N/A */
325N/A
325N/A#ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
325N/A#define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
325N/A
325N/A#include "utilities/top.hpp"
325N/A#ifdef TARGET_ARCH_x86
325N/A# include "bytes_x86.hpp"
325N/A#endif
325N/A#ifdef TARGET_ARCH_sparc
325N/A# include "bytes_sparc.hpp"
325N/A#endif
325N/A#ifdef TARGET_ARCH_zero
325N/A# include "bytes_zero.hpp"
325N/A#endif
325N/A#ifdef TARGET_ARCH_arm
325N/A# include "bytes_arm.hpp"
325N/A#endif
325N/A#ifdef TARGET_ARCH_ppc
325N/A# include "bytes_ppc.hpp"
325N/A#endif
325N/A
325N/A// Input stream for reading .class file
325N/A//
325N/A// The entire input stream is present in a buffer allocated by the caller.
325N/A// The caller is responsible for deallocating the buffer and for using
325N/A// ResourceMarks appropriately when constructing streams.
325N/A
325N/Aclass ClassFileStream: public ResourceObj {
325N/A private:
325N/A u1* _buffer_start; // Buffer bottom
325N/A u1* _buffer_end; // Buffer top (one past last element)
325N/A u1* _current; // Current buffer position
325N/A char* _source; // Source of stream (directory name, ZIP/JAR archive name)
325N/A bool _need_verify; // True if verification is on for the class file
325N/A
325N/A void truncated_file_error(TRAPS);
325N/A public:
325N/A // Constructor
325N/A ClassFileStream(u1* buffer, int length, char* source);
325N/A
325N/A // Buffer access
325N/A u1* buffer() const { return _buffer_start; }
325N/A int length() const { return _buffer_end - _buffer_start; }
325N/A u1* current() const { return _current; }
325N/A void set_current(u1* pos) { _current = pos; }
325N/A char* source() const { return _source; }
325N/A void set_verify(bool flag) { _need_verify = flag; }
325N/A
325N/A void check_truncated_file(bool b, TRAPS) {
325N/A if (b) {
325N/A truncated_file_error(THREAD);
325N/A }
325N/A }
325N/A
325N/A void guarantee_more(int size, TRAPS) {
325N/A size_t remaining = (size_t)(_buffer_end - _current);
325N/A unsigned int usize = (unsigned int)size;
325N/A check_truncated_file(usize > remaining, CHECK);
325N/A }
325N/A
325N/A // Read u1 from stream
325N/A u1 get_u1(TRAPS);
325N/A u1 get_u1_fast() {
325N/A return *_current++;
325N/A }
325N/A
325N/A // Read u2 from stream
325N/A u2 get_u2(TRAPS);
325N/A u2 get_u2_fast() {
325N/A u2 res = Bytes::get_Java_u2(_current);
325N/A _current += 2;
325N/A return res;
325N/A }
325N/A
325N/A // Read u4 from stream
325N/A u4 get_u4(TRAPS);
325N/A u4 get_u4_fast() {
325N/A u4 res = Bytes::get_Java_u4(_current);
325N/A _current += 4;
325N/A return res;
325N/A }
325N/A
325N/A // Read u8 from stream
325N/A u8 get_u8(TRAPS);
325N/A u8 get_u8_fast() {
325N/A u8 res = Bytes::get_Java_u8(_current);
325N/A _current += 8;
325N/A return res;
325N/A }
325N/A
325N/A // Get direct pointer into stream at current position.
325N/A // Returns NULL if length elements are not remaining. The caller is
325N/A // responsible for calling skip below if buffer contents is used.
325N/A u1* get_u1_buffer() {
325N/A return _current;
325N/A }
325N/A
325N/A u2* get_u2_buffer() {
325N/A return (u2*) _current;
325N/A }
325N/A
325N/A // Skip length u1 or u2 elements from stream
325N/A void skip_u1(int length, TRAPS);
325N/A void skip_u1_fast(int length) {
325N/A _current += length;
325N/A }
325N/A
325N/A void skip_u2(int length, TRAPS);
325N/A void skip_u2_fast(int length) {
325N/A _current += 2 * length;
325N/A }
325N/A
325N/A // Tells whether eos is reached
325N/A bool at_eos() const { return _current == _buffer_end; }
325N/A};
325N/A
325N/A#endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
325N/A