Mercurial > hg > truffle
annotate src/share/vm/classfile/verifier.cpp @ 1578:ca3dceda776c
6930994: Code cache is full warning should be visible in product
Reviewed-by: kvn, twisti, ysr
author | never |
---|---|
date | Wed, 02 Jun 2010 20:15:33 -0700 |
parents | de91a2f25c7e |
children | e9ff18c4ace7 |
rev | line source |
---|---|
0 | 1 /* |
1565 | 2 * Copyright 1998-2010 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_verifier.cpp.incl" | |
27 | |
28 // Access to external entry for VerifyClassCodes - old byte code verifier | |
29 | |
30 extern "C" { | |
31 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); | |
32 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint); | |
33 } | |
34 | |
35 static void* volatile _verify_byte_codes_fn = NULL; | |
36 | |
37 static volatile jint _is_new_verify_byte_codes_fn = (jint) true; | |
38 | |
39 static void* verify_byte_codes_fn() { | |
40 if (_verify_byte_codes_fn == NULL) { | |
41 void *lib_handle = os::native_java_library(); | |
42 void *func = hpi::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); | |
43 OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); | |
44 if (func == NULL) { | |
45 OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false); | |
46 func = hpi::dll_lookup(lib_handle, "VerifyClassCodes"); | |
47 OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); | |
48 } | |
49 } | |
50 return (void*)_verify_byte_codes_fn; | |
51 } | |
52 | |
53 | |
54 // Methods in Verifier | |
55 | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
56 bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) { |
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
57 return (class_loader == NULL || !should_verify_class) ? |
0 | 58 BytecodeVerificationLocal : BytecodeVerificationRemote; |
59 } | |
60 | |
61 bool Verifier::relax_verify_for(oop loader) { | |
62 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); | |
63 bool need_verify = | |
64 // verifyAll | |
65 (BytecodeVerificationLocal && BytecodeVerificationRemote) || | |
66 // verifyRemote | |
67 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); | |
68 return !need_verify; | |
69 } | |
70 | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
71 bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { |
0 | 72 ResourceMark rm(THREAD); |
73 HandleMark hm; | |
74 | |
75 symbolHandle exception_name; | |
76 const size_t message_buffer_len = klass->name()->utf8_length() + 1024; | |
77 char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); | |
78 | |
79 const char* klassName = klass->external_name(); | |
80 | |
81 // If the class should be verified, first see if we can use the split | |
82 // verifier. If not, or if verification fails and FailOverToOldVerifier | |
83 // is set, then call the inference verifier. | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
84 if (is_eligible_for_verification(klass, should_verify_class)) { |
0 | 85 if (TraceClassInitialization) { |
86 tty->print_cr("Start class verification for: %s", klassName); | |
87 } | |
88 if (UseSplitVerifier && | |
89 klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { | |
90 ClassVerifier split_verifier( | |
91 klass, message_buffer, message_buffer_len, THREAD); | |
92 split_verifier.verify_class(THREAD); | |
93 exception_name = split_verifier.result(); | |
94 if (FailOverToOldVerifier && !HAS_PENDING_EXCEPTION && | |
95 (exception_name == vmSymbols::java_lang_VerifyError() || | |
96 exception_name == vmSymbols::java_lang_ClassFormatError())) { | |
97 if (TraceClassInitialization) { | |
98 tty->print_cr( | |
99 "Fail over class verification to old verifier for: %s", klassName); | |
100 } | |
101 exception_name = inference_verify( | |
102 klass, message_buffer, message_buffer_len, THREAD); | |
103 } | |
104 } else { | |
105 exception_name = inference_verify( | |
106 klass, message_buffer, message_buffer_len, THREAD); | |
107 } | |
108 | |
109 if (TraceClassInitialization) { | |
110 if (HAS_PENDING_EXCEPTION) { | |
111 tty->print("Verification for %s has", klassName); | |
112 tty->print_cr(" exception pending %s ", | |
113 instanceKlass::cast(PENDING_EXCEPTION->klass())->external_name()); | |
114 } else if (!exception_name.is_null()) { | |
115 tty->print_cr("Verification for %s failed", klassName); | |
116 } | |
117 tty->print_cr("End class verification for: %s", klassName); | |
118 } | |
119 } | |
120 | |
121 if (HAS_PENDING_EXCEPTION) { | |
122 return false; // use the existing exception | |
123 } else if (exception_name.is_null()) { | |
124 return true; // verifcation succeeded | |
125 } else { // VerifyError or ClassFormatError to be created and thrown | |
126 ResourceMark rm(THREAD); | |
127 instanceKlassHandle kls = | |
128 SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); | |
129 while (!kls.is_null()) { | |
130 if (kls == klass) { | |
131 // If the class being verified is the exception we're creating | |
132 // or one of it's superclasses, we're in trouble and are going | |
133 // to infinitely recurse when we try to initialize the exception. | |
134 // So bail out here by throwing the preallocated VM error. | |
135 THROW_OOP_(Universe::virtual_machine_error_instance(), false); | |
136 } | |
137 kls = kls->super(); | |
138 } | |
139 message_buffer[message_buffer_len - 1] = '\0'; // just to be sure | |
140 THROW_MSG_(exception_name, message_buffer, false); | |
141 } | |
142 } | |
143 | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
144 bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) { |
0 | 145 symbolOop name = klass->name(); |
1142 | 146 klassOop refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass(); |
0 | 147 |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
148 return (should_verify_for(klass->class_loader(), should_verify_class) && |
0 | 149 // return if the class is a bootstrapping class |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
844
diff
changeset
|
150 // or defineClass specified not to verify by default (flags override passed arg) |
0 | 151 // We need to skip the following four for bootstraping |
152 name != vmSymbols::java_lang_Object() && | |
153 name != vmSymbols::java_lang_Class() && | |
154 name != vmSymbols::java_lang_String() && | |
155 name != vmSymbols::java_lang_Throwable() && | |
156 | |
157 // Can not verify the bytecodes for shared classes because they have | |
158 // already been rewritten to contain constant pool cache indices, | |
159 // which the verifier can't understand. | |
160 // Shared classes shouldn't have stackmaps either. | |
161 !klass()->is_shared() && | |
162 | |
163 // As of the fix for 4486457 we disable verification for all of the | |
164 // dynamically-generated bytecodes associated with the 1.4 | |
165 // reflection implementation, not just those associated with | |
166 // sun/reflect/SerializationConstructorAccessor. | |
167 // NOTE: this is called too early in the bootstrapping process to be | |
168 // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection. | |
169 (refl_magic_klass == NULL || | |
170 !klass->is_subtype_of(refl_magic_klass) || | |
171 VerifyReflectionBytecodes) | |
172 ); | |
173 } | |
174 | |
175 symbolHandle Verifier::inference_verify( | |
176 instanceKlassHandle klass, char* message, size_t message_len, TRAPS) { | |
177 JavaThread* thread = (JavaThread*)THREAD; | |
178 JNIEnv *env = thread->jni_environment(); | |
179 | |
180 void* verify_func = verify_byte_codes_fn(); | |
181 | |
182 if (verify_func == NULL) { | |
183 jio_snprintf(message, message_len, "Could not link verifier"); | |
184 return vmSymbols::java_lang_VerifyError(); | |
185 } | |
186 | |
187 ResourceMark rm(THREAD); | |
188 if (ClassVerifier::_verify_verbose) { | |
189 tty->print_cr("Verifying class %s with old format", klass->external_name()); | |
190 } | |
191 | |
192 jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); | |
193 jint result; | |
194 | |
195 { | |
196 HandleMark hm(thread); | |
197 ThreadToNativeFromVM ttn(thread); | |
198 // ThreadToNativeFromVM takes care of changing thread_state, so safepoint | |
199 // code knows that we have left the VM | |
200 | |
201 if (_is_new_verify_byte_codes_fn) { | |
202 verify_byte_codes_fn_new_t func = | |
203 CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func); | |
204 result = (*func)(env, cls, message, (int)message_len, | |
205 klass->major_version()); | |
206 } else { | |
207 verify_byte_codes_fn_t func = | |
208 CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func); | |
209 result = (*func)(env, cls, message, (int)message_len); | |
210 } | |
211 } | |
212 | |
213 JNIHandles::destroy_local(cls); | |
214 | |
215 // These numbers are chosen so that VerifyClassCodes interface doesn't need | |
216 // to be changed (still return jboolean (unsigned char)), and result is | |
217 // 1 when verification is passed. | |
218 symbolHandle nh(NULL); | |
219 if (result == 0) { | |
220 return vmSymbols::java_lang_VerifyError(); | |
221 } else if (result == 1) { | |
222 return nh; // verified. | |
223 } else if (result == 2) { | |
224 THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, nh); | |
225 } else if (result == 3) { | |
226 return vmSymbols::java_lang_ClassFormatError(); | |
227 } else { | |
228 ShouldNotReachHere(); | |
229 return nh; | |
230 } | |
231 } | |
232 | |
233 // Methods in ClassVerifier | |
234 | |
235 bool ClassVerifier::_verify_verbose = false; | |
236 | |
237 ClassVerifier::ClassVerifier( | |
238 instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS) | |
239 : _thread(THREAD), _exception_type(symbolHandle()), _message(msg), | |
240 _message_buffer_len(msg_len), _klass(klass) { | |
241 _this_type = VerificationType::reference_type(klass->name()); | |
242 } | |
243 | |
244 ClassVerifier::~ClassVerifier() { | |
245 } | |
246 | |
247 void ClassVerifier::verify_class(TRAPS) { | |
248 if (_verify_verbose) { | |
249 tty->print_cr("Verifying class %s with new format", | |
250 _klass->external_name()); | |
251 } | |
252 | |
253 objArrayHandle methods(THREAD, _klass->methods()); | |
254 int num_methods = methods->length(); | |
255 | |
256 for (int index = 0; index < num_methods; index++) { | |
1570 | 257 // Check for recursive re-verification before each method. |
258 if (was_recursively_verified()) return; | |
259 | |
0 | 260 methodOop m = (methodOop)methods->obj_at(index); |
261 if (m->is_native() || m->is_abstract()) { | |
262 // If m is native or abstract, skip it. It is checked in class file | |
263 // parser that methods do not override a final method. | |
264 continue; | |
265 } | |
266 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); | |
267 } | |
1570 | 268 |
269 if (_verify_verbose || TraceClassInitialization) { | |
270 if (was_recursively_verified()) | |
271 tty->print_cr("Recursive verification detected for: %s", | |
272 _klass->external_name()); | |
273 } | |
0 | 274 } |
275 | |
276 void ClassVerifier::verify_method(methodHandle m, TRAPS) { | |
277 ResourceMark rm(THREAD); | |
278 _method = m; // initialize _method | |
279 if (_verify_verbose) { | |
280 tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); | |
281 } | |
282 | |
283 const char* bad_type_msg = "Bad type on operand stack in %s"; | |
284 | |
285 int32_t max_stack = m->max_stack(); | |
286 int32_t max_locals = m->max_locals(); | |
287 constantPoolHandle cp(THREAD, m->constants()); | |
288 | |
289 if (!SignatureVerifier::is_valid_method_signature(m->signature())) { | |
290 class_format_error("Invalid method signature"); | |
291 return; | |
292 } | |
293 | |
294 // Initial stack map frame: offset is 0, stack is initially empty. | |
295 StackMapFrame current_frame(max_locals, max_stack, this); | |
296 // Set initial locals | |
297 VerificationType return_type = current_frame.set_locals_from_arg( | |
298 m, current_type(), CHECK_VERIFY(this)); | |
299 | |
300 int32_t stackmap_index = 0; // index to the stackmap array | |
301 | |
302 u4 code_length = m->code_size(); | |
303 | |
304 // Scan the bytecode and map each instruction's start offset to a number. | |
305 char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this)); | |
306 | |
307 int ex_min = code_length; | |
308 int ex_max = -1; | |
309 // Look through each item on the exception table. Each of the fields must refer | |
310 // to a legal instruction. | |
311 verify_exception_handler_table( | |
312 code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this)); | |
313 | |
314 // Look through each entry on the local variable table and make sure | |
315 // its range of code array offsets is valid. (4169817) | |
316 if (m->has_localvariable_table()) { | |
317 verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this)); | |
318 } | |
319 | |
320 typeArrayHandle stackmap_data(THREAD, m->stackmap_data()); | |
321 StackMapStream stream(stackmap_data); | |
322 StackMapReader reader(this, &stream, code_data, code_length, THREAD); | |
323 StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, | |
324 code_data, code_length, CHECK_VERIFY(this)); | |
325 | |
326 if (_verify_verbose) { | |
327 stackmap_table.print(); | |
328 } | |
329 | |
330 RawBytecodeStream bcs(m); | |
331 | |
332 // Scan the byte code linearly from the start to the end | |
333 bool no_control_flow = false; // Set to true when there is no direct control | |
334 // flow from current instruction to the next | |
335 // instruction in sequence | |
336 Bytecodes::Code opcode; | |
337 while (!bcs.is_last_bytecode()) { | |
1570 | 338 // Check for recursive re-verification before each bytecode. |
339 if (was_recursively_verified()) return; | |
340 | |
0 | 341 opcode = bcs.raw_next(); |
342 u2 bci = bcs.bci(); | |
343 | |
344 // Set current frame's offset to bci | |
345 current_frame.set_offset(bci); | |
346 | |
347 // Make sure every offset in stackmap table point to the beginning to | |
348 // an instruction. Match current_frame to stackmap_table entry with | |
349 // the same offset if exists. | |
350 stackmap_index = verify_stackmap_table( | |
351 stackmap_index, bci, ¤t_frame, &stackmap_table, | |
352 no_control_flow, CHECK_VERIFY(this)); | |
353 | |
354 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' | |
355 | |
356 // Merge with the next instruction | |
357 { | |
358 u2 index; | |
359 int target; | |
360 VerificationType type, type2; | |
361 VerificationType atype; | |
362 | |
363 #ifndef PRODUCT | |
364 if (_verify_verbose) { | |
365 current_frame.print(); | |
366 tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); | |
367 } | |
368 #endif | |
369 | |
370 // Make sure wide instruction is in correct format | |
371 if (bcs.is_wide()) { | |
372 if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && | |
373 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && | |
374 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && | |
375 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && | |
376 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && | |
377 opcode != Bytecodes::_dstore) { | |
378 verify_error(bci, "Bad wide instruction"); | |
379 return; | |
380 } | |
381 } | |
382 | |
383 switch (opcode) { | |
384 case Bytecodes::_nop : | |
385 no_control_flow = false; break; | |
386 case Bytecodes::_aconst_null : | |
387 current_frame.push_stack( | |
388 VerificationType::null_type(), CHECK_VERIFY(this)); | |
389 no_control_flow = false; break; | |
390 case Bytecodes::_iconst_m1 : | |
391 case Bytecodes::_iconst_0 : | |
392 case Bytecodes::_iconst_1 : | |
393 case Bytecodes::_iconst_2 : | |
394 case Bytecodes::_iconst_3 : | |
395 case Bytecodes::_iconst_4 : | |
396 case Bytecodes::_iconst_5 : | |
397 current_frame.push_stack( | |
398 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
399 no_control_flow = false; break; | |
400 case Bytecodes::_lconst_0 : | |
401 case Bytecodes::_lconst_1 : | |
402 current_frame.push_stack_2( | |
403 VerificationType::long_type(), | |
404 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
405 no_control_flow = false; break; | |
406 case Bytecodes::_fconst_0 : | |
407 case Bytecodes::_fconst_1 : | |
408 case Bytecodes::_fconst_2 : | |
409 current_frame.push_stack( | |
410 VerificationType::float_type(), CHECK_VERIFY(this)); | |
411 no_control_flow = false; break; | |
412 case Bytecodes::_dconst_0 : | |
413 case Bytecodes::_dconst_1 : | |
414 current_frame.push_stack_2( | |
415 VerificationType::double_type(), | |
416 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
417 no_control_flow = false; break; | |
418 case Bytecodes::_sipush : | |
419 case Bytecodes::_bipush : | |
420 current_frame.push_stack( | |
421 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
422 no_control_flow = false; break; | |
423 case Bytecodes::_ldc : | |
424 verify_ldc( | |
1565 | 425 opcode, bcs.get_index_u1(), ¤t_frame, |
0 | 426 cp, bci, CHECK_VERIFY(this)); |
427 no_control_flow = false; break; | |
428 case Bytecodes::_ldc_w : | |
429 case Bytecodes::_ldc2_w : | |
430 verify_ldc( | |
1565 | 431 opcode, bcs.get_index_u2(), ¤t_frame, |
0 | 432 cp, bci, CHECK_VERIFY(this)); |
433 no_control_flow = false; break; | |
434 case Bytecodes::_iload : | |
435 verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
436 no_control_flow = false; break; | |
437 case Bytecodes::_iload_0 : | |
438 case Bytecodes::_iload_1 : | |
439 case Bytecodes::_iload_2 : | |
440 case Bytecodes::_iload_3 : | |
441 index = opcode - Bytecodes::_iload_0; | |
442 verify_iload(index, ¤t_frame, CHECK_VERIFY(this)); | |
443 no_control_flow = false; break; | |
444 case Bytecodes::_lload : | |
445 verify_lload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
446 no_control_flow = false; break; | |
447 case Bytecodes::_lload_0 : | |
448 case Bytecodes::_lload_1 : | |
449 case Bytecodes::_lload_2 : | |
450 case Bytecodes::_lload_3 : | |
451 index = opcode - Bytecodes::_lload_0; | |
452 verify_lload(index, ¤t_frame, CHECK_VERIFY(this)); | |
453 no_control_flow = false; break; | |
454 case Bytecodes::_fload : | |
455 verify_fload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
456 no_control_flow = false; break; | |
457 case Bytecodes::_fload_0 : | |
458 case Bytecodes::_fload_1 : | |
459 case Bytecodes::_fload_2 : | |
460 case Bytecodes::_fload_3 : | |
461 index = opcode - Bytecodes::_fload_0; | |
462 verify_fload(index, ¤t_frame, CHECK_VERIFY(this)); | |
463 no_control_flow = false; break; | |
464 case Bytecodes::_dload : | |
465 verify_dload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
466 no_control_flow = false; break; | |
467 case Bytecodes::_dload_0 : | |
468 case Bytecodes::_dload_1 : | |
469 case Bytecodes::_dload_2 : | |
470 case Bytecodes::_dload_3 : | |
471 index = opcode - Bytecodes::_dload_0; | |
472 verify_dload(index, ¤t_frame, CHECK_VERIFY(this)); | |
473 no_control_flow = false; break; | |
474 case Bytecodes::_aload : | |
475 verify_aload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
476 no_control_flow = false; break; | |
477 case Bytecodes::_aload_0 : | |
478 case Bytecodes::_aload_1 : | |
479 case Bytecodes::_aload_2 : | |
480 case Bytecodes::_aload_3 : | |
481 index = opcode - Bytecodes::_aload_0; | |
482 verify_aload(index, ¤t_frame, CHECK_VERIFY(this)); | |
483 no_control_flow = false; break; | |
484 case Bytecodes::_iaload : | |
485 type = current_frame.pop_stack( | |
486 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
487 atype = current_frame.pop_stack( | |
488 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
489 if (!atype.is_int_array()) { | |
490 verify_error(bci, bad_type_msg, "iaload"); | |
491 return; | |
492 } | |
493 current_frame.push_stack( | |
494 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
495 no_control_flow = false; break; | |
496 case Bytecodes::_baload : | |
497 type = current_frame.pop_stack( | |
498 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
499 atype = current_frame.pop_stack( | |
500 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
501 if (!atype.is_bool_array() && !atype.is_byte_array()) { | |
502 verify_error(bci, bad_type_msg, "baload"); | |
503 return; | |
504 } | |
505 current_frame.push_stack( | |
506 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
507 no_control_flow = false; break; | |
508 case Bytecodes::_caload : | |
509 type = current_frame.pop_stack( | |
510 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
511 atype = current_frame.pop_stack( | |
512 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
513 if (!atype.is_char_array()) { | |
514 verify_error(bci, bad_type_msg, "caload"); | |
515 return; | |
516 } | |
517 current_frame.push_stack( | |
518 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
519 no_control_flow = false; break; | |
520 case Bytecodes::_saload : | |
521 type = current_frame.pop_stack( | |
522 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
523 atype = current_frame.pop_stack( | |
524 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
525 if (!atype.is_short_array()) { | |
526 verify_error(bci, bad_type_msg, "saload"); | |
527 return; | |
528 } | |
529 current_frame.push_stack( | |
530 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
531 no_control_flow = false; break; | |
532 case Bytecodes::_laload : | |
533 type = current_frame.pop_stack( | |
534 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
535 atype = current_frame.pop_stack( | |
536 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
537 if (!atype.is_long_array()) { | |
538 verify_error(bci, bad_type_msg, "laload"); | |
539 return; | |
540 } | |
541 current_frame.push_stack_2( | |
542 VerificationType::long_type(), | |
543 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
544 no_control_flow = false; break; | |
545 case Bytecodes::_faload : | |
546 type = current_frame.pop_stack( | |
547 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
548 atype = current_frame.pop_stack( | |
549 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
550 if (!atype.is_float_array()) { | |
551 verify_error(bci, bad_type_msg, "faload"); | |
552 return; | |
553 } | |
554 current_frame.push_stack( | |
555 VerificationType::float_type(), CHECK_VERIFY(this)); | |
556 no_control_flow = false; break; | |
557 case Bytecodes::_daload : | |
558 type = current_frame.pop_stack( | |
559 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
560 atype = current_frame.pop_stack( | |
561 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
562 if (!atype.is_double_array()) { | |
563 verify_error(bci, bad_type_msg, "daload"); | |
564 return; | |
565 } | |
566 current_frame.push_stack_2( | |
567 VerificationType::double_type(), | |
568 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
569 no_control_flow = false; break; | |
570 case Bytecodes::_aaload : { | |
571 type = current_frame.pop_stack( | |
572 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
573 atype = current_frame.pop_stack( | |
574 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
575 if (!atype.is_reference_array()) { | |
576 verify_error(bci, bad_type_msg, "aaload"); | |
577 return; | |
578 } | |
579 if (atype.is_null()) { | |
580 current_frame.push_stack( | |
581 VerificationType::null_type(), CHECK_VERIFY(this)); | |
582 } else { | |
583 VerificationType component = | |
584 atype.get_component(CHECK_VERIFY(this)); | |
585 current_frame.push_stack(component, CHECK_VERIFY(this)); | |
586 } | |
587 no_control_flow = false; break; | |
588 } | |
589 case Bytecodes::_istore : | |
590 verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
591 no_control_flow = false; break; | |
592 case Bytecodes::_istore_0 : | |
593 case Bytecodes::_istore_1 : | |
594 case Bytecodes::_istore_2 : | |
595 case Bytecodes::_istore_3 : | |
596 index = opcode - Bytecodes::_istore_0; | |
597 verify_istore(index, ¤t_frame, CHECK_VERIFY(this)); | |
598 no_control_flow = false; break; | |
599 case Bytecodes::_lstore : | |
600 verify_lstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
601 no_control_flow = false; break; | |
602 case Bytecodes::_lstore_0 : | |
603 case Bytecodes::_lstore_1 : | |
604 case Bytecodes::_lstore_2 : | |
605 case Bytecodes::_lstore_3 : | |
606 index = opcode - Bytecodes::_lstore_0; | |
607 verify_lstore(index, ¤t_frame, CHECK_VERIFY(this)); | |
608 no_control_flow = false; break; | |
609 case Bytecodes::_fstore : | |
610 verify_fstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
611 no_control_flow = false; break; | |
612 case Bytecodes::_fstore_0 : | |
613 case Bytecodes::_fstore_1 : | |
614 case Bytecodes::_fstore_2 : | |
615 case Bytecodes::_fstore_3 : | |
616 index = opcode - Bytecodes::_fstore_0; | |
617 verify_fstore(index, ¤t_frame, CHECK_VERIFY(this)); | |
618 no_control_flow = false; break; | |
619 case Bytecodes::_dstore : | |
620 verify_dstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
621 no_control_flow = false; break; | |
622 case Bytecodes::_dstore_0 : | |
623 case Bytecodes::_dstore_1 : | |
624 case Bytecodes::_dstore_2 : | |
625 case Bytecodes::_dstore_3 : | |
626 index = opcode - Bytecodes::_dstore_0; | |
627 verify_dstore(index, ¤t_frame, CHECK_VERIFY(this)); | |
628 no_control_flow = false; break; | |
629 case Bytecodes::_astore : | |
630 verify_astore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
631 no_control_flow = false; break; | |
632 case Bytecodes::_astore_0 : | |
633 case Bytecodes::_astore_1 : | |
634 case Bytecodes::_astore_2 : | |
635 case Bytecodes::_astore_3 : | |
636 index = opcode - Bytecodes::_astore_0; | |
637 verify_astore(index, ¤t_frame, CHECK_VERIFY(this)); | |
638 no_control_flow = false; break; | |
639 case Bytecodes::_iastore : | |
640 type = current_frame.pop_stack( | |
641 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
642 type2 = current_frame.pop_stack( | |
643 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
644 atype = current_frame.pop_stack( | |
645 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
646 if (!atype.is_int_array()) { | |
647 verify_error(bci, bad_type_msg, "iastore"); | |
648 return; | |
649 } | |
650 no_control_flow = false; break; | |
651 case Bytecodes::_bastore : | |
652 type = current_frame.pop_stack( | |
653 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
654 type2 = current_frame.pop_stack( | |
655 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
656 atype = current_frame.pop_stack( | |
657 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
658 if (!atype.is_bool_array() && !atype.is_byte_array()) { | |
659 verify_error(bci, bad_type_msg, "bastore"); | |
660 return; | |
661 } | |
662 no_control_flow = false; break; | |
663 case Bytecodes::_castore : | |
664 current_frame.pop_stack( | |
665 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
666 current_frame.pop_stack( | |
667 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
668 atype = current_frame.pop_stack( | |
669 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
670 if (!atype.is_char_array()) { | |
671 verify_error(bci, bad_type_msg, "castore"); | |
672 return; | |
673 } | |
674 no_control_flow = false; break; | |
675 case Bytecodes::_sastore : | |
676 current_frame.pop_stack( | |
677 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
678 current_frame.pop_stack( | |
679 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
680 atype = current_frame.pop_stack( | |
681 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
682 if (!atype.is_short_array()) { | |
683 verify_error(bci, bad_type_msg, "sastore"); | |
684 return; | |
685 } | |
686 no_control_flow = false; break; | |
687 case Bytecodes::_lastore : | |
688 current_frame.pop_stack_2( | |
689 VerificationType::long2_type(), | |
690 VerificationType::long_type(), CHECK_VERIFY(this)); | |
691 current_frame.pop_stack( | |
692 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
693 atype = current_frame.pop_stack( | |
694 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
695 if (!atype.is_long_array()) { | |
696 verify_error(bci, bad_type_msg, "lastore"); | |
697 return; | |
698 } | |
699 no_control_flow = false; break; | |
700 case Bytecodes::_fastore : | |
701 current_frame.pop_stack( | |
702 VerificationType::float_type(), CHECK_VERIFY(this)); | |
703 current_frame.pop_stack | |
704 (VerificationType::integer_type(), CHECK_VERIFY(this)); | |
705 atype = current_frame.pop_stack( | |
706 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
707 if (!atype.is_float_array()) { | |
708 verify_error(bci, bad_type_msg, "fastore"); | |
709 return; | |
710 } | |
711 no_control_flow = false; break; | |
712 case Bytecodes::_dastore : | |
713 current_frame.pop_stack_2( | |
714 VerificationType::double2_type(), | |
715 VerificationType::double_type(), CHECK_VERIFY(this)); | |
716 current_frame.pop_stack( | |
717 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
718 atype = current_frame.pop_stack( | |
719 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
720 if (!atype.is_double_array()) { | |
721 verify_error(bci, bad_type_msg, "dastore"); | |
722 return; | |
723 } | |
724 no_control_flow = false; break; | |
725 case Bytecodes::_aastore : | |
726 type = current_frame.pop_stack( | |
727 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
728 type2 = current_frame.pop_stack( | |
729 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
730 atype = current_frame.pop_stack( | |
731 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
732 // more type-checking is done at runtime | |
733 if (!atype.is_reference_array()) { | |
734 verify_error(bci, bad_type_msg, "aastore"); | |
735 return; | |
736 } | |
737 // 4938384: relaxed constraint in JVMS 3nd edition. | |
738 no_control_flow = false; break; | |
739 case Bytecodes::_pop : | |
740 current_frame.pop_stack( | |
741 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
742 no_control_flow = false; break; | |
743 case Bytecodes::_pop2 : | |
744 type = current_frame.pop_stack(CHECK_VERIFY(this)); | |
745 if (type.is_category1()) { | |
746 current_frame.pop_stack( | |
747 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
748 } else if (type.is_category2_2nd()) { | |
749 current_frame.pop_stack( | |
750 VerificationType::category2_check(), CHECK_VERIFY(this)); | |
751 } else { | |
752 verify_error(bci, bad_type_msg, "pop2"); | |
753 return; | |
754 } | |
755 no_control_flow = false; break; | |
756 case Bytecodes::_dup : | |
757 type = current_frame.pop_stack( | |
758 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
759 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
760 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
761 no_control_flow = false; break; | |
762 case Bytecodes::_dup_x1 : | |
763 type = current_frame.pop_stack( | |
764 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
765 type2 = current_frame.pop_stack( | |
766 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
767 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
768 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
769 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
770 no_control_flow = false; break; | |
771 case Bytecodes::_dup_x2 : | |
772 { | |
773 VerificationType type3; | |
774 type = current_frame.pop_stack( | |
775 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
776 type2 = current_frame.pop_stack(CHECK_VERIFY(this)); | |
777 if (type2.is_category1()) { | |
778 type3 = current_frame.pop_stack( | |
779 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
780 } else if (type2.is_category2_2nd()) { | |
781 type3 = current_frame.pop_stack( | |
782 VerificationType::category2_check(), CHECK_VERIFY(this)); | |
783 } else { | |
784 verify_error(bci, bad_type_msg, "dup_x2"); | |
785 return; | |
786 } | |
787 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
788 current_frame.push_stack(type3, CHECK_VERIFY(this)); | |
789 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
790 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
791 no_control_flow = false; break; | |
792 } | |
793 case Bytecodes::_dup2 : | |
794 type = current_frame.pop_stack(CHECK_VERIFY(this)); | |
795 if (type.is_category1()) { | |
796 type2 = current_frame.pop_stack( | |
797 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
798 } else if (type.is_category2_2nd()) { | |
799 type2 = current_frame.pop_stack( | |
800 VerificationType::category2_check(), CHECK_VERIFY(this)); | |
801 } else { | |
802 verify_error(bci, bad_type_msg, "dup2"); | |
803 return; | |
804 } | |
805 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
806 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
807 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
808 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
809 no_control_flow = false; break; | |
810 case Bytecodes::_dup2_x1 : | |
811 { | |
812 VerificationType type3; | |
813 type = current_frame.pop_stack(CHECK_VERIFY(this)); | |
814 if (type.is_category1()) { | |
815 type2 = current_frame.pop_stack( | |
816 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
817 } else if(type.is_category2_2nd()) { | |
818 type2 = current_frame.pop_stack | |
819 (VerificationType::category2_check(), CHECK_VERIFY(this)); | |
820 } else { | |
821 verify_error(bci, bad_type_msg, "dup2_x1"); | |
822 return; | |
823 } | |
824 type3 = current_frame.pop_stack( | |
825 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
826 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
827 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
828 current_frame.push_stack(type3, CHECK_VERIFY(this)); | |
829 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
830 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
831 no_control_flow = false; break; | |
832 } | |
833 case Bytecodes::_dup2_x2 : | |
834 { | |
835 VerificationType type3, type4; | |
836 type = current_frame.pop_stack(CHECK_VERIFY(this)); | |
837 if (type.is_category1()) { | |
838 type2 = current_frame.pop_stack( | |
839 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
840 } else if (type.is_category2_2nd()) { | |
841 type2 = current_frame.pop_stack( | |
842 VerificationType::category2_check(), CHECK_VERIFY(this)); | |
843 } else { | |
844 verify_error(bci, bad_type_msg, "dup2_x2"); | |
845 return; | |
846 } | |
847 type3 = current_frame.pop_stack(CHECK_VERIFY(this)); | |
848 if (type3.is_category1()) { | |
849 type4 = current_frame.pop_stack( | |
850 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
851 } else if (type3.is_category2_2nd()) { | |
852 type4 = current_frame.pop_stack( | |
853 VerificationType::category2_check(), CHECK_VERIFY(this)); | |
854 } else { | |
855 verify_error(bci, bad_type_msg, "dup2_x2"); | |
856 return; | |
857 } | |
858 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
859 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
860 current_frame.push_stack(type4, CHECK_VERIFY(this)); | |
861 current_frame.push_stack(type3, CHECK_VERIFY(this)); | |
862 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
863 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
864 no_control_flow = false; break; | |
865 } | |
866 case Bytecodes::_swap : | |
867 type = current_frame.pop_stack( | |
868 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
869 type2 = current_frame.pop_stack( | |
870 VerificationType::category1_check(), CHECK_VERIFY(this)); | |
871 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
872 current_frame.push_stack(type2, CHECK_VERIFY(this)); | |
873 no_control_flow = false; break; | |
874 case Bytecodes::_iadd : | |
875 case Bytecodes::_isub : | |
876 case Bytecodes::_imul : | |
877 case Bytecodes::_idiv : | |
878 case Bytecodes::_irem : | |
879 case Bytecodes::_ishl : | |
880 case Bytecodes::_ishr : | |
881 case Bytecodes::_iushr : | |
882 case Bytecodes::_ior : | |
883 case Bytecodes::_ixor : | |
884 case Bytecodes::_iand : | |
885 current_frame.pop_stack( | |
886 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
887 // fall through | |
888 case Bytecodes::_ineg : | |
889 current_frame.pop_stack( | |
890 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
891 current_frame.push_stack( | |
892 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
893 no_control_flow = false; break; | |
894 case Bytecodes::_ladd : | |
895 case Bytecodes::_lsub : | |
896 case Bytecodes::_lmul : | |
897 case Bytecodes::_ldiv : | |
898 case Bytecodes::_lrem : | |
899 case Bytecodes::_land : | |
900 case Bytecodes::_lor : | |
901 case Bytecodes::_lxor : | |
902 current_frame.pop_stack_2( | |
903 VerificationType::long2_type(), | |
904 VerificationType::long_type(), CHECK_VERIFY(this)); | |
905 // fall through | |
906 case Bytecodes::_lneg : | |
907 current_frame.pop_stack_2( | |
908 VerificationType::long2_type(), | |
909 VerificationType::long_type(), CHECK_VERIFY(this)); | |
910 current_frame.push_stack_2( | |
911 VerificationType::long_type(), | |
912 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
913 no_control_flow = false; break; | |
914 case Bytecodes::_lshl : | |
915 case Bytecodes::_lshr : | |
916 case Bytecodes::_lushr : | |
917 current_frame.pop_stack( | |
918 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
919 current_frame.pop_stack_2( | |
920 VerificationType::long2_type(), | |
921 VerificationType::long_type(), CHECK_VERIFY(this)); | |
922 current_frame.push_stack_2( | |
923 VerificationType::long_type(), | |
924 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
925 no_control_flow = false; break; | |
926 case Bytecodes::_fadd : | |
927 case Bytecodes::_fsub : | |
928 case Bytecodes::_fmul : | |
929 case Bytecodes::_fdiv : | |
930 case Bytecodes::_frem : | |
931 current_frame.pop_stack( | |
932 VerificationType::float_type(), CHECK_VERIFY(this)); | |
933 // fall through | |
934 case Bytecodes::_fneg : | |
935 current_frame.pop_stack( | |
936 VerificationType::float_type(), CHECK_VERIFY(this)); | |
937 current_frame.push_stack( | |
938 VerificationType::float_type(), CHECK_VERIFY(this)); | |
939 no_control_flow = false; break; | |
940 case Bytecodes::_dadd : | |
941 case Bytecodes::_dsub : | |
942 case Bytecodes::_dmul : | |
943 case Bytecodes::_ddiv : | |
944 case Bytecodes::_drem : | |
945 current_frame.pop_stack_2( | |
946 VerificationType::double2_type(), | |
947 VerificationType::double_type(), CHECK_VERIFY(this)); | |
948 // fall through | |
949 case Bytecodes::_dneg : | |
950 current_frame.pop_stack_2( | |
951 VerificationType::double2_type(), | |
952 VerificationType::double_type(), CHECK_VERIFY(this)); | |
953 current_frame.push_stack_2( | |
954 VerificationType::double_type(), | |
955 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
956 no_control_flow = false; break; | |
957 case Bytecodes::_iinc : | |
958 verify_iinc(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | |
959 no_control_flow = false; break; | |
960 case Bytecodes::_i2l : | |
961 type = current_frame.pop_stack( | |
962 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
963 current_frame.push_stack_2( | |
964 VerificationType::long_type(), | |
965 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
966 no_control_flow = false; break; | |
967 case Bytecodes::_l2i : | |
968 current_frame.pop_stack_2( | |
969 VerificationType::long2_type(), | |
970 VerificationType::long_type(), CHECK_VERIFY(this)); | |
971 current_frame.push_stack( | |
972 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
973 no_control_flow = false; break; | |
974 case Bytecodes::_i2f : | |
975 current_frame.pop_stack( | |
976 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
977 current_frame.push_stack( | |
978 VerificationType::float_type(), CHECK_VERIFY(this)); | |
979 no_control_flow = false; break; | |
980 case Bytecodes::_i2d : | |
981 current_frame.pop_stack( | |
982 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
983 current_frame.push_stack_2( | |
984 VerificationType::double_type(), | |
985 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
986 no_control_flow = false; break; | |
987 case Bytecodes::_l2f : | |
988 current_frame.pop_stack_2( | |
989 VerificationType::long2_type(), | |
990 VerificationType::long_type(), CHECK_VERIFY(this)); | |
991 current_frame.push_stack( | |
992 VerificationType::float_type(), CHECK_VERIFY(this)); | |
993 no_control_flow = false; break; | |
994 case Bytecodes::_l2d : | |
995 current_frame.pop_stack_2( | |
996 VerificationType::long2_type(), | |
997 VerificationType::long_type(), CHECK_VERIFY(this)); | |
998 current_frame.push_stack_2( | |
999 VerificationType::double_type(), | |
1000 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
1001 no_control_flow = false; break; | |
1002 case Bytecodes::_f2i : | |
1003 current_frame.pop_stack( | |
1004 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1005 current_frame.push_stack( | |
1006 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1007 no_control_flow = false; break; | |
1008 case Bytecodes::_f2l : | |
1009 current_frame.pop_stack( | |
1010 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1011 current_frame.push_stack_2( | |
1012 VerificationType::long_type(), | |
1013 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
1014 no_control_flow = false; break; | |
1015 case Bytecodes::_f2d : | |
1016 current_frame.pop_stack( | |
1017 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1018 current_frame.push_stack_2( | |
1019 VerificationType::double_type(), | |
1020 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
1021 no_control_flow = false; break; | |
1022 case Bytecodes::_d2i : | |
1023 current_frame.pop_stack_2( | |
1024 VerificationType::double2_type(), | |
1025 VerificationType::double_type(), CHECK_VERIFY(this)); | |
1026 current_frame.push_stack( | |
1027 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1028 no_control_flow = false; break; | |
1029 case Bytecodes::_d2l : | |
1030 current_frame.pop_stack_2( | |
1031 VerificationType::double2_type(), | |
1032 VerificationType::double_type(), CHECK_VERIFY(this)); | |
1033 current_frame.push_stack_2( | |
1034 VerificationType::long_type(), | |
1035 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
1036 no_control_flow = false; break; | |
1037 case Bytecodes::_d2f : | |
1038 current_frame.pop_stack_2( | |
1039 VerificationType::double2_type(), | |
1040 VerificationType::double_type(), CHECK_VERIFY(this)); | |
1041 current_frame.push_stack( | |
1042 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1043 no_control_flow = false; break; | |
1044 case Bytecodes::_i2b : | |
1045 case Bytecodes::_i2c : | |
1046 case Bytecodes::_i2s : | |
1047 current_frame.pop_stack( | |
1048 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1049 current_frame.push_stack( | |
1050 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1051 no_control_flow = false; break; | |
1052 case Bytecodes::_lcmp : | |
1053 current_frame.pop_stack_2( | |
1054 VerificationType::long2_type(), | |
1055 VerificationType::long_type(), CHECK_VERIFY(this)); | |
1056 current_frame.pop_stack_2( | |
1057 VerificationType::long2_type(), | |
1058 VerificationType::long_type(), CHECK_VERIFY(this)); | |
1059 current_frame.push_stack( | |
1060 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1061 no_control_flow = false; break; | |
1062 case Bytecodes::_fcmpl : | |
1063 case Bytecodes::_fcmpg : | |
1064 current_frame.pop_stack( | |
1065 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1066 current_frame.pop_stack( | |
1067 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1068 current_frame.push_stack( | |
1069 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1070 no_control_flow = false; break; | |
1071 case Bytecodes::_dcmpl : | |
1072 case Bytecodes::_dcmpg : | |
1073 current_frame.pop_stack_2( | |
1074 VerificationType::double2_type(), | |
1075 VerificationType::double_type(), CHECK_VERIFY(this)); | |
1076 current_frame.pop_stack_2( | |
1077 VerificationType::double2_type(), | |
1078 VerificationType::double_type(), CHECK_VERIFY(this)); | |
1079 current_frame.push_stack( | |
1080 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1081 no_control_flow = false; break; | |
1082 case Bytecodes::_if_icmpeq: | |
1083 case Bytecodes::_if_icmpne: | |
1084 case Bytecodes::_if_icmplt: | |
1085 case Bytecodes::_if_icmpge: | |
1086 case Bytecodes::_if_icmpgt: | |
1087 case Bytecodes::_if_icmple: | |
1088 current_frame.pop_stack( | |
1089 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1090 // fall through | |
1091 case Bytecodes::_ifeq: | |
1092 case Bytecodes::_ifne: | |
1093 case Bytecodes::_iflt: | |
1094 case Bytecodes::_ifge: | |
1095 case Bytecodes::_ifgt: | |
1096 case Bytecodes::_ifle: | |
1097 current_frame.pop_stack( | |
1098 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1099 target = bcs.dest(); | |
1100 stackmap_table.check_jump_target( | |
1101 ¤t_frame, target, CHECK_VERIFY(this)); | |
1102 no_control_flow = false; break; | |
1103 case Bytecodes::_if_acmpeq : | |
1104 case Bytecodes::_if_acmpne : | |
1105 current_frame.pop_stack( | |
1106 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1107 // fall through | |
1108 case Bytecodes::_ifnull : | |
1109 case Bytecodes::_ifnonnull : | |
1110 current_frame.pop_stack( | |
1111 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1112 target = bcs.dest(); | |
1113 stackmap_table.check_jump_target | |
1114 (¤t_frame, target, CHECK_VERIFY(this)); | |
1115 no_control_flow = false; break; | |
1116 case Bytecodes::_goto : | |
1117 target = bcs.dest(); | |
1118 stackmap_table.check_jump_target( | |
1119 ¤t_frame, target, CHECK_VERIFY(this)); | |
1120 no_control_flow = true; break; | |
1121 case Bytecodes::_goto_w : | |
1122 target = bcs.dest_w(); | |
1123 stackmap_table.check_jump_target( | |
1124 ¤t_frame, target, CHECK_VERIFY(this)); | |
1125 no_control_flow = true; break; | |
1126 case Bytecodes::_tableswitch : | |
1127 case Bytecodes::_lookupswitch : | |
1128 verify_switch( | |
1129 &bcs, code_length, code_data, ¤t_frame, | |
1130 &stackmap_table, CHECK_VERIFY(this)); | |
1131 no_control_flow = true; break; | |
1132 case Bytecodes::_ireturn : | |
1133 type = current_frame.pop_stack( | |
1134 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1135 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | |
1136 no_control_flow = true; break; | |
1137 case Bytecodes::_lreturn : | |
1138 type2 = current_frame.pop_stack( | |
1139 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
1140 type = current_frame.pop_stack( | |
1141 VerificationType::long_type(), CHECK_VERIFY(this)); | |
1142 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | |
1143 no_control_flow = true; break; | |
1144 case Bytecodes::_freturn : | |
1145 type = current_frame.pop_stack( | |
1146 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1147 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | |
1148 no_control_flow = true; break; | |
1149 case Bytecodes::_dreturn : | |
1150 type2 = current_frame.pop_stack( | |
1151 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
1152 type = current_frame.pop_stack( | |
1153 VerificationType::double_type(), CHECK_VERIFY(this)); | |
1154 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | |
1155 no_control_flow = true; break; | |
1156 case Bytecodes::_areturn : | |
1157 type = current_frame.pop_stack( | |
1158 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1159 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | |
1160 no_control_flow = true; break; | |
1161 case Bytecodes::_return : | |
1162 if (return_type != VerificationType::bogus_type()) { | |
1163 verify_error(bci, "Method expects no return value"); | |
1164 return; | |
1165 } | |
1166 // Make sure "this" has been initialized if current method is an | |
1167 // <init> | |
1168 if (_method->name() == vmSymbols::object_initializer_name() && | |
1169 current_frame.flag_this_uninit()) { | |
1170 verify_error(bci, | |
1171 "Constructor must call super() or this() before return"); | |
1172 return; | |
1173 } | |
1174 no_control_flow = true; break; | |
1175 case Bytecodes::_getstatic : | |
1176 case Bytecodes::_putstatic : | |
1177 case Bytecodes::_getfield : | |
1178 case Bytecodes::_putfield : | |
1179 verify_field_instructions( | |
1180 &bcs, ¤t_frame, cp, CHECK_VERIFY(this)); | |
1181 no_control_flow = false; break; | |
1182 case Bytecodes::_invokevirtual : | |
1183 case Bytecodes::_invokespecial : | |
1184 case Bytecodes::_invokestatic : | |
1185 verify_invoke_instructions( | |
1186 &bcs, code_length, ¤t_frame, | |
1187 &this_uninit, return_type, cp, CHECK_VERIFY(this)); | |
1188 no_control_flow = false; break; | |
1189 case Bytecodes::_invokeinterface : | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1190 case Bytecodes::_invokedynamic : |
0 | 1191 verify_invoke_instructions( |
1192 &bcs, code_length, ¤t_frame, | |
1193 &this_uninit, return_type, cp, CHECK_VERIFY(this)); | |
1194 no_control_flow = false; break; | |
1195 case Bytecodes::_new : | |
1196 { | |
1565 | 1197 index = bcs.get_index_u2(); |
0 | 1198 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1199 VerificationType new_class_type = | |
1200 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | |
1201 if (!new_class_type.is_object()) { | |
1202 verify_error(bci, "Illegal new instruction"); | |
1203 return; | |
1204 } | |
1205 type = VerificationType::uninitialized_type(bci); | |
1206 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
1207 no_control_flow = false; break; | |
1208 } | |
1209 case Bytecodes::_newarray : | |
1210 type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this)); | |
1211 current_frame.pop_stack( | |
1212 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1213 current_frame.push_stack(type, CHECK_VERIFY(this)); | |
1214 no_control_flow = false; break; | |
1215 case Bytecodes::_anewarray : | |
1216 verify_anewarray( | |
1565 | 1217 bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); |
0 | 1218 no_control_flow = false; break; |
1219 case Bytecodes::_arraylength : | |
1220 type = current_frame.pop_stack( | |
1221 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
134
8a79f7ec8f5d
6692246: Regression : JDK 6u4 b01 fails two JCK tests when fallback is switched off
kamg
parents:
0
diff
changeset
|
1222 if (!(type.is_null() || type.is_array())) { |
0 | 1223 verify_error(bci, bad_type_msg, "arraylength"); |
1224 } | |
1225 current_frame.push_stack( | |
1226 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1227 no_control_flow = false; break; | |
1228 case Bytecodes::_checkcast : | |
1229 { | |
1565 | 1230 index = bcs.get_index_u2(); |
0 | 1231 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1232 current_frame.pop_stack( | |
1233 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1234 VerificationType klass_type = cp_index_to_type( | |
1235 index, cp, CHECK_VERIFY(this)); | |
1236 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); | |
1237 no_control_flow = false; break; | |
1238 } | |
1239 case Bytecodes::_instanceof : { | |
1565 | 1240 index = bcs.get_index_u2(); |
0 | 1241 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1242 current_frame.pop_stack( | |
1243 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1244 current_frame.push_stack( | |
1245 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1246 no_control_flow = false; break; | |
1247 } | |
1248 case Bytecodes::_monitorenter : | |
1249 case Bytecodes::_monitorexit : | |
1250 current_frame.pop_stack( | |
1251 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1252 no_control_flow = false; break; | |
1253 case Bytecodes::_multianewarray : | |
1254 { | |
1565 | 1255 index = bcs.get_index_u2(); |
0 | 1256 u2 dim = *(bcs.bcp()+3); |
1257 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | |
1258 VerificationType new_array_type = | |
1259 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | |
1260 if (!new_array_type.is_array()) { | |
1261 verify_error(bci, | |
1262 "Illegal constant pool index in multianewarray instruction"); | |
1263 return; | |
1264 } | |
1265 if (dim < 1 || new_array_type.dimensions() < dim) { | |
1266 verify_error(bci, | |
1267 "Illegal dimension in multianewarray instruction"); | |
1268 return; | |
1269 } | |
1270 for (int i = 0; i < dim; i++) { | |
1271 current_frame.pop_stack( | |
1272 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1273 } | |
1274 current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); | |
1275 no_control_flow = false; break; | |
1276 } | |
1277 case Bytecodes::_athrow : | |
1278 type = VerificationType::reference_type( | |
1279 vmSymbols::java_lang_Throwable()); | |
1280 current_frame.pop_stack(type, CHECK_VERIFY(this)); | |
1281 no_control_flow = true; break; | |
1282 default: | |
1283 // We only need to check the valid bytecodes in class file. | |
1284 // And jsr and ret are not in the new class file format in JDK1.5. | |
1285 verify_error(bci, "Bad instruction"); | |
1286 no_control_flow = false; | |
1287 return; | |
1288 } // end switch | |
1289 } // end Merge with the next instruction | |
1290 | |
1291 // Look for possible jump target in exception handlers and see if it | |
1292 // matches current_frame | |
1293 if (bci >= ex_min && bci < ex_max) { | |
1294 verify_exception_handler_targets( | |
1295 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); | |
1296 } | |
1297 } // end while | |
1298 | |
1299 // Make sure that control flow does not fall through end of the method | |
1300 if (!no_control_flow) { | |
1301 verify_error(code_length, "Control flow falls through code end"); | |
1302 return; | |
1303 } | |
1304 } | |
1305 | |
1306 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { | |
1307 char* code_data = NEW_RESOURCE_ARRAY(char, code_length); | |
1308 memset(code_data, 0, sizeof(char) * code_length); | |
1309 RawBytecodeStream bcs(m); | |
1310 | |
1311 while (!bcs.is_last_bytecode()) { | |
1312 if (bcs.raw_next() != Bytecodes::_illegal) { | |
1313 int bci = bcs.bci(); | |
1565 | 1314 if (bcs.raw_code() == Bytecodes::_new) { |
0 | 1315 code_data[bci] = NEW_OFFSET; |
1316 } else { | |
1317 code_data[bci] = BYTECODE_OFFSET; | |
1318 } | |
1319 } else { | |
1320 verify_error(bcs.bci(), "Bad instruction"); | |
1321 return NULL; | |
1322 } | |
1323 } | |
1324 | |
1325 return code_data; | |
1326 } | |
1327 | |
1328 void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) { | |
1329 typeArrayHandle exhandlers (THREAD, _method->exception_table()); | |
1330 constantPoolHandle cp (THREAD, _method->constants()); | |
1331 | |
1332 if (exhandlers() != NULL) { | |
1333 for(int i = 0; i < exhandlers->length();) { | |
1334 u2 start_pc = exhandlers->int_at(i++); | |
1335 u2 end_pc = exhandlers->int_at(i++); | |
1336 u2 handler_pc = exhandlers->int_at(i++); | |
1337 if (start_pc >= code_length || code_data[start_pc] == 0) { | |
1338 class_format_error("Illegal exception table start_pc %d", start_pc); | |
1339 return; | |
1340 } | |
1341 if (end_pc != code_length) { // special case: end_pc == code_length | |
1342 if (end_pc > code_length || code_data[end_pc] == 0) { | |
1343 class_format_error("Illegal exception table end_pc %d", end_pc); | |
1344 return; | |
1345 } | |
1346 } | |
1347 if (handler_pc >= code_length || code_data[handler_pc] == 0) { | |
1348 class_format_error("Illegal exception table handler_pc %d", handler_pc); | |
1349 return; | |
1350 } | |
1351 int catch_type_index = exhandlers->int_at(i++); | |
1352 if (catch_type_index != 0) { | |
1353 VerificationType catch_type = cp_index_to_type( | |
1354 catch_type_index, cp, CHECK_VERIFY(this)); | |
1355 VerificationType throwable = | |
1356 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); | |
1357 bool is_subclass = throwable.is_assignable_from( | |
1358 catch_type, current_class(), CHECK_VERIFY(this)); | |
1359 if (!is_subclass) { | |
1360 // 4286534: should throw VerifyError according to recent spec change | |
1361 verify_error( | |
1362 "Catch type is not a subclass of Throwable in handler %d", | |
1363 handler_pc); | |
1364 return; | |
1365 } | |
1366 } | |
1367 if (start_pc < min) min = start_pc; | |
1368 if (end_pc > max) max = end_pc; | |
1369 } | |
1370 } | |
1371 } | |
1372 | |
1373 void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) { | |
1374 int localvariable_table_length = _method()->localvariable_table_length(); | |
1375 if (localvariable_table_length > 0) { | |
1376 LocalVariableTableElement* table = _method()->localvariable_table_start(); | |
1377 for (int i = 0; i < localvariable_table_length; i++) { | |
1378 u2 start_bci = table[i].start_bci; | |
1379 u2 length = table[i].length; | |
1380 | |
1381 if (start_bci >= code_length || code_data[start_bci] == 0) { | |
1382 class_format_error( | |
1383 "Illegal local variable table start_pc %d", start_bci); | |
1384 return; | |
1385 } | |
1386 u4 end_bci = (u4)(start_bci + length); | |
1387 if (end_bci != code_length) { | |
1388 if (end_bci >= code_length || code_data[end_bci] == 0) { | |
1389 class_format_error( "Illegal local variable table length %d", length); | |
1390 return; | |
1391 } | |
1392 } | |
1393 } | |
1394 } | |
1395 } | |
1396 | |
1397 u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci, | |
1398 StackMapFrame* current_frame, | |
1399 StackMapTable* stackmap_table, | |
1400 bool no_control_flow, TRAPS) { | |
1401 if (stackmap_index < stackmap_table->get_frame_count()) { | |
1402 u2 this_offset = stackmap_table->get_offset(stackmap_index); | |
1403 if (no_control_flow && this_offset > bci) { | |
1404 verify_error(bci, "Expecting a stack map frame"); | |
1405 return 0; | |
1406 } | |
1407 if (this_offset == bci) { | |
1408 // See if current stack map can be assigned to the frame in table. | |
1409 // current_frame is the stackmap frame got from the last instruction. | |
1410 // If matched, current_frame will be updated by this method. | |
1411 bool match = stackmap_table->match_stackmap( | |
1412 current_frame, this_offset, stackmap_index, | |
1413 !no_control_flow, true, CHECK_VERIFY_(this, 0)); | |
1414 if (!match) { | |
1415 // report type error | |
1416 verify_error(bci, "Instruction type does not match stack map"); | |
1417 return 0; | |
1418 } | |
1419 stackmap_index++; | |
1420 } else if (this_offset < bci) { | |
1421 // current_offset should have met this_offset. | |
1422 class_format_error("Bad stack map offset %d", this_offset); | |
1423 return 0; | |
1424 } | |
1425 } else if (no_control_flow) { | |
1426 verify_error(bci, "Expecting a stack map frame"); | |
1427 return 0; | |
1428 } | |
1429 return stackmap_index; | |
1430 } | |
1431 | |
1432 void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame, | |
1433 StackMapTable* stackmap_table, TRAPS) { | |
1434 constantPoolHandle cp (THREAD, _method->constants()); | |
1435 typeArrayHandle exhandlers (THREAD, _method->exception_table()); | |
1436 if (exhandlers() != NULL) { | |
1437 for(int i = 0; i < exhandlers->length();) { | |
1438 u2 start_pc = exhandlers->int_at(i++); | |
1439 u2 end_pc = exhandlers->int_at(i++); | |
1440 u2 handler_pc = exhandlers->int_at(i++); | |
1441 int catch_type_index = exhandlers->int_at(i++); | |
1442 if(bci >= start_pc && bci < end_pc) { | |
1443 u1 flags = current_frame->flags(); | |
1444 if (this_uninit) { flags |= FLAG_THIS_UNINIT; } | |
1445 | |
1446 ResourceMark rm(THREAD); | |
1447 StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags); | |
1448 if (catch_type_index != 0) { | |
1449 // We know that this index refers to a subclass of Throwable | |
1450 VerificationType catch_type = cp_index_to_type( | |
1451 catch_type_index, cp, CHECK_VERIFY(this)); | |
1452 new_frame->push_stack(catch_type, CHECK_VERIFY(this)); | |
1453 } else { | |
1454 VerificationType throwable = | |
1455 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); | |
1456 new_frame->push_stack(throwable, CHECK_VERIFY(this)); | |
1457 } | |
1458 bool match = stackmap_table->match_stackmap( | |
1459 new_frame, handler_pc, true, false, CHECK_VERIFY(this)); | |
1460 if (!match) { | |
1461 verify_error(bci, | |
1462 "Stack map does not match the one at exception handler %d", | |
1463 handler_pc); | |
1464 return; | |
1465 } | |
1466 } | |
1467 } | |
1468 } | |
1469 } | |
1470 | |
1471 void ClassVerifier::verify_cp_index(constantPoolHandle cp, int index, TRAPS) { | |
1472 int nconstants = cp->length(); | |
1473 if ((index <= 0) || (index >= nconstants)) { | |
1474 verify_error("Illegal constant pool index %d in class %s", | |
1475 index, instanceKlass::cast(cp->pool_holder())->external_name()); | |
1476 return; | |
1477 } | |
1478 } | |
1479 | |
1480 void ClassVerifier::verify_cp_type( | |
1481 int index, constantPoolHandle cp, unsigned int types, TRAPS) { | |
1482 | |
1483 // In some situations, bytecode rewriting may occur while we're verifying. | |
1484 // In this case, a constant pool cache exists and some indices refer to that | |
1570 | 1485 // instead. Be sure we don't pick up such indices by accident. |
1486 // We must check was_recursively_verified() before we get here. | |
1487 guarantee(cp->cache() == NULL, "not rewritten yet"); | |
0 | 1488 |
1489 verify_cp_index(cp, index, CHECK_VERIFY(this)); | |
1490 unsigned int tag = cp->tag_at(index).value(); | |
1491 if ((types & (1 << tag)) == 0) { | |
1492 verify_error( | |
1493 "Illegal type at constant pool entry %d in class %s", | |
1494 index, instanceKlass::cast(cp->pool_holder())->external_name()); | |
1495 return; | |
1496 } | |
1497 } | |
1498 | |
1499 void ClassVerifier::verify_cp_class_type( | |
1500 int index, constantPoolHandle cp, TRAPS) { | |
1501 verify_cp_index(cp, index, CHECK_VERIFY(this)); | |
1502 constantTag tag = cp->tag_at(index); | |
1503 if (!tag.is_klass() && !tag.is_unresolved_klass()) { | |
1504 verify_error("Illegal type at constant pool entry %d in class %s", | |
1505 index, instanceKlass::cast(cp->pool_holder())->external_name()); | |
1506 return; | |
1507 } | |
1508 } | |
1509 | |
1510 void ClassVerifier::format_error_message( | |
1511 const char* fmt, int offset, va_list va) { | |
1512 ResourceMark rm(_thread); | |
1513 stringStream message(_message, _message_buffer_len); | |
1514 message.vprint(fmt, va); | |
1515 if (!_method.is_null()) { | |
1516 message.print(" in method %s", _method->name_and_sig_as_C_string()); | |
1517 } | |
1518 if (offset != -1) { | |
1519 message.print(" at offset %d", offset); | |
1520 } | |
1521 } | |
1522 | |
1523 void ClassVerifier::verify_error(u2 offset, const char* fmt, ...) { | |
1524 _exception_type = vmSymbols::java_lang_VerifyError(); | |
1525 va_list va; | |
1526 va_start(va, fmt); | |
1527 format_error_message(fmt, offset, va); | |
1528 va_end(va); | |
1529 } | |
1530 | |
1531 void ClassVerifier::verify_error(const char* fmt, ...) { | |
1532 _exception_type = vmSymbols::java_lang_VerifyError(); | |
1533 va_list va; | |
1534 va_start(va, fmt); | |
1535 format_error_message(fmt, -1, va); | |
1536 va_end(va); | |
1537 } | |
1538 | |
1539 void ClassVerifier::class_format_error(const char* msg, ...) { | |
1540 _exception_type = vmSymbols::java_lang_ClassFormatError(); | |
1541 va_list va; | |
1542 va_start(va, msg); | |
1543 format_error_message(msg, -1, va); | |
1544 va_end(va); | |
1545 } | |
1546 | |
1547 klassOop ClassVerifier::load_class(symbolHandle name, TRAPS) { | |
1548 // Get current loader and protection domain first. | |
1549 oop loader = current_class()->class_loader(); | |
1550 oop protection_domain = current_class()->protection_domain(); | |
1551 | |
1552 return SystemDictionary::resolve_or_fail( | |
1553 name, Handle(THREAD, loader), Handle(THREAD, protection_domain), | |
1554 true, CHECK_NULL); | |
1555 } | |
1556 | |
1557 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class, | |
1558 klassOop target_class, | |
1559 symbolOop field_name, | |
1560 symbolOop field_sig, | |
1561 bool is_method) { | |
1562 No_Safepoint_Verifier nosafepoint; | |
1563 | |
1564 // If target class isn't a super class of this class, we don't worry about this case | |
1565 if (!this_class->is_subclass_of(target_class)) { | |
1566 return false; | |
1567 } | |
1568 // Check if the specified method or field is protected | |
1569 instanceKlass* target_instance = instanceKlass::cast(target_class); | |
1570 fieldDescriptor fd; | |
1571 if (is_method) { | |
1572 methodOop m = target_instance->uncached_lookup_method(field_name, field_sig); | |
1573 if (m != NULL && m->is_protected()) { | |
1574 if (!this_class->is_same_class_package(m->method_holder())) { | |
1575 return true; | |
1576 } | |
1577 } | |
1578 } else { | |
1579 klassOop member_klass = target_instance->find_field(field_name, field_sig, &fd); | |
1580 if(member_klass != NULL && fd.is_protected()) { | |
1581 if (!this_class->is_same_class_package(member_klass)) { | |
1582 return true; | |
1583 } | |
1584 } | |
1585 } | |
1586 return false; | |
1587 } | |
1588 | |
1589 void ClassVerifier::verify_ldc( | |
1590 int opcode, u2 index, StackMapFrame *current_frame, | |
1591 constantPoolHandle cp, u2 bci, TRAPS) { | |
1592 verify_cp_index(cp, index, CHECK_VERIFY(this)); | |
1593 constantTag tag = cp->tag_at(index); | |
1594 unsigned int types; | |
1595 if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { | |
1596 if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) { | |
1597 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) | |
1598 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class); | |
1599 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); | |
1600 } | |
1601 } else { | |
1602 assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); | |
1603 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long); | |
1604 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); | |
1605 } | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1606 if (tag.is_string() && cp->is_pseudo_string_at(index)) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1607 current_frame->push_stack( |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1608 VerificationType::reference_type( |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1609 vmSymbols::java_lang_Object()), CHECK_VERIFY(this)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1610 } else if (tag.is_string() || tag.is_unresolved_string()) { |
0 | 1611 current_frame->push_stack( |
1612 VerificationType::reference_type( | |
1613 vmSymbols::java_lang_String()), CHECK_VERIFY(this)); | |
1614 } else if (tag.is_klass() || tag.is_unresolved_klass()) { | |
1615 current_frame->push_stack( | |
1616 VerificationType::reference_type( | |
1617 vmSymbols::java_lang_Class()), CHECK_VERIFY(this)); | |
1618 } else if (tag.is_int()) { | |
1619 current_frame->push_stack( | |
1620 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1621 } else if (tag.is_float()) { | |
1622 current_frame->push_stack( | |
1623 VerificationType::float_type(), CHECK_VERIFY(this)); | |
1624 } else if (tag.is_double()) { | |
1625 current_frame->push_stack_2( | |
1626 VerificationType::double_type(), | |
1627 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
1628 } else if (tag.is_long()) { | |
1629 current_frame->push_stack_2( | |
1630 VerificationType::long_type(), | |
1631 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
1632 } else { | |
1633 verify_error(bci, "Invalid index in ldc"); | |
1634 return; | |
1635 } | |
1636 } | |
1637 | |
1638 void ClassVerifier::verify_switch( | |
1639 RawBytecodeStream* bcs, u4 code_length, char* code_data, | |
1640 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) { | |
1641 int bci = bcs->bci(); | |
1642 address bcp = bcs->bcp(); | |
1643 address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize); | |
1644 | |
1645 // 4639449 & 4647081: padding bytes must be 0 | |
1646 u2 padding_offset = 1; | |
1647 while ((bcp + padding_offset) < aligned_bcp) { | |
1648 if(*(bcp + padding_offset) != 0) { | |
1649 verify_error(bci, "Nonzero padding byte in lookswitch or tableswitch"); | |
1650 return; | |
1651 } | |
1652 padding_offset++; | |
1653 } | |
1654 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); | |
1655 int keys, delta; | |
1656 current_frame->pop_stack( | |
1657 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
1565 | 1658 if (bcs->raw_code() == Bytecodes::_tableswitch) { |
0 | 1659 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); |
1660 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); | |
1661 if (low > high) { | |
1662 verify_error(bci, | |
1663 "low must be less than or equal to high in tableswitch"); | |
1664 return; | |
1665 } | |
1666 keys = high - low + 1; | |
1667 if (keys < 0) { | |
1668 verify_error(bci, "too many keys in tableswitch"); | |
1669 return; | |
1670 } | |
1671 delta = 1; | |
1672 } else { | |
1673 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); | |
1674 if (keys < 0) { | |
1675 verify_error(bci, "number of keys in lookupswitch less than 0"); | |
1676 return; | |
1677 } | |
1678 delta = 2; | |
1679 // Make sure that the lookupswitch items are sorted | |
1680 for (int i = 0; i < (keys - 1); i++) { | |
1681 jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); | |
1682 jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); | |
1683 if (this_key >= next_key) { | |
1684 verify_error(bci, "Bad lookupswitch instruction"); | |
1685 return; | |
1686 } | |
1687 } | |
1688 } | |
1689 int target = bci + default_offset; | |
1690 stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this)); | |
1691 for (int i = 0; i < keys; i++) { | |
1692 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); | |
1693 stackmap_table->check_jump_target( | |
1694 current_frame, target, CHECK_VERIFY(this)); | |
1695 } | |
1696 } | |
1697 | |
1698 bool ClassVerifier::name_in_supers( | |
1699 symbolOop ref_name, instanceKlassHandle current) { | |
1700 klassOop super = current->super(); | |
1701 while (super != NULL) { | |
1702 if (super->klass_part()->name() == ref_name) { | |
1703 return true; | |
1704 } | |
1705 super = super->klass_part()->super(); | |
1706 } | |
1707 return false; | |
1708 } | |
1709 | |
1710 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, | |
1711 StackMapFrame* current_frame, | |
1712 constantPoolHandle cp, | |
1713 TRAPS) { | |
1565 | 1714 u2 index = bcs->get_index_u2(); |
0 | 1715 verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); |
1716 | |
1717 // Get field name and signature | |
1718 symbolHandle field_name = symbolHandle(THREAD, cp->name_ref_at(index)); | |
1719 symbolHandle field_sig = symbolHandle(THREAD, cp->signature_ref_at(index)); | |
1720 | |
1721 if (!SignatureVerifier::is_valid_type_signature(field_sig)) { | |
1722 class_format_error( | |
1723 "Invalid signature for field in class %s referenced " | |
1724 "from constant pool index %d", _klass->external_name(), index); | |
1725 return; | |
1726 } | |
1727 | |
1728 // Get referenced class type | |
1729 VerificationType ref_class_type = cp_ref_index_to_type( | |
1730 index, cp, CHECK_VERIFY(this)); | |
1731 if (!ref_class_type.is_object()) { | |
1732 verify_error( | |
1733 "Expecting reference to class in class %s at constant pool index %d", | |
1734 _klass->external_name(), index); | |
1735 return; | |
1736 } | |
1737 VerificationType target_class_type = ref_class_type; | |
1738 | |
1739 assert(sizeof(VerificationType) == sizeof(uintptr_t), | |
1740 "buffer type must match VerificationType size"); | |
1741 uintptr_t field_type_buffer[2]; | |
1742 VerificationType* field_type = (VerificationType*)field_type_buffer; | |
1743 // If we make a VerificationType[2] array directly, the compiler calls | |
1744 // to the c-runtime library to do the allocation instead of just | |
1745 // stack allocating it. Plus it would run constructors. This shows up | |
1746 // in performance profiles. | |
1747 | |
1748 SignatureStream sig_stream(field_sig, false); | |
1749 VerificationType stack_object_type; | |
1750 int n = change_sig_to_verificationType( | |
1751 &sig_stream, field_type, CHECK_VERIFY(this)); | |
1752 u2 bci = bcs->bci(); | |
1753 bool is_assignable; | |
1565 | 1754 switch (bcs->raw_code()) { |
0 | 1755 case Bytecodes::_getstatic: { |
1756 for (int i = 0; i < n; i++) { | |
1757 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); | |
1758 } | |
1759 break; | |
1760 } | |
1761 case Bytecodes::_putstatic: { | |
1762 for (int i = n - 1; i >= 0; i--) { | |
1763 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); | |
1764 } | |
1765 break; | |
1766 } | |
1767 case Bytecodes::_getfield: { | |
1768 stack_object_type = current_frame->pop_stack( | |
1769 target_class_type, CHECK_VERIFY(this)); | |
1770 for (int i = 0; i < n; i++) { | |
1771 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); | |
1772 } | |
1773 goto check_protected; | |
1774 } | |
1775 case Bytecodes::_putfield: { | |
1776 for (int i = n - 1; i >= 0; i--) { | |
1777 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); | |
1778 } | |
1779 stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this)); | |
1780 | |
1781 // The JVMS 2nd edition allows field initialization before the superclass | |
1782 // initializer, if the field is defined within the current class. | |
1783 fieldDescriptor fd; | |
1784 if (stack_object_type == VerificationType::uninitialized_this_type() && | |
1785 target_class_type.equals(current_type()) && | |
1786 _klass->find_local_field(field_name(), field_sig(), &fd)) { | |
1787 stack_object_type = current_type(); | |
1788 } | |
1789 is_assignable = target_class_type.is_assignable_from( | |
1790 stack_object_type, current_class(), CHECK_VERIFY(this)); | |
1791 if (!is_assignable) { | |
1792 verify_error(bci, "Bad type on operand stack in putfield"); | |
1793 return; | |
1794 } | |
1795 } | |
1796 check_protected: { | |
1797 if (_this_type == stack_object_type) | |
1798 break; // stack_object_type must be assignable to _current_class_type | |
1799 symbolHandle ref_class_name = symbolHandle(THREAD, | |
1800 cp->klass_name_at(cp->klass_ref_index_at(index))); | |
1801 if (!name_in_supers(ref_class_name(), current_class())) | |
1802 // stack_object_type must be assignable to _current_class_type since: | |
1803 // 1. stack_object_type must be assignable to ref_class. | |
1804 // 2. ref_class must be _current_class or a subclass of it. It can't | |
1805 // be a superclass of it. See revised JVMS 5.4.4. | |
1806 break; | |
1807 | |
1808 klassOop ref_class_oop = load_class(ref_class_name, CHECK); | |
1809 if (is_protected_access(current_class(), ref_class_oop, field_name(), | |
1810 field_sig(), false)) { | |
1811 // It's protected access, check if stack object is assignable to | |
1812 // current class. | |
1813 is_assignable = current_type().is_assignable_from( | |
1814 stack_object_type, current_class(), CHECK_VERIFY(this)); | |
1815 if (!is_assignable) { | |
1816 verify_error(bci, "Bad access to protected data in getfield"); | |
1817 return; | |
1818 } | |
1819 } | |
1820 break; | |
1821 } | |
1822 default: ShouldNotReachHere(); | |
1823 } | |
1824 } | |
1825 | |
1826 void ClassVerifier::verify_invoke_init( | |
1827 RawBytecodeStream* bcs, VerificationType ref_class_type, | |
1828 StackMapFrame* current_frame, u4 code_length, bool *this_uninit, | |
1829 constantPoolHandle cp, TRAPS) { | |
1830 u2 bci = bcs->bci(); | |
1831 VerificationType type = current_frame->pop_stack( | |
1832 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
1833 if (type == VerificationType::uninitialized_this_type()) { | |
1834 // The method must be an <init> method of either this class, or one of its | |
1835 // superclasses | |
1836 klassOop oop = current_class()(); | |
1837 Klass* klass = oop->klass_part(); | |
1838 while (klass != NULL && ref_class_type.name() != klass->name()) { | |
1839 klass = klass->super()->klass_part(); | |
1840 } | |
1841 if (klass == NULL) { | |
1842 verify_error(bci, "Bad <init> method call"); | |
1843 return; | |
1844 } | |
1845 current_frame->initialize_object(type, current_type()); | |
1846 *this_uninit = true; | |
1847 } else if (type.is_uninitialized()) { | |
1848 u2 new_offset = type.bci(); | |
1849 address new_bcp = bcs->bcp() - bci + new_offset; | |
1850 if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { | |
1851 verify_error(new_offset, "Expecting new instruction"); | |
1852 return; | |
1853 } | |
1854 u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); | |
1855 verify_cp_class_type(new_class_index, cp, CHECK_VERIFY(this)); | |
1856 | |
1857 // The method must be an <init> method of the indicated class | |
1858 VerificationType new_class_type = cp_index_to_type( | |
1859 new_class_index, cp, CHECK_VERIFY(this)); | |
1860 if (!new_class_type.equals(ref_class_type)) { | |
1861 verify_error(bci, "Call to wrong <init> method"); | |
1862 return; | |
1863 } | |
1864 // According to the VM spec, if the referent class is a superclass of the | |
1865 // current class, and is in a different runtime package, and the method is | |
1866 // protected, then the objectref must be the current class or a subclass | |
1867 // of the current class. | |
1868 VerificationType objectref_type = new_class_type; | |
1869 if (name_in_supers(ref_class_type.name(), current_class())) { | |
1870 klassOop ref_klass = load_class( | |
1871 ref_class_type.name(), CHECK_VERIFY(this)); | |
1872 methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method( | |
1873 vmSymbols::object_initializer_name(), | |
1565 | 1874 cp->signature_ref_at(bcs->get_index_u2())); |
0 | 1875 instanceKlassHandle mh(THREAD, m->method_holder()); |
1876 if (m->is_protected() && !mh->is_same_class_package(_klass())) { | |
1877 bool assignable = current_type().is_assignable_from( | |
1878 objectref_type, current_class(), CHECK_VERIFY(this)); | |
1879 if (!assignable) { | |
1880 verify_error(bci, "Bad access to protected <init> method"); | |
1881 return; | |
1882 } | |
1883 } | |
1884 } | |
1885 current_frame->initialize_object(type, new_class_type); | |
1886 } else { | |
1887 verify_error(bci, "Bad operand type when invoking <init>"); | |
1888 return; | |
1889 } | |
1890 } | |
1891 | |
1892 void ClassVerifier::verify_invoke_instructions( | |
1893 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, | |
1894 bool *this_uninit, VerificationType return_type, | |
1895 constantPoolHandle cp, TRAPS) { | |
1896 // Make sure the constant pool item is the right type | |
1565 | 1897 u2 index = bcs->get_index_u2(); |
1898 Bytecodes::Code opcode = bcs->raw_code(); | |
0 | 1899 unsigned int types = (opcode == Bytecodes::_invokeinterface |
1900 ? 1 << JVM_CONSTANT_InterfaceMethodref | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1901 : opcode == Bytecodes::_invokedynamic |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1902 ? 1 << JVM_CONSTANT_NameAndType |
0 | 1903 : 1 << JVM_CONSTANT_Methodref); |
1904 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); | |
1905 | |
1906 // Get method name and signature | |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
973
diff
changeset
|
1907 symbolHandle method_name(THREAD, cp->name_ref_at(index)); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
973
diff
changeset
|
1908 symbolHandle method_sig(THREAD, cp->signature_ref_at(index)); |
0 | 1909 |
1910 if (!SignatureVerifier::is_valid_method_signature(method_sig)) { | |
1911 class_format_error( | |
1912 "Invalid method signature in class %s referenced " | |
1913 "from constant pool index %d", _klass->external_name(), index); | |
1914 return; | |
1915 } | |
1916 | |
1917 // Get referenced class type | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1918 VerificationType ref_class_type; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1919 if (opcode == Bytecodes::_invokedynamic) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1920 if (!EnableInvokeDynamic) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1921 class_format_error( |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1922 "invokedynamic instructions not enabled on this JVM", |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1923 _klass->external_name()); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1924 return; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1925 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1926 } else { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1927 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this)); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1928 } |
0 | 1929 |
1930 // For a small signature length, we just allocate 128 bytes instead | |
1931 // of parsing the signature once to find its size. | |
1932 // -3 is for '(', ')' and return descriptor; multiply by 2 is for | |
1933 // longs/doubles to be consertive. | |
1934 assert(sizeof(VerificationType) == sizeof(uintptr_t), | |
1935 "buffer type must match VerificationType size"); | |
1936 uintptr_t on_stack_sig_types_buffer[128]; | |
1937 // If we make a VerificationType[128] array directly, the compiler calls | |
1938 // to the c-runtime library to do the allocation instead of just | |
1939 // stack allocating it. Plus it would run constructors. This shows up | |
1940 // in performance profiles. | |
1941 | |
1942 VerificationType* sig_types; | |
1943 int size = (method_sig->utf8_length() - 3) * 2; | |
1944 if (size > 128) { | |
1945 // Long and double occupies two slots here. | |
1946 ArgumentSizeComputer size_it(method_sig); | |
1947 size = size_it.size(); | |
1948 sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size); | |
1949 } else{ | |
1950 sig_types = (VerificationType*)on_stack_sig_types_buffer; | |
1951 } | |
1952 SignatureStream sig_stream(method_sig); | |
1953 int sig_i = 0; | |
1954 while (!sig_stream.at_return_type()) { | |
1955 sig_i += change_sig_to_verificationType( | |
1956 &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this)); | |
1957 sig_stream.next(); | |
1958 } | |
1959 int nargs = sig_i; | |
1960 | |
1961 #ifdef ASSERT | |
1962 { | |
1963 ArgumentSizeComputer size_it(method_sig); | |
1964 assert(nargs == size_it.size(), "Argument sizes do not match"); | |
1965 assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough"); | |
1966 } | |
1967 #endif | |
1968 | |
1969 // Check instruction operands | |
1970 u2 bci = bcs->bci(); | |
1971 if (opcode == Bytecodes::_invokeinterface) { | |
1972 address bcp = bcs->bcp(); | |
1973 // 4905268: count operand in invokeinterface should be nargs+1, not nargs. | |
1974 // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is | |
1975 // the difference between the size of the operand stack before and after the instruction | |
1976 // executes. | |
1977 if (*(bcp+3) != (nargs+1)) { | |
1978 verify_error(bci, "Inconsistent args count operand in invokeinterface"); | |
1979 return; | |
1980 } | |
1981 if (*(bcp+4) != 0) { | |
1982 verify_error(bci, "Fourth operand byte of invokeinterface must be zero"); | |
1983 return; | |
1984 } | |
1985 } | |
1986 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1987 if (opcode == Bytecodes::_invokedynamic) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1988 address bcp = bcs->bcp(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1989 if (*(bcp+3) != 0 || *(bcp+4) != 0) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1990 verify_error(bci, "Third and fourth operand bytes of invokedynamic must be zero"); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1991 return; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1992 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1993 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
1994 |
0 | 1995 if (method_name->byte_at(0) == '<') { |
1996 // Make sure <init> can only be invoked by invokespecial | |
1997 if (opcode != Bytecodes::_invokespecial || | |
1998 method_name() != vmSymbols::object_initializer_name()) { | |
1999 verify_error(bci, "Illegal call to internal method"); | |
2000 return; | |
2001 } | |
2002 } else if (opcode == Bytecodes::_invokespecial | |
2003 && !ref_class_type.equals(current_type()) | |
2004 && !ref_class_type.equals(VerificationType::reference_type( | |
2005 current_class()->super()->klass_part()->name()))) { | |
2006 bool subtype = ref_class_type.is_assignable_from( | |
2007 current_type(), current_class(), CHECK_VERIFY(this)); | |
2008 if (!subtype) { | |
2009 verify_error(bci, "Bad invokespecial instruction: " | |
2010 "current class isn't assignable to reference class."); | |
2011 return; | |
2012 } | |
2013 } | |
2014 // Match method descriptor with operand stack | |
2015 for (int i = nargs - 1; i >= 0; i--) { // Run backwards | |
2016 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); | |
2017 } | |
2018 // Check objectref on operand stack | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
2019 if (opcode != Bytecodes::_invokestatic && |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
431
diff
changeset
|
2020 opcode != Bytecodes::_invokedynamic) { |
0 | 2021 if (method_name() == vmSymbols::object_initializer_name()) { // <init> method |
2022 verify_invoke_init(bcs, ref_class_type, current_frame, | |
2023 code_length, this_uninit, cp, CHECK_VERIFY(this)); | |
2024 } else { // other methods | |
2025 // Ensures that target class is assignable to method class. | |
2026 if (opcode == Bytecodes::_invokespecial) { | |
2027 current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); | |
2028 } else if (opcode == Bytecodes::_invokevirtual) { | |
2029 VerificationType stack_object_type = | |
2030 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); | |
2031 if (current_type() != stack_object_type) { | |
2032 assert(cp->cache() == NULL, "not rewritten yet"); | |
2033 symbolHandle ref_class_name = symbolHandle(THREAD, | |
2034 cp->klass_name_at(cp->klass_ref_index_at(index))); | |
2035 // See the comments in verify_field_instructions() for | |
2036 // the rationale behind this. | |
2037 if (name_in_supers(ref_class_name(), current_class())) { | |
2038 klassOop ref_class = load_class(ref_class_name, CHECK); | |
2039 if (is_protected_access( | |
2040 _klass, ref_class, method_name(), method_sig(), true)) { | |
2041 // It's protected access, check if stack object is | |
2042 // assignable to current class. | |
2043 bool is_assignable = current_type().is_assignable_from( | |
2044 stack_object_type, current_class(), CHECK_VERIFY(this)); | |
2045 if (!is_assignable) { | |
2046 if (ref_class_type.name() == vmSymbols::java_lang_Object() | |
2047 && stack_object_type.is_array() | |
2048 && method_name() == vmSymbols::clone_name()) { | |
2049 // Special case: arrays pretend to implement public Object | |
2050 // clone(). | |
2051 } else { | |
2052 verify_error(bci, | |
2053 "Bad access to protected data in invokevirtual"); | |
2054 return; | |
2055 } | |
2056 } | |
2057 } | |
2058 } | |
2059 } | |
2060 } else { | |
2061 assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered"); | |
2062 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); | |
2063 } | |
2064 } | |
2065 } | |
2066 // Push the result type. | |
2067 if (sig_stream.type() != T_VOID) { | |
2068 if (method_name() == vmSymbols::object_initializer_name()) { | |
2069 // <init> method must have a void return type | |
2070 verify_error(bci, "Return type must be void in <init> method"); | |
2071 return; | |
2072 } | |
2073 VerificationType return_type[2]; | |
2074 int n = change_sig_to_verificationType( | |
2075 &sig_stream, return_type, CHECK_VERIFY(this)); | |
2076 for (int i = 0; i < n; i++) { | |
2077 current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards | |
2078 } | |
2079 } | |
2080 } | |
2081 | |
2082 VerificationType ClassVerifier::get_newarray_type( | |
2083 u2 index, u2 bci, TRAPS) { | |
2084 const char* from_bt[] = { | |
2085 NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", | |
2086 }; | |
2087 if (index < T_BOOLEAN || index > T_LONG) { | |
2088 verify_error(bci, "Illegal newarray instruction"); | |
2089 return VerificationType::bogus_type(); | |
2090 } | |
2091 | |
2092 // from_bt[index] contains the array signature which has a length of 2 | |
2093 symbolHandle sig = oopFactory::new_symbol_handle( | |
2094 from_bt[index], 2, CHECK_(VerificationType::bogus_type())); | |
2095 return VerificationType::reference_type(sig); | |
2096 } | |
2097 | |
2098 void ClassVerifier::verify_anewarray( | |
2099 u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS) { | |
2100 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | |
2101 current_frame->pop_stack( | |
2102 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
2103 | |
2104 VerificationType component_type = | |
2105 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | |
2106 ResourceMark rm(THREAD); | |
2107 int length; | |
2108 char* arr_sig_str; | |
2109 if (component_type.is_array()) { // it's an array | |
2110 const char* component_name = component_type.name()->as_utf8(); | |
2111 // add one dimension to component | |
2112 length = (int)strlen(component_name) + 1; | |
2113 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); | |
2114 arr_sig_str[0] = '['; | |
2115 strncpy(&arr_sig_str[1], component_name, length - 1); | |
2116 } else { // it's an object or interface | |
2117 const char* component_name = component_type.name()->as_utf8(); | |
2118 // add one dimension to component with 'L' prepended and ';' postpended. | |
2119 length = (int)strlen(component_name) + 3; | |
2120 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); | |
2121 arr_sig_str[0] = '['; | |
2122 arr_sig_str[1] = 'L'; | |
2123 strncpy(&arr_sig_str[2], component_name, length - 2); | |
2124 arr_sig_str[length - 1] = ';'; | |
2125 } | |
2126 symbolHandle arr_sig = oopFactory::new_symbol_handle( | |
2127 arr_sig_str, length, CHECK_VERIFY(this)); | |
2128 VerificationType new_array_type = VerificationType::reference_type(arr_sig); | |
2129 current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); | |
2130 } | |
2131 | |
2132 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2133 current_frame->get_local( | |
2134 index, VerificationType::integer_type(), CHECK_VERIFY(this)); | |
2135 current_frame->push_stack( | |
2136 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
2137 } | |
2138 | |
2139 void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2140 current_frame->get_local_2( | |
2141 index, VerificationType::long_type(), | |
2142 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
2143 current_frame->push_stack_2( | |
2144 VerificationType::long_type(), | |
2145 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
2146 } | |
2147 | |
2148 void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2149 current_frame->get_local( | |
2150 index, VerificationType::float_type(), CHECK_VERIFY(this)); | |
2151 current_frame->push_stack( | |
2152 VerificationType::float_type(), CHECK_VERIFY(this)); | |
2153 } | |
2154 | |
2155 void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2156 current_frame->get_local_2( | |
2157 index, VerificationType::double_type(), | |
2158 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
2159 current_frame->push_stack_2( | |
2160 VerificationType::double_type(), | |
2161 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
2162 } | |
2163 | |
2164 void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2165 VerificationType type = current_frame->get_local( | |
2166 index, VerificationType::reference_check(), CHECK_VERIFY(this)); | |
2167 current_frame->push_stack(type, CHECK_VERIFY(this)); | |
2168 } | |
2169 | |
2170 void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2171 current_frame->pop_stack( | |
2172 VerificationType::integer_type(), CHECK_VERIFY(this)); | |
2173 current_frame->set_local( | |
2174 index, VerificationType::integer_type(), CHECK_VERIFY(this)); | |
2175 } | |
2176 | |
2177 void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2178 current_frame->pop_stack_2( | |
2179 VerificationType::long2_type(), | |
2180 VerificationType::long_type(), CHECK_VERIFY(this)); | |
2181 current_frame->set_local_2( | |
2182 index, VerificationType::long_type(), | |
2183 VerificationType::long2_type(), CHECK_VERIFY(this)); | |
2184 } | |
2185 | |
2186 void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2187 current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this)); | |
2188 current_frame->set_local( | |
2189 index, VerificationType::float_type(), CHECK_VERIFY(this)); | |
2190 } | |
2191 | |
2192 void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2193 current_frame->pop_stack_2( | |
2194 VerificationType::double2_type(), | |
2195 VerificationType::double_type(), CHECK_VERIFY(this)); | |
2196 current_frame->set_local_2( | |
2197 index, VerificationType::double_type(), | |
2198 VerificationType::double2_type(), CHECK_VERIFY(this)); | |
2199 } | |
2200 | |
2201 void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2202 VerificationType type = current_frame->pop_stack( | |
2203 VerificationType::reference_check(), CHECK_VERIFY(this)); | |
2204 current_frame->set_local(index, type, CHECK_VERIFY(this)); | |
2205 } | |
2206 | |
2207 void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) { | |
2208 VerificationType type = current_frame->get_local( | |
2209 index, VerificationType::integer_type(), CHECK_VERIFY(this)); | |
2210 current_frame->set_local(index, type, CHECK_VERIFY(this)); | |
2211 } | |
2212 | |
2213 void ClassVerifier::verify_return_value( | |
2214 VerificationType return_type, VerificationType type, u2 bci, TRAPS) { | |
2215 if (return_type == VerificationType::bogus_type()) { | |
2216 verify_error(bci, "Method expects a return value"); | |
2217 return; | |
2218 } | |
2219 bool match = return_type.is_assignable_from(type, _klass, CHECK_VERIFY(this)); | |
2220 if (!match) { | |
2221 verify_error(bci, "Bad return type"); | |
2222 return; | |
2223 } | |
2224 } |