29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "code/nmethod.hpp"
32 #include "code/pcDesc.hpp"
33 #include "code/scopeDesc.hpp"
34 #include "compiler/compilationPolicy.hpp"
35 #include "gc/shared/collectedHeap.hpp"
36 #include "gc/shared/gcLocker.hpp"
37 #include "gc/shared/oopStorage.hpp"
38 #include "gc/shared/strongRootsScope.hpp"
39 #include "gc/shared/workerThread.hpp"
40 #include "gc/shared/workerUtils.hpp"
41 #include "interpreter/interpreter.hpp"
42 #include "jfr/jfrEvents.hpp"
43 #include "logging/log.hpp"
44 #include "logging/logStream.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "memory/universe.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "oops/symbol.hpp"
49 #include "runtime/atomic.hpp"
50 #include "runtime/deoptimization.hpp"
51 #include "runtime/frame.inline.hpp"
52 #include "runtime/globals.hpp"
53 #include "runtime/handles.inline.hpp"
54 #include "runtime/interfaceSupport.inline.hpp"
55 #include "runtime/javaThread.inline.hpp"
56 #include "runtime/mutexLocker.hpp"
57 #include "runtime/orderAccess.hpp"
58 #include "runtime/osThread.hpp"
59 #include "runtime/safepoint.hpp"
60 #include "runtime/safepointMechanism.inline.hpp"
61 #include "runtime/signature.hpp"
62 #include "runtime/stackWatermarkSet.inline.hpp"
63 #include "runtime/stubCodeGenerator.hpp"
64 #include "runtime/stubRoutines.hpp"
65 #include "runtime/synchronizer.hpp"
66 #include "runtime/threads.hpp"
67 #include "runtime/threadSMR.hpp"
68 #include "runtime/threadWXSetters.inline.hpp"
922
923 // Find frame of caller
924 frame stub_fr = self->last_frame();
925 CodeBlob* stub_cb = stub_fr.cb();
926 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
927 RegisterMap map(self,
928 RegisterMap::UpdateMap::include,
929 RegisterMap::ProcessFrames::skip,
930 RegisterMap::WalkContinuation::skip);
931 frame caller_fr = stub_fr.sender(&map);
932
933 // Should only be poll_return or poll
934 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
935
936 // This is a poll immediately before a return. The exception handling code
937 // has already had the effect of causing the return to occur, so the execution
938 // will continue immediately after the call. In addition, the oopmap at the
939 // return point does not mark the return value as an oop (if it is), so
940 // it needs a handle here to be updated.
941 if( nm->is_at_poll_return(real_return_addr) ) {
942 // See if return type is an oop.
943 bool return_oop = nm->method()->is_returning_oop();
944 HandleMark hm(self);
945 Handle return_value;
946 if (return_oop) {
947 // The oop result has been saved on the stack together with all
948 // the other registers. In order to preserve it over GCs we need
949 // to keep it in a handle.
950 oop result = caller_fr.saved_oop_result(&map);
951 assert(oopDesc::is_oop_or_null(result), "must be oop");
952 return_value = Handle(self, result);
953 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
954 }
955
956 // We get here if compiled return polls found a reason to call into the VM.
957 // One condition for that is that the top frame is not yet safe to use.
958 // The following stack watermark barrier poll will catch such situations.
959 StackWatermarkSet::after_unwind(self);
960
961 // Process pending operation
962 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
963
964 // restore oop result, if any
965 if (return_oop) {
966 caller_fr.set_saved_oop_result(&map, return_value());
967 }
968 }
969
970 // This is a safepoint poll. Verify the return address and block.
971 else {
972
973 // verify the blob built the "return address" correctly
974 assert(real_return_addr == caller_fr.pc(), "must match");
975
976 set_at_poll_safepoint(true);
977 // Process pending operation
978 // We never deliver an async exception at a polling point as the
979 // compiler may not have an exception handler for it (polling at
980 // a return point is ok though). We will check for a pending async
981 // exception below and deoptimize if needed. We also cannot deoptimize
982 // and still install the exception here because live registers needed
983 // during deoptimization are clobbered by the exception path. The
984 // exception will just be delivered once we get into the interpreter.
985 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
986 set_at_poll_safepoint(false);
|
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "code/nmethod.hpp"
32 #include "code/pcDesc.hpp"
33 #include "code/scopeDesc.hpp"
34 #include "compiler/compilationPolicy.hpp"
35 #include "gc/shared/collectedHeap.hpp"
36 #include "gc/shared/gcLocker.hpp"
37 #include "gc/shared/oopStorage.hpp"
38 #include "gc/shared/strongRootsScope.hpp"
39 #include "gc/shared/workerThread.hpp"
40 #include "gc/shared/workerUtils.hpp"
41 #include "interpreter/interpreter.hpp"
42 #include "jfr/jfrEvents.hpp"
43 #include "logging/log.hpp"
44 #include "logging/logStream.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "memory/universe.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "oops/symbol.hpp"
49 #include "oops/inlineKlass.hpp"
50 #include "runtime/atomic.hpp"
51 #include "runtime/deoptimization.hpp"
52 #include "runtime/frame.inline.hpp"
53 #include "runtime/globals.hpp"
54 #include "runtime/handles.inline.hpp"
55 #include "runtime/interfaceSupport.inline.hpp"
56 #include "runtime/javaThread.inline.hpp"
57 #include "runtime/mutexLocker.hpp"
58 #include "runtime/orderAccess.hpp"
59 #include "runtime/osThread.hpp"
60 #include "runtime/safepoint.hpp"
61 #include "runtime/safepointMechanism.inline.hpp"
62 #include "runtime/signature.hpp"
63 #include "runtime/stackWatermarkSet.inline.hpp"
64 #include "runtime/stubCodeGenerator.hpp"
65 #include "runtime/stubRoutines.hpp"
66 #include "runtime/synchronizer.hpp"
67 #include "runtime/threads.hpp"
68 #include "runtime/threadSMR.hpp"
69 #include "runtime/threadWXSetters.inline.hpp"
923
924 // Find frame of caller
925 frame stub_fr = self->last_frame();
926 CodeBlob* stub_cb = stub_fr.cb();
927 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
928 RegisterMap map(self,
929 RegisterMap::UpdateMap::include,
930 RegisterMap::ProcessFrames::skip,
931 RegisterMap::WalkContinuation::skip);
932 frame caller_fr = stub_fr.sender(&map);
933
934 // Should only be poll_return or poll
935 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
936
937 // This is a poll immediately before a return. The exception handling code
938 // has already had the effect of causing the return to occur, so the execution
939 // will continue immediately after the call. In addition, the oopmap at the
940 // return point does not mark the return value as an oop (if it is), so
941 // it needs a handle here to be updated.
942 if( nm->is_at_poll_return(real_return_addr) ) {
943 ResourceMark rm;
944 // See if return type is an oop.
945 Method* method = nm->method();
946 bool return_oop = method->is_returning_oop();
947 HandleMark hm(self);
948 GrowableArray<Handle> return_values;
949 InlineKlass* vk = nullptr;
950 if (return_oop && InlineTypeReturnedAsFields &&
951 (method->result_type() == T_OBJECT)) {
952 // Check if an inline type is returned as fields
953 vk = InlineKlass::returned_inline_klass(map);
954 if (vk != nullptr) {
955 // We're at a safepoint at the return of a method that returns
956 // multiple values. We must make sure we preserve the oop values
957 // across the safepoint.
958 assert(vk == method->returns_inline_type(thread()), "bad inline klass");
959 vk->save_oop_fields(map, return_values);
960 return_oop = false;
961 }
962 }
963
964 if (return_oop) {
965 // The oop result has been saved on the stack together with all
966 // the other registers. In order to preserve it over GCs we need
967 // to keep it in a handle.
968 oop result = caller_fr.saved_oop_result(&map);
969 assert(oopDesc::is_oop_or_null(result), "must be oop");
970 return_values.push(Handle(self, result));
971 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
972 }
973
974 // We get here if compiled return polls found a reason to call into the VM.
975 // One condition for that is that the top frame is not yet safe to use.
976 // The following stack watermark barrier poll will catch such situations.
977 StackWatermarkSet::after_unwind(self);
978
979 // Process pending operation
980 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
981
982 // restore oop result, if any
983 if (return_oop) {
984 assert(return_values.length() == 1, "only one return value");
985 caller_fr.set_saved_oop_result(&map, return_values.pop()());
986 } else if (vk != nullptr) {
987 vk->restore_oop_results(map, return_values);
988 }
989 }
990
991 // This is a safepoint poll. Verify the return address and block.
992 else {
993
994 // verify the blob built the "return address" correctly
995 assert(real_return_addr == caller_fr.pc(), "must match");
996
997 set_at_poll_safepoint(true);
998 // Process pending operation
999 // We never deliver an async exception at a polling point as the
1000 // compiler may not have an exception handler for it (polling at
1001 // a return point is ok though). We will check for a pending async
1002 // exception below and deoptimize if needed. We also cannot deoptimize
1003 // and still install the exception here because live registers needed
1004 // during deoptimization are clobbered by the exception path. The
1005 // exception will just be delivered once we get into the interpreter.
1006 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
1007 set_at_poll_safepoint(false);
|