< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page




  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "code/codeCache.hpp"
  32 #include "code/icBuffer.hpp"
  33 #include "code/nmethod.hpp"
  34 #include "code/pcDesc.hpp"
  35 #include "code/scopeDesc.hpp"
  36 #include "gc/shared/collectedHeap.hpp"
  37 #include "gc/shared/gcLocker.hpp"
  38 #include "gc/shared/strongRootsScope.hpp"
  39 #include "gc/shared/workgroup.hpp"
  40 #include "interpreter/interpreter.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logStream.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "memory/universe.hpp"
  46 #include "oops/oop.inline.hpp"
  47 #include "oops/symbol.hpp"

  48 #include "runtime/atomic.hpp"
  49 #include "runtime/compilationPolicy.hpp"
  50 #include "runtime/deoptimization.hpp"
  51 #include "runtime/frame.inline.hpp"
  52 #include "runtime/handles.inline.hpp"
  53 #include "runtime/interfaceSupport.inline.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/orderAccess.hpp"
  56 #include "runtime/osThread.hpp"
  57 #include "runtime/safepoint.hpp"
  58 #include "runtime/safepointMechanism.inline.hpp"
  59 #include "runtime/signature.hpp"
  60 #include "runtime/stubCodeGenerator.hpp"
  61 #include "runtime/stubRoutines.hpp"
  62 #include "runtime/sweeper.hpp"
  63 #include "runtime/synchronizer.hpp"
  64 #include "runtime/thread.inline.hpp"
  65 #include "runtime/threadSMR.hpp"
  66 #include "runtime/timerTrace.hpp"
  67 #include "services/runtimeService.hpp"


1059   CodeBlob *cb = CodeCache::find_blob(real_return_addr);
1060   assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod");
1061   CompiledMethod* nm = (CompiledMethod*)cb;
1062 
1063   // Find frame of caller
1064   frame stub_fr = thread()->last_frame();
1065   CodeBlob* stub_cb = stub_fr.cb();
1066   assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
1067   RegisterMap map(thread(), true);
1068   frame caller_fr = stub_fr.sender(&map);
1069 
1070   // Should only be poll_return or poll
1071   assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1072 
1073   // This is a poll immediately before a return. The exception handling code
1074   // has already had the effect of causing the return to occur, so the execution
1075   // will continue immediately after the call. In addition, the oopmap at the
1076   // return point does not mark the return value as an oop (if it is), so
1077   // it needs a handle here to be updated.
1078   if( nm->is_at_poll_return(real_return_addr) ) {

1079     // See if return type is an oop.
1080     bool return_oop = nm->method()->is_returning_oop();
1081     Handle return_value;























1082     if (return_oop) {
1083       // The oop result has been saved on the stack together with all
1084       // the other registers. In order to preserve it over GCs we need
1085       // to keep it in a handle.
1086       oop result = caller_fr.saved_oop_result(&map);
1087       assert(oopDesc::is_oop_or_null(result), "must be oop");
1088       return_value = Handle(thread(), result);
1089       assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1090     }
1091 
1092     // Block the thread
1093     SafepointMechanism::block_if_requested(thread());
1094 
1095     // restore oop result, if any
1096     if (return_oop) {
1097       caller_fr.set_saved_oop_result(&map, return_value());



1098     }
1099   }
1100 
1101   // This is a safepoint poll. Verify the return address and block.
1102   else {
1103     set_at_poll_safepoint(true);
1104 
1105     // verify the blob built the "return address" correctly
1106     assert(real_return_addr == caller_fr.pc(), "must match");
1107 
1108     // Block the thread
1109     SafepointMechanism::block_if_requested(thread());
1110     set_at_poll_safepoint(false);
1111 
1112     // If we have a pending async exception deoptimize the frame
1113     // as otherwise we may never deliver it.
1114     if (thread()->has_async_condition()) {
1115       ThreadInVMfromJavaNoAsyncException __tiv(thread());
1116       Deoptimization::deoptimize_frame(thread(), caller_fr.id());
1117     }




  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "code/codeCache.hpp"
  32 #include "code/icBuffer.hpp"
  33 #include "code/nmethod.hpp"
  34 #include "code/pcDesc.hpp"
  35 #include "code/scopeDesc.hpp"
  36 #include "gc/shared/collectedHeap.hpp"
  37 #include "gc/shared/gcLocker.hpp"
  38 #include "gc/shared/strongRootsScope.hpp"
  39 #include "gc/shared/workgroup.hpp"
  40 #include "interpreter/interpreter.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logStream.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "memory/universe.hpp"
  46 #include "oops/oop.inline.hpp"
  47 #include "oops/symbol.hpp"
  48 #include "oops/valueKlass.hpp"
  49 #include "runtime/atomic.hpp"
  50 #include "runtime/compilationPolicy.hpp"
  51 #include "runtime/deoptimization.hpp"
  52 #include "runtime/frame.inline.hpp"
  53 #include "runtime/handles.inline.hpp"
  54 #include "runtime/interfaceSupport.inline.hpp"
  55 #include "runtime/mutexLocker.hpp"
  56 #include "runtime/orderAccess.hpp"
  57 #include "runtime/osThread.hpp"
  58 #include "runtime/safepoint.hpp"
  59 #include "runtime/safepointMechanism.inline.hpp"
  60 #include "runtime/signature.hpp"
  61 #include "runtime/stubCodeGenerator.hpp"
  62 #include "runtime/stubRoutines.hpp"
  63 #include "runtime/sweeper.hpp"
  64 #include "runtime/synchronizer.hpp"
  65 #include "runtime/thread.inline.hpp"
  66 #include "runtime/threadSMR.hpp"
  67 #include "runtime/timerTrace.hpp"
  68 #include "services/runtimeService.hpp"


1060   CodeBlob *cb = CodeCache::find_blob(real_return_addr);
1061   assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod");
1062   CompiledMethod* nm = (CompiledMethod*)cb;
1063 
1064   // Find frame of caller
1065   frame stub_fr = thread()->last_frame();
1066   CodeBlob* stub_cb = stub_fr.cb();
1067   assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
1068   RegisterMap map(thread(), true);
1069   frame caller_fr = stub_fr.sender(&map);
1070 
1071   // Should only be poll_return or poll
1072   assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1073 
1074   // This is a poll immediately before a return. The exception handling code
1075   // has already had the effect of causing the return to occur, so the execution
1076   // will continue immediately after the call. In addition, the oopmap at the
1077   // return point does not mark the return value as an oop (if it is), so
1078   // it needs a handle here to be updated.
1079   if( nm->is_at_poll_return(real_return_addr) ) {
1080     ResourceMark rm;
1081     // See if return type is an oop.
1082     Method* method = nm->method();
1083     bool return_oop = method->may_return_oop();
1084 
1085     GrowableArray<Handle> return_values;
1086     ValueKlass* vk = NULL;
1087 
1088     if (return_oop && ValueTypeReturnedAsFields) {
1089       SignatureStream ss(method->signature());
1090       while (!ss.at_return_type()) {
1091         ss.next();
1092       }
1093       if (ss.type() == T_VALUETYPE) {
1094         // Check if value type is returned as fields
1095         vk = ValueKlass::returned_value_klass(map);
1096         if (vk != NULL) {
1097           // We're at a safepoint at the return of a method that returns
1098           // multiple values. We must make sure we preserve the oop values
1099           // across the safepoint.
1100           assert(vk == method->returned_value_type(thread()), "bad value klass");
1101           vk->save_oop_fields(map, return_values);
1102           return_oop = false;
1103         }
1104       }
1105     }
1106 
1107     if (return_oop) {
1108       // The oop result has been saved on the stack together with all
1109       // the other registers. In order to preserve it over GCs we need
1110       // to keep it in a handle.
1111       oop result = caller_fr.saved_oop_result(&map);
1112       assert(oopDesc::is_oop_or_null(result), "must be oop");
1113       return_values.push(Handle(thread(), result));
1114       assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1115     }
1116 
1117     // Block the thread
1118     SafepointMechanism::block_if_requested(thread());
1119 
1120     // restore oop result, if any
1121     if (return_oop) {
1122       assert(return_values.length() == 1, "only one return value");
1123       caller_fr.set_saved_oop_result(&map, return_values.pop()());
1124     } else if (vk != NULL) {
1125       vk->restore_oop_results(map, return_values);
1126     }
1127   }
1128 
1129   // This is a safepoint poll. Verify the return address and block.
1130   else {
1131     set_at_poll_safepoint(true);
1132 
1133     // verify the blob built the "return address" correctly
1134     assert(real_return_addr == caller_fr.pc(), "must match");
1135 
1136     // Block the thread
1137     SafepointMechanism::block_if_requested(thread());
1138     set_at_poll_safepoint(false);
1139 
1140     // If we have a pending async exception deoptimize the frame
1141     // as otherwise we may never deliver it.
1142     if (thread()->has_async_condition()) {
1143       ThreadInVMfromJavaNoAsyncException __tiv(thread());
1144       Deoptimization::deoptimize_frame(thread(), caller_fr.id());
1145     }


< prev index next >