Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
iklam@7090 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@1 | 25 | /* |
aoqi@1 | 26 | * This file has been modified by Loongson Technology in 2015. These |
aoqi@1 | 27 | * modifications are Copyright (c) 2015 Loongson Technology, and are made |
aoqi@1 | 28 | * available on the same license terms set forth above. |
aoqi@1 | 29 | */ |
aoqi@1 | 30 | |
aoqi@0 | 31 | #ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |
aoqi@0 | 32 | #define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |
aoqi@0 | 33 | |
aoqi@0 | 34 | #include "utilities/top.hpp" |
aoqi@0 | 35 | #ifdef TARGET_ARCH_x86 |
aoqi@0 | 36 | # include "bytes_x86.hpp" |
aoqi@0 | 37 | #endif |
aoqi@1 | 38 | #ifdef TARGET_ARCH_mips |
aoqi@1 | 39 | # include "bytes_mips.hpp" |
aoqi@1 | 40 | #endif |
aoqi@0 | 41 | #ifdef TARGET_ARCH_sparc |
aoqi@0 | 42 | # include "bytes_sparc.hpp" |
aoqi@0 | 43 | #endif |
aoqi@0 | 44 | #ifdef TARGET_ARCH_zero |
aoqi@0 | 45 | # include "bytes_zero.hpp" |
aoqi@0 | 46 | #endif |
aoqi@0 | 47 | #ifdef TARGET_ARCH_arm |
aoqi@0 | 48 | # include "bytes_arm.hpp" |
aoqi@0 | 49 | #endif |
aoqi@0 | 50 | #ifdef TARGET_ARCH_ppc |
aoqi@0 | 51 | # include "bytes_ppc.hpp" |
aoqi@0 | 52 | #endif |
aoqi@0 | 53 | |
aoqi@0 | 54 | // Input stream for reading .class file |
aoqi@0 | 55 | // |
aoqi@0 | 56 | // The entire input stream is present in a buffer allocated by the caller. |
aoqi@0 | 57 | // The caller is responsible for deallocating the buffer and for using |
aoqi@0 | 58 | // ResourceMarks appropriately when constructing streams. |
aoqi@0 | 59 | |
aoqi@0 | 60 | class ClassFileStream: public ResourceObj { |
aoqi@0 | 61 | private: |
aoqi@0 | 62 | u1* _buffer_start; // Buffer bottom |
aoqi@0 | 63 | u1* _buffer_end; // Buffer top (one past last element) |
aoqi@0 | 64 | u1* _current; // Current buffer position |
iklam@7090 | 65 | const char* _source; // Source of stream (directory name, ZIP/JAR archive name) |
aoqi@0 | 66 | bool _need_verify; // True if verification is on for the class file |
aoqi@0 | 67 | |
aoqi@0 | 68 | void truncated_file_error(TRAPS); |
aoqi@0 | 69 | public: |
aoqi@0 | 70 | // Constructor |
iklam@7090 | 71 | ClassFileStream(u1* buffer, int length, const char* source); |
aoqi@0 | 72 | |
aoqi@0 | 73 | // Buffer access |
aoqi@0 | 74 | u1* buffer() const { return _buffer_start; } |
aoqi@0 | 75 | int length() const { return _buffer_end - _buffer_start; } |
aoqi@0 | 76 | u1* current() const { return _current; } |
aoqi@0 | 77 | void set_current(u1* pos) { _current = pos; } |
iklam@7090 | 78 | const char* source() const { return _source; } |
aoqi@0 | 79 | void set_verify(bool flag) { _need_verify = flag; } |
aoqi@0 | 80 | |
aoqi@0 | 81 | void check_truncated_file(bool b, TRAPS) { |
aoqi@0 | 82 | if (b) { |
aoqi@0 | 83 | truncated_file_error(THREAD); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | void guarantee_more(int size, TRAPS) { |
aoqi@0 | 88 | size_t remaining = (size_t)(_buffer_end - _current); |
aoqi@0 | 89 | unsigned int usize = (unsigned int)size; |
aoqi@0 | 90 | check_truncated_file(usize > remaining, CHECK); |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | // Read u1 from stream |
aoqi@0 | 94 | u1 get_u1(TRAPS); |
aoqi@0 | 95 | u1 get_u1_fast() { |
aoqi@0 | 96 | return *_current++; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | // Read u2 from stream |
aoqi@0 | 100 | u2 get_u2(TRAPS); |
aoqi@0 | 101 | u2 get_u2_fast() { |
aoqi@0 | 102 | u2 res = Bytes::get_Java_u2(_current); |
aoqi@0 | 103 | _current += 2; |
aoqi@0 | 104 | return res; |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | // Read u4 from stream |
aoqi@0 | 108 | u4 get_u4(TRAPS); |
aoqi@0 | 109 | u4 get_u4_fast() { |
aoqi@0 | 110 | u4 res = Bytes::get_Java_u4(_current); |
aoqi@0 | 111 | _current += 4; |
aoqi@0 | 112 | return res; |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | // Read u8 from stream |
aoqi@0 | 116 | u8 get_u8(TRAPS); |
aoqi@0 | 117 | u8 get_u8_fast() { |
aoqi@0 | 118 | u8 res = Bytes::get_Java_u8(_current); |
aoqi@0 | 119 | _current += 8; |
aoqi@0 | 120 | return res; |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | // Get direct pointer into stream at current position. |
aoqi@0 | 124 | // Returns NULL if length elements are not remaining. The caller is |
aoqi@0 | 125 | // responsible for calling skip below if buffer contents is used. |
aoqi@0 | 126 | u1* get_u1_buffer() { |
aoqi@0 | 127 | return _current; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | u2* get_u2_buffer() { |
aoqi@0 | 131 | return (u2*) _current; |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | // Skip length u1 or u2 elements from stream |
aoqi@0 | 135 | void skip_u1(int length, TRAPS); |
aoqi@0 | 136 | void skip_u1_fast(int length) { |
aoqi@0 | 137 | _current += length; |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | void skip_u2(int length, TRAPS); |
aoqi@0 | 141 | void skip_u2_fast(int length) { |
aoqi@0 | 142 | _current += 2 * length; |
aoqi@0 | 143 | } |
aoqi@0 | 144 | |
aoqi@0 | 145 | void skip_u4(int length, TRAPS); |
aoqi@0 | 146 | void skip_u4_fast(int length) { |
aoqi@0 | 147 | _current += 4 * length; |
aoqi@0 | 148 | } |
aoqi@0 | 149 | |
aoqi@0 | 150 | // Tells whether eos is reached |
aoqi@0 | 151 | bool at_eos() const { return _current == _buffer_end; } |
aoqi@0 | 152 | }; |
aoqi@0 | 153 | |
aoqi@0 | 154 | #endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |