1068 vframeStream vfst(thread, true); // Do not skip and javaCalls |
1068 vframeStream vfst(thread, true); // Do not skip and javaCalls |
1069 |
1069 |
1070 return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD); |
1070 return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD); |
1071 } |
1071 } |
1072 |
1072 |
|
1073 methodHandle SharedRuntime::extract_attached_method(vframeStream& vfst) { |
|
1074 nmethod* caller_nm = vfst.nm(); |
|
1075 |
|
1076 nmethodLocker caller_lock(caller_nm); |
|
1077 |
|
1078 address pc = vfst.frame_pc(); |
|
1079 { // Get call instruction under lock because another thread may be busy patching it. |
|
1080 MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag); |
|
1081 if (NativeCall::is_call_before(pc)) { |
|
1082 NativeCall* ncall = nativeCall_before(pc); |
|
1083 return caller_nm->attached_method(ncall->instruction_address()); |
|
1084 } |
|
1085 } |
|
1086 return NULL; |
|
1087 } |
1073 |
1088 |
1074 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode |
1089 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode |
1075 // for a call current in progress, i.e., arguments has been pushed on stack |
1090 // for a call current in progress, i.e., arguments has been pushed on stack |
1076 // but callee has not been invoked yet. Caller frame must be compiled. |
1091 // but callee has not been invoked yet. Caller frame must be compiled. |
1077 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread, |
1092 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread, |
1085 |
1100 |
1086 // Find caller and bci from vframe |
1101 // Find caller and bci from vframe |
1087 methodHandle caller(THREAD, vfst.method()); |
1102 methodHandle caller(THREAD, vfst.method()); |
1088 int bci = vfst.bci(); |
1103 int bci = vfst.bci(); |
1089 |
1104 |
1090 // Find bytecode |
|
1091 Bytecode_invoke bytecode(caller, bci); |
1105 Bytecode_invoke bytecode(caller, bci); |
1092 bc = bytecode.invoke_code(); |
|
1093 int bytecode_index = bytecode.index(); |
1106 int bytecode_index = bytecode.index(); |
1094 |
1107 |
|
1108 methodHandle attached_method = extract_attached_method(vfst); |
|
1109 if (attached_method.not_null()) { |
|
1110 methodHandle callee = bytecode.static_target(CHECK_NH); |
|
1111 vmIntrinsics::ID id = callee->intrinsic_id(); |
|
1112 // When VM replaces MH.invokeBasic/linkTo* call with a direct/virtual call, |
|
1113 // it attaches statically resolved method to the call site. |
|
1114 if (MethodHandles::is_signature_polymorphic(id) && |
|
1115 MethodHandles::is_signature_polymorphic_intrinsic(id)) { |
|
1116 bc = MethodHandles::signature_polymorphic_intrinsic_bytecode(id); |
|
1117 |
|
1118 // Need to adjust invokehandle since inlining through signature-polymorphic |
|
1119 // method happened. |
|
1120 if (bc == Bytecodes::_invokehandle && |
|
1121 !MethodHandles::is_signature_polymorphic_method(attached_method())) { |
|
1122 bc = attached_method->is_static() ? Bytecodes::_invokestatic |
|
1123 : Bytecodes::_invokevirtual; |
|
1124 } |
|
1125 } |
|
1126 } else { |
|
1127 bc = bytecode.invoke_code(); |
|
1128 } |
|
1129 |
|
1130 bool has_receiver = bc != Bytecodes::_invokestatic && |
|
1131 bc != Bytecodes::_invokedynamic && |
|
1132 bc != Bytecodes::_invokehandle; |
|
1133 |
1095 // Find receiver for non-static call |
1134 // Find receiver for non-static call |
1096 if (bc != Bytecodes::_invokestatic && |
1135 if (has_receiver) { |
1097 bc != Bytecodes::_invokedynamic && |
|
1098 bc != Bytecodes::_invokehandle) { |
|
1099 // This register map must be update since we need to find the receiver for |
1136 // This register map must be update since we need to find the receiver for |
1100 // compiled frames. The receiver might be in a register. |
1137 // compiled frames. The receiver might be in a register. |
1101 RegisterMap reg_map2(thread); |
1138 RegisterMap reg_map2(thread); |
1102 frame stubFrame = thread->last_frame(); |
1139 frame stubFrame = thread->last_frame(); |
1103 // Caller-frame is a compiled frame |
1140 // Caller-frame is a compiled frame |
1104 frame callerFrame = stubFrame.sender(®_map2); |
1141 frame callerFrame = stubFrame.sender(®_map2); |
1105 |
1142 |
1106 methodHandle callee = bytecode.static_target(CHECK_(nullHandle)); |
1143 if (attached_method.is_null()) { |
1107 if (callee.is_null()) { |
1144 methodHandle callee = bytecode.static_target(CHECK_NH); |
1108 THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle); |
1145 if (callee.is_null()) { |
1109 } |
1146 THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle); |
|
1147 } |
|
1148 } |
|
1149 |
1110 // Retrieve from a compiled argument list |
1150 // Retrieve from a compiled argument list |
1111 receiver = Handle(THREAD, callerFrame.retrieve_receiver(®_map2)); |
1151 receiver = Handle(THREAD, callerFrame.retrieve_receiver(®_map2)); |
1112 |
1152 |
1113 if (receiver.is_null()) { |
1153 if (receiver.is_null()) { |
1114 THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle); |
1154 THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle); |
1115 } |
1155 } |
1116 } |
1156 } |
1117 |
1157 |
1118 // Resolve method. This is parameterized by bytecode. |
|
1119 constantPoolHandle constants(THREAD, caller->constants()); |
|
1120 assert(receiver.is_null() || receiver->is_oop(), "wrong receiver"); |
1158 assert(receiver.is_null() || receiver->is_oop(), "wrong receiver"); |
1121 LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle)); |
1159 |
|
1160 // Resolve method |
|
1161 if (attached_method.not_null()) { |
|
1162 // Parameterized by attached method. |
|
1163 LinkResolver::resolve_invoke(callinfo, receiver, attached_method, bc, CHECK_NH); |
|
1164 } else { |
|
1165 // Parameterized by bytecode. |
|
1166 constantPoolHandle constants(THREAD, caller->constants()); |
|
1167 LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_NH); |
|
1168 } |
1122 |
1169 |
1123 #ifdef ASSERT |
1170 #ifdef ASSERT |
1124 // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls |
1171 // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls |
1125 if (bc != Bytecodes::_invokestatic && bc != Bytecodes::_invokedynamic && bc != Bytecodes::_invokehandle) { |
1172 if (has_receiver) { |
1126 assert(receiver.not_null(), "should have thrown exception"); |
1173 assert(receiver.not_null(), "should have thrown exception"); |
1127 KlassHandle receiver_klass(THREAD, receiver->klass()); |
1174 KlassHandle receiver_klass(THREAD, receiver->klass()); |
1128 Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle)); |
1175 Klass* rk = NULL; |
1129 // klass is already loaded |
1176 if (attached_method.not_null()) { |
|
1177 // In case there's resolved method attached, use its holder during the check. |
|
1178 rk = attached_method->method_holder(); |
|
1179 } else { |
|
1180 // Klass is already loaded. |
|
1181 constantPoolHandle constants(THREAD, caller->constants()); |
|
1182 rk = constants->klass_ref_at(bytecode_index, CHECK_NH); |
|
1183 } |
1130 KlassHandle static_receiver_klass(THREAD, rk); |
1184 KlassHandle static_receiver_klass(THREAD, rk); |
1131 // Method handle invokes might have been optimized to a direct call |
|
1132 // so don't check for the receiver class. |
|
1133 // FIXME this weakens the assert too much |
|
1134 methodHandle callee = callinfo.selected_method(); |
1185 methodHandle callee = callinfo.selected_method(); |
1135 assert(receiver_klass->is_subtype_of(static_receiver_klass()) || |
1186 assert(receiver_klass->is_subtype_of(static_receiver_klass()), |
1136 callee->is_method_handle_intrinsic() || |
|
1137 callee->is_compiled_lambda_form(), |
|
1138 "actual receiver must be subclass of static receiver klass"); |
1187 "actual receiver must be subclass of static receiver klass"); |
1139 if (receiver_klass->is_instance_klass()) { |
1188 if (receiver_klass->is_instance_klass()) { |
1140 if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) { |
1189 if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) { |
1141 tty->print_cr("ERROR: Klass not yet initialized!!"); |
1190 tty->print_cr("ERROR: Klass not yet initialized!!"); |
1142 receiver_klass()->print(); |
1191 receiver_klass()->print(); |