Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/classFileStream.hpp
32285 views
/*1* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP25#define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP2627#include "utilities/top.hpp"28#ifdef TARGET_ARCH_x8629# include "bytes_x86.hpp"30#endif31#ifdef TARGET_ARCH_aarch3232# include "bytes_aarch32.hpp"33#endif34#ifdef TARGET_ARCH_aarch6435# include "bytes_aarch64.hpp"36#endif37#ifdef TARGET_ARCH_sparc38# include "bytes_sparc.hpp"39#endif40#ifdef TARGET_ARCH_zero41# include "bytes_zero.hpp"42#endif43#ifdef TARGET_ARCH_arm44# include "bytes_arm.hpp"45#endif46#ifdef TARGET_ARCH_ppc47# include "bytes_ppc.hpp"48#endif4950// Input stream for reading .class file51//52// The entire input stream is present in a buffer allocated by the caller.53// The caller is responsible for deallocating the buffer and for using54// ResourceMarks appropriately when constructing streams.5556class ClassFileStream: public ResourceObj {57private:58u1* _buffer_start; // Buffer bottom59u1* _buffer_end; // Buffer top (one past last element)60u1* _current; // Current buffer position61const char* _source; // Source of stream (directory name, ZIP/JAR archive name)62bool _need_verify; // True if verification is on for the class file6364void truncated_file_error(TRAPS);6566#if INCLUDE_JFR67u1* clone_buffer() const;68const char* const clone_source() const;69#endif7071public:72// Constructor73ClassFileStream(u1* buffer, int length, const char* source, bool need_verify = false);7475// Buffer access76u1* buffer() const { return _buffer_start; }77int length() const { return _buffer_end - _buffer_start; }78u1* current() const { return _current; }79void set_current(u1* pos) { _current = pos; }80// for relative positioning81juint current_offset() const {82return (juint)(_current - _buffer_start);83}84const char* source() const { return _source; }85void set_verify(bool flag) { _need_verify = flag; }8687void check_truncated_file(bool b, TRAPS) {88if (b) {89truncated_file_error(THREAD);90}91}9293void guarantee_more(int size, TRAPS) {94size_t remaining = (size_t)(_buffer_end - _current);95unsigned int usize = (unsigned int)size;96check_truncated_file(usize > remaining, CHECK);97}9899// Read u1 from stream100u1 get_u1(TRAPS);101u1 get_u1_fast() {102return *_current++;103}104105// Read u2 from stream106u2 get_u2(TRAPS);107u2 get_u2_fast() {108u2 res = Bytes::get_Java_u2(_current);109_current += 2;110return res;111}112113// Read u4 from stream114u4 get_u4(TRAPS);115u4 get_u4_fast() {116u4 res = Bytes::get_Java_u4(_current);117_current += 4;118return res;119}120121// Read u8 from stream122u8 get_u8(TRAPS);123u8 get_u8_fast() {124u8 res = Bytes::get_Java_u8(_current);125_current += 8;126return res;127}128129// Get direct pointer into stream at current position.130// Returns NULL if length elements are not remaining. The caller is131// responsible for calling skip below if buffer contents is used.132u1* get_u1_buffer() {133return _current;134}135136u2* get_u2_buffer() {137return (u2*) _current;138}139140// Skip length u1 or u2 elements from stream141void skip_u1(int length, TRAPS);142void skip_u1_fast(int length) {143_current += length;144}145146void skip_u2(int length, TRAPS);147void skip_u2_fast(int length) {148_current += 2 * length;149}150151void skip_u4(int length, TRAPS);152void skip_u4_fast(int length) {153_current += 4 * length;154}155156// Tells whether eos is reached157bool at_eos() const { return _current == _buffer_end; }158159#if INCLUDE_JFR160ClassFileStream* clone() const;161162bool need_verify() const { return _need_verify; }163#endif164};165166#endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP167168169