< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page

  24 
  25 #include "code/codeCache.hpp"
  26 #include "code/nmethod.hpp"
  27 #include "code/pcDesc.hpp"
  28 #include "code/scopeDesc.hpp"
  29 #include "compiler/compilationPolicy.hpp"
  30 #include "gc/shared/collectedHeap.hpp"
  31 #include "gc/shared/gcLocker.hpp"
  32 #include "gc/shared/oopStorage.hpp"
  33 #include "gc/shared/strongRootsScope.hpp"
  34 #include "gc/shared/workerThread.hpp"
  35 #include "gc/shared/workerUtils.hpp"
  36 #include "interpreter/interpreter.hpp"
  37 #include "jfr/jfrEvents.hpp"
  38 #include "logging/log.hpp"
  39 #include "logging/logStream.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "memory/universe.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "oops/symbol.hpp"

  44 #include "runtime/atomic.hpp"
  45 #include "runtime/deoptimization.hpp"
  46 #include "runtime/frame.inline.hpp"
  47 #include "runtime/globals.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/interfaceSupport.inline.hpp"
  50 #include "runtime/javaThread.inline.hpp"
  51 #include "runtime/mutexLocker.hpp"
  52 #include "runtime/orderAccess.hpp"
  53 #include "runtime/osThread.hpp"
  54 #include "runtime/safepoint.hpp"
  55 #include "runtime/safepointMechanism.inline.hpp"
  56 #include "runtime/signature.hpp"
  57 #include "runtime/stackWatermarkSet.inline.hpp"
  58 #include "runtime/stubCodeGenerator.hpp"
  59 #include "runtime/stubRoutines.hpp"
  60 #include "runtime/synchronizer.hpp"
  61 #include "runtime/threads.hpp"
  62 #include "runtime/threadSMR.hpp"
  63 #include "runtime/threadWXSetters.inline.hpp"

 767 
 768   // Find frame of caller
 769   frame stub_fr = self->last_frame();
 770   CodeBlob* stub_cb = stub_fr.cb();
 771   assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
 772   RegisterMap map(self,
 773                   RegisterMap::UpdateMap::include,
 774                   RegisterMap::ProcessFrames::skip,
 775                   RegisterMap::WalkContinuation::skip);
 776   frame caller_fr = stub_fr.sender(&map);
 777 
 778   // Should only be poll_return or poll
 779   assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
 780 
 781   // This is a poll immediately before a return. The exception handling code
 782   // has already had the effect of causing the return to occur, so the execution
 783   // will continue immediately after the call. In addition, the oopmap at the
 784   // return point does not mark the return value as an oop (if it is), so
 785   // it needs a handle here to be updated.
 786   if( nm->is_at_poll_return(real_return_addr) ) {

 787     // See if return type is an oop.
 788     bool return_oop = nm->method()->is_returning_oop();

 789     HandleMark hm(self);
 790     Handle return_value;












 791     if (return_oop) {
 792       // The oop result has been saved on the stack together with all
 793       // the other registers. In order to preserve it over GCs we need
 794       // to keep it in a handle.
 795       oop result = caller_fr.saved_oop_result(&map);
 796       assert(oopDesc::is_oop_or_null(result), "must be oop");
 797       return_value = Handle(self, result);
 798       assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
 799     }
 800 
 801     // We get here if compiled return polls found a reason to call into the VM.
 802     // One condition for that is that the top frame is not yet safe to use.
 803     // The following stack watermark barrier poll will catch such situations.
 804     StackWatermarkSet::after_unwind(self);
 805 
 806     // Process pending operation
 807     SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
 808 
 809     // restore oop result, if any
 810     if (return_oop) {
 811       caller_fr.set_saved_oop_result(&map, return_value());





 812     }
 813   }
 814 
 815   // This is a safepoint poll. Verify the return address and block.
 816   else {
 817 
 818     // verify the blob built the "return address" correctly
 819     assert(real_return_addr == caller_fr.pc(), "must match");
 820 
 821     set_at_poll_safepoint(true);
 822     // Process pending operation
 823     // We never deliver an async exception at a polling point as the
 824     // compiler may not have an exception handler for it (polling at
 825     // a return point is ok though). We will check for a pending async
 826     // exception below and deoptimize if needed. We also cannot deoptimize
 827     // and still install the exception here because live registers needed
 828     // during deoptimization are clobbered by the exception path. The
 829     // exception will just be delivered once we get into the interpreter.
 830     SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
 831     set_at_poll_safepoint(false);

  24 
  25 #include "code/codeCache.hpp"
  26 #include "code/nmethod.hpp"
  27 #include "code/pcDesc.hpp"
  28 #include "code/scopeDesc.hpp"
  29 #include "compiler/compilationPolicy.hpp"
  30 #include "gc/shared/collectedHeap.hpp"
  31 #include "gc/shared/gcLocker.hpp"
  32 #include "gc/shared/oopStorage.hpp"
  33 #include "gc/shared/strongRootsScope.hpp"
  34 #include "gc/shared/workerThread.hpp"
  35 #include "gc/shared/workerUtils.hpp"
  36 #include "interpreter/interpreter.hpp"
  37 #include "jfr/jfrEvents.hpp"
  38 #include "logging/log.hpp"
  39 #include "logging/logStream.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "memory/universe.hpp"
  42 #include "oops/oop.inline.hpp"
  43 #include "oops/symbol.hpp"
  44 #include "oops/inlineKlass.hpp"
  45 #include "runtime/atomic.hpp"
  46 #include "runtime/deoptimization.hpp"
  47 #include "runtime/frame.inline.hpp"
  48 #include "runtime/globals.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/interfaceSupport.inline.hpp"
  51 #include "runtime/javaThread.inline.hpp"
  52 #include "runtime/mutexLocker.hpp"
  53 #include "runtime/orderAccess.hpp"
  54 #include "runtime/osThread.hpp"
  55 #include "runtime/safepoint.hpp"
  56 #include "runtime/safepointMechanism.inline.hpp"
  57 #include "runtime/signature.hpp"
  58 #include "runtime/stackWatermarkSet.inline.hpp"
  59 #include "runtime/stubCodeGenerator.hpp"
  60 #include "runtime/stubRoutines.hpp"
  61 #include "runtime/synchronizer.hpp"
  62 #include "runtime/threads.hpp"
  63 #include "runtime/threadSMR.hpp"
  64 #include "runtime/threadWXSetters.inline.hpp"

 768 
 769   // Find frame of caller
 770   frame stub_fr = self->last_frame();
 771   CodeBlob* stub_cb = stub_fr.cb();
 772   assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
 773   RegisterMap map(self,
 774                   RegisterMap::UpdateMap::include,
 775                   RegisterMap::ProcessFrames::skip,
 776                   RegisterMap::WalkContinuation::skip);
 777   frame caller_fr = stub_fr.sender(&map);
 778 
 779   // Should only be poll_return or poll
 780   assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
 781 
 782   // This is a poll immediately before a return. The exception handling code
 783   // has already had the effect of causing the return to occur, so the execution
 784   // will continue immediately after the call. In addition, the oopmap at the
 785   // return point does not mark the return value as an oop (if it is), so
 786   // it needs a handle here to be updated.
 787   if( nm->is_at_poll_return(real_return_addr) ) {
 788     ResourceMark rm;
 789     // See if return type is an oop.
 790     Method* method = nm->method();
 791     bool return_oop = method->is_returning_oop();
 792     HandleMark hm(self);
 793     GrowableArray<Handle> return_values;
 794     InlineKlass* vk = nullptr;
 795     if (InlineTypeReturnedAsFields && return_oop) {
 796       // Check if an inline type is returned as fields
 797       vk = InlineKlass::returned_inline_klass(map, &return_oop, method);
 798       if (vk != nullptr) {
 799         // We're at a safepoint at the return of a method that returns
 800         // multiple values. We must make sure we preserve the oop values
 801         // across the safepoint.
 802         vk->save_oop_fields(map, return_values);
 803       }
 804     }
 805 
 806     if (return_oop) {
 807       // The oop result has been saved on the stack together with all
 808       // the other registers. In order to preserve it over GCs we need
 809       // to keep it in a handle.
 810       oop result = caller_fr.saved_oop_result(&map);
 811       assert(oopDesc::is_oop_or_null(result), "must be oop");
 812       return_values.push(Handle(self, result));
 813       assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
 814     }
 815 
 816     // We get here if compiled return polls found a reason to call into the VM.
 817     // One condition for that is that the top frame is not yet safe to use.
 818     // The following stack watermark barrier poll will catch such situations.
 819     StackWatermarkSet::after_unwind(self);
 820 
 821     // Process pending operation
 822     SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
 823 
 824     // restore oop result, if any
 825     if (return_oop) {
 826       assert(vk != nullptr || return_values.length() == 1, "only one return value");
 827       caller_fr.set_saved_oop_result(&map, return_values.pop()());
 828     }
 829     // restore oops in scalarized fields
 830     if (vk != nullptr) {
 831       vk->restore_oop_results(map, return_values);
 832     }
 833   }
 834 
 835   // This is a safepoint poll. Verify the return address and block.
 836   else {
 837 
 838     // verify the blob built the "return address" correctly
 839     assert(real_return_addr == caller_fr.pc(), "must match");
 840 
 841     set_at_poll_safepoint(true);
 842     // Process pending operation
 843     // We never deliver an async exception at a polling point as the
 844     // compiler may not have an exception handler for it (polling at
 845     // a return point is ok though). We will check for a pending async
 846     // exception below and deoptimize if needed. We also cannot deoptimize
 847     // and still install the exception here because live registers needed
 848     // during deoptimization are clobbered by the exception path. The
 849     // exception will just be delivered once we get into the interpreter.
 850     SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
 851     set_at_poll_safepoint(false);
< prev index next >