1053 (char *) kname->bytes(), kname->utf8_length(),
1054 (char *) name->bytes(), name->utf8_length(),
1055 (char *) sig->bytes(), sig->utf8_length());
1056 return 0;
1057 JRT_END
1058
1059
1060 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode)
1061 // for a call current in progress, i.e., arguments has been pushed on stack
1062 // put callee has not been invoked yet. Used by: resolve virtual/static,
1063 // vtable updates, etc. Caller frame must be compiled.
1064 Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
1065 ResourceMark rm(THREAD);
1066
1067 // last java frame on stack (which includes native call frames)
1068 vframeStream vfst(thread, true); // Do not skip and javaCalls
1069
1070 return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
1071 }
1072
1073
1074 // 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
1076 // but callee has not been invoked yet. Caller frame must be compiled.
1077 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1078 vframeStream& vfst,
1079 Bytecodes::Code& bc,
1080 CallInfo& callinfo, TRAPS) {
1081 Handle receiver;
1082 Handle nullHandle; //create a handy null handle for exception returns
1083
1084 assert(!vfst.at_end(), "Java frame must exist");
1085
1086 // Find caller and bci from vframe
1087 methodHandle caller(THREAD, vfst.method());
1088 int bci = vfst.bci();
1089
1090 // Find bytecode
1091 Bytecode_invoke bytecode(caller, bci);
1092 bc = bytecode.invoke_code();
1093 int bytecode_index = bytecode.index();
1094
1095 // Find receiver for non-static call
1096 if (bc != Bytecodes::_invokestatic &&
1097 bc != Bytecodes::_invokedynamic &&
1098 bc != Bytecodes::_invokehandle) {
1099 // This register map must be update since we need to find the receiver for
1100 // compiled frames. The receiver might be in a register.
1101 RegisterMap reg_map2(thread);
1102 frame stubFrame = thread->last_frame();
1103 // Caller-frame is a compiled frame
1104 frame callerFrame = stubFrame.sender(®_map2);
1105
1106 methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
1107 if (callee.is_null()) {
1108 THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1109 }
1110 // Retrieve from a compiled argument list
1111 receiver = Handle(THREAD, callerFrame.retrieve_receiver(®_map2));
1112
1113 if (receiver.is_null()) {
1114 THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1115 }
1116 }
1117
1118 // Resolve method. This is parameterized by bytecode.
1119 constantPoolHandle constants(THREAD, caller->constants());
1120 assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1121 LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle));
1122
1123 #ifdef ASSERT
1124 // 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) {
1126 assert(receiver.not_null(), "should have thrown exception");
1127 KlassHandle receiver_klass(THREAD, receiver->klass());
1128 Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle));
1129 // klass is already loaded
1130 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();
1135 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");
1139 if (receiver_klass->is_instance_klass()) {
1140 if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1141 tty->print_cr("ERROR: Klass not yet initialized!!");
1142 receiver_klass()->print();
1143 }
1144 assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1145 }
1146 }
1147 #endif
1148
1149 return receiver;
1150 }
1151
1152 methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
1153 ResourceMark rm(THREAD);
1154 // We need first to check if any Java activations (compiled, interpreted)
1155 // exist on the stack since last JavaCall. If not, we need
1156 // to get the target method from the JavaCall wrapper.
1157 vframeStream vfst(thread, true); // Do not skip any javaCalls
1653 assert(!UseInlineCaches, "relocation info. must exist for this address");
1654 }
1655
1656 // Cleaning the inline cache will force a new resolve. This is more robust
1657 // than directly setting it to the new destination, since resolving of calls
1658 // is always done through the same code path. (experience shows that it
1659 // leads to very hard to track down bugs, if an inline cache gets updated
1660 // to a wrong method). It should not be performance critical, since the
1661 // resolve is only done once.
1662
1663 MutexLocker ml(CompiledIC_lock);
1664 if (is_static_call) {
1665 CompiledStaticCall* ssc= compiledStaticCall_at(call_addr);
1666 ssc->set_to_clean();
1667 } else {
1668 // compiled, dispatched call (which used to call an interpreted method)
1669 CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr);
1670 inline_cache->set_to_clean();
1671 }
1672 }
1673
1674 }
1675
1676 methodHandle callee_method = find_callee_method(thread, CHECK_(methodHandle()));
1677
1678
1679 #ifndef PRODUCT
1680 Atomic::inc(&_wrong_method_ctr);
1681
1682 if (TraceCallFixup) {
1683 ResourceMark rm(thread);
1684 tty->print("handle_wrong_method reresolving call to");
1685 callee_method->print_short_name(tty);
1686 tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1687 }
1688 #endif
1689
1690 return callee_method;
1691 }
1692
1693 #ifdef ASSERT
|
1053 (char *) kname->bytes(), kname->utf8_length(),
1054 (char *) name->bytes(), name->utf8_length(),
1055 (char *) sig->bytes(), sig->utf8_length());
1056 return 0;
1057 JRT_END
1058
1059
1060 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode)
1061 // for a call current in progress, i.e., arguments has been pushed on stack
1062 // put callee has not been invoked yet. Used by: resolve virtual/static,
1063 // vtable updates, etc. Caller frame must be compiled.
1064 Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
1065 ResourceMark rm(THREAD);
1066
1067 // last java frame on stack (which includes native call frames)
1068 vframeStream vfst(thread, true); // Do not skip and javaCalls
1069
1070 return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
1071 }
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 }
1088
1089 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode
1090 // for a call current in progress, i.e., arguments has been pushed on stack
1091 // but callee has not been invoked yet. Caller frame must be compiled.
1092 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1093 vframeStream& vfst,
1094 Bytecodes::Code& bc,
1095 CallInfo& callinfo, TRAPS) {
1096 Handle receiver;
1097 Handle nullHandle; //create a handy null handle for exception returns
1098
1099 assert(!vfst.at_end(), "Java frame must exist");
1100
1101 // Find caller and bci from vframe
1102 methodHandle caller(THREAD, vfst.method());
1103 int bci = vfst.bci();
1104
1105 Bytecode_invoke bytecode(caller, bci);
1106 int bytecode_index = bytecode.index();
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
1134 // Find receiver for non-static call
1135 if (has_receiver) {
1136 // This register map must be update since we need to find the receiver for
1137 // compiled frames. The receiver might be in a register.
1138 RegisterMap reg_map2(thread);
1139 frame stubFrame = thread->last_frame();
1140 // Caller-frame is a compiled frame
1141 frame callerFrame = stubFrame.sender(®_map2);
1142
1143 if (attached_method.is_null()) {
1144 methodHandle callee = bytecode.static_target(CHECK_NH);
1145 if (callee.is_null()) {
1146 THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1147 }
1148 }
1149
1150 // Retrieve from a compiled argument list
1151 receiver = Handle(THREAD, callerFrame.retrieve_receiver(®_map2));
1152
1153 if (receiver.is_null()) {
1154 THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1155 }
1156 }
1157
1158 assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
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 }
1169
1170 #ifdef ASSERT
1171 // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1172 if (has_receiver) {
1173 assert(receiver.not_null(), "should have thrown exception");
1174 KlassHandle receiver_klass(THREAD, receiver->klass());
1175 Klass* rk = NULL;
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 }
1184 KlassHandle static_receiver_klass(THREAD, rk);
1185 methodHandle callee = callinfo.selected_method();
1186 assert(receiver_klass->is_subtype_of(static_receiver_klass()),
1187 "actual receiver must be subclass of static receiver klass");
1188 if (receiver_klass->is_instance_klass()) {
1189 if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1190 tty->print_cr("ERROR: Klass not yet initialized!!");
1191 receiver_klass()->print();
1192 }
1193 assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1194 }
1195 }
1196 #endif
1197
1198 return receiver;
1199 }
1200
1201 methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
1202 ResourceMark rm(THREAD);
1203 // We need first to check if any Java activations (compiled, interpreted)
1204 // exist on the stack since last JavaCall. If not, we need
1205 // to get the target method from the JavaCall wrapper.
1206 vframeStream vfst(thread, true); // Do not skip any javaCalls
1702 assert(!UseInlineCaches, "relocation info. must exist for this address");
1703 }
1704
1705 // Cleaning the inline cache will force a new resolve. This is more robust
1706 // than directly setting it to the new destination, since resolving of calls
1707 // is always done through the same code path. (experience shows that it
1708 // leads to very hard to track down bugs, if an inline cache gets updated
1709 // to a wrong method). It should not be performance critical, since the
1710 // resolve is only done once.
1711
1712 MutexLocker ml(CompiledIC_lock);
1713 if (is_static_call) {
1714 CompiledStaticCall* ssc= compiledStaticCall_at(call_addr);
1715 ssc->set_to_clean();
1716 } else {
1717 // compiled, dispatched call (which used to call an interpreted method)
1718 CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr);
1719 inline_cache->set_to_clean();
1720 }
1721 }
1722 }
1723
1724 methodHandle callee_method = find_callee_method(thread, CHECK_(methodHandle()));
1725
1726
1727 #ifndef PRODUCT
1728 Atomic::inc(&_wrong_method_ctr);
1729
1730 if (TraceCallFixup) {
1731 ResourceMark rm(thread);
1732 tty->print("handle_wrong_method reresolving call to");
1733 callee_method->print_short_name(tty);
1734 tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1735 }
1736 #endif
1737
1738 return callee_method;
1739 }
1740
1741 #ifdef ASSERT
|