src/share/vm/classfile/verifier.cpp

changeset 6824
2373a1f4987c
parent 6771
b5ae226b7516
child 6827
1fa005fb28f5
equal deleted inserted replaced
6823:21444610cb92 6824:2373a1f4987c
1731 VerificationType catch_type = cp_index_to_type( 1731 VerificationType catch_type = cp_index_to_type(
1732 catch_type_index, cp, CHECK_VERIFY(this)); 1732 catch_type_index, cp, CHECK_VERIFY(this));
1733 VerificationType throwable = 1733 VerificationType throwable =
1734 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); 1734 VerificationType::reference_type(vmSymbols::java_lang_Throwable());
1735 bool is_subclass = throwable.is_assignable_from( 1735 bool is_subclass = throwable.is_assignable_from(
1736 catch_type, this, CHECK_VERIFY(this)); 1736 catch_type, this, false, CHECK_VERIFY(this));
1737 if (!is_subclass) { 1737 if (!is_subclass) {
1738 // 4286534: should throw VerifyError according to recent spec change 1738 // 4286534: should throw VerifyError according to recent spec change
1739 verify_error(ErrorContext::bad_type(handler_pc, 1739 verify_error(ErrorContext::bad_type(handler_pc,
1740 TypeOrigin::cp(catch_type_index, catch_type), 1740 TypeOrigin::cp(catch_type_index, catch_type),
1741 TypeOrigin::implicit(throwable)), 1741 TypeOrigin::implicit(throwable)),
2186 target_class_type.equals(current_type()) && 2186 target_class_type.equals(current_type()) &&
2187 _klass->find_local_field(field_name, field_sig, &fd)) { 2187 _klass->find_local_field(field_name, field_sig, &fd)) {
2188 stack_object_type = current_type(); 2188 stack_object_type = current_type();
2189 } 2189 }
2190 is_assignable = target_class_type.is_assignable_from( 2190 is_assignable = target_class_type.is_assignable_from(
2191 stack_object_type, this, CHECK_VERIFY(this)); 2191 stack_object_type, this, false, CHECK_VERIFY(this));
2192 if (!is_assignable) { 2192 if (!is_assignable) {
2193 verify_error(ErrorContext::bad_type(bci, 2193 verify_error(ErrorContext::bad_type(bci,
2194 current_frame->stack_top_ctx(), 2194 current_frame->stack_top_ctx(),
2195 TypeOrigin::cp(index, target_class_type)), 2195 TypeOrigin::cp(index, target_class_type)),
2196 "Bad type on operand stack in putfield"); 2196 "Bad type on operand stack in putfield");
2213 if (is_protected_access(current_class(), ref_class_oop, field_name, 2213 if (is_protected_access(current_class(), ref_class_oop, field_name,
2214 field_sig, false)) { 2214 field_sig, false)) {
2215 // It's protected access, check if stack object is assignable to 2215 // It's protected access, check if stack object is assignable to
2216 // current class. 2216 // current class.
2217 is_assignable = current_type().is_assignable_from( 2217 is_assignable = current_type().is_assignable_from(
2218 stack_object_type, this, CHECK_VERIFY(this)); 2218 stack_object_type, this, true, CHECK_VERIFY(this));
2219 if (!is_assignable) { 2219 if (!is_assignable) {
2220 verify_error(ErrorContext::bad_type(bci, 2220 verify_error(ErrorContext::bad_type(bci,
2221 current_frame->stack_top_ctx(), 2221 current_frame->stack_top_ctx(),
2222 TypeOrigin::implicit(current_type())), 2222 TypeOrigin::implicit(current_type())),
2223 "Bad access to protected data in getfield"); 2223 "Bad access to protected data in getfield");
2313 return; 2313 return;
2314 } 2314 }
2315 instanceKlassHandle mh(THREAD, m->method_holder()); 2315 instanceKlassHandle mh(THREAD, m->method_holder());
2316 if (m->is_protected() && !mh->is_same_class_package(_klass())) { 2316 if (m->is_protected() && !mh->is_same_class_package(_klass())) {
2317 bool assignable = current_type().is_assignable_from( 2317 bool assignable = current_type().is_assignable_from(
2318 objectref_type, this, CHECK_VERIFY(this)); 2318 objectref_type, this, true, CHECK_VERIFY(this));
2319 if (!assignable) { 2319 if (!assignable) {
2320 verify_error(ErrorContext::bad_type(bci, 2320 verify_error(ErrorContext::bad_type(bci,
2321 TypeOrigin::cp(new_class_index, objectref_type), 2321 TypeOrigin::cp(new_class_index, objectref_type),
2322 TypeOrigin::implicit(current_type())), 2322 TypeOrigin::implicit(current_type())),
2323 "Bad access to protected <init> method"); 2323 "Bad access to protected <init> method");
2486 current_class()->super()->name()))) { 2486 current_class()->super()->name()))) {
2487 bool subtype = false; 2487 bool subtype = false;
2488 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref; 2488 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
2489 if (!current_class()->is_anonymous()) { 2489 if (!current_class()->is_anonymous()) {
2490 subtype = ref_class_type.is_assignable_from( 2490 subtype = ref_class_type.is_assignable_from(
2491 current_type(), this, CHECK_VERIFY(this)); 2491 current_type(), this, false, CHECK_VERIFY(this));
2492 } else { 2492 } else {
2493 VerificationType host_klass_type = 2493 VerificationType host_klass_type =
2494 VerificationType::reference_type(current_class()->host_klass()->name()); 2494 VerificationType::reference_type(current_class()->host_klass()->name());
2495 subtype = ref_class_type.is_assignable_from(host_klass_type, this, CHECK_VERIFY(this)); 2495 subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this));
2496 2496
2497 // If invokespecial of IMR, need to recheck for same or 2497 // If invokespecial of IMR, need to recheck for same or
2498 // direct interface relative to the host class 2498 // direct interface relative to the host class
2499 have_imr_indirect = (have_imr_indirect && 2499 have_imr_indirect = (have_imr_indirect &&
2500 !is_same_or_direct_interface( 2500 !is_same_or_direct_interface(
2534 // objectref is a subtype of the host_klass of the current class 2534 // objectref is a subtype of the host_klass of the current class
2535 // to allow an anonymous class to reference methods in the host_klass 2535 // to allow an anonymous class to reference methods in the host_klass
2536 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this)); 2536 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
2537 VerificationType hosttype = 2537 VerificationType hosttype =
2538 VerificationType::reference_type(current_class()->host_klass()->name()); 2538 VerificationType::reference_type(current_class()->host_klass()->name());
2539 bool subtype = hosttype.is_assignable_from(top, this, CHECK_VERIFY(this)); 2539 bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this));
2540 if (!subtype) { 2540 if (!subtype) {
2541 verify_error( ErrorContext::bad_type(current_frame->offset(), 2541 verify_error( ErrorContext::bad_type(current_frame->offset(),
2542 current_frame->stack_top_ctx(), 2542 current_frame->stack_top_ctx(),
2543 TypeOrigin::implicit(top)), 2543 TypeOrigin::implicit(top)),
2544 "Bad type on operand stack"); 2544 "Bad type on operand stack");
2559 if (is_protected_access( 2559 if (is_protected_access(
2560 _klass, ref_class, method_name, method_sig, true)) { 2560 _klass, ref_class, method_name, method_sig, true)) {
2561 // It's protected access, check if stack object is 2561 // It's protected access, check if stack object is
2562 // assignable to current class. 2562 // assignable to current class.
2563 bool is_assignable = current_type().is_assignable_from( 2563 bool is_assignable = current_type().is_assignable_from(
2564 stack_object_type, this, CHECK_VERIFY(this)); 2564 stack_object_type, this, true, CHECK_VERIFY(this));
2565 if (!is_assignable) { 2565 if (!is_assignable) {
2566 if (ref_class_type.name() == vmSymbols::java_lang_Object() 2566 if (ref_class_type.name() == vmSymbols::java_lang_Object()
2567 && stack_object_type.is_array() 2567 && stack_object_type.is_array()
2568 && method_name == vmSymbols::clone_name()) { 2568 && method_name == vmSymbols::clone_name()) {
2569 // Special case: arrays pretend to implement public Object 2569 // Special case: arrays pretend to implement public Object
2742 verify_error(ErrorContext::bad_type(bci, 2742 verify_error(ErrorContext::bad_type(bci,
2743 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), 2743 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
2744 "Method expects a return value"); 2744 "Method expects a return value");
2745 return; 2745 return;
2746 } 2746 }
2747 bool match = return_type.is_assignable_from(type, this, CHECK_VERIFY(this)); 2747 bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this));
2748 if (!match) { 2748 if (!match) {
2749 verify_error(ErrorContext::bad_type(bci, 2749 verify_error(ErrorContext::bad_type(bci,
2750 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), 2750 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
2751 "Bad return type"); 2751 "Bad return type");
2752 return; 2752 return;

mercurial