@@ -1141,7 +1141,7 @@ int CodeInstaller::map_jvmci_bci(int bci) {
11411141 return bci;
11421142}
11431143
1144- void CodeInstaller::record_scope (jint pc_offset, HotSpotCompiledCodeStream* stream, u1 debug_info_flags, bool full_info, bool is_mh_invoke, bool return_oop, JVMCI_TRAPS) {
1144+ void CodeInstaller::record_scope (jint pc_offset, HotSpotCompiledCodeStream* stream, u1 debug_info_flags, bool full_info, bool is_mh_invoke, bool return_oop, CallSiteBindingContext* binding_context, JVMCI_TRAPS) {
11451145 if (full_info) {
11461146 read_virtual_objects (stream, JVMCI_CHECK);
11471147 }
@@ -1170,6 +1170,11 @@ void CodeInstaller::record_scope(jint pc_offset, HotSpotCompiledCodeStream* stre
11701170
11711171 if (bci >= 0 ) {
11721172 reexecute = !is_set (frame_flags, DIF_DURING_CALL);
1173+ if (i == depth - 1 && binding_context != nullptr ) {
1174+ binding_context->bci = bci;
1175+ binding_context->caller = method;
1176+ binding_context->reexecute = reexecute;
1177+ }
11731178 }
11741179
11751180 GrowableArray<ScopeValue*>* locals = read_local_or_stack_values (stream, frame_flags, true , JVMCI_CHECK);
@@ -1199,7 +1204,7 @@ void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, HotSpotCo
11991204 u1 flags = stream->read_u1 (" debugInfo:flags" );
12001205 OopMap *map = create_oop_map (stream, flags, JVMCI_CHECK);
12011206 _debug_recorder->add_safepoint (pc_offset, map);
1202- record_scope (pc_offset, stream, flags, true , JVMCI_CHECK);
1207+ record_scope (pc_offset, stream, flags, true , nullptr , JVMCI_CHECK);
12031208 _debug_recorder->end_safepoint (pc_offset);
12041209 if (_orig_pc_offset < 0 ) {
12051210 JVMCI_ERROR (" method contains safepoint, but has no deopt rescue slot" );
@@ -1215,15 +1220,32 @@ void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, HotSpotCo
12151220void CodeInstaller::site_Infopoint (CodeBuffer& buffer, jint pc_offset, HotSpotCompiledCodeStream* stream, JVMCI_TRAPS) {
12161221 u1 flags = stream->read_u1 (" debugInfo:flags" );
12171222 _debug_recorder->add_non_safepoint (pc_offset);
1218- record_scope (pc_offset, stream, flags, false , JVMCI_CHECK);
1223+ record_scope (pc_offset, stream, flags, false , nullptr , JVMCI_CHECK);
12191224 _debug_recorder->end_non_safepoint (pc_offset);
12201225}
12211226
1227+ // see CallGenerator::is_inlined_method_handle_intrinsic
1228+ bool is_inlined_method_handle_intrinsic (JavaThread* thread, methodHandle& caller, int bci, methodHandle& method) {
1229+ constantPoolHandle cpool (thread, caller->constants ());
1230+ InstanceKlass* pool_holder = cpool->pool_holder ();
1231+ Bytecode_invoke bytecode (caller, bci);
1232+ Method* symbolic_info = JVMCIRuntime::get_method_by_index (cpool, bytecode.index (), caller->java_code_at (bci), pool_holder);
1233+ return symbolic_info->is_method_handle_intrinsic () && !method->is_method_handle_intrinsic ();
1234+ }
1235+
1236+ // computation if binding is necessary corresponds to SharedRuntime::find_callee_info_helper
1237+ bool bind_call (JavaThread* thread, CallSiteBindingContext& binding_context, methodHandle& method, JVMCI_TRAPS) {
1238+ // TODO for Valhalla: if method has scalarized parameters bind as well
1239+ return binding_context.reexecute || is_inlined_method_handle_intrinsic (thread, binding_context.caller , binding_context.bci , method);
1240+ }
1241+
12221242void CodeInstaller::site_Call (CodeBuffer& buffer, u1 tag, jint pc_offset, HotSpotCompiledCodeStream* stream, JVMCI_TRAPS) {
12231243 JavaThread* thread = stream->thread ();
12241244 jlong target = stream->read_u8 (" target" );
12251245 methodHandle method;
12261246 bool direct_call = false ;
1247+ int method_index = 0 ;
1248+ CallSiteBindingContext binding_context;
12271249 if (tag == SITE_CALL) {
12281250 method = methodHandle (thread, (Method*) target);
12291251 assert (Method::is_valid_method (method ()), " invalid method" );
@@ -1249,17 +1271,20 @@ void CodeInstaller::site_Call(CodeBuffer& buffer, u1 tag, jint pc_offset, HotSpo
12491271 (MethodHandles::is_signature_polymorphic (iid) && MethodHandles::is_signature_polymorphic_intrinsic (iid)));
12501272 }
12511273 bool return_oop = method->is_returning_oop ();
1252- record_scope (next_pc_offset, stream, flags, true , is_mh_invoke, return_oop, JVMCI_CHECK);
1274+ record_scope (next_pc_offset, stream, flags, true , is_mh_invoke, return_oop, &binding_context, JVMCI_CHECK);
12531275 } else {
1254- record_scope (next_pc_offset, stream, flags, true , JVMCI_CHECK);
1276+ record_scope (next_pc_offset, stream, flags, true , &binding_context, JVMCI_CHECK);
12551277 }
12561278 }
12571279
12581280 if (tag != SITE_CALL) {
12591281 jlong foreign_call_destination = target;
12601282 CodeInstaller::pd_relocate_ForeignCall (inst, foreign_call_destination, JVMCI_CHECK);
12611283 } else {
1262- CodeInstaller::pd_relocate_JavaMethod (buffer, method, pc_offset, JVMCI_CHECK);
1284+ if (direct_call && bind_call (thread, binding_context, method, __jvmci_env__)) {
1285+ method_index = _oop_recorder->find_index (method ());
1286+ }
1287+ CodeInstaller::pd_relocate_JavaMethod (buffer, method, pc_offset, method_index, JVMCI_CHECK);
12631288 if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) {
12641289 // Need a static call stub for transitions from compiled to interpreted.
12651290 MacroAssembler masm (&buffer);
0 commit comments