25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp"
27 #include "code/nmethod.hpp"
28 #include "code/pcDesc.hpp"
29 #include "code/scopeDesc.hpp"
30 #include "compiler/compilationPolicy.hpp"
31 #include "gc/shared/collectedHeap.hpp"
32 #include "gc/shared/gcLocker.hpp"
33 #include "gc/shared/oopStorage.hpp"
34 #include "gc/shared/strongRootsScope.hpp"
35 #include "gc/shared/workerThread.hpp"
36 #include "gc/shared/workerUtils.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "jfr/jfrEvents.hpp"
39 #include "logging/log.hpp"
40 #include "logging/logStream.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "oops/symbol.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"
769
770 // Find frame of caller
771 frame stub_fr = self->last_frame();
772 CodeBlob* stub_cb = stub_fr.cb();
773 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
774 RegisterMap map(self,
775 RegisterMap::UpdateMap::include,
776 RegisterMap::ProcessFrames::skip,
777 RegisterMap::WalkContinuation::skip);
778 frame caller_fr = stub_fr.sender(&map);
779
780 // Should only be poll_return or poll
781 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
782
783 // This is a poll immediately before a return. The exception handling code
784 // has already had the effect of causing the return to occur, so the execution
785 // will continue immediately after the call. In addition, the oopmap at the
786 // return point does not mark the return value as an oop (if it is), so
787 // it needs a handle here to be updated.
788 if( nm->is_at_poll_return(real_return_addr) ) {
789 // See if return type is an oop.
790 bool return_oop = nm->method()->is_returning_oop();
791 HandleMark hm(self);
792 Handle return_value;
793 if (return_oop) {
794 // The oop result has been saved on the stack together with all
795 // the other registers. In order to preserve it over GCs we need
796 // to keep it in a handle.
797 oop result = caller_fr.saved_oop_result(&map);
798 assert(oopDesc::is_oop_or_null(result), "must be oop");
799 return_value = Handle(self, result);
800 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
801 }
802
803 // We get here if compiled return polls found a reason to call into the VM.
804 // One condition for that is that the top frame is not yet safe to use.
805 // The following stack watermark barrier poll will catch such situations.
806 StackWatermarkSet::after_unwind(self);
807
808 // Process pending operation
809 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
810
811 // restore oop result, if any
812 if (return_oop) {
813 caller_fr.set_saved_oop_result(&map, return_value());
814 }
815 }
816
817 // This is a safepoint poll. Verify the return address and block.
818 else {
819
820 // verify the blob built the "return address" correctly
821 assert(real_return_addr == caller_fr.pc(), "must match");
822
823 set_at_poll_safepoint(true);
824 // Process pending operation
825 // We never deliver an async exception at a polling point as the
826 // compiler may not have an exception handler for it (polling at
827 // a return point is ok though). We will check for a pending async
828 // exception below and deoptimize if needed. We also cannot deoptimize
829 // and still install the exception here because live registers needed
830 // during deoptimization are clobbered by the exception path. The
831 // exception will just be delivered once we get into the interpreter.
832 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
833 set_at_poll_safepoint(false);
|
25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp"
27 #include "code/nmethod.hpp"
28 #include "code/pcDesc.hpp"
29 #include "code/scopeDesc.hpp"
30 #include "compiler/compilationPolicy.hpp"
31 #include "gc/shared/collectedHeap.hpp"
32 #include "gc/shared/gcLocker.hpp"
33 #include "gc/shared/oopStorage.hpp"
34 #include "gc/shared/strongRootsScope.hpp"
35 #include "gc/shared/workerThread.hpp"
36 #include "gc/shared/workerUtils.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "jfr/jfrEvents.hpp"
39 #include "logging/log.hpp"
40 #include "logging/logStream.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "oops/symbol.hpp"
45 #include "oops/inlineKlass.hpp"
46 #include "runtime/atomic.hpp"
47 #include "runtime/deoptimization.hpp"
48 #include "runtime/frame.inline.hpp"
49 #include "runtime/globals.hpp"
50 #include "runtime/handles.inline.hpp"
51 #include "runtime/interfaceSupport.inline.hpp"
52 #include "runtime/javaThread.inline.hpp"
53 #include "runtime/mutexLocker.hpp"
54 #include "runtime/orderAccess.hpp"
55 #include "runtime/osThread.hpp"
56 #include "runtime/safepoint.hpp"
57 #include "runtime/safepointMechanism.inline.hpp"
58 #include "runtime/signature.hpp"
59 #include "runtime/stackWatermarkSet.inline.hpp"
60 #include "runtime/stubCodeGenerator.hpp"
61 #include "runtime/stubRoutines.hpp"
62 #include "runtime/synchronizer.hpp"
63 #include "runtime/threads.hpp"
64 #include "runtime/threadSMR.hpp"
65 #include "runtime/threadWXSetters.inline.hpp"
770
771 // Find frame of caller
772 frame stub_fr = self->last_frame();
773 CodeBlob* stub_cb = stub_fr.cb();
774 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
775 RegisterMap map(self,
776 RegisterMap::UpdateMap::include,
777 RegisterMap::ProcessFrames::skip,
778 RegisterMap::WalkContinuation::skip);
779 frame caller_fr = stub_fr.sender(&map);
780
781 // Should only be poll_return or poll
782 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
783
784 // This is a poll immediately before a return. The exception handling code
785 // has already had the effect of causing the return to occur, so the execution
786 // will continue immediately after the call. In addition, the oopmap at the
787 // return point does not mark the return value as an oop (if it is), so
788 // it needs a handle here to be updated.
789 if( nm->is_at_poll_return(real_return_addr) ) {
790 ResourceMark rm;
791 // See if return type is an oop.
792 Method* method = nm->method();
793 bool return_oop = method->is_returning_oop();
794 HandleMark hm(self);
795 GrowableArray<Handle> return_values;
796 InlineKlass* vk = nullptr;
797 if (return_oop && InlineTypeReturnedAsFields &&
798 (method->result_type() == T_OBJECT)) {
799 // Check if an inline type is returned as fields
800 vk = InlineKlass::returned_inline_klass(map);
801 if (vk != nullptr) {
802 // We're at a safepoint at the return of a method that returns
803 // multiple values. We must make sure we preserve the oop values
804 // across the safepoint.
805 assert(vk == method->returns_inline_type(thread()), "bad inline klass");
806 vk->save_oop_fields(map, return_values);
807 return_oop = false;
808 }
809 }
810
811 if (return_oop) {
812 // The oop result has been saved on the stack together with all
813 // the other registers. In order to preserve it over GCs we need
814 // to keep it in a handle.
815 oop result = caller_fr.saved_oop_result(&map);
816 assert(oopDesc::is_oop_or_null(result), "must be oop");
817 return_values.push(Handle(self, result));
818 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
819 }
820
821 // We get here if compiled return polls found a reason to call into the VM.
822 // One condition for that is that the top frame is not yet safe to use.
823 // The following stack watermark barrier poll will catch such situations.
824 StackWatermarkSet::after_unwind(self);
825
826 // Process pending operation
827 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
828
829 // restore oop result, if any
830 if (return_oop) {
831 assert(return_values.length() == 1, "only one return value");
832 caller_fr.set_saved_oop_result(&map, return_values.pop()());
833 } else if (vk != nullptr) {
834 vk->restore_oop_results(map, return_values);
835 }
836 }
837
838 // This is a safepoint poll. Verify the return address and block.
839 else {
840
841 // verify the blob built the "return address" correctly
842 assert(real_return_addr == caller_fr.pc(), "must match");
843
844 set_at_poll_safepoint(true);
845 // Process pending operation
846 // We never deliver an async exception at a polling point as the
847 // compiler may not have an exception handler for it (polling at
848 // a return point is ok though). We will check for a pending async
849 // exception below and deoptimize if needed. We also cannot deoptimize
850 // and still install the exception here because live registers needed
851 // during deoptimization are clobbered by the exception path. The
852 // exception will just be delivered once we get into the interpreter.
853 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
854 set_at_poll_safepoint(false);
|