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




1059       (char *) kname->bytes(), kname->utf8_length(),
1060       (char *) name->bytes(), name->utf8_length(),
1061       (char *) sig->bytes(), sig->utf8_length());
1062   return 0;
1063 JRT_END
1064 
1065 
1066 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode)
1067 // for a call current in progress, i.e., arguments has been pushed on stack
1068 // put callee has not been invoked yet.  Used by: resolve virtual/static,
1069 // vtable updates, etc.  Caller frame must be compiled.
1070 Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
1071   ResourceMark rm(THREAD);
1072 
1073   // last java frame on stack (which includes native call frames)
1074   vframeStream vfst(thread, true);  // Do not skip and javaCalls
1075 
1076   return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
1077 }
1078 















































































1079 
1080 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode
1081 // for a call current in progress, i.e., arguments has been pushed on stack
1082 // but callee has not been invoked yet.  Caller frame must be compiled.
1083 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1084                                               vframeStream& vfst,
1085                                               Bytecodes::Code& bc,
1086                                               CallInfo& callinfo, TRAPS) {
1087   Handle receiver;
1088   Handle nullHandle;  //create a handy null handle for exception returns
1089 
1090   assert(!vfst.at_end(), "Java frame must exist");
1091 
1092   // Find caller and bci from vframe
1093   methodHandle caller(THREAD, vfst.method());
1094   int          bci   = vfst.bci();
1095 
1096   // Find bytecode
1097   Bytecode_invoke bytecode(caller, bci);
1098   bc = bytecode.invoke_code();


1109     // Caller-frame is a compiled frame
1110     frame callerFrame = stubFrame.sender(&reg_map2);
1111 
1112     methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
1113     if (callee.is_null()) {
1114       THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1115     }
1116     // Retrieve from a compiled argument list
1117     receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1118 
1119     if (receiver.is_null()) {
1120       THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1121     }
1122   }
1123 
1124   // Resolve method. This is parameterized by bytecode.
1125   constantPoolHandle constants(THREAD, caller->constants());
1126   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1127   LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle));
1128 















1129 #ifdef ASSERT
1130   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1131   if (bc != Bytecodes::_invokestatic && bc != Bytecodes::_invokedynamic && bc != Bytecodes::_invokehandle) {
1132     assert(receiver.not_null(), "should have thrown exception");
1133     KlassHandle receiver_klass(THREAD, receiver->klass());
1134     Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle));
1135                             // klass is already loaded




1136     KlassHandle static_receiver_klass(THREAD, rk);
1137     // Method handle invokes might have been optimized to a direct call
1138     // so don't check for the receiver class.
1139     // FIXME this weakens the assert too much
1140     methodHandle callee = callinfo.selected_method();
1141     assert(receiver_klass->is_subtype_of(static_receiver_klass()) ||
1142            callee->is_method_handle_intrinsic() ||
1143            callee->is_compiled_lambda_form(),
1144            "actual receiver must be subclass of static receiver klass");
1145     if (receiver_klass->oop_is_instance()) {
1146       if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1147         tty->print_cr("ERROR: Klass not yet initialized!!");
1148         receiver_klass()->print();
1149       }
1150       assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1151     }
1152   }
1153 #endif
1154 
1155   return receiver;
1156 }
1157 
1158 methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
1159   ResourceMark rm(THREAD);
1160   // We need first to check if any Java activations (compiled, interpreted)
1161   // exist on the stack since last JavaCall.  If not, we need
1162   // to get the target method from the JavaCall wrapper.
1163   vframeStream vfst(thread, true);  // Do not skip any javaCalls




1059       (char *) kname->bytes(), kname->utf8_length(),
1060       (char *) name->bytes(), name->utf8_length(),
1061       (char *) sig->bytes(), sig->utf8_length());
1062   return 0;
1063 JRT_END
1064 
1065 
1066 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode)
1067 // for a call current in progress, i.e., arguments has been pushed on stack
1068 // put callee has not been invoked yet.  Used by: resolve virtual/static,
1069 // vtable updates, etc.  Caller frame must be compiled.
1070 Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
1071   ResourceMark rm(THREAD);
1072 
1073   // last java frame on stack (which includes native call frames)
1074   vframeStream vfst(thread, true);  // Do not skip and javaCalls
1075 
1076   return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
1077 }
1078 
1079 methodHandle SharedRuntime::extract_attached_call_info(JavaThread* thread) {
1080   ResourceMark rm(thread);
1081   RegisterMap cbl_map(thread, false);
1082   frame caller_frame = thread->last_frame().sender(&cbl_map);
1083   CodeBlob* caller_cb = caller_frame.cb();
1084   guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
1085   nmethod* caller_nm = caller_cb->as_nmethod_or_null();
1086 
1087   //assert(caller_nm is locked));
1088 
1089   NativeCall* call = nativeCall_before(caller_frame.pc());
1090   RelocIterator iter(caller_nm, call->instruction_address());
1091   while (iter.next()) {
1092     if (iter.addr() == call->instruction_address()) {
1093       switch(iter.type()) {
1094         case relocInfo::static_call_type:      return iter.static_call_reloc()->method_value();
1095         case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value();
1096         case relocInfo::virtual_call_type:     return iter.virtual_call_reloc()->method_value();
1097         default:
1098           fatal("unexpected reloc type: %d", iter.type());
1099       }
1100     }
1101   }
1102   return NULL;
1103 }
1104 
1105 static Bytecodes::Code compute_bc(vmIntrinsics::ID id) {
1106   switch(id) {
1107     case vmIntrinsics::_linkToVirtual:   return Bytecodes::_invokevirtual;
1108     case vmIntrinsics::_linkToInterface: return Bytecodes::_invokeinterface;
1109     case vmIntrinsics::_linkToStatic:    return Bytecodes::_invokestatic;
1110     case vmIntrinsics::_linkToSpecial:   return Bytecodes::_invokespecial;
1111     case vmIntrinsics::_invokeBasic:     return Bytecodes::_invokestatic;
1112     default:
1113       fatal("unexpected id: (%d) %s", (uint)id, vmIntrinsics::name_at(id));
1114       return Bytecodes::_illegal;
1115   }
1116 }
1117 
1118 static Handle extract_receiver(JavaThread* thread, TRAPS) {
1119   // This register map must be update since we need to find the receiver for
1120   // compiled frames. The receiver might be in a register.
1121   RegisterMap reg_map2(thread);
1122   frame stubFrame   = thread->last_frame();
1123   // Caller-frame is a compiled frame
1124   frame callerFrame = stubFrame.sender(&reg_map2);
1125   // Retrieve from a compiled argument list
1126   Handle receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1127   if (receiver.is_null()) {
1128     THROW_(vmSymbols::java_lang_NullPointerException(), Handle());
1129   }
1130   return receiver;
1131 }
1132 
1133 void SharedRuntime::resolve_attached_call_info(JavaThread* thread, methodHandle info, Bytecodes::Code bc,
1134                                                Handle& receiver, CallInfo& callinfo, TRAPS) {
1135   KlassHandle defc = info->method_holder();
1136   Symbol* name = info->name();
1137   Symbol* type = info->signature();
1138   LinkInfo link_info(defc, name, type, KlassHandle(), /*check_access=*/false);
1139   switch(bc) {
1140     case Bytecodes::_invokevirtual:
1141       LinkResolver::resolve_virtual_call(callinfo, receiver, receiver->klass(),
1142                                          link_info, /*check_null_and_abstract=*/true, THREAD);
1143       break;
1144     case Bytecodes::_invokeinterface:
1145       LinkResolver::resolve_interface_call(callinfo, receiver, receiver->klass(),
1146                                            link_info, /*check_null_and_abstract=*/true, THREAD);
1147       break;
1148     case Bytecodes::_invokestatic:
1149       LinkResolver::resolve_static_call(callinfo, link_info, /*initialize_class=*/false, THREAD);
1150       break;
1151     case Bytecodes::_invokespecial:
1152       LinkResolver::resolve_special_call(callinfo, link_info, THREAD);
1153       break;
1154     default:
1155       fatal("bad call");
1156   }
1157 }
1158 
1159 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode
1160 // for a call current in progress, i.e., arguments has been pushed on stack
1161 // but callee has not been invoked yet.  Caller frame must be compiled.
1162 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1163                                               vframeStream& vfst,
1164                                               Bytecodes::Code& bc,
1165                                               CallInfo& callinfo, TRAPS) {
1166   Handle receiver;
1167   Handle nullHandle;  //create a handy null handle for exception returns
1168 
1169   assert(!vfst.at_end(), "Java frame must exist");
1170 
1171   // Find caller and bci from vframe
1172   methodHandle caller(THREAD, vfst.method());
1173   int          bci   = vfst.bci();
1174 
1175   // Find bytecode
1176   Bytecode_invoke bytecode(caller, bci);
1177   bc = bytecode.invoke_code();


1188     // Caller-frame is a compiled frame
1189     frame callerFrame = stubFrame.sender(&reg_map2);
1190 
1191     methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
1192     if (callee.is_null()) {
1193       THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1194     }
1195     // Retrieve from a compiled argument list
1196     receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1197 
1198     if (receiver.is_null()) {
1199       THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1200     }
1201   }
1202 
1203   // Resolve method. This is parameterized by bytecode.
1204   constantPoolHandle constants(THREAD, caller->constants());
1205   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1206   LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle));
1207 
1208   // When VM replaces MH.invokeBasic/linkTo* call with a direct/virtual call,
1209   // it attaches statically resolved method to the call site.
1210   methodHandle call_info;
1211   vmIntrinsics::ID id = callinfo.resolved_method()->intrinsic_id();
1212   if (MethodHandles::is_signature_polymorphic(id) && id != vmIntrinsics::_invokeGeneric) {
1213     call_info = extract_attached_call_info(thread);
1214     if (!call_info.is_null()) {
1215       bc = compute_bc(id);
1216       // Find receiver for non-static call
1217       if (bc != Bytecodes::_invokestatic) {
1218         receiver = extract_receiver(thread, CHECK_(nullHandle));
1219       }
1220       resolve_attached_call_info(thread, call_info, bc, receiver, callinfo, CHECK_(nullHandle));
1221     }
1222   }
1223 #ifdef ASSERT
1224   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1225   if (bc != Bytecodes::_invokestatic && bc != Bytecodes::_invokedynamic && bc != Bytecodes::_invokehandle) {
1226     assert(receiver.not_null(), "should have thrown exception");
1227     KlassHandle receiver_klass(THREAD, receiver->klass());
1228     Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle));
1229                             // klass is already loaded
1230     if (!call_info.is_null()) {
1231       // In case there's resolved method attached, use it's holder during the check.
1232       rk = call_info->method_holder();
1233     }
1234     KlassHandle static_receiver_klass(THREAD, rk);



1235     methodHandle callee = callinfo.selected_method();
1236     assert(receiver_klass->is_subtype_of(static_receiver_klass()),


1237            "actual receiver must be subclass of static receiver klass");
1238     if (receiver_klass->oop_is_instance()) {
1239       if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1240         tty->print_cr("ERROR: Klass not yet initialized!!");
1241         receiver_klass()->print();
1242       }
1243       assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1244     }
1245   }
1246 #endif
1247 
1248   return receiver;
1249 }
1250 
1251 methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
1252   ResourceMark rm(THREAD);
1253   // We need first to check if any Java activations (compiled, interpreted)
1254   // exist on the stack since last JavaCall.  If not, we need
1255   // to get the target method from the JavaCall wrapper.
1256   vframeStream vfst(thread, true);  // Do not skip any javaCalls


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