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