author | alanb |
Thu, 17 Mar 2016 19:04:01 +0000 | |
changeset 36508 | 5f9eee6b383b |
parent 34666 | 1c7168ea0034 |
child 37466 | 287c4ebd11b0 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
34666 | 2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |
26 |
#define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |
|
27 |
||
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
22234
diff
changeset
|
28 |
#include "utilities/bytes.hpp" |
7397 | 29 |
#include "utilities/top.hpp" |
30 |
||
1 | 31 |
// Input stream for reading .class file |
32 |
// |
|
33 |
// The entire input stream is present in a buffer allocated by the caller. |
|
34 |
// The caller is responsible for deallocating the buffer and for using |
|
35 |
// ResourceMarks appropriately when constructing streams. |
|
36 |
||
34666 | 37 |
class ClassPathEntry; |
38 |
||
1 | 39 |
class ClassFileStream: public ResourceObj { |
40 |
private: |
|
34666 | 41 |
const u1* const _buffer_start; // Buffer bottom |
42 |
const u1* const _buffer_end; // Buffer top (one past last element) |
|
43 |
mutable const u1* _current; // Current buffer position |
|
44 |
const char* const _source; // Source of stream (directory name, ZIP/JAR archive name) |
|
45 |
bool _need_verify; // True if verification is on for the class file |
|
46 |
||
47 |
void truncated_file_error(TRAPS) const ; |
|
1 | 48 |
|
34666 | 49 |
protected: |
50 |
const u1* clone_buffer() const; |
|
51 |
const char* const clone_source() const; |
|
52 |
||
1 | 53 |
public: |
34666 | 54 |
static const bool no_verification; |
55 |
static const bool verify; |
|
56 |
||
57 |
ClassFileStream(const u1* buffer, |
|
58 |
int length, |
|
59 |
const char* source, |
|
60 |
bool verify_stream = verify); // to be verified by default |
|
61 |
||
62 |
virtual const ClassFileStream* clone() const; |
|
1 | 63 |
|
64 |
// Buffer access |
|
34666 | 65 |
const u1* buffer() const { return _buffer_start; } |
66 |
int length() const { return _buffer_end - _buffer_start; } |
|
67 |
const u1* current() const { return _current; } |
|
68 |
void set_current(const u1* pos) const { |
|
69 |
assert(pos >= _buffer_start && pos <= _buffer_end, "invariant"); |
|
70 |
_current = pos; |
|
71 |
} |
|
1 | 72 |
|
34666 | 73 |
// for relative positioning |
74 |
juint current_offset() const { |
|
75 |
return (juint)(_current - _buffer_start); |
|
76 |
} |
|
77 |
const char* source() const { return _source; } |
|
78 |
bool need_verify() const { return _need_verify; } |
|
79 |
void set_verify(bool flag) { _need_verify = flag; } |
|
80 |
||
81 |
void check_truncated_file(bool b, TRAPS) const { |
|
1 | 82 |
if (b) { |
83 |
truncated_file_error(THREAD); |
|
84 |
} |
|
85 |
} |
|
86 |
||
34666 | 87 |
void guarantee_more(int size, TRAPS) const { |
1 | 88 |
size_t remaining = (size_t)(_buffer_end - _current); |
89 |
unsigned int usize = (unsigned int)size; |
|
90 |
check_truncated_file(usize > remaining, CHECK); |
|
91 |
} |
|
92 |
||
93 |
// Read u1 from stream |
|
34666 | 94 |
u1 get_u1(TRAPS) const; |
95 |
u1 get_u1_fast() const { |
|
1 | 96 |
return *_current++; |
97 |
} |
|
98 |
||
99 |
// Read u2 from stream |
|
34666 | 100 |
u2 get_u2(TRAPS) const; |
101 |
u2 get_u2_fast() const { |
|
102 |
u2 res = Bytes::get_Java_u2((address)_current); |
|
1 | 103 |
_current += 2; |
104 |
return res; |
|
105 |
} |
|
106 |
||
107 |
// Read u4 from stream |
|
34666 | 108 |
u4 get_u4(TRAPS) const; |
109 |
u4 get_u4_fast() const { |
|
110 |
u4 res = Bytes::get_Java_u4((address)_current); |
|
1 | 111 |
_current += 4; |
112 |
return res; |
|
113 |
} |
|
114 |
||
115 |
// Read u8 from stream |
|
34666 | 116 |
u8 get_u8(TRAPS) const; |
117 |
u8 get_u8_fast() const { |
|
118 |
u8 res = Bytes::get_Java_u8((address)_current); |
|
1 | 119 |
_current += 8; |
120 |
return res; |
|
121 |
} |
|
122 |
||
123 |
// Get direct pointer into stream at current position. |
|
124 |
// Returns NULL if length elements are not remaining. The caller is |
|
125 |
// responsible for calling skip below if buffer contents is used. |
|
34666 | 126 |
const u1* get_u1_buffer() const { |
1 | 127 |
return _current; |
128 |
} |
|
129 |
||
34666 | 130 |
const u2* get_u2_buffer() const { |
131 |
return (const u2*) _current; |
|
1 | 132 |
} |
133 |
||
134 |
// Skip length u1 or u2 elements from stream |
|
34666 | 135 |
void skip_u1(int length, TRAPS) const; |
136 |
void skip_u1_fast(int length) const { |
|
1 | 137 |
_current += length; |
138 |
} |
|
139 |
||
34666 | 140 |
void skip_u2(int length, TRAPS) const; |
141 |
void skip_u2_fast(int length) const { |
|
1 | 142 |
_current += 2 * length; |
143 |
} |
|
144 |
||
34666 | 145 |
void skip_u4(int length, TRAPS) const; |
146 |
void skip_u4_fast(int length) const { |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
8921
diff
changeset
|
147 |
_current += 4 * length; |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
8921
diff
changeset
|
148 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
8921
diff
changeset
|
149 |
|
1 | 150 |
// Tells whether eos is reached |
34666 | 151 |
bool at_eos() const { return _current == _buffer_end; } |
1 | 152 |
}; |
7397 | 153 |
|
154 |
#endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |