< 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"

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

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

 787     HandleMark hm(self);
 788     Handle return_value;















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



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

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