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 (InlineTypeReturnedAsFields && return_oop) {
794 // Check if an inline type is returned as fields
795 vk = InlineKlass::returned_inline_klass(map, &return_oop, method);
796 if (vk != nullptr) {
797 // We're at a safepoint at the return of a method that returns
798 // multiple values. We must make sure we preserve the oop values
799 // across the safepoint.
800 vk->save_oop_fields(map, return_values);
801 }
802 }
803
804 if (return_oop) {
805 // The oop result has been saved on the stack together with all
806 // the other registers. In order to preserve it over GCs we need
807 // to keep it in a handle.
808 oop result = caller_fr.saved_oop_result(&map);
809 assert(oopDesc::is_oop_or_null(result), "must be oop");
810 return_values.push(Handle(self, result));
811 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
812 }
813
814 // We get here if compiled return polls found a reason to call into the VM.
815 // One condition for that is that the top frame is not yet safe to use.
816 // The following stack watermark barrier poll will catch such situations.
817 StackWatermarkSet::after_unwind(self);
818
819 // Process pending operation
820 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
821
822 // restore oop result, if any
823 if (return_oop) {
824 assert(vk != nullptr || return_values.length() == 1, "only one return value");
825 caller_fr.set_saved_oop_result(&map, return_values.pop()());
826 }
827 // restore oops in scalarized fields
828 if (vk != nullptr) {
829 vk->restore_oop_results(map, return_values);
830 }
831 }
832
833 // This is a safepoint poll. Verify the return address and block.
834 else {
835
836 // verify the blob built the "return address" correctly
837 assert(real_return_addr == caller_fr.pc(), "must match");
838
839 set_at_poll_safepoint(true);
840 // Process pending operation
841 // We never deliver an async exception at a polling point as the
842 // compiler may not have an exception handler for it (polling at
843 // a return point is ok though). We will check for a pending async
844 // exception below and deoptimize if needed. We also cannot deoptimize
845 // and still install the exception here because live registers needed
846 // during deoptimization are clobbered by the exception path. The
847 // exception will just be delivered once we get into the interpreter.
848 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
849 set_at_poll_safepoint(false);
|