705 Deoptimization::DeoptAction action = Deoptimization::trap_request_action(trap_request);
706 Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);
707
708 if (action == Deoptimization::Action_make_not_entrant) {
709 if (nm->make_not_entrant()) {
710 if (reason == Deoptimization::Reason_tenured) {
711 MethodData* trap_mdo = Deoptimization::get_method_data(thread, method, true /*create_if_missing*/);
712 if (trap_mdo != NULL) {
713 trap_mdo->inc_tenure_traps();
714 }
715 }
716 }
717 }
718
719 // Deoptimize the caller frame.
720 Deoptimization::deoptimize_frame(thread, caller_frame.id());
721 // Return to the now deoptimized frame.
722 JRT_END
723
724
725 static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
726 Bytecode_field field_access(caller, bci);
727 // This can be static or non-static field access
728 Bytecodes::Code code = field_access.code();
729
730 // We must load class, initialize class and resolvethe field
731 fieldDescriptor result; // initialize class if needed
732 constantPoolHandle constants(THREAD, caller->constants());
733 LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL);
734 return result.field_holder();
735 }
736
737
738 //
739 // This routine patches sites where a class wasn't loaded or
740 // initialized at the time the code was generated. It handles
741 // references to classes, fields and forcing of initialization. Most
742 // of the cases are straightforward and involving simply forcing
743 // resolution of a class, rewriting the instruction stream with the
744 // needed constant and replacing the call in this function with the
1192 }
1193 }
1194 }
1195
1196 // If we are patching in a non-perm oop, make sure the nmethod
1197 // is on the right list.
1198 if (ScavengeRootsInCode && ((mirror.not_null() && mirror()->is_scavengable()) ||
1199 (appendix.not_null() && appendix->is_scavengable()))) {
1200 MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
1201 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1202 guarantee(nm != NULL, "only nmethods can contain non-perm oops");
1203 if (!nm->on_scavenge_root_list()) {
1204 CodeCache::add_scavenge_root_nmethod(nm);
1205 }
1206
1207 // Since we've patched some oops in the nmethod,
1208 // (re)register it with the heap.
1209 Universe::heap()->register_nmethod(nm);
1210 }
1211 JRT_END
1212
1213 //
1214 // Entry point for compiled code. We want to patch a nmethod.
1215 // We don't do a normal VM transition here because we want to
1216 // know after the patching is complete and any safepoint(s) are taken
1217 // if the calling nmethod was deoptimized. We do this by calling a
1218 // helper method which does the normal VM transition and when it
1219 // completes we can check for deoptimization. This simplifies the
1220 // assembly code in the cpu directories.
1221 //
1222 int Runtime1::move_klass_patching(JavaThread* thread) {
1223 //
1224 // NOTE: we are still in Java
1225 //
1226 Thread* THREAD = thread;
1227 debug_only(NoHandleMark nhm;)
1228 {
1229 // Enter VM mode
1230
1231 ResetNoHandleMark rnhm;
|
705 Deoptimization::DeoptAction action = Deoptimization::trap_request_action(trap_request);
706 Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);
707
708 if (action == Deoptimization::Action_make_not_entrant) {
709 if (nm->make_not_entrant()) {
710 if (reason == Deoptimization::Reason_tenured) {
711 MethodData* trap_mdo = Deoptimization::get_method_data(thread, method, true /*create_if_missing*/);
712 if (trap_mdo != NULL) {
713 trap_mdo->inc_tenure_traps();
714 }
715 }
716 }
717 }
718
719 // Deoptimize the caller frame.
720 Deoptimization::deoptimize_frame(thread, caller_frame.id());
721 // Return to the now deoptimized frame.
722 JRT_END
723
724
725 #ifndef DEOPTIMIZE_WHEN_PATCHING
726
727 static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
728 Bytecode_field field_access(caller, bci);
729 // This can be static or non-static field access
730 Bytecodes::Code code = field_access.code();
731
732 // We must load class, initialize class and resolvethe field
733 fieldDescriptor result; // initialize class if needed
734 constantPoolHandle constants(THREAD, caller->constants());
735 LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL);
736 return result.field_holder();
737 }
738
739
740 //
741 // This routine patches sites where a class wasn't loaded or
742 // initialized at the time the code was generated. It handles
743 // references to classes, fields and forcing of initialization. Most
744 // of the cases are straightforward and involving simply forcing
745 // resolution of a class, rewriting the instruction stream with the
746 // needed constant and replacing the call in this function with the
1194 }
1195 }
1196 }
1197
1198 // If we are patching in a non-perm oop, make sure the nmethod
1199 // is on the right list.
1200 if (ScavengeRootsInCode && ((mirror.not_null() && mirror()->is_scavengable()) ||
1201 (appendix.not_null() && appendix->is_scavengable()))) {
1202 MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
1203 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1204 guarantee(nm != NULL, "only nmethods can contain non-perm oops");
1205 if (!nm->on_scavenge_root_list()) {
1206 CodeCache::add_scavenge_root_nmethod(nm);
1207 }
1208
1209 // Since we've patched some oops in the nmethod,
1210 // (re)register it with the heap.
1211 Universe::heap()->register_nmethod(nm);
1212 }
1213 JRT_END
1214
1215 #else // DEOPTIMIZE_WHEN_PATCHING
1216
1217 JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id ))
1218 RegisterMap reg_map(thread, false);
1219
1220 NOT_PRODUCT(_patch_code_slowcase_cnt++;)
1221 if (TracePatching) {
1222 tty->print_cr("Deoptimizing because patch is needed");
1223 }
1224
1225 frame runtime_frame = thread->last_frame();
1226 frame caller_frame = runtime_frame.sender(®_map);
1227
1228 // It's possible the nmethod was invalidated in the last
1229 // safepoint, but if it's still alive then make it not_entrant.
1230 nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1231 if (nm != NULL) {
1232 nm->make_not_entrant();
1233 }
1234
1235 Deoptimization::deoptimize_frame(thread, caller_frame.id());
1236
1237 // Return to the now deoptimized frame.
1238 JRT_END
1239
1240 #endif // DEOPTIMIZE_WHEN_PATCHING
1241
1242 //
1243 // Entry point for compiled code. We want to patch a nmethod.
1244 // We don't do a normal VM transition here because we want to
1245 // know after the patching is complete and any safepoint(s) are taken
1246 // if the calling nmethod was deoptimized. We do this by calling a
1247 // helper method which does the normal VM transition and when it
1248 // completes we can check for deoptimization. This simplifies the
1249 // assembly code in the cpu directories.
1250 //
1251 int Runtime1::move_klass_patching(JavaThread* thread) {
1252 //
1253 // NOTE: we are still in Java
1254 //
1255 Thread* THREAD = thread;
1256 debug_only(NoHandleMark nhm;)
1257 {
1258 // Enter VM mode
1259
1260 ResetNoHandleMark rnhm;
|