comparison src/share/vm/opto/doCall.cpp @ 18003:dda2ae6f9557

8046542: [I.finalize() calls from methods compiled by C1 do not cause IllegalAccessError on Sparc Summary: call to Object.finalize() sometimes allowed by compilers on array type Reviewed-by: iveresov, vlivanov
author roland
date Wed, 02 Jul 2014 22:54:18 +0200
parents 1555c0843770
children 52b4284cb496 922c87c9aed4
comparison
equal deleted inserted replaced
18002:dad84b3f55a5 18003:dda2ae6f9557
458 ciKlass* speculative_receiver_type = NULL; 458 ciKlass* speculative_receiver_type = NULL;
459 if (is_virtual_or_interface) { 459 if (is_virtual_or_interface) {
460 Node* receiver_node = stack(sp() - nargs); 460 Node* receiver_node = stack(sp() - nargs);
461 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr(); 461 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
462 // call_does_dispatch and vtable_index are out-parameters. They might be changed. 462 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
463 callee = C->optimize_virtual_call(method(), bci(), klass, orig_callee, receiver_type, 463 // For arrays, klass below is Object. When vtable calls are used,
464 is_virtual, 464 // resolving the call with Object would allow an illegal call to
465 // finalize() on an array. We use holder instead: illegal calls to
466 // finalize() won't be compiled as vtable calls (IC call
467 // resolution will catch the illegal call) and the few legal calls
468 // on array types won't be either.
469 callee = C->optimize_virtual_call(method(), bci(), klass, holder, orig_callee,
470 receiver_type, is_virtual,
465 call_does_dispatch, vtable_index); // out-parameters 471 call_does_dispatch, vtable_index); // out-parameters
466 speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL; 472 speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL;
467 } 473 }
468 474
469 // Note: It's OK to try to inline a virtual call. 475 // Note: It's OK to try to inline a virtual call.
935 } 941 }
936 #endif //PRODUCT 942 #endif //PRODUCT
937 943
938 944
939 ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass, 945 ciMethod* Compile::optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
940 ciMethod* callee, const TypeOopPtr* receiver_type, 946 ciKlass* holder, ciMethod* callee,
941 bool is_virtual, 947 const TypeOopPtr* receiver_type, bool is_virtual,
942 bool& call_does_dispatch, int& vtable_index) { 948 bool& call_does_dispatch, int& vtable_index) {
943 // Set default values for out-parameters. 949 // Set default values for out-parameters.
944 call_does_dispatch = true; 950 call_does_dispatch = true;
945 vtable_index = Method::invalid_vtable_index; 951 vtable_index = Method::invalid_vtable_index;
946 952
951 if (optimized_virtual_method != NULL) { 957 if (optimized_virtual_method != NULL) {
952 callee = optimized_virtual_method; 958 callee = optimized_virtual_method;
953 call_does_dispatch = false; 959 call_does_dispatch = false;
954 } else if (!UseInlineCaches && is_virtual && callee->is_loaded()) { 960 } else if (!UseInlineCaches && is_virtual && callee->is_loaded()) {
955 // We can make a vtable call at this site 961 // We can make a vtable call at this site
956 vtable_index = callee->resolve_vtable_index(caller->holder(), klass); 962 vtable_index = callee->resolve_vtable_index(caller->holder(), holder);
957 } 963 }
958 return callee; 964 return callee;
959 } 965 }
960 966
961 // Identify possible target method and inlining style 967 // Identify possible target method and inlining style
974 // Attempt to improve the receiver 980 // Attempt to improve the receiver
975 bool actual_receiver_is_exact = false; 981 bool actual_receiver_is_exact = false;
976 ciInstanceKlass* actual_receiver = klass; 982 ciInstanceKlass* actual_receiver = klass;
977 if (receiver_type != NULL) { 983 if (receiver_type != NULL) {
978 // Array methods are all inherited from Object, and are monomorphic. 984 // Array methods are all inherited from Object, and are monomorphic.
985 // finalize() call on array is not allowed.
979 if (receiver_type->isa_aryptr() && 986 if (receiver_type->isa_aryptr() &&
980 callee->holder() == env()->Object_klass()) { 987 callee->holder() == env()->Object_klass() &&
988 callee->name() != ciSymbol::finalize_method_name()) {
981 return callee; 989 return callee;
982 } 990 }
983 991
984 // All other interesting cases are instance klasses. 992 // All other interesting cases are instance klasses.
985 if (!receiver_type->isa_instptr()) { 993 if (!receiver_type->isa_instptr()) {