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) { |
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 |
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 |
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 : |
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 } |
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( |
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; |
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 |
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 |
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)); |