src/share/vm/runtime/sharedRuntime.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/runtime

src/share/vm/runtime/sharedRuntime.cpp

Print this page
rev 5100 : 7199175: JSR 292: C1 needs patching when invokedynamic/invokehandle call site is not linked
Summary: Do patching rather bailing out for unlinked call with appendix
Reviewed-by: twisti, kvn


1034 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1035                                               vframeStream& vfst,
1036                                               Bytecodes::Code& bc,
1037                                               CallInfo& callinfo, TRAPS) {
1038   Handle receiver;
1039   Handle nullHandle;  //create a handy null handle for exception returns
1040 
1041   assert(!vfst.at_end(), "Java frame must exist");
1042 
1043   // Find caller and bci from vframe
1044   methodHandle caller(THREAD, vfst.method());
1045   int          bci   = vfst.bci();
1046 
1047   // Find bytecode
1048   Bytecode_invoke bytecode(caller, bci);
1049   bc = bytecode.invoke_code();
1050   int bytecode_index = bytecode.index();
1051 
1052   // Find receiver for non-static call
1053   if (bc != Bytecodes::_invokestatic &&
1054       bc != Bytecodes::_invokedynamic) {

1055     // This register map must be update since we need to find the receiver for
1056     // compiled frames. The receiver might be in a register.
1057     RegisterMap reg_map2(thread);
1058     frame stubFrame   = thread->last_frame();
1059     // Caller-frame is a compiled frame
1060     frame callerFrame = stubFrame.sender(&reg_map2);
1061 
1062     methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
1063     if (callee.is_null()) {
1064       THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1065     }
1066     // Retrieve from a compiled argument list
1067     receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1068 
1069     if (receiver.is_null()) {
1070       THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1071     }
1072   }
1073 
1074   // Resolve method. This is parameterized by bytecode.
1075   constantPoolHandle constants(THREAD, caller->constants());
1076   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1077   LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle));
1078 
1079 #ifdef ASSERT
1080   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1081   if (bc != Bytecodes::_invokestatic && bc != Bytecodes::_invokedynamic) {
1082     assert(receiver.not_null(), "should have thrown exception");
1083     KlassHandle receiver_klass(THREAD, receiver->klass());
1084     Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle));
1085                             // klass is already loaded
1086     KlassHandle static_receiver_klass(THREAD, rk);
1087     // Method handle invokes might have been optimized to a direct call
1088     // so don't check for the receiver class.
1089     // FIXME this weakens the assert too much
1090     methodHandle callee = callinfo.selected_method();
1091     assert(receiver_klass->is_subtype_of(static_receiver_klass()) ||
1092            callee->is_method_handle_intrinsic() ||
1093            callee->is_compiled_lambda_form(),
1094            "actual receiver must be subclass of static receiver klass");
1095     if (receiver_klass->oop_is_instance()) {
1096       if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1097         tty->print_cr("ERROR: Klass not yet initialized!!");
1098         receiver_klass()->print();
1099       }
1100       assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1101     }


1223   // Compute entry points. This might require generation of C2I converter
1224   // frames, so we cannot be holding any locks here. Furthermore, the
1225   // computation of the entry points is independent of patching the call.  We
1226   // always return the entry-point, but we only patch the stub if the call has
1227   // not been deoptimized.  Return values: For a virtual call this is an
1228   // (cached_oop, destination address) pair. For a static call/optimized
1229   // virtual this is just a destination address.
1230 
1231   StaticCallInfo static_call_info;
1232   CompiledICInfo virtual_call_info;
1233 
1234   // Make sure the callee nmethod does not get deoptimized and removed before
1235   // we are done patching the code.
1236   nmethod* callee_nm = callee_method->code();
1237   nmethodLocker nl_callee(callee_nm);
1238 #ifdef ASSERT
1239   address dest_entry_point = callee_nm == NULL ? 0 : callee_nm->entry_point(); // used below
1240 #endif
1241 
1242   if (is_virtual) {
1243     assert(receiver.not_null(), "sanity check");
1244     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1245     KlassHandle h_klass(THREAD, receiver->klass());
1246     CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
1247                      is_optimized, static_bound, virtual_call_info,
1248                      CHECK_(methodHandle()));
1249   } else {
1250     // static call
1251     CompiledStaticCall::compute_entry(callee_method, static_call_info);
1252   }
1253 
1254   // grab lock, check for deoptimization and potentially patch caller
1255   {
1256     MutexLocker ml_patch(CompiledIC_lock);
1257 
1258     // Now that we are ready to patch if the Method* was redefined then
1259     // don't update call site and let the caller retry.
1260 
1261     if (!callee_method->is_old()) {
1262 #ifdef ASSERT
1263       // We must not try to patch to jump to an already unloaded method.
1264       if (dest_entry_point != 0) {
1265         assert(CodeCache::find_blob(dest_entry_point) != NULL,




1034 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1035                                               vframeStream& vfst,
1036                                               Bytecodes::Code& bc,
1037                                               CallInfo& callinfo, TRAPS) {
1038   Handle receiver;
1039   Handle nullHandle;  //create a handy null handle for exception returns
1040 
1041   assert(!vfst.at_end(), "Java frame must exist");
1042 
1043   // Find caller and bci from vframe
1044   methodHandle caller(THREAD, vfst.method());
1045   int          bci   = vfst.bci();
1046 
1047   // Find bytecode
1048   Bytecode_invoke bytecode(caller, bci);
1049   bc = bytecode.invoke_code();
1050   int bytecode_index = bytecode.index();
1051 
1052   // Find receiver for non-static call
1053   if (bc != Bytecodes::_invokestatic &&
1054       bc != Bytecodes::_invokedynamic &&
1055       bc != Bytecodes::_invokehandle) {
1056     // This register map must be update since we need to find the receiver for
1057     // compiled frames. The receiver might be in a register.
1058     RegisterMap reg_map2(thread);
1059     frame stubFrame   = thread->last_frame();
1060     // Caller-frame is a compiled frame
1061     frame callerFrame = stubFrame.sender(&reg_map2);
1062 
1063     methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
1064     if (callee.is_null()) {
1065       THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1066     }
1067     // Retrieve from a compiled argument list
1068     receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1069 
1070     if (receiver.is_null()) {
1071       THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1072     }
1073   }
1074 
1075   // Resolve method. This is parameterized by bytecode.
1076   constantPoolHandle constants(THREAD, caller->constants());
1077   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1078   LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle));
1079 
1080 #ifdef ASSERT
1081   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1082   if (bc != Bytecodes::_invokestatic && bc != Bytecodes::_invokedynamic && bc != Bytecodes::_invokehandle) {
1083     assert(receiver.not_null(), "should have thrown exception");
1084     KlassHandle receiver_klass(THREAD, receiver->klass());
1085     Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle));
1086                             // klass is already loaded
1087     KlassHandle static_receiver_klass(THREAD, rk);
1088     // Method handle invokes might have been optimized to a direct call
1089     // so don't check for the receiver class.
1090     // FIXME this weakens the assert too much
1091     methodHandle callee = callinfo.selected_method();
1092     assert(receiver_klass->is_subtype_of(static_receiver_klass()) ||
1093            callee->is_method_handle_intrinsic() ||
1094            callee->is_compiled_lambda_form(),
1095            "actual receiver must be subclass of static receiver klass");
1096     if (receiver_klass->oop_is_instance()) {
1097       if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1098         tty->print_cr("ERROR: Klass not yet initialized!!");
1099         receiver_klass()->print();
1100       }
1101       assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1102     }


1224   // Compute entry points. This might require generation of C2I converter
1225   // frames, so we cannot be holding any locks here. Furthermore, the
1226   // computation of the entry points is independent of patching the call.  We
1227   // always return the entry-point, but we only patch the stub if the call has
1228   // not been deoptimized.  Return values: For a virtual call this is an
1229   // (cached_oop, destination address) pair. For a static call/optimized
1230   // virtual this is just a destination address.
1231 
1232   StaticCallInfo static_call_info;
1233   CompiledICInfo virtual_call_info;
1234 
1235   // Make sure the callee nmethod does not get deoptimized and removed before
1236   // we are done patching the code.
1237   nmethod* callee_nm = callee_method->code();
1238   nmethodLocker nl_callee(callee_nm);
1239 #ifdef ASSERT
1240   address dest_entry_point = callee_nm == NULL ? 0 : callee_nm->entry_point(); // used below
1241 #endif
1242 
1243   if (is_virtual) {
1244     assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
1245     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1246     KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass());
1247     CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
1248                      is_optimized, static_bound, virtual_call_info,
1249                      CHECK_(methodHandle()));
1250   } else {
1251     // static call
1252     CompiledStaticCall::compute_entry(callee_method, static_call_info);
1253   }
1254 
1255   // grab lock, check for deoptimization and potentially patch caller
1256   {
1257     MutexLocker ml_patch(CompiledIC_lock);
1258 
1259     // Now that we are ready to patch if the Method* was redefined then
1260     // don't update call site and let the caller retry.
1261 
1262     if (!callee_method->is_old()) {
1263 #ifdef ASSERT
1264       // We must not try to patch to jump to an already unloaded method.
1265       if (dest_entry_point != 0) {
1266         assert(CodeCache::find_blob(dest_entry_point) != NULL,


src/share/vm/runtime/sharedRuntime.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File