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