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