Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/classFileStream.hpp
32285 views
1
/*
2
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
26
#define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
27
28
#include "utilities/top.hpp"
29
#ifdef TARGET_ARCH_x86
30
# include "bytes_x86.hpp"
31
#endif
32
#ifdef TARGET_ARCH_aarch32
33
# include "bytes_aarch32.hpp"
34
#endif
35
#ifdef TARGET_ARCH_aarch64
36
# include "bytes_aarch64.hpp"
37
#endif
38
#ifdef TARGET_ARCH_sparc
39
# include "bytes_sparc.hpp"
40
#endif
41
#ifdef TARGET_ARCH_zero
42
# include "bytes_zero.hpp"
43
#endif
44
#ifdef TARGET_ARCH_arm
45
# include "bytes_arm.hpp"
46
#endif
47
#ifdef TARGET_ARCH_ppc
48
# include "bytes_ppc.hpp"
49
#endif
50
51
// Input stream for reading .class file
52
//
53
// The entire input stream is present in a buffer allocated by the caller.
54
// The caller is responsible for deallocating the buffer and for using
55
// ResourceMarks appropriately when constructing streams.
56
57
class ClassFileStream: public ResourceObj {
58
private:
59
u1* _buffer_start; // Buffer bottom
60
u1* _buffer_end; // Buffer top (one past last element)
61
u1* _current; // Current buffer position
62
const char* _source; // Source of stream (directory name, ZIP/JAR archive name)
63
bool _need_verify; // True if verification is on for the class file
64
65
void truncated_file_error(TRAPS);
66
67
#if INCLUDE_JFR
68
u1* clone_buffer() const;
69
const char* const clone_source() const;
70
#endif
71
72
public:
73
// Constructor
74
ClassFileStream(u1* buffer, int length, const char* source, bool need_verify = false);
75
76
// Buffer access
77
u1* buffer() const { return _buffer_start; }
78
int length() const { return _buffer_end - _buffer_start; }
79
u1* current() const { return _current; }
80
void set_current(u1* pos) { _current = pos; }
81
// for relative positioning
82
juint current_offset() const {
83
return (juint)(_current - _buffer_start);
84
}
85
const char* source() const { return _source; }
86
void set_verify(bool flag) { _need_verify = flag; }
87
88
void check_truncated_file(bool b, TRAPS) {
89
if (b) {
90
truncated_file_error(THREAD);
91
}
92
}
93
94
void guarantee_more(int size, TRAPS) {
95
size_t remaining = (size_t)(_buffer_end - _current);
96
unsigned int usize = (unsigned int)size;
97
check_truncated_file(usize > remaining, CHECK);
98
}
99
100
// Read u1 from stream
101
u1 get_u1(TRAPS);
102
u1 get_u1_fast() {
103
return *_current++;
104
}
105
106
// Read u2 from stream
107
u2 get_u2(TRAPS);
108
u2 get_u2_fast() {
109
u2 res = Bytes::get_Java_u2(_current);
110
_current += 2;
111
return res;
112
}
113
114
// Read u4 from stream
115
u4 get_u4(TRAPS);
116
u4 get_u4_fast() {
117
u4 res = Bytes::get_Java_u4(_current);
118
_current += 4;
119
return res;
120
}
121
122
// Read u8 from stream
123
u8 get_u8(TRAPS);
124
u8 get_u8_fast() {
125
u8 res = Bytes::get_Java_u8(_current);
126
_current += 8;
127
return res;
128
}
129
130
// Get direct pointer into stream at current position.
131
// Returns NULL if length elements are not remaining. The caller is
132
// responsible for calling skip below if buffer contents is used.
133
u1* get_u1_buffer() {
134
return _current;
135
}
136
137
u2* get_u2_buffer() {
138
return (u2*) _current;
139
}
140
141
// Skip length u1 or u2 elements from stream
142
void skip_u1(int length, TRAPS);
143
void skip_u1_fast(int length) {
144
_current += length;
145
}
146
147
void skip_u2(int length, TRAPS);
148
void skip_u2_fast(int length) {
149
_current += 2 * length;
150
}
151
152
void skip_u4(int length, TRAPS);
153
void skip_u4_fast(int length) {
154
_current += 4 * length;
155
}
156
157
// Tells whether eos is reached
158
bool at_eos() const { return _current == _buffer_end; }
159
160
#if INCLUDE_JFR
161
ClassFileStream* clone() const;
162
163
bool need_verify() const { return _need_verify; }
164
#endif
165
};
166
167
#endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
168
169