27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
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 "gc/shared/collectedHeap.hpp"
36 #include "gc/shared/gcLocker.hpp"
37 #include "gc/shared/strongRootsScope.hpp"
38 #include "gc/shared/workgroup.hpp"
39 #include "interpreter/interpreter.hpp"
40 #include "jfr/jfrEvents.hpp"
41 #include "logging/log.hpp"
42 #include "logging/logStream.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "memory/universe.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "oops/symbol.hpp"
47 #include "runtime/atomic.hpp"
48 #include "runtime/compilationPolicy.hpp"
49 #include "runtime/deoptimization.hpp"
50 #include "runtime/frame.inline.hpp"
51 #include "runtime/handles.inline.hpp"
52 #include "runtime/interfaceSupport.inline.hpp"
53 #include "runtime/mutexLocker.hpp"
54 #include "runtime/orderAccess.hpp"
55 #include "runtime/osThread.hpp"
56 #include "runtime/safepoint.hpp"
57 #include "runtime/safepointMechanism.inline.hpp"
58 #include "runtime/signature.hpp"
59 #include "runtime/stubCodeGenerator.hpp"
60 #include "runtime/stubRoutines.hpp"
61 #include "runtime/sweeper.hpp"
62 #include "runtime/synchronizer.hpp"
63 #include "runtime/thread.inline.hpp"
64 #include "runtime/threadSMR.hpp"
65 #include "runtime/timerTrace.hpp"
66 #include "services/runtimeService.hpp"
1036 CodeBlob *cb = CodeCache::find_blob(real_return_addr);
1037 assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod");
1038 CompiledMethod* nm = (CompiledMethod*)cb;
1039
1040 // Find frame of caller
1041 frame stub_fr = thread()->last_frame();
1042 CodeBlob* stub_cb = stub_fr.cb();
1043 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
1044 RegisterMap map(thread(), true);
1045 frame caller_fr = stub_fr.sender(&map);
1046
1047 // Should only be poll_return or poll
1048 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1049
1050 // This is a poll immediately before a return. The exception handling code
1051 // has already had the effect of causing the return to occur, so the execution
1052 // will continue immediately after the call. In addition, the oopmap at the
1053 // return point does not mark the return value as an oop (if it is), so
1054 // it needs a handle here to be updated.
1055 if( nm->is_at_poll_return(real_return_addr) ) {
1056 // See if return type is an oop.
1057 bool return_oop = nm->method()->is_returning_oop();
1058 Handle return_value;
1059 if (return_oop) {
1060 // The oop result has been saved on the stack together with all
1061 // the other registers. In order to preserve it over GCs we need
1062 // to keep it in a handle.
1063 oop result = caller_fr.saved_oop_result(&map);
1064 assert(oopDesc::is_oop_or_null(result), "must be oop");
1065 return_value = Handle(thread(), result);
1066 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1067 }
1068
1069 // Block the thread
1070 SafepointMechanism::block_if_requested(thread());
1071
1072 // restore oop result, if any
1073 if (return_oop) {
1074 caller_fr.set_saved_oop_result(&map, return_value());
1075 }
1076 }
1077
1078 // This is a safepoint poll. Verify the return address and block.
1079 else {
1080 set_at_poll_safepoint(true);
1081
1082 // verify the blob built the "return address" correctly
1083 assert(real_return_addr == caller_fr.pc(), "must match");
1084
1085 // Block the thread
1086 SafepointMechanism::block_if_requested(thread());
1087 set_at_poll_safepoint(false);
1088
1089 // If we have a pending async exception deoptimize the frame
1090 // as otherwise we may never deliver it.
1091 if (thread()->has_async_condition()) {
1092 ThreadInVMfromJavaNoAsyncException __tiv(thread());
1093 Deoptimization::deoptimize_frame(thread(), caller_fr.id());
1094 }
|
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
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 "gc/shared/collectedHeap.hpp"
36 #include "gc/shared/gcLocker.hpp"
37 #include "gc/shared/strongRootsScope.hpp"
38 #include "gc/shared/workgroup.hpp"
39 #include "interpreter/interpreter.hpp"
40 #include "jfr/jfrEvents.hpp"
41 #include "logging/log.hpp"
42 #include "logging/logStream.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "memory/universe.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "oops/symbol.hpp"
47 #include "oops/valueKlass.hpp"
48 #include "runtime/atomic.hpp"
49 #include "runtime/compilationPolicy.hpp"
50 #include "runtime/deoptimization.hpp"
51 #include "runtime/frame.inline.hpp"
52 #include "runtime/handles.inline.hpp"
53 #include "runtime/interfaceSupport.inline.hpp"
54 #include "runtime/mutexLocker.hpp"
55 #include "runtime/orderAccess.hpp"
56 #include "runtime/osThread.hpp"
57 #include "runtime/safepoint.hpp"
58 #include "runtime/safepointMechanism.inline.hpp"
59 #include "runtime/signature.hpp"
60 #include "runtime/stubCodeGenerator.hpp"
61 #include "runtime/stubRoutines.hpp"
62 #include "runtime/sweeper.hpp"
63 #include "runtime/synchronizer.hpp"
64 #include "runtime/thread.inline.hpp"
65 #include "runtime/threadSMR.hpp"
66 #include "runtime/timerTrace.hpp"
67 #include "services/runtimeService.hpp"
1037 CodeBlob *cb = CodeCache::find_blob(real_return_addr);
1038 assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod");
1039 CompiledMethod* nm = (CompiledMethod*)cb;
1040
1041 // Find frame of caller
1042 frame stub_fr = thread()->last_frame();
1043 CodeBlob* stub_cb = stub_fr.cb();
1044 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
1045 RegisterMap map(thread(), true);
1046 frame caller_fr = stub_fr.sender(&map);
1047
1048 // Should only be poll_return or poll
1049 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1050
1051 // This is a poll immediately before a return. The exception handling code
1052 // has already had the effect of causing the return to occur, so the execution
1053 // will continue immediately after the call. In addition, the oopmap at the
1054 // return point does not mark the return value as an oop (if it is), so
1055 // it needs a handle here to be updated.
1056 if( nm->is_at_poll_return(real_return_addr) ) {
1057 ResourceMark rm;
1058 // See if return type is an oop.
1059 Method* method = nm->method();
1060 bool return_oop = method->may_return_oop();
1061
1062 GrowableArray<Handle> return_values;
1063 ValueKlass* vk = NULL;
1064
1065 if (return_oop && ValueTypeReturnedAsFields) {
1066 SignatureStream ss(method->signature());
1067 while (!ss.at_return_type()) {
1068 ss.next();
1069 }
1070 if (ss.type() == T_VALUETYPE) {
1071 // Check if value type is returned as fields
1072 vk = ValueKlass::returned_value_klass(map);
1073 if (vk != NULL) {
1074 // We're at a safepoint at the return of a method that returns
1075 // multiple values. We must make sure we preserve the oop values
1076 // across the safepoint.
1077 assert(vk == method->returned_value_type(thread()), "bad value klass");
1078 vk->save_oop_fields(map, return_values);
1079 return_oop = false;
1080 }
1081 }
1082 }
1083
1084 if (return_oop) {
1085 // The oop result has been saved on the stack together with all
1086 // the other registers. In order to preserve it over GCs we need
1087 // to keep it in a handle.
1088 oop result = caller_fr.saved_oop_result(&map);
1089 assert(oopDesc::is_oop_or_null(result), "must be oop");
1090 return_values.push(Handle(thread(), result));
1091 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1092 }
1093
1094 // Block the thread
1095 SafepointMechanism::block_if_requested(thread());
1096
1097 // restore oop result, if any
1098 if (return_oop) {
1099 assert(return_values.length() == 1, "only one return value");
1100 caller_fr.set_saved_oop_result(&map, return_values.pop()());
1101 } else if (vk != NULL) {
1102 vk->restore_oop_results(map, return_values);
1103 }
1104 }
1105
1106 // This is a safepoint poll. Verify the return address and block.
1107 else {
1108 set_at_poll_safepoint(true);
1109
1110 // verify the blob built the "return address" correctly
1111 assert(real_return_addr == caller_fr.pc(), "must match");
1112
1113 // Block the thread
1114 SafepointMechanism::block_if_requested(thread());
1115 set_at_poll_safepoint(false);
1116
1117 // If we have a pending async exception deoptimize the frame
1118 // as otherwise we may never deliver it.
1119 if (thread()->has_async_condition()) {
1120 ThreadInVMfromJavaNoAsyncException __tiv(thread());
1121 Deoptimization::deoptimize_frame(thread(), caller_fr.id());
1122 }
|