author | mchung |
Tue, 24 Nov 2015 14:59:17 -0800 | |
changeset 34280 | 72bfaaffee36 |
parent 33593 | 60764a78fa5c |
child 34628 | 6d08ec72803b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
28612
164db20ecb94
8055146: Split Verifier incorrectly throws VerifyError for getstatic of an array field
hseigel
parents:
26928
diff
changeset
|
2 |
* Copyright (c) 1998, 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:
3820
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3820
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:
3820
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_CLASSFILE_VERIFIER_HPP |
26 |
#define SHARE_VM_CLASSFILE_VERIFIER_HPP |
|
27 |
||
28 |
#include "classfile/verificationType.hpp" |
|
30764 | 29 |
#include "gc/shared/gcLocker.hpp" |
7397 | 30 |
#include "oops/klass.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
31 |
#include "oops/method.hpp" |
7397 | 32 |
#include "runtime/handles.hpp" |
30764 | 33 |
#include "utilities/exceptions.hpp" |
25955
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
34 |
#include "utilities/growableArray.hpp" |
7397 | 35 |
|
1 | 36 |
// The verifier class |
37 |
class Verifier : AllStatic { |
|
38 |
public: |
|
5882 | 39 |
enum { |
17863
d77007cf03c1
8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents:
17370
diff
changeset
|
40 |
STRICTER_ACCESS_CTRL_CHECK_VERSION = 49, |
5882 | 41 |
STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50, |
17863
d77007cf03c1
8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents:
17370
diff
changeset
|
42 |
INVOKEDYNAMIC_MAJOR_VERSION = 51, |
d77007cf03c1
8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents:
17370
diff
changeset
|
43 |
NO_RELAX_ACCESS_CTRL_CHECK_VERSION = 52 |
5882 | 44 |
}; |
1 | 45 |
typedef enum { ThrowException, NoException } Mode; |
46 |
||
47 |
/** |
|
48 |
* Verify the bytecodes for a class. If 'throw_exception' is true |
|
49 |
* then the appropriate VerifyError or ClassFormatError will be thrown. |
|
50 |
* Otherwise, no exception is thrown and the return indicates the |
|
51 |
* error. |
|
52 |
*/ |
|
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
1
diff
changeset
|
53 |
static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS); |
1 | 54 |
|
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
1
diff
changeset
|
55 |
// Return false if the class is loaded by the bootstrap loader, |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
1
diff
changeset
|
56 |
// or if defineClass was called requesting skipping verification |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
1
diff
changeset
|
57 |
// -Xverify:all/none override this value |
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
1
diff
changeset
|
58 |
static bool should_verify_for(oop class_loader, bool should_verify_class); |
1 | 59 |
|
60 |
// Relax certain verifier checks to enable some broken 1.1 apps to run on 1.2. |
|
61 |
static bool relax_verify_for(oop class_loader); |
|
62 |
||
30616
fde3a4fee412
8076318: split verifier needs to add TraceClassResolution
hseigel
parents:
30102
diff
changeset
|
63 |
// Print output for -XX:+TraceClassResolution |
fde3a4fee412
8076318: split verifier needs to add TraceClassResolution
hseigel
parents:
30102
diff
changeset
|
64 |
static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class); |
fde3a4fee412
8076318: split verifier needs to add TraceClassResolution
hseigel
parents:
30102
diff
changeset
|
65 |
|
1 | 66 |
private: |
3820
0a8fbbe180db
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
1
diff
changeset
|
67 |
static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
68 |
static Symbol* inference_verify( |
1 | 69 |
instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS); |
70 |
}; |
|
71 |
||
72 |
class RawBytecodeStream; |
|
73 |
class StackMapFrame; |
|
74 |
class StackMapTable; |
|
75 |
||
76 |
// Summary of verifier's memory usage: |
|
77 |
// StackMapTable is stack allocated. |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
78 |
// StackMapFrame are resource allocated. There is only one ResourceMark |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
79 |
// for each class verification, which is created at the top level. |
1 | 80 |
// There is one mutable StackMapFrame (current_frame) which is updated |
81 |
// by abstract bytecode interpretation. frame_in_exception_handler() returns |
|
82 |
// a frame that has a mutable one-item stack (ready for pushing the |
|
83 |
// catch type exception object). All the other StackMapFrame's |
|
84 |
// are immutable (including their locals and stack arrays) after |
|
85 |
// their constructions. |
|
86 |
// locals/stack arrays in StackMapFrame are resource allocated. |
|
87 |
// locals/stack arrays can be shared between StackMapFrame's, except |
|
88 |
// the mutable StackMapFrame (current_frame). |
|
89 |
||
90 |
// These macros are used similarly to CHECK macros but also check |
|
91 |
// the status of the verifier and return if that has an error. |
|
92 |
#define CHECK_VERIFY(verifier) \ |
|
18073
f02460441ddc
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents:
17863
diff
changeset
|
93 |
CHECK); if ((verifier)->has_error()) return; ((void)0 |
1 | 94 |
#define CHECK_VERIFY_(verifier, result) \ |
18073
f02460441ddc
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents:
17863
diff
changeset
|
95 |
CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0 |
1 | 96 |
|
13476 | 97 |
class TypeOrigin VALUE_OBJ_CLASS_SPEC { |
98 |
private: |
|
99 |
typedef enum { |
|
100 |
CF_LOCALS, // Comes from the current frame locals |
|
101 |
CF_STACK, // Comes from the current frame expression stack |
|
102 |
SM_LOCALS, // Comes from stackmap locals |
|
103 |
SM_STACK, // Comes from stackmap expression stack |
|
104 |
CONST_POOL, // Comes from the constant pool |
|
105 |
SIG, // Comes from method signature |
|
106 |
IMPLICIT, // Comes implicitly from code or context |
|
107 |
BAD_INDEX, // No type, but the index is bad |
|
108 |
FRAME_ONLY, // No type, context just contains the frame |
|
109 |
NONE |
|
110 |
} Origin; |
|
111 |
||
112 |
Origin _origin; |
|
113 |
u2 _index; // local, stack, or constant pool index |
|
114 |
StackMapFrame* _frame; // source frame if CF or SM |
|
115 |
VerificationType _type; // The actual type |
|
116 |
||
117 |
TypeOrigin( |
|
118 |
Origin origin, u2 index, StackMapFrame* frame, VerificationType type) |
|
119 |
: _origin(origin), _index(index), _frame(frame), _type(type) {} |
|
120 |
||
121 |
public: |
|
122 |
TypeOrigin() : _origin(NONE), _index(0), _frame(NULL) {} |
|
123 |
||
124 |
static TypeOrigin null(); |
|
125 |
static TypeOrigin local(u2 index, StackMapFrame* frame); |
|
126 |
static TypeOrigin stack(u2 index, StackMapFrame* frame); |
|
127 |
static TypeOrigin sm_local(u2 index, StackMapFrame* frame); |
|
128 |
static TypeOrigin sm_stack(u2 index, StackMapFrame* frame); |
|
129 |
static TypeOrigin cp(u2 index, VerificationType vt); |
|
130 |
static TypeOrigin signature(VerificationType vt); |
|
131 |
static TypeOrigin bad_index(u2 index); |
|
132 |
static TypeOrigin implicit(VerificationType t); |
|
133 |
static TypeOrigin frame(StackMapFrame* frame); |
|
134 |
||
135 |
void reset_frame(); |
|
136 |
void details(outputStream* ss) const; |
|
137 |
void print_frame(outputStream* ss) const; |
|
138 |
const StackMapFrame* frame() const { return _frame; } |
|
139 |
bool is_valid() const { return _origin != NONE; } |
|
140 |
u2 index() const { return _index; } |
|
141 |
||
142 |
#ifdef ASSERT |
|
143 |
void print_on(outputStream* str) const; |
|
144 |
#endif |
|
145 |
}; |
|
146 |
||
147 |
class ErrorContext VALUE_OBJ_CLASS_SPEC { |
|
148 |
private: |
|
149 |
typedef enum { |
|
150 |
INVALID_BYTECODE, // There was a problem with the bytecode |
|
151 |
WRONG_TYPE, // Type value was not as expected |
|
152 |
FLAGS_MISMATCH, // Frame flags are not assignable |
|
153 |
BAD_CP_INDEX, // Invalid constant pool index |
|
154 |
BAD_LOCAL_INDEX, // Invalid local index |
|
155 |
LOCALS_SIZE_MISMATCH, // Frames have differing local counts |
|
156 |
STACK_SIZE_MISMATCH, // Frames have different stack sizes |
|
157 |
STACK_OVERFLOW, // Attempt to push onto a full expression stack |
|
158 |
STACK_UNDERFLOW, // Attempt to pop and empty expression stack |
|
159 |
MISSING_STACKMAP, // No stackmap for this location and there should be |
|
160 |
BAD_STACKMAP, // Format error in stackmap |
|
161 |
NO_FAULT, // No error |
|
162 |
UNKNOWN |
|
163 |
} FaultType; |
|
164 |
||
165 |
int _bci; |
|
166 |
FaultType _fault; |
|
167 |
TypeOrigin _type; |
|
168 |
TypeOrigin _expected; |
|
169 |
||
170 |
ErrorContext(int bci, FaultType fault) : |
|
171 |
_bci(bci), _fault(fault) {} |
|
172 |
ErrorContext(int bci, FaultType fault, TypeOrigin type) : |
|
173 |
_bci(bci), _fault(fault), _type(type) {} |
|
174 |
ErrorContext(int bci, FaultType fault, TypeOrigin type, TypeOrigin exp) : |
|
175 |
_bci(bci), _fault(fault), _type(type), _expected(exp) {} |
|
176 |
||
177 |
public: |
|
178 |
ErrorContext() : _bci(-1), _fault(NO_FAULT) {} |
|
179 |
||
180 |
static ErrorContext bad_code(u2 bci) { |
|
181 |
return ErrorContext(bci, INVALID_BYTECODE); |
|
182 |
} |
|
183 |
static ErrorContext bad_type(u2 bci, TypeOrigin type) { |
|
184 |
return ErrorContext(bci, WRONG_TYPE, type); |
|
185 |
} |
|
186 |
static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) { |
|
187 |
return ErrorContext(bci, WRONG_TYPE, type, exp); |
|
188 |
} |
|
189 |
static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) { |
|
190 |
return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame)); |
|
191 |
} |
|
192 |
static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) { |
|
193 |
return ErrorContext(bci, FLAGS_MISMATCH, |
|
194 |
TypeOrigin::frame(cur), TypeOrigin::frame(sm)); |
|
195 |
} |
|
196 |
static ErrorContext bad_cp_index(u2 bci, u2 index) { |
|
197 |
return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index)); |
|
198 |
} |
|
199 |
static ErrorContext bad_local_index(u2 bci, u2 index) { |
|
200 |
return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index)); |
|
201 |
} |
|
202 |
static ErrorContext locals_size_mismatch( |
|
203 |
u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) { |
|
204 |
return ErrorContext(bci, LOCALS_SIZE_MISMATCH, |
|
205 |
TypeOrigin::frame(frame0), TypeOrigin::frame(frame1)); |
|
206 |
} |
|
207 |
static ErrorContext stack_size_mismatch( |
|
208 |
u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) { |
|
209 |
return ErrorContext(bci, STACK_SIZE_MISMATCH, |
|
210 |
TypeOrigin::frame(frame0), TypeOrigin::frame(frame1)); |
|
211 |
} |
|
212 |
static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) { |
|
213 |
return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame)); |
|
214 |
} |
|
215 |
static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) { |
|
216 |
return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame)); |
|
217 |
} |
|
218 |
static ErrorContext missing_stackmap(u2 bci) { |
|
219 |
return ErrorContext(bci, MISSING_STACKMAP); |
|
220 |
} |
|
221 |
static ErrorContext bad_stackmap(int index, StackMapFrame* frame) { |
|
222 |
return ErrorContext(0, BAD_STACKMAP, TypeOrigin::frame(frame)); |
|
223 |
} |
|
224 |
||
225 |
bool is_valid() const { return _fault != NO_FAULT; } |
|
226 |
int bci() const { return _bci; } |
|
227 |
||
228 |
void reset_frames() { |
|
229 |
_type.reset_frame(); |
|
230 |
_expected.reset_frame(); |
|
231 |
} |
|
232 |
||
17370
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
13728
diff
changeset
|
233 |
void details(outputStream* ss, const Method* method) const; |
13476 | 234 |
|
235 |
#ifdef ASSERT |
|
236 |
void print_on(outputStream* str) const { |
|
237 |
str->print("error_context(%d, %d,", _bci, _fault); |
|
238 |
_type.print_on(str); |
|
239 |
str->print(","); |
|
240 |
_expected.print_on(str); |
|
241 |
str->print(")"); |
|
242 |
} |
|
243 |
#endif |
|
244 |
||
245 |
private: |
|
17370
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
13728
diff
changeset
|
246 |
void location_details(outputStream* ss, const Method* method) const; |
13476 | 247 |
void reason_details(outputStream* ss) const; |
248 |
void frame_details(outputStream* ss) const; |
|
17370
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
13728
diff
changeset
|
249 |
void bytecode_details(outputStream* ss, const Method* method) const; |
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
13728
diff
changeset
|
250 |
void handler_details(outputStream* ss, const Method* method) const; |
59a0620561fa
8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents:
13728
diff
changeset
|
251 |
void stackmap_details(outputStream* ss, const Method* method) const; |
13476 | 252 |
}; |
253 |
||
1 | 254 |
// A new instance of this class is created for each class being verified |
255 |
class ClassVerifier : public StackObj { |
|
256 |
private: |
|
257 |
Thread* _thread; |
|
13476 | 258 |
GrowableArray<Symbol*>* _symbols; // keep a list of symbols created |
259 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
260 |
Symbol* _exception_type; |
1 | 261 |
char* _message; |
13476 | 262 |
|
263 |
ErrorContext _error_context; // contains information about an error |
|
1 | 264 |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
265 |
void verify_method(const methodHandle& method, TRAPS); |
1 | 266 |
char* generate_code_data(methodHandle m, u4 code_length, TRAPS); |
13476 | 267 |
void verify_exception_handler_table(u4 code_length, char* code_data, |
268 |
int& min, int& max, TRAPS); |
|
1 | 269 |
void verify_local_variable_table(u4 code_length, char* code_data, TRAPS); |
270 |
||
271 |
VerificationType cp_ref_index_to_type( |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
272 |
int index, const constantPoolHandle& cp, TRAPS) { |
1 | 273 |
return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD); |
274 |
} |
|
275 |
||
276 |
bool is_protected_access( |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
277 |
instanceKlassHandle this_class, Klass* target_class, |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
278 |
Symbol* field_name, Symbol* field_sig, bool is_method); |
1 | 279 |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
280 |
void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS); |
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
281 |
void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp, |
13476 | 282 |
unsigned int types, TRAPS); |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
283 |
void verify_cp_class_type(u2 bci, int index, const constantPoolHandle& cp, TRAPS); |
1 | 284 |
|
285 |
u2 verify_stackmap_table( |
|
286 |
u2 stackmap_index, u2 bci, StackMapFrame* current_frame, |
|
287 |
StackMapTable* stackmap_table, bool no_control_flow, TRAPS); |
|
288 |
||
289 |
void verify_exception_handler_targets( |
|
290 |
u2 bci, bool this_uninit, StackMapFrame* current_frame, |
|
291 |
StackMapTable* stackmap_table, TRAPS); |
|
292 |
||
293 |
void verify_ldc( |
|
294 |
int opcode, u2 index, StackMapFrame *current_frame, |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
295 |
const constantPoolHandle& cp, u2 bci, TRAPS); |
1 | 296 |
|
297 |
void verify_switch( |
|
298 |
RawBytecodeStream* bcs, u4 code_length, char* code_data, |
|
299 |
StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS); |
|
300 |
||
301 |
void verify_field_instructions( |
|
302 |
RawBytecodeStream* bcs, StackMapFrame* current_frame, |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
303 |
const constantPoolHandle& cp, bool allow_arrays, TRAPS); |
1 | 304 |
|
305 |
void verify_invoke_init( |
|
13476 | 306 |
RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type, |
28512
968fe01e1f82
8058982: Better verification of an exceptional invokespecial
hseigel
parents:
26928
diff
changeset
|
307 |
StackMapFrame* current_frame, u4 code_length, bool in_try_block, |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
308 |
bool* this_uninit, const constantPoolHandle& cp, StackMapTable* stackmap_table, |
28512
968fe01e1f82
8058982: Better verification of an exceptional invokespecial
hseigel
parents:
26928
diff
changeset
|
309 |
TRAPS); |
1 | 310 |
|
30102
d932845db0fe
8075118: JVM stuck in infinite loop during verification
hseigel
parents:
28652
diff
changeset
|
311 |
// Used by ends_in_athrow() to push all handlers that contain bci onto the |
d932845db0fe
8075118: JVM stuck in infinite loop during verification
hseigel
parents:
28652
diff
changeset
|
312 |
// handler_stack, if the handler has not already been pushed on the stack. |
25955
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
313 |
void push_handlers(ExceptionTable* exhandlers, |
30102
d932845db0fe
8075118: JVM stuck in infinite loop during verification
hseigel
parents:
28652
diff
changeset
|
314 |
GrowableArray<u4>* handler_list, |
25955
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
315 |
GrowableArray<u4>* handler_stack, |
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
316 |
u4 bci); |
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
317 |
|
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
318 |
// Returns true if all paths starting with start_bc_offset end in athrow |
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
319 |
// bytecode or loop. |
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
320 |
bool ends_in_athrow(u4 start_bc_offset); |
8ccc2eddcf22
8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents:
25899
diff
changeset
|
321 |
|
1 | 322 |
void verify_invoke_instructions( |
323 |
RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, |
|
28512
968fe01e1f82
8058982: Better verification of an exceptional invokespecial
hseigel
parents:
26928
diff
changeset
|
324 |
bool in_try_block, bool* this_uninit, VerificationType return_type, |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
325 |
const constantPoolHandle& cp, StackMapTable* stackmap_table, TRAPS); |
1 | 326 |
|
327 |
VerificationType get_newarray_type(u2 index, u2 bci, TRAPS); |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
328 |
void verify_anewarray(u2 bci, u2 index, const constantPoolHandle& cp, |
13476 | 329 |
StackMapFrame* current_frame, TRAPS); |
1 | 330 |
void verify_return_value( |
13476 | 331 |
VerificationType return_type, VerificationType type, u2 offset, |
332 |
StackMapFrame* current_frame, TRAPS); |
|
1 | 333 |
|
334 |
void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS); |
|
335 |
void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS); |
|
336 |
void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS); |
|
337 |
void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS); |
|
338 |
void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS); |
|
339 |
void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS); |
|
340 |
void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS); |
|
341 |
void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS); |
|
342 |
void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS); |
|
343 |
void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS); |
|
344 |
void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS); |
|
345 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
346 |
bool name_in_supers(Symbol* ref_name, instanceKlassHandle current); |
1 | 347 |
|
7380
041cf7f1cce6
6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents:
5882
diff
changeset
|
348 |
VerificationType object_type() const; |
041cf7f1cce6
6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents:
5882
diff
changeset
|
349 |
|
1 | 350 |
instanceKlassHandle _klass; // the class being verified |
351 |
methodHandle _method; // current method being verified |
|
352 |
VerificationType _this_type; // the verification type of the current class |
|
353 |
||
5693 | 354 |
// Some recursive calls from the verifier to the name resolver |
355 |
// can cause the current class to be re-verified and rewritten. |
|
356 |
// If this happens, the original verification should not continue, |
|
357 |
// because constant pool indexes will have changed. |
|
358 |
// The rewriter is preceded by the verifier. If the verifier throws |
|
359 |
// an error, rewriting is prevented. Also, rewriting always precedes |
|
360 |
// bytecode execution or compilation. Thus, is_rewritten implies |
|
361 |
// that a class has been verified and prepared for execution. |
|
362 |
bool was_recursively_verified() { return _klass->is_rewritten(); } |
|
363 |
||
21768
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
18073
diff
changeset
|
364 |
bool is_same_or_direct_interface(instanceKlassHandle klass, |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
18073
diff
changeset
|
365 |
VerificationType klass_type, VerificationType ref_class_type); |
b7dba4cde1c6
8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents:
18073
diff
changeset
|
366 |
|
1 | 367 |
public: |
368 |
enum { |
|
369 |
BYTECODE_OFFSET = 1, |
|
370 |
NEW_OFFSET = 2 |
|
371 |
}; |
|
372 |
||
373 |
// constructor |
|
13476 | 374 |
ClassVerifier(instanceKlassHandle klass, TRAPS); |
1 | 375 |
|
376 |
// destructor |
|
377 |
~ClassVerifier(); |
|
378 |
||
379 |
Thread* thread() { return _thread; } |
|
380 |
methodHandle method() { return _method; } |
|
381 |
instanceKlassHandle current_class() const { return _klass; } |
|
382 |
VerificationType current_type() const { return _this_type; } |
|
383 |
||
384 |
// Verifies the class. If a verify or class file format error occurs, |
|
385 |
// the '_exception_name' symbols will set to the exception name and |
|
386 |
// the message_buffer will be filled in with the exception message. |
|
387 |
void verify_class(TRAPS); |
|
388 |
||
389 |
// Return status modes |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
390 |
Symbol* result() const { return _exception_type; } |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
391 |
bool has_error() const { return result() != NULL; } |
13476 | 392 |
char* exception_message() { |
393 |
stringStream ss; |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
21768
diff
changeset
|
394 |
ss.print("%s", _message); |
13476 | 395 |
_error_context.details(&ss, _method()); |
396 |
return ss.as_string(); |
|
397 |
} |
|
1 | 398 |
|
399 |
// Called when verify or class format errors are encountered. |
|
400 |
// May throw an exception based upon the mode. |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
21768
diff
changeset
|
401 |
void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4); |
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
21768
diff
changeset
|
402 |
void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3); |
1 | 403 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13476
diff
changeset
|
404 |
Klass* load_class(Symbol* name, TRAPS); |
1 | 405 |
|
406 |
int change_sig_to_verificationType( |
|
407 |
SignatureStream* sig_type, VerificationType* inference_type, TRAPS); |
|
408 |
||
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
30768
diff
changeset
|
409 |
VerificationType cp_index_to_type(int index, const constantPoolHandle& cp, TRAPS) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
410 |
return VerificationType::reference_type(cp->klass_name_at(index)); |
1 | 411 |
} |
412 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
413 |
// Keep a list of temporary symbols created during verification because |
26928
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
414 |
// their reference counts need to be decremented when the verifier object |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
415 |
// goes out of scope. Since these symbols escape the scope in which they're |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
416 |
// created, we can't use a TempNewSymbol. |
26928
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
417 |
Symbol* create_temporary_symbol(const Symbol* s, int begin, int end, TRAPS); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
418 |
Symbol* create_temporary_symbol(const char *s, int length, TRAPS); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
419 |
|
26928
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
420 |
Symbol* create_temporary_symbol(Symbol* s) { |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
421 |
// This version just updates the reference count and saves the symbol to be |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
422 |
// dereferenced later. |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
423 |
s->increment_refcount(); |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
424 |
_symbols->push(s); |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
425 |
return s; |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
426 |
} |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
427 |
|
13476 | 428 |
TypeOrigin ref_ctx(const char* str, TRAPS); |
25505 | 429 |
|
1 | 430 |
}; |
431 |
||
432 |
inline int ClassVerifier::change_sig_to_verificationType( |
|
433 |
SignatureStream* sig_type, VerificationType* inference_type, TRAPS) { |
|
434 |
BasicType bt = sig_type->type(); |
|
435 |
switch (bt) { |
|
436 |
case T_OBJECT: |
|
437 |
case T_ARRAY: |
|
438 |
{ |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
439 |
Symbol* name = sig_type->as_symbol(CHECK_0); |
26928
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
440 |
// Create another symbol to save as signature stream unreferences this symbol. |
744b310d4fdd
8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents:
25955
diff
changeset
|
441 |
Symbol* name_copy = create_temporary_symbol(name); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
442 |
assert(name_copy == name, "symbols don't match"); |
1 | 443 |
*inference_type = |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
444 |
VerificationType::reference_type(name_copy); |
1 | 445 |
return 1; |
446 |
} |
|
447 |
case T_LONG: |
|
448 |
*inference_type = VerificationType::long_type(); |
|
449 |
*++inference_type = VerificationType::long2_type(); |
|
450 |
return 2; |
|
451 |
case T_DOUBLE: |
|
452 |
*inference_type = VerificationType::double_type(); |
|
453 |
*++inference_type = VerificationType::double2_type(); |
|
454 |
return 2; |
|
455 |
case T_INT: |
|
456 |
case T_BOOLEAN: |
|
457 |
case T_BYTE: |
|
458 |
case T_CHAR: |
|
459 |
case T_SHORT: |
|
460 |
*inference_type = VerificationType::integer_type(); |
|
461 |
return 1; |
|
462 |
case T_FLOAT: |
|
463 |
*inference_type = VerificationType::float_type(); |
|
464 |
return 1; |
|
465 |
default: |
|
466 |
ShouldNotReachHere(); |
|
467 |
return 1; |
|
468 |
} |
|
469 |
} |
|
7397 | 470 |
|
471 |
#endif // SHARE_VM_CLASSFILE_VERIFIER_HPP |