Mercurial > hg > graal-compiler
comparison src/share/vm/classfile/verifier.cpp @ 6605:4ee06e614636
7116786: RFE: Detailed information on VerifyErrors
Summary: Provide additional detail in VerifyError messages
Reviewed-by: sspitsyn, acorn
author | kamg |
---|---|
date | Mon, 06 Aug 2012 15:54:45 -0400 |
parents | f0b82641fb7e |
children | fce6d7280776 |
comparison
equal
deleted
inserted
replaced
6604:c3c2141203e7 | 6605:4ee06e614636 |
---|---|
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/classFileStream.hpp" | 26 #include "classfile/classFileStream.hpp" |
27 #include "classfile/javaClasses.hpp" | 27 #include "classfile/javaClasses.hpp" |
28 #include "classfile/stackMapTable.hpp" | 28 #include "classfile/stackMapTable.hpp" |
29 #include "classfile/stackMapFrame.hpp" | |
30 #include "classfile/stackMapTableFormat.hpp" | |
29 #include "classfile/systemDictionary.hpp" | 31 #include "classfile/systemDictionary.hpp" |
30 #include "classfile/verifier.hpp" | 32 #include "classfile/verifier.hpp" |
31 #include "classfile/vmSymbols.hpp" | 33 #include "classfile/vmSymbols.hpp" |
34 #include "interpreter/bytecodes.hpp" | |
32 #include "interpreter/bytecodeStream.hpp" | 35 #include "interpreter/bytecodeStream.hpp" |
33 #include "memory/oopFactory.hpp" | 36 #include "memory/oopFactory.hpp" |
34 #include "memory/resourceArea.hpp" | 37 #include "memory/resourceArea.hpp" |
35 #include "oops/instanceKlass.hpp" | 38 #include "oops/instanceKlass.hpp" |
36 #include "oops/oop.inline.hpp" | 39 #include "oops/oop.inline.hpp" |
108 ResourceMark rm(THREAD); | 111 ResourceMark rm(THREAD); |
109 | 112 |
110 Symbol* exception_name = NULL; | 113 Symbol* exception_name = NULL; |
111 const size_t message_buffer_len = klass->name()->utf8_length() + 1024; | 114 const size_t message_buffer_len = klass->name()->utf8_length() + 1024; |
112 char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); | 115 char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); |
116 char* exception_message = message_buffer; | |
113 | 117 |
114 const char* klassName = klass->external_name(); | 118 const char* klassName = klass->external_name(); |
119 bool can_failover = FailOverToOldVerifier && | |
120 klass->major_version() < NOFAILOVER_MAJOR_VERSION; | |
115 | 121 |
116 // If the class should be verified, first see if we can use the split | 122 // If the class should be verified, first see if we can use the split |
117 // verifier. If not, or if verification fails and FailOverToOldVerifier | 123 // verifier. If not, or if verification fails and FailOverToOldVerifier |
118 // is set, then call the inference verifier. | 124 // is set, then call the inference verifier. |
119 if (is_eligible_for_verification(klass, should_verify_class)) { | 125 if (is_eligible_for_verification(klass, should_verify_class)) { |
120 if (TraceClassInitialization) { | 126 if (TraceClassInitialization) { |
121 tty->print_cr("Start class verification for: %s", klassName); | 127 tty->print_cr("Start class verification for: %s", klassName); |
122 } | 128 } |
123 if (UseSplitVerifier && | 129 if (UseSplitVerifier && |
124 klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { | 130 klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { |
125 ClassVerifier split_verifier( | 131 ClassVerifier split_verifier(klass, THREAD); |
126 klass, message_buffer, message_buffer_len, THREAD); | 132 split_verifier.verify_class(THREAD); |
127 split_verifier.verify_class(THREAD); | 133 exception_name = split_verifier.result(); |
128 exception_name = split_verifier.result(); | 134 if (can_failover && !HAS_PENDING_EXCEPTION && |
129 if (klass->major_version() < NOFAILOVER_MAJOR_VERSION && | |
130 FailOverToOldVerifier && !HAS_PENDING_EXCEPTION && | |
131 (exception_name == vmSymbols::java_lang_VerifyError() || | 135 (exception_name == vmSymbols::java_lang_VerifyError() || |
132 exception_name == vmSymbols::java_lang_ClassFormatError())) { | 136 exception_name == vmSymbols::java_lang_ClassFormatError())) { |
133 if (TraceClassInitialization) { | 137 if (TraceClassInitialization || VerboseVerification) { |
134 tty->print_cr( | 138 tty->print_cr( |
135 "Fail over class verification to old verifier for: %s", klassName); | 139 "Fail over class verification to old verifier for: %s", klassName); |
136 } | 140 } |
137 exception_name = inference_verify( | 141 exception_name = inference_verify( |
138 klass, message_buffer, message_buffer_len, THREAD); | 142 klass, message_buffer, message_buffer_len, THREAD); |
139 } | 143 } |
144 if (exception_name != NULL) { | |
145 exception_message = split_verifier.exception_message(); | |
146 } | |
140 } else { | 147 } else { |
141 exception_name = inference_verify( | 148 exception_name = inference_verify( |
142 klass, message_buffer, message_buffer_len, THREAD); | 149 klass, message_buffer, message_buffer_len, THREAD); |
143 } | 150 } |
144 | 151 |
145 if (TraceClassInitialization) { | 152 if (TraceClassInitialization || VerboseVerification) { |
146 if (HAS_PENDING_EXCEPTION) { | 153 if (HAS_PENDING_EXCEPTION) { |
147 tty->print("Verification for %s has", klassName); | 154 tty->print("Verification for %s has", klassName); |
148 tty->print_cr(" exception pending %s ", | 155 tty->print_cr(" exception pending %s ", |
149 instanceKlass::cast(PENDING_EXCEPTION->klass())->external_name()); | 156 instanceKlass::cast(PENDING_EXCEPTION->klass())->external_name()); |
150 } else if (exception_name != NULL) { | 157 } else if (exception_name != NULL) { |
171 THROW_OOP_(Universe::virtual_machine_error_instance(), false); | 178 THROW_OOP_(Universe::virtual_machine_error_instance(), false); |
172 } | 179 } |
173 kls = kls->super(); | 180 kls = kls->super(); |
174 } | 181 } |
175 message_buffer[message_buffer_len - 1] = '\0'; // just to be sure | 182 message_buffer[message_buffer_len - 1] = '\0'; // just to be sure |
176 THROW_MSG_(exception_name, message_buffer, false); | 183 THROW_MSG_(exception_name, exception_message, false); |
177 } | 184 } |
178 } | 185 } |
179 | 186 |
180 bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) { | 187 bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) { |
181 Symbol* name = klass->name(); | 188 Symbol* name = klass->name(); |
219 jio_snprintf(message, message_len, "Could not link verifier"); | 226 jio_snprintf(message, message_len, "Could not link verifier"); |
220 return vmSymbols::java_lang_VerifyError(); | 227 return vmSymbols::java_lang_VerifyError(); |
221 } | 228 } |
222 | 229 |
223 ResourceMark rm(THREAD); | 230 ResourceMark rm(THREAD); |
224 if (ClassVerifier::_verify_verbose) { | 231 if (VerboseVerification) { |
225 tty->print_cr("Verifying class %s with old format", klass->external_name()); | 232 tty->print_cr("Verifying class %s with old format", klass->external_name()); |
226 } | 233 } |
227 | 234 |
228 jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); | 235 jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); |
229 jint result; | 236 jint result; |
263 ShouldNotReachHere(); | 270 ShouldNotReachHere(); |
264 return NULL; | 271 return NULL; |
265 } | 272 } |
266 } | 273 } |
267 | 274 |
275 TypeOrigin TypeOrigin::null() { | |
276 return TypeOrigin(); | |
277 } | |
278 TypeOrigin TypeOrigin::local(u2 index, StackMapFrame* frame) { | |
279 assert(frame != NULL, "Must have a frame"); | |
280 return TypeOrigin(CF_LOCALS, index, StackMapFrame::copy(frame), | |
281 frame->local_at(index)); | |
282 } | |
283 TypeOrigin TypeOrigin::stack(u2 index, StackMapFrame* frame) { | |
284 assert(frame != NULL, "Must have a frame"); | |
285 return TypeOrigin(CF_STACK, index, StackMapFrame::copy(frame), | |
286 frame->stack_at(index)); | |
287 } | |
288 TypeOrigin TypeOrigin::sm_local(u2 index, StackMapFrame* frame) { | |
289 assert(frame != NULL, "Must have a frame"); | |
290 return TypeOrigin(SM_LOCALS, index, StackMapFrame::copy(frame), | |
291 frame->local_at(index)); | |
292 } | |
293 TypeOrigin TypeOrigin::sm_stack(u2 index, StackMapFrame* frame) { | |
294 assert(frame != NULL, "Must have a frame"); | |
295 return TypeOrigin(SM_STACK, index, StackMapFrame::copy(frame), | |
296 frame->stack_at(index)); | |
297 } | |
298 TypeOrigin TypeOrigin::bad_index(u2 index) { | |
299 return TypeOrigin(BAD_INDEX, index, NULL, VerificationType::bogus_type()); | |
300 } | |
301 TypeOrigin TypeOrigin::cp(u2 index, VerificationType vt) { | |
302 return TypeOrigin(CONST_POOL, index, NULL, vt); | |
303 } | |
304 TypeOrigin TypeOrigin::signature(VerificationType vt) { | |
305 return TypeOrigin(SIG, 0, NULL, vt); | |
306 } | |
307 TypeOrigin TypeOrigin::implicit(VerificationType t) { | |
308 return TypeOrigin(IMPLICIT, 0, NULL, t); | |
309 } | |
310 TypeOrigin TypeOrigin::frame(StackMapFrame* frame) { | |
311 return TypeOrigin(FRAME_ONLY, 0, StackMapFrame::copy(frame), | |
312 VerificationType::bogus_type()); | |
313 } | |
314 | |
315 void TypeOrigin::reset_frame() { | |
316 if (_frame != NULL) { | |
317 _frame->restore(); | |
318 } | |
319 } | |
320 | |
321 void TypeOrigin::details(outputStream* ss) const { | |
322 _type.print_on(ss); | |
323 switch (_origin) { | |
324 case CF_LOCALS: | |
325 ss->print(" (current frame, locals[%d])", _index); | |
326 break; | |
327 case CF_STACK: | |
328 ss->print(" (current frame, stack[%d])", _index); | |
329 break; | |
330 case SM_LOCALS: | |
331 ss->print(" (stack map, locals[%d])", _index); | |
332 break; | |
333 case SM_STACK: | |
334 ss->print(" (stack map, stack[%d])", _index); | |
335 break; | |
336 case CONST_POOL: | |
337 ss->print(" (constant pool %d)", _index); | |
338 break; | |
339 case SIG: | |
340 ss->print(" (from method signature)"); | |
341 break; | |
342 case IMPLICIT: | |
343 case FRAME_ONLY: | |
344 case NONE: | |
345 default: | |
346 ; | |
347 } | |
348 } | |
349 | |
350 #ifdef ASSERT | |
351 void TypeOrigin::print_on(outputStream* str) const { | |
352 str->print("{%d,%d,%p:", _origin, _index, _frame); | |
353 if (_frame != NULL) { | |
354 _frame->print_on(str); | |
355 } else { | |
356 str->print("null"); | |
357 } | |
358 str->print(","); | |
359 _type.print_on(str); | |
360 str->print("}"); | |
361 } | |
362 #endif | |
363 | |
364 void ErrorContext::details(outputStream* ss, methodOop method) const { | |
365 if (is_valid()) { | |
366 ss->print_cr(""); | |
367 ss->print_cr("Exception Details:"); | |
368 location_details(ss, method); | |
369 reason_details(ss); | |
370 frame_details(ss); | |
371 bytecode_details(ss, method); | |
372 handler_details(ss, method); | |
373 stackmap_details(ss, method); | |
374 } | |
375 } | |
376 | |
377 void ErrorContext::reason_details(outputStream* ss) const { | |
378 streamIndentor si(ss); | |
379 ss->indent().print_cr("Reason:"); | |
380 streamIndentor si2(ss); | |
381 ss->indent().print(""); | |
382 switch (_fault) { | |
383 case INVALID_BYTECODE: | |
384 ss->print("Error exists in the bytecode"); | |
385 break; | |
386 case WRONG_TYPE: | |
387 if (_expected.is_valid()) { | |
388 ss->print("Type "); | |
389 _type.details(ss); | |
390 ss->print(" is not assignable to "); | |
391 _expected.details(ss); | |
392 } else { | |
393 ss->print("Invalid type: "); | |
394 _type.details(ss); | |
395 } | |
396 break; | |
397 case FLAGS_MISMATCH: | |
398 if (_expected.is_valid()) { | |
399 ss->print("Current frame's flags are not assignable " | |
400 "to stack map frame's."); | |
401 } else { | |
402 ss->print("Current frame's flags are invalid in this context."); | |
403 } | |
404 break; | |
405 case BAD_CP_INDEX: | |
406 ss->print("Constant pool index %d is invalid", _type.index()); | |
407 break; | |
408 case BAD_LOCAL_INDEX: | |
409 ss->print("Local index %d is invalid", _type.index()); | |
410 break; | |
411 case LOCALS_SIZE_MISMATCH: | |
412 ss->print("Current frame's local size doesn't match stackmap."); | |
413 break; | |
414 case STACK_SIZE_MISMATCH: | |
415 ss->print("Current frame's stack size doesn't match stackmap."); | |
416 break; | |
417 case STACK_OVERFLOW: | |
418 ss->print("Exceeded max stack size."); | |
419 break; | |
420 case STACK_UNDERFLOW: | |
421 ss->print("Attempt to pop empty stack."); | |
422 break; | |
423 case MISSING_STACKMAP: | |
424 ss->print("Expected stackmap frame at this location."); | |
425 break; | |
426 case BAD_STACKMAP: | |
427 ss->print("Invalid stackmap specification."); | |
428 break; | |
429 case UNKNOWN: | |
430 default: | |
431 ShouldNotReachHere(); | |
432 ss->print_cr("Unknown"); | |
433 } | |
434 ss->print_cr(""); | |
435 } | |
436 | |
437 void ErrorContext::location_details(outputStream* ss, methodOop method) const { | |
438 if (_bci != -1 && method != NULL) { | |
439 streamIndentor si(ss); | |
440 const char* bytecode_name = "<invalid>"; | |
441 if (method->validate_bci_from_bcx(_bci) != -1) { | |
442 Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci)); | |
443 if (Bytecodes::is_defined(code)) { | |
444 bytecode_name = Bytecodes::name(code); | |
445 } else { | |
446 bytecode_name = "<illegal>"; | |
447 } | |
448 } | |
449 instanceKlass* ik = instanceKlass::cast(method->method_holder()); | |
450 ss->indent().print_cr("Location:"); | |
451 streamIndentor si2(ss); | |
452 ss->indent().print_cr("%s.%s%s @%d: %s", | |
453 ik->name()->as_C_string(), method->name()->as_C_string(), | |
454 method->signature()->as_C_string(), _bci, bytecode_name); | |
455 } | |
456 } | |
457 | |
458 void ErrorContext::frame_details(outputStream* ss) const { | |
459 streamIndentor si(ss); | |
460 if (_type.is_valid() && _type.frame() != NULL) { | |
461 ss->indent().print_cr("Current Frame:"); | |
462 streamIndentor si2(ss); | |
463 _type.frame()->print_on(ss); | |
464 } | |
465 if (_expected.is_valid() && _expected.frame() != NULL) { | |
466 ss->indent().print_cr("Stackmap Frame:"); | |
467 streamIndentor si2(ss); | |
468 _expected.frame()->print_on(ss); | |
469 } | |
470 } | |
471 | |
472 void ErrorContext::bytecode_details(outputStream* ss, methodOop method) const { | |
473 if (method != NULL) { | |
474 streamIndentor si(ss); | |
475 ss->indent().print_cr("Bytecode:"); | |
476 streamIndentor si2(ss); | |
477 ss->print_data(method->code_base(), method->code_size(), false); | |
478 } | |
479 } | |
480 | |
481 void ErrorContext::handler_details(outputStream* ss, methodOop method) const { | |
482 if (method != NULL) { | |
483 streamIndentor si(ss); | |
484 ExceptionTable table(method); | |
485 if (table.length() > 0) { | |
486 ss->indent().print_cr("Exception Handler Table:"); | |
487 streamIndentor si2(ss); | |
488 for (int i = 0; i < table.length(); ++i) { | |
489 ss->indent().print_cr("bci [%d, %d] => handler: %d", table.start_pc(i), | |
490 table.end_pc(i), table.handler_pc(i)); | |
491 } | |
492 } | |
493 } | |
494 } | |
495 | |
496 void ErrorContext::stackmap_details(outputStream* ss, methodOop method) const { | |
497 if (method != NULL && method->has_stackmap_table()) { | |
498 streamIndentor si(ss); | |
499 ss->indent().print_cr("Stackmap Table:"); | |
500 typeArrayOop data = method->stackmap_data(); | |
501 stack_map_table* sm_table = | |
502 stack_map_table::at((address)data->byte_at_addr(0)); | |
503 stack_map_frame* sm_frame = sm_table->entries(); | |
504 streamIndentor si2(ss); | |
505 int current_offset = -1; | |
506 for (u2 i = 0; i < sm_table->number_of_entries(); ++i) { | |
507 ss->indent(); | |
508 sm_frame->print_on(ss, current_offset); | |
509 ss->print_cr(""); | |
510 current_offset += sm_frame->offset_delta(); | |
511 sm_frame = sm_frame->next(); | |
512 } | |
513 } | |
514 } | |
515 | |
268 // Methods in ClassVerifier | 516 // Methods in ClassVerifier |
269 | 517 |
270 bool ClassVerifier::_verify_verbose = false; | |
271 | |
272 ClassVerifier::ClassVerifier( | 518 ClassVerifier::ClassVerifier( |
273 instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS) | 519 instanceKlassHandle klass, TRAPS) |
274 : _thread(THREAD), _exception_type(NULL), _message(msg), | 520 : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) { |
275 _message_buffer_len(msg_len), _klass(klass) { | |
276 _this_type = VerificationType::reference_type(klass->name()); | 521 _this_type = VerificationType::reference_type(klass->name()); |
277 // Create list to hold symbols in reference area. | 522 // Create list to hold symbols in reference area. |
278 _symbols = new GrowableArray<Symbol*>(100, 0, NULL); | 523 _symbols = new GrowableArray<Symbol*>(100, 0, NULL); |
279 } | 524 } |
280 | 525 |
288 | 533 |
289 VerificationType ClassVerifier::object_type() const { | 534 VerificationType ClassVerifier::object_type() const { |
290 return VerificationType::reference_type(vmSymbols::java_lang_Object()); | 535 return VerificationType::reference_type(vmSymbols::java_lang_Object()); |
291 } | 536 } |
292 | 537 |
538 TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) { | |
539 VerificationType vt = VerificationType::reference_type( | |
540 create_temporary_symbol(sig, (int)strlen(sig), THREAD)); | |
541 return TypeOrigin::implicit(vt); | |
542 } | |
543 | |
293 void ClassVerifier::verify_class(TRAPS) { | 544 void ClassVerifier::verify_class(TRAPS) { |
294 if (_verify_verbose) { | 545 if (VerboseVerification) { |
295 tty->print_cr("Verifying class %s with new format", | 546 tty->print_cr("Verifying class %s with new format", |
296 _klass->external_name()); | 547 _klass->external_name()); |
297 } | 548 } |
298 | 549 |
299 objArrayHandle methods(THREAD, _klass->methods()); | 550 objArrayHandle methods(THREAD, _klass->methods()); |
310 continue; | 561 continue; |
311 } | 562 } |
312 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); | 563 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); |
313 } | 564 } |
314 | 565 |
315 if (_verify_verbose || TraceClassInitialization) { | 566 if (VerboseVerification || TraceClassInitialization) { |
316 if (was_recursively_verified()) | 567 if (was_recursively_verified()) |
317 tty->print_cr("Recursive verification detected for: %s", | 568 tty->print_cr("Recursive verification detected for: %s", |
318 _klass->external_name()); | 569 _klass->external_name()); |
319 } | 570 } |
320 } | 571 } |
321 | 572 |
322 void ClassVerifier::verify_method(methodHandle m, TRAPS) { | 573 void ClassVerifier::verify_method(methodHandle m, TRAPS) { |
323 _method = m; // initialize _method | 574 _method = m; // initialize _method |
324 if (_verify_verbose) { | 575 if (VerboseVerification) { |
325 tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); | 576 tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); |
326 } | 577 } |
327 | 578 |
328 const char* bad_type_msg = "Bad type on operand stack in %s"; | 579 const char* bad_type_msg = "Bad type on operand stack in %s"; |
329 | 580 |
366 StackMapStream stream(stackmap_data); | 617 StackMapStream stream(stackmap_data); |
367 StackMapReader reader(this, &stream, code_data, code_length, THREAD); | 618 StackMapReader reader(this, &stream, code_data, code_length, THREAD); |
368 StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, | 619 StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, |
369 code_data, code_length, CHECK_VERIFY(this)); | 620 code_data, code_length, CHECK_VERIFY(this)); |
370 | 621 |
371 if (_verify_verbose) { | 622 if (VerboseVerification) { |
372 stackmap_table.print(); | 623 stackmap_table.print_on(tty); |
373 } | 624 } |
374 | 625 |
375 RawBytecodeStream bcs(m); | 626 RawBytecodeStream bcs(m); |
376 | 627 |
377 // Scan the byte code linearly from the start to the end | 628 // Scan the byte code linearly from the start to the end |
386 opcode = bcs.raw_next(); | 637 opcode = bcs.raw_next(); |
387 u2 bci = bcs.bci(); | 638 u2 bci = bcs.bci(); |
388 | 639 |
389 // Set current frame's offset to bci | 640 // Set current frame's offset to bci |
390 current_frame.set_offset(bci); | 641 current_frame.set_offset(bci); |
642 current_frame.set_mark(); | |
391 | 643 |
392 // Make sure every offset in stackmap table point to the beginning to | 644 // Make sure every offset in stackmap table point to the beginning to |
393 // an instruction. Match current_frame to stackmap_table entry with | 645 // an instruction. Match current_frame to stackmap_table entry with |
394 // the same offset if exists. | 646 // the same offset if exists. |
395 stackmap_index = verify_stackmap_table( | 647 stackmap_index = verify_stackmap_table( |
396 stackmap_index, bci, ¤t_frame, &stackmap_table, | 648 stackmap_index, bci, ¤t_frame, &stackmap_table, |
397 no_control_flow, CHECK_VERIFY(this)); | 649 no_control_flow, CHECK_VERIFY(this)); |
398 | 650 |
651 | |
399 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' | 652 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' |
400 | 653 |
401 // Merge with the next instruction | 654 // Merge with the next instruction |
402 { | 655 { |
403 u2 index; | 656 u2 index; |
404 int target; | 657 int target; |
405 VerificationType type, type2; | 658 VerificationType type, type2; |
406 VerificationType atype; | 659 VerificationType atype; |
407 | 660 |
408 #ifndef PRODUCT | 661 #ifndef PRODUCT |
409 if (_verify_verbose) { | 662 if (VerboseVerification) { |
410 current_frame.print(); | 663 current_frame.print_on(tty); |
411 tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); | 664 tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); |
412 } | 665 } |
413 #endif | 666 #endif |
414 | 667 |
415 // Make sure wide instruction is in correct format | 668 // Make sure wide instruction is in correct format |
418 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && | 671 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && |
419 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && | 672 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && |
420 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && | 673 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && |
421 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && | 674 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && |
422 opcode != Bytecodes::_dstore) { | 675 opcode != Bytecodes::_dstore) { |
423 verify_error(bci, "Bad wide instruction"); | 676 /* Unreachable? RawBytecodeStream's raw_next() returns 'illegal' |
677 * if we encounter a wide instruction that modifies an invalid | |
678 * opcode (not one of the ones listed above) */ | |
679 verify_error(ErrorContext::bad_code(bci), "Bad wide instruction"); | |
424 return; | 680 return; |
425 } | 681 } |
426 } | 682 } |
427 | 683 |
428 switch (opcode) { | 684 switch (opcode) { |
530 type = current_frame.pop_stack( | 786 type = current_frame.pop_stack( |
531 VerificationType::integer_type(), CHECK_VERIFY(this)); | 787 VerificationType::integer_type(), CHECK_VERIFY(this)); |
532 atype = current_frame.pop_stack( | 788 atype = current_frame.pop_stack( |
533 VerificationType::reference_check(), CHECK_VERIFY(this)); | 789 VerificationType::reference_check(), CHECK_VERIFY(this)); |
534 if (!atype.is_int_array()) { | 790 if (!atype.is_int_array()) { |
535 verify_error(bci, bad_type_msg, "iaload"); | 791 verify_error(ErrorContext::bad_type(bci, |
792 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), | |
793 bad_type_msg, "iaload"); | |
536 return; | 794 return; |
537 } | 795 } |
538 current_frame.push_stack( | 796 current_frame.push_stack( |
539 VerificationType::integer_type(), CHECK_VERIFY(this)); | 797 VerificationType::integer_type(), CHECK_VERIFY(this)); |
540 no_control_flow = false; break; | 798 no_control_flow = false; break; |
542 type = current_frame.pop_stack( | 800 type = current_frame.pop_stack( |
543 VerificationType::integer_type(), CHECK_VERIFY(this)); | 801 VerificationType::integer_type(), CHECK_VERIFY(this)); |
544 atype = current_frame.pop_stack( | 802 atype = current_frame.pop_stack( |
545 VerificationType::reference_check(), CHECK_VERIFY(this)); | 803 VerificationType::reference_check(), CHECK_VERIFY(this)); |
546 if (!atype.is_bool_array() && !atype.is_byte_array()) { | 804 if (!atype.is_bool_array() && !atype.is_byte_array()) { |
547 verify_error(bci, bad_type_msg, "baload"); | 805 verify_error( |
806 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
807 bad_type_msg, "baload"); | |
548 return; | 808 return; |
549 } | 809 } |
550 current_frame.push_stack( | 810 current_frame.push_stack( |
551 VerificationType::integer_type(), CHECK_VERIFY(this)); | 811 VerificationType::integer_type(), CHECK_VERIFY(this)); |
552 no_control_flow = false; break; | 812 no_control_flow = false; break; |
554 type = current_frame.pop_stack( | 814 type = current_frame.pop_stack( |
555 VerificationType::integer_type(), CHECK_VERIFY(this)); | 815 VerificationType::integer_type(), CHECK_VERIFY(this)); |
556 atype = current_frame.pop_stack( | 816 atype = current_frame.pop_stack( |
557 VerificationType::reference_check(), CHECK_VERIFY(this)); | 817 VerificationType::reference_check(), CHECK_VERIFY(this)); |
558 if (!atype.is_char_array()) { | 818 if (!atype.is_char_array()) { |
559 verify_error(bci, bad_type_msg, "caload"); | 819 verify_error(ErrorContext::bad_type(bci, |
820 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), | |
821 bad_type_msg, "caload"); | |
560 return; | 822 return; |
561 } | 823 } |
562 current_frame.push_stack( | 824 current_frame.push_stack( |
563 VerificationType::integer_type(), CHECK_VERIFY(this)); | 825 VerificationType::integer_type(), CHECK_VERIFY(this)); |
564 no_control_flow = false; break; | 826 no_control_flow = false; break; |
566 type = current_frame.pop_stack( | 828 type = current_frame.pop_stack( |
567 VerificationType::integer_type(), CHECK_VERIFY(this)); | 829 VerificationType::integer_type(), CHECK_VERIFY(this)); |
568 atype = current_frame.pop_stack( | 830 atype = current_frame.pop_stack( |
569 VerificationType::reference_check(), CHECK_VERIFY(this)); | 831 VerificationType::reference_check(), CHECK_VERIFY(this)); |
570 if (!atype.is_short_array()) { | 832 if (!atype.is_short_array()) { |
571 verify_error(bci, bad_type_msg, "saload"); | 833 verify_error(ErrorContext::bad_type(bci, |
834 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), | |
835 bad_type_msg, "saload"); | |
572 return; | 836 return; |
573 } | 837 } |
574 current_frame.push_stack( | 838 current_frame.push_stack( |
575 VerificationType::integer_type(), CHECK_VERIFY(this)); | 839 VerificationType::integer_type(), CHECK_VERIFY(this)); |
576 no_control_flow = false; break; | 840 no_control_flow = false; break; |
578 type = current_frame.pop_stack( | 842 type = current_frame.pop_stack( |
579 VerificationType::integer_type(), CHECK_VERIFY(this)); | 843 VerificationType::integer_type(), CHECK_VERIFY(this)); |
580 atype = current_frame.pop_stack( | 844 atype = current_frame.pop_stack( |
581 VerificationType::reference_check(), CHECK_VERIFY(this)); | 845 VerificationType::reference_check(), CHECK_VERIFY(this)); |
582 if (!atype.is_long_array()) { | 846 if (!atype.is_long_array()) { |
583 verify_error(bci, bad_type_msg, "laload"); | 847 verify_error(ErrorContext::bad_type(bci, |
848 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), | |
849 bad_type_msg, "laload"); | |
584 return; | 850 return; |
585 } | 851 } |
586 current_frame.push_stack_2( | 852 current_frame.push_stack_2( |
587 VerificationType::long_type(), | 853 VerificationType::long_type(), |
588 VerificationType::long2_type(), CHECK_VERIFY(this)); | 854 VerificationType::long2_type(), CHECK_VERIFY(this)); |
591 type = current_frame.pop_stack( | 857 type = current_frame.pop_stack( |
592 VerificationType::integer_type(), CHECK_VERIFY(this)); | 858 VerificationType::integer_type(), CHECK_VERIFY(this)); |
593 atype = current_frame.pop_stack( | 859 atype = current_frame.pop_stack( |
594 VerificationType::reference_check(), CHECK_VERIFY(this)); | 860 VerificationType::reference_check(), CHECK_VERIFY(this)); |
595 if (!atype.is_float_array()) { | 861 if (!atype.is_float_array()) { |
596 verify_error(bci, bad_type_msg, "faload"); | 862 verify_error(ErrorContext::bad_type(bci, |
863 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), | |
864 bad_type_msg, "faload"); | |
597 return; | 865 return; |
598 } | 866 } |
599 current_frame.push_stack( | 867 current_frame.push_stack( |
600 VerificationType::float_type(), CHECK_VERIFY(this)); | 868 VerificationType::float_type(), CHECK_VERIFY(this)); |
601 no_control_flow = false; break; | 869 no_control_flow = false; break; |
603 type = current_frame.pop_stack( | 871 type = current_frame.pop_stack( |
604 VerificationType::integer_type(), CHECK_VERIFY(this)); | 872 VerificationType::integer_type(), CHECK_VERIFY(this)); |
605 atype = current_frame.pop_stack( | 873 atype = current_frame.pop_stack( |
606 VerificationType::reference_check(), CHECK_VERIFY(this)); | 874 VerificationType::reference_check(), CHECK_VERIFY(this)); |
607 if (!atype.is_double_array()) { | 875 if (!atype.is_double_array()) { |
608 verify_error(bci, bad_type_msg, "daload"); | 876 verify_error(ErrorContext::bad_type(bci, |
877 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), | |
878 bad_type_msg, "daload"); | |
609 return; | 879 return; |
610 } | 880 } |
611 current_frame.push_stack_2( | 881 current_frame.push_stack_2( |
612 VerificationType::double_type(), | 882 VerificationType::double_type(), |
613 VerificationType::double2_type(), CHECK_VERIFY(this)); | 883 VerificationType::double2_type(), CHECK_VERIFY(this)); |
616 type = current_frame.pop_stack( | 886 type = current_frame.pop_stack( |
617 VerificationType::integer_type(), CHECK_VERIFY(this)); | 887 VerificationType::integer_type(), CHECK_VERIFY(this)); |
618 atype = current_frame.pop_stack( | 888 atype = current_frame.pop_stack( |
619 VerificationType::reference_check(), CHECK_VERIFY(this)); | 889 VerificationType::reference_check(), CHECK_VERIFY(this)); |
620 if (!atype.is_reference_array()) { | 890 if (!atype.is_reference_array()) { |
621 verify_error(bci, bad_type_msg, "aaload"); | 891 verify_error(ErrorContext::bad_type(bci, |
892 current_frame.stack_top_ctx(), | |
893 TypeOrigin::implicit(VerificationType::reference_check())), | |
894 bad_type_msg, "aaload"); | |
622 return; | 895 return; |
623 } | 896 } |
624 if (atype.is_null()) { | 897 if (atype.is_null()) { |
625 current_frame.push_stack( | 898 current_frame.push_stack( |
626 VerificationType::null_type(), CHECK_VERIFY(this)); | 899 VerificationType::null_type(), CHECK_VERIFY(this)); |
687 type2 = current_frame.pop_stack( | 960 type2 = current_frame.pop_stack( |
688 VerificationType::integer_type(), CHECK_VERIFY(this)); | 961 VerificationType::integer_type(), CHECK_VERIFY(this)); |
689 atype = current_frame.pop_stack( | 962 atype = current_frame.pop_stack( |
690 VerificationType::reference_check(), CHECK_VERIFY(this)); | 963 VerificationType::reference_check(), CHECK_VERIFY(this)); |
691 if (!atype.is_int_array()) { | 964 if (!atype.is_int_array()) { |
692 verify_error(bci, bad_type_msg, "iastore"); | 965 verify_error(ErrorContext::bad_type(bci, |
966 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), | |
967 bad_type_msg, "iastore"); | |
693 return; | 968 return; |
694 } | 969 } |
695 no_control_flow = false; break; | 970 no_control_flow = false; break; |
696 case Bytecodes::_bastore : | 971 case Bytecodes::_bastore : |
697 type = current_frame.pop_stack( | 972 type = current_frame.pop_stack( |
699 type2 = current_frame.pop_stack( | 974 type2 = current_frame.pop_stack( |
700 VerificationType::integer_type(), CHECK_VERIFY(this)); | 975 VerificationType::integer_type(), CHECK_VERIFY(this)); |
701 atype = current_frame.pop_stack( | 976 atype = current_frame.pop_stack( |
702 VerificationType::reference_check(), CHECK_VERIFY(this)); | 977 VerificationType::reference_check(), CHECK_VERIFY(this)); |
703 if (!atype.is_bool_array() && !atype.is_byte_array()) { | 978 if (!atype.is_bool_array() && !atype.is_byte_array()) { |
704 verify_error(bci, bad_type_msg, "bastore"); | 979 verify_error( |
980 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
981 bad_type_msg, "bastore"); | |
705 return; | 982 return; |
706 } | 983 } |
707 no_control_flow = false; break; | 984 no_control_flow = false; break; |
708 case Bytecodes::_castore : | 985 case Bytecodes::_castore : |
709 current_frame.pop_stack( | 986 current_frame.pop_stack( |
711 current_frame.pop_stack( | 988 current_frame.pop_stack( |
712 VerificationType::integer_type(), CHECK_VERIFY(this)); | 989 VerificationType::integer_type(), CHECK_VERIFY(this)); |
713 atype = current_frame.pop_stack( | 990 atype = current_frame.pop_stack( |
714 VerificationType::reference_check(), CHECK_VERIFY(this)); | 991 VerificationType::reference_check(), CHECK_VERIFY(this)); |
715 if (!atype.is_char_array()) { | 992 if (!atype.is_char_array()) { |
716 verify_error(bci, bad_type_msg, "castore"); | 993 verify_error(ErrorContext::bad_type(bci, |
994 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), | |
995 bad_type_msg, "castore"); | |
717 return; | 996 return; |
718 } | 997 } |
719 no_control_flow = false; break; | 998 no_control_flow = false; break; |
720 case Bytecodes::_sastore : | 999 case Bytecodes::_sastore : |
721 current_frame.pop_stack( | 1000 current_frame.pop_stack( |
723 current_frame.pop_stack( | 1002 current_frame.pop_stack( |
724 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1003 VerificationType::integer_type(), CHECK_VERIFY(this)); |
725 atype = current_frame.pop_stack( | 1004 atype = current_frame.pop_stack( |
726 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1005 VerificationType::reference_check(), CHECK_VERIFY(this)); |
727 if (!atype.is_short_array()) { | 1006 if (!atype.is_short_array()) { |
728 verify_error(bci, bad_type_msg, "sastore"); | 1007 verify_error(ErrorContext::bad_type(bci, |
1008 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), | |
1009 bad_type_msg, "sastore"); | |
729 return; | 1010 return; |
730 } | 1011 } |
731 no_control_flow = false; break; | 1012 no_control_flow = false; break; |
732 case Bytecodes::_lastore : | 1013 case Bytecodes::_lastore : |
733 current_frame.pop_stack_2( | 1014 current_frame.pop_stack_2( |
736 current_frame.pop_stack( | 1017 current_frame.pop_stack( |
737 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1018 VerificationType::integer_type(), CHECK_VERIFY(this)); |
738 atype = current_frame.pop_stack( | 1019 atype = current_frame.pop_stack( |
739 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1020 VerificationType::reference_check(), CHECK_VERIFY(this)); |
740 if (!atype.is_long_array()) { | 1021 if (!atype.is_long_array()) { |
741 verify_error(bci, bad_type_msg, "lastore"); | 1022 verify_error(ErrorContext::bad_type(bci, |
1023 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), | |
1024 bad_type_msg, "lastore"); | |
742 return; | 1025 return; |
743 } | 1026 } |
744 no_control_flow = false; break; | 1027 no_control_flow = false; break; |
745 case Bytecodes::_fastore : | 1028 case Bytecodes::_fastore : |
746 current_frame.pop_stack( | 1029 current_frame.pop_stack( |
748 current_frame.pop_stack | 1031 current_frame.pop_stack |
749 (VerificationType::integer_type(), CHECK_VERIFY(this)); | 1032 (VerificationType::integer_type(), CHECK_VERIFY(this)); |
750 atype = current_frame.pop_stack( | 1033 atype = current_frame.pop_stack( |
751 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1034 VerificationType::reference_check(), CHECK_VERIFY(this)); |
752 if (!atype.is_float_array()) { | 1035 if (!atype.is_float_array()) { |
753 verify_error(bci, bad_type_msg, "fastore"); | 1036 verify_error(ErrorContext::bad_type(bci, |
1037 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), | |
1038 bad_type_msg, "fastore"); | |
754 return; | 1039 return; |
755 } | 1040 } |
756 no_control_flow = false; break; | 1041 no_control_flow = false; break; |
757 case Bytecodes::_dastore : | 1042 case Bytecodes::_dastore : |
758 current_frame.pop_stack_2( | 1043 current_frame.pop_stack_2( |
761 current_frame.pop_stack( | 1046 current_frame.pop_stack( |
762 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1047 VerificationType::integer_type(), CHECK_VERIFY(this)); |
763 atype = current_frame.pop_stack( | 1048 atype = current_frame.pop_stack( |
764 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1049 VerificationType::reference_check(), CHECK_VERIFY(this)); |
765 if (!atype.is_double_array()) { | 1050 if (!atype.is_double_array()) { |
766 verify_error(bci, bad_type_msg, "dastore"); | 1051 verify_error(ErrorContext::bad_type(bci, |
1052 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), | |
1053 bad_type_msg, "dastore"); | |
767 return; | 1054 return; |
768 } | 1055 } |
769 no_control_flow = false; break; | 1056 no_control_flow = false; break; |
770 case Bytecodes::_aastore : | 1057 case Bytecodes::_aastore : |
771 type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); | 1058 type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); |
773 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1060 VerificationType::integer_type(), CHECK_VERIFY(this)); |
774 atype = current_frame.pop_stack( | 1061 atype = current_frame.pop_stack( |
775 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1062 VerificationType::reference_check(), CHECK_VERIFY(this)); |
776 // more type-checking is done at runtime | 1063 // more type-checking is done at runtime |
777 if (!atype.is_reference_array()) { | 1064 if (!atype.is_reference_array()) { |
778 verify_error(bci, bad_type_msg, "aastore"); | 1065 verify_error(ErrorContext::bad_type(bci, |
1066 current_frame.stack_top_ctx(), | |
1067 TypeOrigin::implicit(VerificationType::reference_check())), | |
1068 bad_type_msg, "aastore"); | |
779 return; | 1069 return; |
780 } | 1070 } |
781 // 4938384: relaxed constraint in JVMS 3nd edition. | 1071 // 4938384: relaxed constraint in JVMS 3nd edition. |
782 no_control_flow = false; break; | 1072 no_control_flow = false; break; |
783 case Bytecodes::_pop : | 1073 case Bytecodes::_pop : |
791 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1081 VerificationType::category1_check(), CHECK_VERIFY(this)); |
792 } else if (type.is_category2_2nd()) { | 1082 } else if (type.is_category2_2nd()) { |
793 current_frame.pop_stack( | 1083 current_frame.pop_stack( |
794 VerificationType::category2_check(), CHECK_VERIFY(this)); | 1084 VerificationType::category2_check(), CHECK_VERIFY(this)); |
795 } else { | 1085 } else { |
796 verify_error(bci, bad_type_msg, "pop2"); | 1086 /* Unreachable? Would need a category2_1st on TOS |
1087 * which does not appear possible. */ | |
1088 verify_error( | |
1089 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
1090 bad_type_msg, "pop2"); | |
797 return; | 1091 return; |
798 } | 1092 } |
799 no_control_flow = false; break; | 1093 no_control_flow = false; break; |
800 case Bytecodes::_dup : | 1094 case Bytecodes::_dup : |
801 type = current_frame.pop_stack( | 1095 type = current_frame.pop_stack( |
823 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1117 VerificationType::category1_check(), CHECK_VERIFY(this)); |
824 } else if (type2.is_category2_2nd()) { | 1118 } else if (type2.is_category2_2nd()) { |
825 type3 = current_frame.pop_stack( | 1119 type3 = current_frame.pop_stack( |
826 VerificationType::category2_check(), CHECK_VERIFY(this)); | 1120 VerificationType::category2_check(), CHECK_VERIFY(this)); |
827 } else { | 1121 } else { |
828 verify_error(bci, bad_type_msg, "dup_x2"); | 1122 /* Unreachable? Would need a category2_1st at stack depth 2 with |
1123 * a category1 on TOS which does not appear possible. */ | |
1124 verify_error(ErrorContext::bad_type( | |
1125 bci, current_frame.stack_top_ctx()), bad_type_msg, "dup_x2"); | |
829 return; | 1126 return; |
830 } | 1127 } |
831 current_frame.push_stack(type, CHECK_VERIFY(this)); | 1128 current_frame.push_stack(type, CHECK_VERIFY(this)); |
832 current_frame.push_stack(type3, CHECK_VERIFY(this)); | 1129 current_frame.push_stack(type3, CHECK_VERIFY(this)); |
833 current_frame.push_stack(type2, CHECK_VERIFY(this)); | 1130 current_frame.push_stack(type2, CHECK_VERIFY(this)); |
841 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1138 VerificationType::category1_check(), CHECK_VERIFY(this)); |
842 } else if (type.is_category2_2nd()) { | 1139 } else if (type.is_category2_2nd()) { |
843 type2 = current_frame.pop_stack( | 1140 type2 = current_frame.pop_stack( |
844 VerificationType::category2_check(), CHECK_VERIFY(this)); | 1141 VerificationType::category2_check(), CHECK_VERIFY(this)); |
845 } else { | 1142 } else { |
846 verify_error(bci, bad_type_msg, "dup2"); | 1143 /* Unreachable? Would need a category2_1st on TOS which does not |
1144 * appear possible. */ | |
1145 verify_error( | |
1146 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
1147 bad_type_msg, "dup2"); | |
847 return; | 1148 return; |
848 } | 1149 } |
849 current_frame.push_stack(type2, CHECK_VERIFY(this)); | 1150 current_frame.push_stack(type2, CHECK_VERIFY(this)); |
850 current_frame.push_stack(type, CHECK_VERIFY(this)); | 1151 current_frame.push_stack(type, CHECK_VERIFY(this)); |
851 current_frame.push_stack(type2, CHECK_VERIFY(this)); | 1152 current_frame.push_stack(type2, CHECK_VERIFY(this)); |
856 VerificationType type3; | 1157 VerificationType type3; |
857 type = current_frame.pop_stack(CHECK_VERIFY(this)); | 1158 type = current_frame.pop_stack(CHECK_VERIFY(this)); |
858 if (type.is_category1()) { | 1159 if (type.is_category1()) { |
859 type2 = current_frame.pop_stack( | 1160 type2 = current_frame.pop_stack( |
860 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1161 VerificationType::category1_check(), CHECK_VERIFY(this)); |
861 } else if(type.is_category2_2nd()) { | 1162 } else if (type.is_category2_2nd()) { |
862 type2 = current_frame.pop_stack | 1163 type2 = current_frame.pop_stack( |
863 (VerificationType::category2_check(), CHECK_VERIFY(this)); | 1164 VerificationType::category2_check(), CHECK_VERIFY(this)); |
864 } else { | 1165 } else { |
865 verify_error(bci, bad_type_msg, "dup2_x1"); | 1166 /* Unreachable? Would need a category2_1st on TOS which does |
1167 * not appear possible. */ | |
1168 verify_error( | |
1169 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
1170 bad_type_msg, "dup2_x1"); | |
866 return; | 1171 return; |
867 } | 1172 } |
868 type3 = current_frame.pop_stack( | 1173 type3 = current_frame.pop_stack( |
869 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1174 VerificationType::category1_check(), CHECK_VERIFY(this)); |
870 current_frame.push_stack(type2, CHECK_VERIFY(this)); | 1175 current_frame.push_stack(type2, CHECK_VERIFY(this)); |
883 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1188 VerificationType::category1_check(), CHECK_VERIFY(this)); |
884 } else if (type.is_category2_2nd()) { | 1189 } else if (type.is_category2_2nd()) { |
885 type2 = current_frame.pop_stack( | 1190 type2 = current_frame.pop_stack( |
886 VerificationType::category2_check(), CHECK_VERIFY(this)); | 1191 VerificationType::category2_check(), CHECK_VERIFY(this)); |
887 } else { | 1192 } else { |
888 verify_error(bci, bad_type_msg, "dup2_x2"); | 1193 /* Unreachable? Would need a category2_1st on TOS which does |
1194 * not appear possible. */ | |
1195 verify_error( | |
1196 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
1197 bad_type_msg, "dup2_x2"); | |
889 return; | 1198 return; |
890 } | 1199 } |
891 type3 = current_frame.pop_stack(CHECK_VERIFY(this)); | 1200 type3 = current_frame.pop_stack(CHECK_VERIFY(this)); |
892 if (type3.is_category1()) { | 1201 if (type3.is_category1()) { |
893 type4 = current_frame.pop_stack( | 1202 type4 = current_frame.pop_stack( |
894 VerificationType::category1_check(), CHECK_VERIFY(this)); | 1203 VerificationType::category1_check(), CHECK_VERIFY(this)); |
895 } else if (type3.is_category2_2nd()) { | 1204 } else if (type3.is_category2_2nd()) { |
896 type4 = current_frame.pop_stack( | 1205 type4 = current_frame.pop_stack( |
897 VerificationType::category2_check(), CHECK_VERIFY(this)); | 1206 VerificationType::category2_check(), CHECK_VERIFY(this)); |
898 } else { | 1207 } else { |
899 verify_error(bci, bad_type_msg, "dup2_x2"); | 1208 /* Unreachable? Would need a category2_1st on TOS after popping |
1209 * a long/double or two category 1's, which does not | |
1210 * appear possible. */ | |
1211 verify_error( | |
1212 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), | |
1213 bad_type_msg, "dup2_x2"); | |
900 return; | 1214 return; |
901 } | 1215 } |
902 current_frame.push_stack(type2, CHECK_VERIFY(this)); | 1216 current_frame.push_stack(type2, CHECK_VERIFY(this)); |
903 current_frame.push_stack(type, CHECK_VERIFY(this)); | 1217 current_frame.push_stack(type, CHECK_VERIFY(this)); |
904 current_frame.push_stack(type4, CHECK_VERIFY(this)); | 1218 current_frame.push_stack(type4, CHECK_VERIFY(this)); |
1174 &stackmap_table, CHECK_VERIFY(this)); | 1488 &stackmap_table, CHECK_VERIFY(this)); |
1175 no_control_flow = true; break; | 1489 no_control_flow = true; break; |
1176 case Bytecodes::_ireturn : | 1490 case Bytecodes::_ireturn : |
1177 type = current_frame.pop_stack( | 1491 type = current_frame.pop_stack( |
1178 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1492 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1179 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | 1493 verify_return_value(return_type, type, bci, |
1494 ¤t_frame, CHECK_VERIFY(this)); | |
1180 no_control_flow = true; break; | 1495 no_control_flow = true; break; |
1181 case Bytecodes::_lreturn : | 1496 case Bytecodes::_lreturn : |
1182 type2 = current_frame.pop_stack( | 1497 type2 = current_frame.pop_stack( |
1183 VerificationType::long2_type(), CHECK_VERIFY(this)); | 1498 VerificationType::long2_type(), CHECK_VERIFY(this)); |
1184 type = current_frame.pop_stack( | 1499 type = current_frame.pop_stack( |
1185 VerificationType::long_type(), CHECK_VERIFY(this)); | 1500 VerificationType::long_type(), CHECK_VERIFY(this)); |
1186 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | 1501 verify_return_value(return_type, type, bci, |
1502 ¤t_frame, CHECK_VERIFY(this)); | |
1187 no_control_flow = true; break; | 1503 no_control_flow = true; break; |
1188 case Bytecodes::_freturn : | 1504 case Bytecodes::_freturn : |
1189 type = current_frame.pop_stack( | 1505 type = current_frame.pop_stack( |
1190 VerificationType::float_type(), CHECK_VERIFY(this)); | 1506 VerificationType::float_type(), CHECK_VERIFY(this)); |
1191 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | 1507 verify_return_value(return_type, type, bci, |
1508 ¤t_frame, CHECK_VERIFY(this)); | |
1192 no_control_flow = true; break; | 1509 no_control_flow = true; break; |
1193 case Bytecodes::_dreturn : | 1510 case Bytecodes::_dreturn : |
1194 type2 = current_frame.pop_stack( | 1511 type2 = current_frame.pop_stack( |
1195 VerificationType::double2_type(), CHECK_VERIFY(this)); | 1512 VerificationType::double2_type(), CHECK_VERIFY(this)); |
1196 type = current_frame.pop_stack( | 1513 type = current_frame.pop_stack( |
1197 VerificationType::double_type(), CHECK_VERIFY(this)); | 1514 VerificationType::double_type(), CHECK_VERIFY(this)); |
1198 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | 1515 verify_return_value(return_type, type, bci, |
1516 ¤t_frame, CHECK_VERIFY(this)); | |
1199 no_control_flow = true; break; | 1517 no_control_flow = true; break; |
1200 case Bytecodes::_areturn : | 1518 case Bytecodes::_areturn : |
1201 type = current_frame.pop_stack( | 1519 type = current_frame.pop_stack( |
1202 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1520 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1203 verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); | 1521 verify_return_value(return_type, type, bci, |
1522 ¤t_frame, CHECK_VERIFY(this)); | |
1204 no_control_flow = true; break; | 1523 no_control_flow = true; break; |
1205 case Bytecodes::_return : | 1524 case Bytecodes::_return : |
1206 if (return_type != VerificationType::bogus_type()) { | 1525 if (return_type != VerificationType::bogus_type()) { |
1207 verify_error(bci, "Method expects no return value"); | 1526 verify_error(ErrorContext::bad_code(bci), |
1527 "Method expects a return value"); | |
1208 return; | 1528 return; |
1209 } | 1529 } |
1210 // Make sure "this" has been initialized if current method is an | 1530 // Make sure "this" has been initialized if current method is an |
1211 // <init> | 1531 // <init> |
1212 if (_method->name() == vmSymbols::object_initializer_name() && | 1532 if (_method->name() == vmSymbols::object_initializer_name() && |
1213 current_frame.flag_this_uninit()) { | 1533 current_frame.flag_this_uninit()) { |
1214 verify_error(bci, | 1534 verify_error(ErrorContext::bad_code(bci), |
1215 "Constructor must call super() or this() before return"); | 1535 "Constructor must call super() or this() " |
1536 "before return"); | |
1216 return; | 1537 return; |
1217 } | 1538 } |
1218 no_control_flow = true; break; | 1539 no_control_flow = true; break; |
1219 case Bytecodes::_getstatic : | 1540 case Bytecodes::_getstatic : |
1220 case Bytecodes::_putstatic : | 1541 case Bytecodes::_putstatic : |
1237 &this_uninit, return_type, cp, CHECK_VERIFY(this)); | 1558 &this_uninit, return_type, cp, CHECK_VERIFY(this)); |
1238 no_control_flow = false; break; | 1559 no_control_flow = false; break; |
1239 case Bytecodes::_new : | 1560 case Bytecodes::_new : |
1240 { | 1561 { |
1241 index = bcs.get_index_u2(); | 1562 index = bcs.get_index_u2(); |
1242 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1563 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); |
1243 VerificationType new_class_type = | 1564 VerificationType new_class_type = |
1244 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | 1565 cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
1245 if (!new_class_type.is_object()) { | 1566 if (!new_class_type.is_object()) { |
1246 verify_error(bci, "Illegal new instruction"); | 1567 verify_error(ErrorContext::bad_type(bci, |
1568 TypeOrigin::cp(index, new_class_type)), | |
1569 "Illegal new instruction"); | |
1247 return; | 1570 return; |
1248 } | 1571 } |
1249 type = VerificationType::uninitialized_type(bci); | 1572 type = VerificationType::uninitialized_type(bci); |
1250 current_frame.push_stack(type, CHECK_VERIFY(this)); | 1573 current_frame.push_stack(type, CHECK_VERIFY(this)); |
1251 no_control_flow = false; break; | 1574 no_control_flow = false; break; |
1256 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1579 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1257 current_frame.push_stack(type, CHECK_VERIFY(this)); | 1580 current_frame.push_stack(type, CHECK_VERIFY(this)); |
1258 no_control_flow = false; break; | 1581 no_control_flow = false; break; |
1259 case Bytecodes::_anewarray : | 1582 case Bytecodes::_anewarray : |
1260 verify_anewarray( | 1583 verify_anewarray( |
1261 bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); | 1584 bci, bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); |
1262 no_control_flow = false; break; | 1585 no_control_flow = false; break; |
1263 case Bytecodes::_arraylength : | 1586 case Bytecodes::_arraylength : |
1264 type = current_frame.pop_stack( | 1587 type = current_frame.pop_stack( |
1265 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1588 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1266 if (!(type.is_null() || type.is_array())) { | 1589 if (!(type.is_null() || type.is_array())) { |
1267 verify_error(bci, bad_type_msg, "arraylength"); | 1590 verify_error(ErrorContext::bad_type( |
1591 bci, current_frame.stack_top_ctx()), | |
1592 bad_type_msg, "arraylength"); | |
1268 } | 1593 } |
1269 current_frame.push_stack( | 1594 current_frame.push_stack( |
1270 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1595 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1271 no_control_flow = false; break; | 1596 no_control_flow = false; break; |
1272 case Bytecodes::_checkcast : | 1597 case Bytecodes::_checkcast : |
1273 { | 1598 { |
1274 index = bcs.get_index_u2(); | 1599 index = bcs.get_index_u2(); |
1275 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1600 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); |
1276 current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); | 1601 current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); |
1277 VerificationType klass_type = cp_index_to_type( | 1602 VerificationType klass_type = cp_index_to_type( |
1278 index, cp, CHECK_VERIFY(this)); | 1603 index, cp, CHECK_VERIFY(this)); |
1279 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); | 1604 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); |
1280 no_control_flow = false; break; | 1605 no_control_flow = false; break; |
1281 } | 1606 } |
1282 case Bytecodes::_instanceof : { | 1607 case Bytecodes::_instanceof : { |
1283 index = bcs.get_index_u2(); | 1608 index = bcs.get_index_u2(); |
1284 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1609 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); |
1285 current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); | 1610 current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); |
1286 current_frame.push_stack( | 1611 current_frame.push_stack( |
1287 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1612 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1288 no_control_flow = false; break; | 1613 no_control_flow = false; break; |
1289 } | 1614 } |
1294 no_control_flow = false; break; | 1619 no_control_flow = false; break; |
1295 case Bytecodes::_multianewarray : | 1620 case Bytecodes::_multianewarray : |
1296 { | 1621 { |
1297 index = bcs.get_index_u2(); | 1622 index = bcs.get_index_u2(); |
1298 u2 dim = *(bcs.bcp()+3); | 1623 u2 dim = *(bcs.bcp()+3); |
1299 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1624 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); |
1300 VerificationType new_array_type = | 1625 VerificationType new_array_type = |
1301 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | 1626 cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
1302 if (!new_array_type.is_array()) { | 1627 if (!new_array_type.is_array()) { |
1303 verify_error(bci, | 1628 verify_error(ErrorContext::bad_type(bci, |
1304 "Illegal constant pool index in multianewarray instruction"); | 1629 TypeOrigin::cp(index, new_array_type)), |
1630 "Illegal constant pool index in multianewarray instruction"); | |
1305 return; | 1631 return; |
1306 } | 1632 } |
1307 if (dim < 1 || new_array_type.dimensions() < dim) { | 1633 if (dim < 1 || new_array_type.dimensions() < dim) { |
1308 verify_error(bci, | 1634 verify_error(ErrorContext::bad_code(bci), |
1309 "Illegal dimension in multianewarray instruction"); | 1635 "Illegal dimension in multianewarray instruction: %d", dim); |
1310 return; | 1636 return; |
1311 } | 1637 } |
1312 for (int i = 0; i < dim; i++) { | 1638 for (int i = 0; i < dim; i++) { |
1313 current_frame.pop_stack( | 1639 current_frame.pop_stack( |
1314 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1640 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1322 current_frame.pop_stack(type, CHECK_VERIFY(this)); | 1648 current_frame.pop_stack(type, CHECK_VERIFY(this)); |
1323 no_control_flow = true; break; | 1649 no_control_flow = true; break; |
1324 default: | 1650 default: |
1325 // We only need to check the valid bytecodes in class file. | 1651 // We only need to check the valid bytecodes in class file. |
1326 // And jsr and ret are not in the new class file format in JDK1.5. | 1652 // And jsr and ret are not in the new class file format in JDK1.5. |
1327 verify_error(bci, "Bad instruction"); | 1653 verify_error(ErrorContext::bad_code(bci), |
1654 "Bad instruction: %02x", opcode); | |
1328 no_control_flow = false; | 1655 no_control_flow = false; |
1329 return; | 1656 return; |
1330 } // end switch | 1657 } // end switch |
1331 } // end Merge with the next instruction | 1658 } // end Merge with the next instruction |
1332 | 1659 |
1338 } | 1665 } |
1339 } // end while | 1666 } // end while |
1340 | 1667 |
1341 // Make sure that control flow does not fall through end of the method | 1668 // Make sure that control flow does not fall through end of the method |
1342 if (!no_control_flow) { | 1669 if (!no_control_flow) { |
1343 verify_error(code_length, "Control flow falls through code end"); | 1670 verify_error(ErrorContext::bad_code(code_length), |
1671 "Control flow falls through code end"); | |
1344 return; | 1672 return; |
1345 } | 1673 } |
1346 } | 1674 } |
1347 | 1675 |
1348 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { | 1676 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { |
1357 code_data[bci] = NEW_OFFSET; | 1685 code_data[bci] = NEW_OFFSET; |
1358 } else { | 1686 } else { |
1359 code_data[bci] = BYTECODE_OFFSET; | 1687 code_data[bci] = BYTECODE_OFFSET; |
1360 } | 1688 } |
1361 } else { | 1689 } else { |
1362 verify_error(bcs.bci(), "Bad instruction"); | 1690 verify_error(ErrorContext::bad_code(bcs.bci()), "Bad instruction"); |
1363 return NULL; | 1691 return NULL; |
1364 } | 1692 } |
1365 } | 1693 } |
1366 | 1694 |
1367 return code_data; | 1695 return code_data; |
1400 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); | 1728 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); |
1401 bool is_subclass = throwable.is_assignable_from( | 1729 bool is_subclass = throwable.is_assignable_from( |
1402 catch_type, this, CHECK_VERIFY(this)); | 1730 catch_type, this, CHECK_VERIFY(this)); |
1403 if (!is_subclass) { | 1731 if (!is_subclass) { |
1404 // 4286534: should throw VerifyError according to recent spec change | 1732 // 4286534: should throw VerifyError according to recent spec change |
1405 verify_error( | 1733 verify_error(ErrorContext::bad_type(handler_pc, |
1406 "Catch type is not a subclass of Throwable in handler %d", | 1734 TypeOrigin::cp(catch_type_index, catch_type), |
1407 handler_pc); | 1735 TypeOrigin::implicit(throwable)), |
1736 "Catch type is not a subclass " | |
1737 "of Throwable in exception handler %d", handler_pc); | |
1408 return; | 1738 return; |
1409 } | 1739 } |
1410 } | 1740 } |
1411 if (start_pc < min) min = start_pc; | 1741 if (start_pc < min) min = start_pc; |
1412 if (end_pc > max) max = end_pc; | 1742 if (end_pc > max) max = end_pc; |
1442 StackMapTable* stackmap_table, | 1772 StackMapTable* stackmap_table, |
1443 bool no_control_flow, TRAPS) { | 1773 bool no_control_flow, TRAPS) { |
1444 if (stackmap_index < stackmap_table->get_frame_count()) { | 1774 if (stackmap_index < stackmap_table->get_frame_count()) { |
1445 u2 this_offset = stackmap_table->get_offset(stackmap_index); | 1775 u2 this_offset = stackmap_table->get_offset(stackmap_index); |
1446 if (no_control_flow && this_offset > bci) { | 1776 if (no_control_flow && this_offset > bci) { |
1447 verify_error(bci, "Expecting a stack map frame"); | 1777 verify_error(ErrorContext::missing_stackmap(bci), |
1778 "Expecting a stack map frame"); | |
1448 return 0; | 1779 return 0; |
1449 } | 1780 } |
1450 if (this_offset == bci) { | 1781 if (this_offset == bci) { |
1782 ErrorContext ctx; | |
1451 // See if current stack map can be assigned to the frame in table. | 1783 // See if current stack map can be assigned to the frame in table. |
1452 // current_frame is the stackmap frame got from the last instruction. | 1784 // current_frame is the stackmap frame got from the last instruction. |
1453 // If matched, current_frame will be updated by this method. | 1785 // If matched, current_frame will be updated by this method. |
1454 bool match = stackmap_table->match_stackmap( | 1786 bool matches = stackmap_table->match_stackmap( |
1455 current_frame, this_offset, stackmap_index, | 1787 current_frame, this_offset, stackmap_index, |
1456 !no_control_flow, true, CHECK_VERIFY_(this, 0)); | 1788 !no_control_flow, true, &ctx, CHECK_VERIFY_(this, 0)); |
1457 if (!match) { | 1789 if (!matches) { |
1458 // report type error | 1790 // report type error |
1459 verify_error(bci, "Instruction type does not match stack map"); | 1791 verify_error(ctx, "Instruction type does not match stack map"); |
1460 return 0; | 1792 return 0; |
1461 } | 1793 } |
1462 stackmap_index++; | 1794 stackmap_index++; |
1463 } else if (this_offset < bci) { | 1795 } else if (this_offset < bci) { |
1464 // current_offset should have met this_offset. | 1796 // current_offset should have met this_offset. |
1465 class_format_error("Bad stack map offset %d", this_offset); | 1797 class_format_error("Bad stack map offset %d", this_offset); |
1466 return 0; | 1798 return 0; |
1467 } | 1799 } |
1468 } else if (no_control_flow) { | 1800 } else if (no_control_flow) { |
1469 verify_error(bci, "Expecting a stack map frame"); | 1801 verify_error(ErrorContext::bad_code(bci), "Expecting a stack map frame"); |
1470 return 0; | 1802 return 0; |
1471 } | 1803 } |
1472 return stackmap_index; | 1804 return stackmap_index; |
1473 } | 1805 } |
1474 | 1806 |
1496 } else { | 1828 } else { |
1497 VerificationType throwable = | 1829 VerificationType throwable = |
1498 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); | 1830 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); |
1499 new_frame->push_stack(throwable, CHECK_VERIFY(this)); | 1831 new_frame->push_stack(throwable, CHECK_VERIFY(this)); |
1500 } | 1832 } |
1501 bool match = stackmap_table->match_stackmap( | 1833 ErrorContext ctx; |
1502 new_frame, handler_pc, true, false, CHECK_VERIFY(this)); | 1834 bool matches = stackmap_table->match_stackmap( |
1503 if (!match) { | 1835 new_frame, handler_pc, true, false, &ctx, CHECK_VERIFY(this)); |
1504 verify_error(bci, | 1836 if (!matches) { |
1505 "Stack map does not match the one at exception handler %d", | 1837 verify_error(ctx, "Stack map does not match the one at " |
1506 handler_pc); | 1838 "exception handler %d", handler_pc); |
1507 return; | 1839 return; |
1508 } | 1840 } |
1509 } | 1841 } |
1510 } | 1842 } |
1511 } | 1843 } |
1512 | 1844 |
1513 void ClassVerifier::verify_cp_index(constantPoolHandle cp, int index, TRAPS) { | 1845 void ClassVerifier::verify_cp_index( |
1846 u2 bci, constantPoolHandle cp, int index, TRAPS) { | |
1514 int nconstants = cp->length(); | 1847 int nconstants = cp->length(); |
1515 if ((index <= 0) || (index >= nconstants)) { | 1848 if ((index <= 0) || (index >= nconstants)) { |
1516 verify_error("Illegal constant pool index %d in class %s", | 1849 verify_error(ErrorContext::bad_cp_index(bci, index), |
1517 index, instanceKlass::cast(cp->pool_holder())->external_name()); | 1850 "Illegal constant pool index %d in class %s", |
1851 index, instanceKlass::cast(cp->pool_holder())->external_name()); | |
1518 return; | 1852 return; |
1519 } | 1853 } |
1520 } | 1854 } |
1521 | 1855 |
1522 void ClassVerifier::verify_cp_type( | 1856 void ClassVerifier::verify_cp_type( |
1523 int index, constantPoolHandle cp, unsigned int types, TRAPS) { | 1857 u2 bci, int index, constantPoolHandle cp, unsigned int types, TRAPS) { |
1524 | 1858 |
1525 // In some situations, bytecode rewriting may occur while we're verifying. | 1859 // In some situations, bytecode rewriting may occur while we're verifying. |
1526 // In this case, a constant pool cache exists and some indices refer to that | 1860 // In this case, a constant pool cache exists and some indices refer to that |
1527 // instead. Be sure we don't pick up such indices by accident. | 1861 // instead. Be sure we don't pick up such indices by accident. |
1528 // We must check was_recursively_verified() before we get here. | 1862 // We must check was_recursively_verified() before we get here. |
1529 guarantee(cp->cache() == NULL, "not rewritten yet"); | 1863 guarantee(cp->cache() == NULL, "not rewritten yet"); |
1530 | 1864 |
1531 verify_cp_index(cp, index, CHECK_VERIFY(this)); | 1865 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); |
1532 unsigned int tag = cp->tag_at(index).value(); | 1866 unsigned int tag = cp->tag_at(index).value(); |
1533 if ((types & (1 << tag)) == 0) { | 1867 if ((types & (1 << tag)) == 0) { |
1534 verify_error( | 1868 verify_error(ErrorContext::bad_cp_index(bci, index), |
1535 "Illegal type at constant pool entry %d in class %s", | 1869 "Illegal type at constant pool entry %d in class %s", |
1536 index, instanceKlass::cast(cp->pool_holder())->external_name()); | 1870 index, instanceKlass::cast(cp->pool_holder())->external_name()); |
1537 return; | 1871 return; |
1538 } | 1872 } |
1539 } | 1873 } |
1540 | 1874 |
1541 void ClassVerifier::verify_cp_class_type( | 1875 void ClassVerifier::verify_cp_class_type( |
1542 int index, constantPoolHandle cp, TRAPS) { | 1876 u2 bci, int index, constantPoolHandle cp, TRAPS) { |
1543 verify_cp_index(cp, index, CHECK_VERIFY(this)); | 1877 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); |
1544 constantTag tag = cp->tag_at(index); | 1878 constantTag tag = cp->tag_at(index); |
1545 if (!tag.is_klass() && !tag.is_unresolved_klass()) { | 1879 if (!tag.is_klass() && !tag.is_unresolved_klass()) { |
1546 verify_error("Illegal type at constant pool entry %d in class %s", | 1880 verify_error(ErrorContext::bad_cp_index(bci, index), |
1547 index, instanceKlass::cast(cp->pool_holder())->external_name()); | 1881 "Illegal type at constant pool entry %d in class %s", |
1882 index, instanceKlass::cast(cp->pool_holder())->external_name()); | |
1548 return; | 1883 return; |
1549 } | 1884 } |
1550 } | 1885 } |
1551 | 1886 |
1552 void ClassVerifier::format_error_message( | 1887 void ClassVerifier::verify_error(ErrorContext ctx, const char* msg, ...) { |
1553 const char* fmt, int offset, va_list va) { | 1888 stringStream ss; |
1554 ResourceMark rm(_thread); | 1889 |
1555 stringStream message(_message, _message_buffer_len); | 1890 ctx.reset_frames(); |
1556 message.vprint(fmt, va); | |
1557 if (!_method.is_null()) { | |
1558 message.print(" in method %s", _method->name_and_sig_as_C_string()); | |
1559 } | |
1560 if (offset != -1) { | |
1561 message.print(" at offset %d", offset); | |
1562 } | |
1563 } | |
1564 | |
1565 void ClassVerifier::verify_error(u2 offset, const char* fmt, ...) { | |
1566 _exception_type = vmSymbols::java_lang_VerifyError(); | 1891 _exception_type = vmSymbols::java_lang_VerifyError(); |
1892 _error_context = ctx; | |
1567 va_list va; | 1893 va_list va; |
1568 va_start(va, fmt); | 1894 va_start(va, msg); |
1569 format_error_message(fmt, offset, va); | 1895 ss.vprint(msg, va); |
1570 va_end(va); | 1896 va_end(va); |
1571 } | 1897 _message = ss.as_string(); |
1572 | 1898 #ifdef ASSERT |
1573 void ClassVerifier::verify_error(const char* fmt, ...) { | 1899 ResourceMark rm; |
1574 _exception_type = vmSymbols::java_lang_VerifyError(); | 1900 const char* exception_name = _exception_type->as_C_string(); |
1575 va_list va; | 1901 Exceptions::debug_check_abort(exception_name, NULL); |
1576 va_start(va, fmt); | 1902 #endif // ndef ASSERT |
1577 format_error_message(fmt, -1, va); | |
1578 va_end(va); | |
1579 } | 1903 } |
1580 | 1904 |
1581 void ClassVerifier::class_format_error(const char* msg, ...) { | 1905 void ClassVerifier::class_format_error(const char* msg, ...) { |
1906 stringStream ss; | |
1582 _exception_type = vmSymbols::java_lang_ClassFormatError(); | 1907 _exception_type = vmSymbols::java_lang_ClassFormatError(); |
1583 va_list va; | 1908 va_list va; |
1584 va_start(va, msg); | 1909 va_start(va, msg); |
1585 format_error_message(msg, -1, va); | 1910 ss.vprint(msg, va); |
1586 va_end(va); | 1911 va_end(va); |
1912 if (!_method.is_null()) { | |
1913 ss.print(" in method %s", _method->name_and_sig_as_C_string()); | |
1914 } | |
1915 _message = ss.as_string(); | |
1587 } | 1916 } |
1588 | 1917 |
1589 klassOop ClassVerifier::load_class(Symbol* name, TRAPS) { | 1918 klassOop ClassVerifier::load_class(Symbol* name, TRAPS) { |
1590 // Get current loader and protection domain first. | 1919 // Get current loader and protection domain first. |
1591 oop loader = current_class()->class_loader(); | 1920 oop loader = current_class()->class_loader(); |
1617 return true; | 1946 return true; |
1618 } | 1947 } |
1619 } | 1948 } |
1620 } else { | 1949 } else { |
1621 klassOop member_klass = target_instance->find_field(field_name, field_sig, &fd); | 1950 klassOop member_klass = target_instance->find_field(field_name, field_sig, &fd); |
1622 if(member_klass != NULL && fd.is_protected()) { | 1951 if (member_klass != NULL && fd.is_protected()) { |
1623 if (!this_class->is_same_class_package(member_klass)) { | 1952 if (!this_class->is_same_class_package(member_klass)) { |
1624 return true; | 1953 return true; |
1625 } | 1954 } |
1626 } | 1955 } |
1627 } | 1956 } |
1628 return false; | 1957 return false; |
1629 } | 1958 } |
1630 | 1959 |
1631 void ClassVerifier::verify_ldc( | 1960 void ClassVerifier::verify_ldc( |
1632 int opcode, u2 index, StackMapFrame *current_frame, | 1961 int opcode, u2 index, StackMapFrame* current_frame, |
1633 constantPoolHandle cp, u2 bci, TRAPS) { | 1962 constantPoolHandle cp, u2 bci, TRAPS) { |
1634 verify_cp_index(cp, index, CHECK_VERIFY(this)); | 1963 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); |
1635 constantTag tag = cp->tag_at(index); | 1964 constantTag tag = cp->tag_at(index); |
1636 unsigned int types; | 1965 unsigned int types; |
1637 if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { | 1966 if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { |
1638 if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) { | 1967 if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) { |
1639 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) | 1968 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) |
1640 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) | 1969 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) |
1641 | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType); | 1970 | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType); |
1642 // Note: The class file parser already verified the legality of | 1971 // Note: The class file parser already verified the legality of |
1643 // MethodHandle and MethodType constants. | 1972 // MethodHandle and MethodType constants. |
1644 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); | 1973 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); |
1645 } | 1974 } |
1646 } else { | 1975 } else { |
1647 assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); | 1976 assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); |
1648 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long); | 1977 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long); |
1649 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); | 1978 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); |
1650 } | 1979 } |
1651 if (tag.is_string() && cp->is_pseudo_string_at(index)) { | 1980 if (tag.is_string() && cp->is_pseudo_string_at(index)) { |
1652 current_frame->push_stack(object_type(), CHECK_VERIFY(this)); | 1981 current_frame->push_stack(object_type(), CHECK_VERIFY(this)); |
1653 } else if (tag.is_string() || tag.is_unresolved_string()) { | 1982 } else if (tag.is_string() || tag.is_unresolved_string()) { |
1654 current_frame->push_stack( | 1983 current_frame->push_stack( |
1679 } else if (tag.is_method_type()) { | 2008 } else if (tag.is_method_type()) { |
1680 current_frame->push_stack( | 2009 current_frame->push_stack( |
1681 VerificationType::reference_type( | 2010 VerificationType::reference_type( |
1682 vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this)); | 2011 vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this)); |
1683 } else { | 2012 } else { |
1684 verify_error(bci, "Invalid index in ldc"); | 2013 /* Unreachable? verify_cp_type has already validated the cp type. */ |
2014 verify_error( | |
2015 ErrorContext::bad_cp_index(bci, index), "Invalid index in ldc"); | |
1685 return; | 2016 return; |
1686 } | 2017 } |
1687 } | 2018 } |
1688 | 2019 |
1689 void ClassVerifier::verify_switch( | 2020 void ClassVerifier::verify_switch( |
1695 | 2026 |
1696 // 4639449 & 4647081: padding bytes must be 0 | 2027 // 4639449 & 4647081: padding bytes must be 0 |
1697 u2 padding_offset = 1; | 2028 u2 padding_offset = 1; |
1698 while ((bcp + padding_offset) < aligned_bcp) { | 2029 while ((bcp + padding_offset) < aligned_bcp) { |
1699 if(*(bcp + padding_offset) != 0) { | 2030 if(*(bcp + padding_offset) != 0) { |
1700 verify_error(bci, "Nonzero padding byte in lookswitch or tableswitch"); | 2031 verify_error(ErrorContext::bad_code(bci), |
2032 "Nonzero padding byte in lookswitch or tableswitch"); | |
1701 return; | 2033 return; |
1702 } | 2034 } |
1703 padding_offset++; | 2035 padding_offset++; |
1704 } | 2036 } |
1705 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); | 2037 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); |
1708 VerificationType::integer_type(), CHECK_VERIFY(this)); | 2040 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1709 if (bcs->raw_code() == Bytecodes::_tableswitch) { | 2041 if (bcs->raw_code() == Bytecodes::_tableswitch) { |
1710 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); | 2042 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); |
1711 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); | 2043 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); |
1712 if (low > high) { | 2044 if (low > high) { |
1713 verify_error(bci, | 2045 verify_error(ErrorContext::bad_code(bci), |
1714 "low must be less than or equal to high in tableswitch"); | 2046 "low must be less than or equal to high in tableswitch"); |
1715 return; | 2047 return; |
1716 } | 2048 } |
1717 keys = high - low + 1; | 2049 keys = high - low + 1; |
1718 if (keys < 0) { | 2050 if (keys < 0) { |
1719 verify_error(bci, "too many keys in tableswitch"); | 2051 verify_error(ErrorContext::bad_code(bci), "too many keys in tableswitch"); |
1720 return; | 2052 return; |
1721 } | 2053 } |
1722 delta = 1; | 2054 delta = 1; |
1723 } else { | 2055 } else { |
1724 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); | 2056 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); |
1725 if (keys < 0) { | 2057 if (keys < 0) { |
1726 verify_error(bci, "number of keys in lookupswitch less than 0"); | 2058 verify_error(ErrorContext::bad_code(bci), |
2059 "number of keys in lookupswitch less than 0"); | |
1727 return; | 2060 return; |
1728 } | 2061 } |
1729 delta = 2; | 2062 delta = 2; |
1730 // Make sure that the lookupswitch items are sorted | 2063 // Make sure that the lookupswitch items are sorted |
1731 for (int i = 0; i < (keys - 1); i++) { | 2064 for (int i = 0; i < (keys - 1); i++) { |
1732 jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); | 2065 jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); |
1733 jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); | 2066 jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); |
1734 if (this_key >= next_key) { | 2067 if (this_key >= next_key) { |
1735 verify_error(bci, "Bad lookupswitch instruction"); | 2068 verify_error(ErrorContext::bad_code(bci), |
2069 "Bad lookupswitch instruction"); | |
1736 return; | 2070 return; |
1737 } | 2071 } |
1738 } | 2072 } |
1739 } | 2073 } |
1740 int target = bci + default_offset; | 2074 int target = bci + default_offset; |
1765 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, | 2099 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, |
1766 StackMapFrame* current_frame, | 2100 StackMapFrame* current_frame, |
1767 constantPoolHandle cp, | 2101 constantPoolHandle cp, |
1768 TRAPS) { | 2102 TRAPS) { |
1769 u2 index = bcs->get_index_u2(); | 2103 u2 index = bcs->get_index_u2(); |
1770 verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); | 2104 verify_cp_type(bcs->bci(), index, cp, |
2105 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); | |
1771 | 2106 |
1772 // Get field name and signature | 2107 // Get field name and signature |
1773 Symbol* field_name = cp->name_ref_at(index); | 2108 Symbol* field_name = cp->name_ref_at(index); |
1774 Symbol* field_sig = cp->signature_ref_at(index); | 2109 Symbol* field_sig = cp->signature_ref_at(index); |
1775 | 2110 |
1782 | 2117 |
1783 // Get referenced class type | 2118 // Get referenced class type |
1784 VerificationType ref_class_type = cp_ref_index_to_type( | 2119 VerificationType ref_class_type = cp_ref_index_to_type( |
1785 index, cp, CHECK_VERIFY(this)); | 2120 index, cp, CHECK_VERIFY(this)); |
1786 if (!ref_class_type.is_object()) { | 2121 if (!ref_class_type.is_object()) { |
1787 verify_error( | 2122 /* Unreachable? Class file parser verifies Fieldref contents */ |
1788 "Expecting reference to class in class %s at constant pool index %d", | 2123 verify_error(ErrorContext::bad_type(bcs->bci(), |
1789 _klass->external_name(), index); | 2124 TypeOrigin::cp(index, ref_class_type)), |
2125 "Expecting reference to class in class %s at constant pool index %d", | |
2126 _klass->external_name(), index); | |
1790 return; | 2127 return; |
1791 } | 2128 } |
1792 VerificationType target_class_type = ref_class_type; | 2129 VerificationType target_class_type = ref_class_type; |
1793 | 2130 |
1794 assert(sizeof(VerificationType) == sizeof(uintptr_t), | 2131 assert(sizeof(VerificationType) == sizeof(uintptr_t), |
1842 stack_object_type = current_type(); | 2179 stack_object_type = current_type(); |
1843 } | 2180 } |
1844 is_assignable = target_class_type.is_assignable_from( | 2181 is_assignable = target_class_type.is_assignable_from( |
1845 stack_object_type, this, CHECK_VERIFY(this)); | 2182 stack_object_type, this, CHECK_VERIFY(this)); |
1846 if (!is_assignable) { | 2183 if (!is_assignable) { |
1847 verify_error(bci, "Bad type on operand stack in putfield"); | 2184 verify_error(ErrorContext::bad_type(bci, |
2185 current_frame->stack_top_ctx(), | |
2186 TypeOrigin::cp(index, target_class_type)), | |
2187 "Bad type on operand stack in putfield"); | |
1848 return; | 2188 return; |
1849 } | 2189 } |
1850 } | 2190 } |
1851 check_protected: { | 2191 check_protected: { |
1852 if (_this_type == stack_object_type) | 2192 if (_this_type == stack_object_type) |
1866 // It's protected access, check if stack object is assignable to | 2206 // It's protected access, check if stack object is assignable to |
1867 // current class. | 2207 // current class. |
1868 is_assignable = current_type().is_assignable_from( | 2208 is_assignable = current_type().is_assignable_from( |
1869 stack_object_type, this, CHECK_VERIFY(this)); | 2209 stack_object_type, this, CHECK_VERIFY(this)); |
1870 if (!is_assignable) { | 2210 if (!is_assignable) { |
1871 verify_error(bci, "Bad access to protected data in getfield"); | 2211 verify_error(ErrorContext::bad_type(bci, |
2212 current_frame->stack_top_ctx(), | |
2213 TypeOrigin::implicit(current_type())), | |
2214 "Bad access to protected data in getfield"); | |
1872 return; | 2215 return; |
1873 } | 2216 } |
1874 } | 2217 } |
1875 break; | 2218 break; |
1876 } | 2219 } |
1877 default: ShouldNotReachHere(); | 2220 default: ShouldNotReachHere(); |
1878 } | 2221 } |
1879 } | 2222 } |
1880 | 2223 |
1881 void ClassVerifier::verify_invoke_init( | 2224 void ClassVerifier::verify_invoke_init( |
1882 RawBytecodeStream* bcs, VerificationType ref_class_type, | 2225 RawBytecodeStream* bcs, u2 ref_class_index, VerificationType ref_class_type, |
1883 StackMapFrame* current_frame, u4 code_length, bool *this_uninit, | 2226 StackMapFrame* current_frame, u4 code_length, bool *this_uninit, |
1884 constantPoolHandle cp, TRAPS) { | 2227 constantPoolHandle cp, TRAPS) { |
1885 u2 bci = bcs->bci(); | 2228 u2 bci = bcs->bci(); |
1886 VerificationType type = current_frame->pop_stack( | 2229 VerificationType type = current_frame->pop_stack( |
1887 VerificationType::reference_check(), CHECK_VERIFY(this)); | 2230 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1888 if (type == VerificationType::uninitialized_this_type()) { | 2231 if (type == VerificationType::uninitialized_this_type()) { |
1889 // The method must be an <init> method of this class or its superclass | 2232 // The method must be an <init> method of this class or its superclass |
1890 klassOop superk = current_class()->super(); | 2233 klassOop superk = current_class()->super(); |
1891 if (ref_class_type.name() != current_class()->name() && | 2234 if (ref_class_type.name() != current_class()->name() && |
1892 ref_class_type.name() != superk->klass_part()->name()) { | 2235 ref_class_type.name() != superk->klass_part()->name()) { |
1893 verify_error(bci, "Bad <init> method call"); | 2236 verify_error(ErrorContext::bad_type(bci, |
2237 TypeOrigin::implicit(ref_class_type), | |
2238 TypeOrigin::implicit(current_type())), | |
2239 "Bad <init> method call"); | |
1894 return; | 2240 return; |
1895 } | 2241 } |
1896 current_frame->initialize_object(type, current_type()); | 2242 current_frame->initialize_object(type, current_type()); |
1897 *this_uninit = true; | 2243 *this_uninit = true; |
1898 } else if (type.is_uninitialized()) { | 2244 } else if (type.is_uninitialized()) { |
1899 u2 new_offset = type.bci(); | 2245 u2 new_offset = type.bci(); |
1900 address new_bcp = bcs->bcp() - bci + new_offset; | 2246 address new_bcp = bcs->bcp() - bci + new_offset; |
1901 if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { | 2247 if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { |
1902 verify_error(new_offset, "Expecting new instruction"); | 2248 /* Unreachable? Stack map parsing ensures valid type and new |
2249 * instructions have a valid BCI. */ | |
2250 verify_error(ErrorContext::bad_code(new_offset), | |
2251 "Expecting new instruction"); | |
1903 return; | 2252 return; |
1904 } | 2253 } |
1905 u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); | 2254 u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); |
1906 verify_cp_class_type(new_class_index, cp, CHECK_VERIFY(this)); | 2255 verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this)); |
1907 | 2256 |
1908 // The method must be an <init> method of the indicated class | 2257 // The method must be an <init> method of the indicated class |
1909 VerificationType new_class_type = cp_index_to_type( | 2258 VerificationType new_class_type = cp_index_to_type( |
1910 new_class_index, cp, CHECK_VERIFY(this)); | 2259 new_class_index, cp, CHECK_VERIFY(this)); |
1911 if (!new_class_type.equals(ref_class_type)) { | 2260 if (!new_class_type.equals(ref_class_type)) { |
1912 verify_error(bci, "Call to wrong <init> method"); | 2261 verify_error(ErrorContext::bad_type(bci, |
2262 TypeOrigin::cp(new_class_index, new_class_type), | |
2263 TypeOrigin::cp(ref_class_index, ref_class_type)), | |
2264 "Call to wrong <init> method"); | |
1913 return; | 2265 return; |
1914 } | 2266 } |
1915 // According to the VM spec, if the referent class is a superclass of the | 2267 // According to the VM spec, if the referent class is a superclass of the |
1916 // current class, and is in a different runtime package, and the method is | 2268 // current class, and is in a different runtime package, and the method is |
1917 // protected, then the objectref must be the current class or a subclass | 2269 // protected, then the objectref must be the current class or a subclass |
1926 instanceKlassHandle mh(THREAD, m->method_holder()); | 2278 instanceKlassHandle mh(THREAD, m->method_holder()); |
1927 if (m->is_protected() && !mh->is_same_class_package(_klass())) { | 2279 if (m->is_protected() && !mh->is_same_class_package(_klass())) { |
1928 bool assignable = current_type().is_assignable_from( | 2280 bool assignable = current_type().is_assignable_from( |
1929 objectref_type, this, CHECK_VERIFY(this)); | 2281 objectref_type, this, CHECK_VERIFY(this)); |
1930 if (!assignable) { | 2282 if (!assignable) { |
1931 verify_error(bci, "Bad access to protected <init> method"); | 2283 verify_error(ErrorContext::bad_type(bci, |
2284 TypeOrigin::cp(new_class_index, objectref_type), | |
2285 TypeOrigin::implicit(current_type())), | |
2286 "Bad access to protected <init> method"); | |
1932 return; | 2287 return; |
1933 } | 2288 } |
1934 } | 2289 } |
1935 } | 2290 } |
1936 current_frame->initialize_object(type, new_class_type); | 2291 current_frame->initialize_object(type, new_class_type); |
1937 } else { | 2292 } else { |
1938 verify_error(bci, "Bad operand type when invoking <init>"); | 2293 verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()), |
2294 "Bad operand type when invoking <init>"); | |
1939 return; | 2295 return; |
1940 } | 2296 } |
1941 } | 2297 } |
1942 | 2298 |
1943 void ClassVerifier::verify_invoke_instructions( | 2299 void ClassVerifier::verify_invoke_instructions( |
1950 unsigned int types = (opcode == Bytecodes::_invokeinterface | 2306 unsigned int types = (opcode == Bytecodes::_invokeinterface |
1951 ? 1 << JVM_CONSTANT_InterfaceMethodref | 2307 ? 1 << JVM_CONSTANT_InterfaceMethodref |
1952 : opcode == Bytecodes::_invokedynamic | 2308 : opcode == Bytecodes::_invokedynamic |
1953 ? 1 << JVM_CONSTANT_InvokeDynamic | 2309 ? 1 << JVM_CONSTANT_InvokeDynamic |
1954 : 1 << JVM_CONSTANT_Methodref); | 2310 : 1 << JVM_CONSTANT_Methodref); |
1955 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); | 2311 verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this)); |
1956 | 2312 |
1957 // Get method name and signature | 2313 // Get method name and signature |
1958 Symbol* method_name = cp->name_ref_at(index); | 2314 Symbol* method_name = cp->name_ref_at(index); |
1959 Symbol* method_sig = cp->signature_ref_at(index); | 2315 Symbol* method_sig = cp->signature_ref_at(index); |
1960 | 2316 |
2027 // 4905268: count operand in invokeinterface should be nargs+1, not nargs. | 2383 // 4905268: count operand in invokeinterface should be nargs+1, not nargs. |
2028 // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is | 2384 // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is |
2029 // the difference between the size of the operand stack before and after the instruction | 2385 // the difference between the size of the operand stack before and after the instruction |
2030 // executes. | 2386 // executes. |
2031 if (*(bcp+3) != (nargs+1)) { | 2387 if (*(bcp+3) != (nargs+1)) { |
2032 verify_error(bci, "Inconsistent args count operand in invokeinterface"); | 2388 verify_error(ErrorContext::bad_code(bci), |
2389 "Inconsistent args count operand in invokeinterface"); | |
2033 return; | 2390 return; |
2034 } | 2391 } |
2035 if (*(bcp+4) != 0) { | 2392 if (*(bcp+4) != 0) { |
2036 verify_error(bci, "Fourth operand byte of invokeinterface must be zero"); | 2393 verify_error(ErrorContext::bad_code(bci), |
2394 "Fourth operand byte of invokeinterface must be zero"); | |
2037 return; | 2395 return; |
2038 } | 2396 } |
2039 } | 2397 } |
2040 | 2398 |
2041 if (opcode == Bytecodes::_invokedynamic) { | 2399 if (opcode == Bytecodes::_invokedynamic) { |
2042 address bcp = bcs->bcp(); | 2400 address bcp = bcs->bcp(); |
2043 if (*(bcp+3) != 0 || *(bcp+4) != 0) { | 2401 if (*(bcp+3) != 0 || *(bcp+4) != 0) { |
2044 verify_error(bci, "Third and fourth operand bytes of invokedynamic must be zero"); | 2402 verify_error(ErrorContext::bad_code(bci), |
2403 "Third and fourth operand bytes of invokedynamic must be zero"); | |
2045 return; | 2404 return; |
2046 } | 2405 } |
2047 } | 2406 } |
2048 | 2407 |
2049 if (method_name->byte_at(0) == '<') { | 2408 if (method_name->byte_at(0) == '<') { |
2050 // Make sure <init> can only be invoked by invokespecial | 2409 // Make sure <init> can only be invoked by invokespecial |
2051 if (opcode != Bytecodes::_invokespecial || | 2410 if (opcode != Bytecodes::_invokespecial || |
2052 method_name != vmSymbols::object_initializer_name()) { | 2411 method_name != vmSymbols::object_initializer_name()) { |
2053 verify_error(bci, "Illegal call to internal method"); | 2412 verify_error(ErrorContext::bad_code(bci), |
2413 "Illegal call to internal method"); | |
2054 return; | 2414 return; |
2055 } | 2415 } |
2056 } else if (opcode == Bytecodes::_invokespecial | 2416 } else if (opcode == Bytecodes::_invokespecial |
2057 && !ref_class_type.equals(current_type()) | 2417 && !ref_class_type.equals(current_type()) |
2058 && !ref_class_type.equals(VerificationType::reference_type( | 2418 && !ref_class_type.equals(VerificationType::reference_type( |
2059 current_class()->super()->klass_part()->name()))) { | 2419 current_class()->super()->klass_part()->name()))) { |
2060 bool subtype = ref_class_type.is_assignable_from( | 2420 bool subtype = ref_class_type.is_assignable_from( |
2061 current_type(), this, CHECK_VERIFY(this)); | 2421 current_type(), this, CHECK_VERIFY(this)); |
2062 if (!subtype) { | 2422 if (!subtype) { |
2063 verify_error(bci, "Bad invokespecial instruction: " | 2423 verify_error(ErrorContext::bad_code(bci), |
2424 "Bad invokespecial instruction: " | |
2064 "current class isn't assignable to reference class."); | 2425 "current class isn't assignable to reference class."); |
2065 return; | 2426 return; |
2066 } | 2427 } |
2067 } | 2428 } |
2068 // Match method descriptor with operand stack | 2429 // Match method descriptor with operand stack |
2071 } | 2432 } |
2072 // Check objectref on operand stack | 2433 // Check objectref on operand stack |
2073 if (opcode != Bytecodes::_invokestatic && | 2434 if (opcode != Bytecodes::_invokestatic && |
2074 opcode != Bytecodes::_invokedynamic) { | 2435 opcode != Bytecodes::_invokedynamic) { |
2075 if (method_name == vmSymbols::object_initializer_name()) { // <init> method | 2436 if (method_name == vmSymbols::object_initializer_name()) { // <init> method |
2076 verify_invoke_init(bcs, ref_class_type, current_frame, | 2437 verify_invoke_init(bcs, index, ref_class_type, current_frame, |
2077 code_length, this_uninit, cp, CHECK_VERIFY(this)); | 2438 code_length, this_uninit, cp, CHECK_VERIFY(this)); |
2078 } else { // other methods | 2439 } else { // other methods |
2079 // Ensures that target class is assignable to method class. | 2440 // Ensures that target class is assignable to method class. |
2080 if (opcode == Bytecodes::_invokespecial) { | 2441 if (opcode == Bytecodes::_invokespecial) { |
2081 current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); | 2442 current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); |
2101 && stack_object_type.is_array() | 2462 && stack_object_type.is_array() |
2102 && method_name == vmSymbols::clone_name()) { | 2463 && method_name == vmSymbols::clone_name()) { |
2103 // Special case: arrays pretend to implement public Object | 2464 // Special case: arrays pretend to implement public Object |
2104 // clone(). | 2465 // clone(). |
2105 } else { | 2466 } else { |
2106 verify_error(bci, | 2467 verify_error(ErrorContext::bad_type(bci, |
2107 "Bad access to protected data in invokevirtual"); | 2468 current_frame->stack_top_ctx(), |
2469 TypeOrigin::implicit(current_type())), | |
2470 "Bad access to protected data in invokevirtual"); | |
2108 return; | 2471 return; |
2109 } | 2472 } |
2110 } | 2473 } |
2111 } | 2474 } |
2112 } | 2475 } |
2119 } | 2482 } |
2120 // Push the result type. | 2483 // Push the result type. |
2121 if (sig_stream.type() != T_VOID) { | 2484 if (sig_stream.type() != T_VOID) { |
2122 if (method_name == vmSymbols::object_initializer_name()) { | 2485 if (method_name == vmSymbols::object_initializer_name()) { |
2123 // <init> method must have a void return type | 2486 // <init> method must have a void return type |
2124 verify_error(bci, "Return type must be void in <init> method"); | 2487 /* Unreachable? Class file parser verifies that methods with '<' have |
2488 * void return */ | |
2489 verify_error(ErrorContext::bad_code(bci), | |
2490 "Return type must be void in <init> method"); | |
2125 return; | 2491 return; |
2126 } | 2492 } |
2127 VerificationType return_type[2]; | 2493 VerificationType return_type[2]; |
2128 int n = change_sig_to_verificationType( | 2494 int n = change_sig_to_verificationType( |
2129 &sig_stream, return_type, CHECK_VERIFY(this)); | 2495 &sig_stream, return_type, CHECK_VERIFY(this)); |
2137 u2 index, u2 bci, TRAPS) { | 2503 u2 index, u2 bci, TRAPS) { |
2138 const char* from_bt[] = { | 2504 const char* from_bt[] = { |
2139 NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", | 2505 NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", |
2140 }; | 2506 }; |
2141 if (index < T_BOOLEAN || index > T_LONG) { | 2507 if (index < T_BOOLEAN || index > T_LONG) { |
2142 verify_error(bci, "Illegal newarray instruction"); | 2508 verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction"); |
2143 return VerificationType::bogus_type(); | 2509 return VerificationType::bogus_type(); |
2144 } | 2510 } |
2145 | 2511 |
2146 // from_bt[index] contains the array signature which has a length of 2 | 2512 // from_bt[index] contains the array signature which has a length of 2 |
2147 Symbol* sig = create_temporary_symbol( | 2513 Symbol* sig = create_temporary_symbol( |
2148 from_bt[index], 2, CHECK_(VerificationType::bogus_type())); | 2514 from_bt[index], 2, CHECK_(VerificationType::bogus_type())); |
2149 return VerificationType::reference_type(sig); | 2515 return VerificationType::reference_type(sig); |
2150 } | 2516 } |
2151 | 2517 |
2152 void ClassVerifier::verify_anewarray( | 2518 void ClassVerifier::verify_anewarray( |
2153 u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS) { | 2519 u2 bci, u2 index, constantPoolHandle cp, |
2154 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 2520 StackMapFrame* current_frame, TRAPS) { |
2521 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); | |
2155 current_frame->pop_stack( | 2522 current_frame->pop_stack( |
2156 VerificationType::integer_type(), CHECK_VERIFY(this)); | 2523 VerificationType::integer_type(), CHECK_VERIFY(this)); |
2157 | 2524 |
2158 VerificationType component_type = | 2525 VerificationType component_type = |
2159 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | 2526 cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
2262 index, VerificationType::integer_type(), CHECK_VERIFY(this)); | 2629 index, VerificationType::integer_type(), CHECK_VERIFY(this)); |
2263 current_frame->set_local(index, type, CHECK_VERIFY(this)); | 2630 current_frame->set_local(index, type, CHECK_VERIFY(this)); |
2264 } | 2631 } |
2265 | 2632 |
2266 void ClassVerifier::verify_return_value( | 2633 void ClassVerifier::verify_return_value( |
2267 VerificationType return_type, VerificationType type, u2 bci, TRAPS) { | 2634 VerificationType return_type, VerificationType type, u2 bci, |
2635 StackMapFrame* current_frame, TRAPS) { | |
2268 if (return_type == VerificationType::bogus_type()) { | 2636 if (return_type == VerificationType::bogus_type()) { |
2269 verify_error(bci, "Method expects a return value"); | 2637 verify_error(ErrorContext::bad_type(bci, |
2638 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), | |
2639 "Method expects a return value"); | |
2270 return; | 2640 return; |
2271 } | 2641 } |
2272 bool match = return_type.is_assignable_from(type, this, CHECK_VERIFY(this)); | 2642 bool match = return_type.is_assignable_from(type, this, CHECK_VERIFY(this)); |
2273 if (!match) { | 2643 if (!match) { |
2274 verify_error(bci, "Bad return type"); | 2644 verify_error(ErrorContext::bad_type(bci, |
2645 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), | |
2646 "Bad return type"); | |
2275 return; | 2647 return; |
2276 } | 2648 } |
2277 } | 2649 } |
2278 | 2650 |
2279 // The verifier creates symbols which are substrings of Symbols. | 2651 // The verifier creates symbols which are substrings of Symbols. |