22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/stringTable.hpp"
27 #include "classfile/symbolTable.hpp"
28 #include "classfile/systemDictionary.hpp"
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 "gc/shared/collectedHeap.hpp"
35 #include "gc/shared/gcLocker.inline.hpp"
36 #include "interpreter/interpreter.hpp"
37 #include "logging/log.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "memory/universe.inline.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/symbol.hpp"
42 #include "runtime/atomic.hpp"
43 #include "runtime/compilationPolicy.hpp"
44 #include "runtime/deoptimization.hpp"
45 #include "runtime/frame.inline.hpp"
46 #include "runtime/interfaceSupport.hpp"
47 #include "runtime/mutexLocker.hpp"
48 #include "runtime/orderAccess.inline.hpp"
49 #include "runtime/osThread.hpp"
50 #include "runtime/safepoint.hpp"
51 #include "runtime/signature.hpp"
52 #include "runtime/stubCodeGenerator.hpp"
53 #include "runtime/stubRoutines.hpp"
54 #include "runtime/sweeper.hpp"
55 #include "runtime/synchronizer.hpp"
56 #include "runtime/thread.inline.hpp"
57 #include "runtime/timerTrace.hpp"
58 #include "services/runtimeService.hpp"
59 #include "trace/tracing.hpp"
60 #include "trace/traceMacros.hpp"
61 #include "utilities/events.hpp"
1012 CodeBlob *cb = CodeCache::find_blob(real_return_addr);
1013 assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod");
1014 CompiledMethod* nm = (CompiledMethod*)cb;
1015
1016 // Find frame of caller
1017 frame stub_fr = thread()->last_frame();
1018 CodeBlob* stub_cb = stub_fr.cb();
1019 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
1020 RegisterMap map(thread(), true);
1021 frame caller_fr = stub_fr.sender(&map);
1022
1023 // Should only be poll_return or poll
1024 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1025
1026 // This is a poll immediately before a return. The exception handling code
1027 // has already had the effect of causing the return to occur, so the execution
1028 // will continue immediately after the call. In addition, the oopmap at the
1029 // return point does not mark the return value as an oop (if it is), so
1030 // it needs a handle here to be updated.
1031 if( nm->is_at_poll_return(real_return_addr) ) {
1032 // See if return type is an oop.
1033 bool return_oop = nm->method()->is_returning_oop();
1034 Handle return_value;
1035 if (return_oop) {
1036 // The oop result has been saved on the stack together with all
1037 // the other registers. In order to preserve it over GCs we need
1038 // to keep it in a handle.
1039 oop result = caller_fr.saved_oop_result(&map);
1040 assert(result == NULL || result->is_oop(), "must be oop");
1041 return_value = Handle(thread(), result);
1042 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1043 }
1044
1045 // Block the thread
1046 SafepointSynchronize::block(thread());
1047
1048 // restore oop result, if any
1049 if (return_oop) {
1050 caller_fr.set_saved_oop_result(&map, return_value());
1051 }
1052 }
1053
1054 // This is a safepoint poll. Verify the return address and block.
1055 else {
1056 set_at_poll_safepoint(true);
1057
1058 // verify the blob built the "return address" correctly
1059 assert(real_return_addr == caller_fr.pc(), "must match");
1060
1061 // Block the thread
1062 SafepointSynchronize::block(thread());
1063 set_at_poll_safepoint(false);
1064
1065 // If we have a pending async exception deoptimize the frame
1066 // as otherwise we may never deliver it.
1067 if (thread()->has_async_condition()) {
1068 ThreadInVMfromJavaNoAsyncException __tiv(thread());
1069 Deoptimization::deoptimize_frame(thread(), caller_fr.id());
1070 }
|
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/stringTable.hpp"
27 #include "classfile/symbolTable.hpp"
28 #include "classfile/systemDictionary.hpp"
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 "gc/shared/collectedHeap.hpp"
35 #include "gc/shared/gcLocker.inline.hpp"
36 #include "interpreter/interpreter.hpp"
37 #include "logging/log.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "memory/universe.inline.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/symbol.hpp"
42 #include "oops/valueKlass.hpp"
43 #include "runtime/atomic.hpp"
44 #include "runtime/compilationPolicy.hpp"
45 #include "runtime/deoptimization.hpp"
46 #include "runtime/frame.inline.hpp"
47 #include "runtime/interfaceSupport.hpp"
48 #include "runtime/mutexLocker.hpp"
49 #include "runtime/orderAccess.inline.hpp"
50 #include "runtime/osThread.hpp"
51 #include "runtime/safepoint.hpp"
52 #include "runtime/signature.hpp"
53 #include "runtime/stubCodeGenerator.hpp"
54 #include "runtime/stubRoutines.hpp"
55 #include "runtime/sweeper.hpp"
56 #include "runtime/synchronizer.hpp"
57 #include "runtime/thread.inline.hpp"
58 #include "runtime/timerTrace.hpp"
59 #include "services/runtimeService.hpp"
60 #include "trace/tracing.hpp"
61 #include "trace/traceMacros.hpp"
62 #include "utilities/events.hpp"
1013 CodeBlob *cb = CodeCache::find_blob(real_return_addr);
1014 assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod");
1015 CompiledMethod* nm = (CompiledMethod*)cb;
1016
1017 // Find frame of caller
1018 frame stub_fr = thread()->last_frame();
1019 CodeBlob* stub_cb = stub_fr.cb();
1020 assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
1021 RegisterMap map(thread(), true);
1022 frame caller_fr = stub_fr.sender(&map);
1023
1024 // Should only be poll_return or poll
1025 assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
1026
1027 // This is a poll immediately before a return. The exception handling code
1028 // has already had the effect of causing the return to occur, so the execution
1029 // will continue immediately after the call. In addition, the oopmap at the
1030 // return point does not mark the return value as an oop (if it is), so
1031 // it needs a handle here to be updated.
1032 if( nm->is_at_poll_return(real_return_addr) ) {
1033 ResourceMark rm;
1034 // See if return type is an oop.
1035 Method* method = nm->method();
1036 bool return_oop = method->is_returning_oop();
1037
1038 GrowableArray<Handle> return_values;
1039 ValueKlass* vk = NULL;
1040 if (!return_oop && method->is_returning_vt()) {
1041 // We're at a safepoint at the return of a method that returns
1042 // multiple values. We must make sure we preserve the oop values
1043 // across the safepoint.
1044 vk = ValueKlass::returned_value_type(map);
1045 assert(vk == NULL || vk == method->returned_value_type(thread()) ||
1046 method->returned_value_type(thread()) == SystemDictionary::___Value_klass(), "Bad value klass");
1047 if (vk != NULL && !vk->save_oop_results(map, return_values)) {
1048 return_oop = true;
1049 vk = NULL;
1050 }
1051 }
1052
1053 if (return_oop) {
1054 // The oop result has been saved on the stack together with all
1055 // the other registers. In order to preserve it over GCs we need
1056 // to keep it in a handle.
1057 oop result = caller_fr.saved_oop_result(&map);
1058 assert(result == NULL || result->is_oop(), "must be oop");
1059 return_values.push(Handle(thread(), result));
1060 assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
1061 }
1062
1063 // Block the thread
1064 SafepointSynchronize::block(thread());
1065
1066 // restore oop result, if any
1067 if (return_oop) {
1068 assert(return_values.length() == 1, "only one return value");
1069 caller_fr.set_saved_oop_result(&map, return_values.pop()());
1070 } else if (vk != NULL) {
1071 vk->restore_oop_results(map, return_values);
1072 }
1073 }
1074
1075 // This is a safepoint poll. Verify the return address and block.
1076 else {
1077 set_at_poll_safepoint(true);
1078
1079 // verify the blob built the "return address" correctly
1080 assert(real_return_addr == caller_fr.pc(), "must match");
1081
1082 // Block the thread
1083 SafepointSynchronize::block(thread());
1084 set_at_poll_safepoint(false);
1085
1086 // If we have a pending async exception deoptimize the frame
1087 // as otherwise we may never deliver it.
1088 if (thread()->has_async_condition()) {
1089 ThreadInVMfromJavaNoAsyncException __tiv(thread());
1090 Deoptimization::deoptimize_frame(thread(), caller_fr.id());
1091 }
|