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"
898
899 // Find frame of caller
900 frame stub_fr = self->last_frame();
901 CodeBlob* stub_cb = stub_fr.cb();
902 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
903 RegisterMap map(self,
904 RegisterMap::UpdateMap::include,
905 RegisterMap::ProcessFrames::skip,
906 RegisterMap::WalkContinuation::skip);
907 frame caller_fr = stub_fr.sender(&map);
908
909 // Should only be poll_return or poll
910 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
911
912 // This is a poll immediately before a return. The exception handling code
913 // has already had the effect of causing the return to occur, so the execution
914 // will continue immediately after the call. In addition, the oopmap at the
915 // return point does not mark the return value as an oop (if it is), so
916 // it needs a handle here to be updated.
917 if( nm->is_at_poll_return(real_return_addr) ) {
918 // See if return type is an oop.
919 bool return_oop = nm->method()->is_returning_oop();
920 HandleMark hm(self);
921 Handle return_value;
922 if (return_oop) {
923 // The oop result has been saved on the stack together with all
924 // the other registers. In order to preserve it over GCs we need
925 // to keep it in a handle.
926 oop result = caller_fr.saved_oop_result(&map);
927 assert(oopDesc::is_oop_or_null(result), "must be oop");
928 return_value = Handle(self, result);
929 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
930 }
931
932 // We get here if compiled return polls found a reason to call into the VM.
933 // One condition for that is that the top frame is not yet safe to use.
934 // The following stack watermark barrier poll will catch such situations.
935 StackWatermarkSet::after_unwind(self);
936
937 // Process pending operation
938 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
939
940 // restore oop result, if any
941 if (return_oop) {
942 caller_fr.set_saved_oop_result(&map, return_value());
943 }
944 }
945
946 // This is a safepoint poll. Verify the return address and block.
947 else {
948
949 // verify the blob built the "return address" correctly
950 assert(real_return_addr == caller_fr.pc(), "must match");
951
952 set_at_poll_safepoint(true);
953 // Process pending operation
954 // We never deliver an async exception at a polling point as the
955 // compiler may not have an exception handler for it (polling at
956 // a return point is ok though). We will check for a pending async
957 // exception below and deoptimize if needed. We also cannot deoptimize
958 // and still install the exception here because live registers needed
959 // during deoptimization are clobbered by the exception path. The
960 // exception will just be delivered once we get into the interpreter.
961 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
962 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"
899
900 // Find frame of caller
901 frame stub_fr = self->last_frame();
902 CodeBlob* stub_cb = stub_fr.cb();
903 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
904 RegisterMap map(self,
905 RegisterMap::UpdateMap::include,
906 RegisterMap::ProcessFrames::skip,
907 RegisterMap::WalkContinuation::skip);
908 frame caller_fr = stub_fr.sender(&map);
909
910 // Should only be poll_return or poll
911 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
912
913 // This is a poll immediately before a return. The exception handling code
914 // has already had the effect of causing the return to occur, so the execution
915 // will continue immediately after the call. In addition, the oopmap at the
916 // return point does not mark the return value as an oop (if it is), so
917 // it needs a handle here to be updated.
918 if( nm->is_at_poll_return(real_return_addr) ) {
919 ResourceMark rm;
920 // See if return type is an oop.
921 Method* method = nm->method();
922 bool return_oop = method->is_returning_oop();
923 HandleMark hm(self);
924
925 GrowableArray<Handle> return_values;
926 InlineKlass* vk = NULL;
927 if (return_oop && InlineTypeReturnedAsFields &&
928 (method->result_type() == T_PRIMITIVE_OBJECT || method->result_type() == T_OBJECT)) {
929 // Check if an inline type is returned as fields
930 vk = InlineKlass::returned_inline_klass(map);
931 if (vk != NULL) {
932 // We're at a safepoint at the return of a method that returns
933 // multiple values. We must make sure we preserve the oop values
934 // across the safepoint.
935 assert(vk == method->returns_inline_type(thread()), "bad inline klass");
936 vk->save_oop_fields(map, return_values);
937 return_oop = false;
938 }
939 }
940
941 if (return_oop) {
942 // The oop result has been saved on the stack together with all
943 // the other registers. In order to preserve it over GCs we need
944 // to keep it in a handle.
945 oop result = caller_fr.saved_oop_result(&map);
946 assert(oopDesc::is_oop_or_null(result), "must be oop");
947 return_values.push(Handle(self, result));
948 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
949 }
950
951 // We get here if compiled return polls found a reason to call into the VM.
952 // One condition for that is that the top frame is not yet safe to use.
953 // The following stack watermark barrier poll will catch such situations.
954 StackWatermarkSet::after_unwind(self);
955
956 // Process pending operation
957 SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */);
958
959 // restore oop result, if any
960 if (return_oop) {
961 assert(return_values.length() == 1, "only one return value");
962 caller_fr.set_saved_oop_result(&map, return_values.pop()());
963 } else if (vk != NULL) {
964 vk->restore_oop_results(map, return_values);
965 }
966 }
967
968 // This is a safepoint poll. Verify the return address and block.
969 else {
970
971 // verify the blob built the "return address" correctly
972 assert(real_return_addr == caller_fr.pc(), "must match");
973
974 set_at_poll_safepoint(true);
975 // Process pending operation
976 // We never deliver an async exception at a polling point as the
977 // compiler may not have an exception handler for it (polling at
978 // a return point is ok though). We will check for a pending async
979 // exception below and deoptimize if needed. We also cannot deoptimize
980 // and still install the exception here because live registers needed
981 // during deoptimization are clobbered by the exception path. The
982 // exception will just be delivered once we get into the interpreter.
983 SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */);
984 set_at_poll_safepoint(false);
|