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