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/stackMapTable.hpp
32285 views
1
/*
2
* Copyright (c) 2003, 2016, 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_STACKMAPTABLE_HPP
26
#define SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
27
28
#include "classfile/stackMapFrame.hpp"
29
#include "classfile/verifier.hpp"
30
#include "memory/allocation.hpp"
31
#include "oops/constantPool.hpp"
32
#include "oops/method.hpp"
33
#include "utilities/globalDefinitions.hpp"
34
#ifdef TARGET_ARCH_x86
35
# include "bytes_x86.hpp"
36
#endif
37
#ifdef TARGET_ARCH_aarch32
38
# include "bytes_aarch32.hpp"
39
#endif
40
#ifdef TARGET_ARCH_aarch64
41
# include "bytes_aarch64.hpp"
42
#endif
43
#ifdef TARGET_ARCH_sparc
44
# include "bytes_sparc.hpp"
45
#endif
46
#ifdef TARGET_ARCH_zero
47
# include "bytes_zero.hpp"
48
#endif
49
#ifdef TARGET_ARCH_arm
50
# include "bytes_arm.hpp"
51
#endif
52
#ifdef TARGET_ARCH_ppc
53
# include "bytes_ppc.hpp"
54
#endif
55
56
class StackMapReader;
57
58
// StackMapTable class is the StackMap table used by type checker
59
class StackMapTable : public StackObj {
60
private:
61
// Logically, the _frame_count (as well as many fields in the StackFrame)
62
// should be a u2, but if we defined the variable as that type it will
63
// be difficult to detect/recover from overflow or underflow conditions.
64
// Widening the type and making it signed will help detect these.
65
int32_t _code_length;
66
int32_t _frame_count; // Stackmap frame count
67
StackMapFrame** _frame_array;
68
69
public:
70
StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
71
u2 max_locals, u2 max_stack,
72
char* code_data, int code_len, TRAPS);
73
74
inline int32_t get_frame_count() const { return _frame_count; }
75
inline int get_offset(int index) const {
76
return _frame_array[index]->offset();
77
}
78
79
// Match and/or update current_frame to the frame in stackmap table with
80
// specified offset. Return true if the two frames match.
81
bool match_stackmap(
82
StackMapFrame* current_frame, int32_t offset,
83
bool match, bool update, ErrorContext* ctx, TRAPS) const;
84
// Match and/or update current_frame to the frame in stackmap table with
85
// specified offset and frame index. Return true if the two frames match.
86
bool match_stackmap(
87
StackMapFrame* current_frame, int32_t offset, int32_t frame_index,
88
bool match, bool update, ErrorContext* ctx, TRAPS) const;
89
90
// Check jump instructions. Make sure there are no uninitialized
91
// instances on backward branch.
92
void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
93
94
// The following methods are only used inside this class.
95
96
// Returns the frame array index where the frame with offset is stored.
97
int get_index_from_offset(int32_t offset) const;
98
99
void print_on(outputStream* str) const;
100
};
101
102
class StackMapStream : StackObj {
103
private:
104
Array<u1>* _data;
105
int _index;
106
public:
107
StackMapStream(Array<u1>* ah)
108
: _data(ah), _index(0) {
109
}
110
u1 get_u1(TRAPS) {
111
if (_data == NULL || _index >= _data->length()) {
112
stackmap_format_error("access beyond the end of attribute", CHECK_0);
113
}
114
return _data->at(_index++);
115
}
116
u2 get_u2(TRAPS) {
117
if (_data == NULL || _index >= _data->length() - 1) {
118
stackmap_format_error("access beyond the end of attribute", CHECK_0);
119
}
120
u2 res = Bytes::get_Java_u2(_data->adr_at(_index));
121
_index += 2;
122
return res;
123
}
124
bool at_end() {
125
return (_data == NULL) || (_index == _data->length());
126
}
127
static void stackmap_format_error(const char* msg, TRAPS);
128
};
129
130
class StackMapReader : StackObj {
131
private:
132
// information about the class and method
133
constantPoolHandle _cp;
134
ClassVerifier* _verifier;
135
StackMapStream* _stream;
136
char* _code_data;
137
int32_t _code_length;
138
139
// information get from the attribute
140
int32_t _frame_count; // frame count
141
142
int32_t chop(VerificationType* locals, int32_t length, int32_t chops);
143
VerificationType parse_verification_type(u1* flags, TRAPS);
144
void check_verification_type_array_size(
145
int32_t size, int32_t max_size, TRAPS) {
146
if (size < 0 || size > max_size) {
147
// Since this error could be caused someone rewriting the method
148
// but not knowing to update the stackmap data, we call the the
149
// verifier's error method, which may not throw an exception and
150
// failover to the old verifier instead.
151
_verifier->class_format_error(
152
"StackMapTable format error: bad type array size");
153
}
154
}
155
156
enum {
157
SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247,
158
SAME_EXTENDED = 251,
159
FULL = 255
160
};
161
162
public:
163
// Constructor
164
StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data,
165
int32_t code_len, TRAPS) :
166
_verifier(v), _stream(stream),
167
_code_data(code_data), _code_length(code_len) {
168
methodHandle m = v->method();
169
if (m->has_stackmap_table()) {
170
_cp = constantPoolHandle(THREAD, m->constants());
171
_frame_count = _stream->get_u2(CHECK);
172
} else {
173
// There's no stackmap table present. Frame count and size are 0.
174
_frame_count = 0;
175
}
176
}
177
178
inline int32_t get_frame_count() const { return _frame_count; }
179
StackMapFrame* next(StackMapFrame* pre_frame, bool first,
180
u2 max_locals, u2 max_stack, TRAPS);
181
182
void check_end(TRAPS) {
183
if (!_stream->at_end()) {
184
StackMapStream::stackmap_format_error("wrong attribute size", CHECK);
185
}
186
}
187
};
188
189
#endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
190
191