< prev index next >

src/hotspot/share/runtime/sharedRuntime.cpp

Print this page

  59 #include "runtime/biasedLocking.hpp"
  60 #include "runtime/frame.inline.hpp"
  61 #include "runtime/handles.inline.hpp"
  62 #include "runtime/init.hpp"
  63 #include "runtime/interfaceSupport.inline.hpp"
  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/sharedRuntime.hpp"
  67 #include "runtime/stubRoutines.hpp"
  68 #include "runtime/vframe.inline.hpp"
  69 #include "runtime/vframeArray.hpp"
  70 #include "utilities/copy.hpp"
  71 #include "utilities/dtrace.hpp"
  72 #include "utilities/events.hpp"
  73 #include "utilities/hashtable.inline.hpp"
  74 #include "utilities/macros.hpp"
  75 #include "utilities/xmlstream.hpp"
  76 #ifdef COMPILER1
  77 #include "c1/c1_Runtime1.hpp"
  78 #endif




  79 
  80 // Shared stub locations
  81 RuntimeStub*        SharedRuntime::_wrong_method_blob;
  82 RuntimeStub*        SharedRuntime::_wrong_method_abstract_blob;
  83 RuntimeStub*        SharedRuntime::_ic_miss_blob;
  84 RuntimeStub*        SharedRuntime::_resolve_opt_virtual_call_blob;
  85 RuntimeStub*        SharedRuntime::_resolve_virtual_call_blob;
  86 RuntimeStub*        SharedRuntime::_resolve_static_call_blob;
  87 address             SharedRuntime::_resolve_static_call_entry;
  88 
  89 DeoptimizationBlob* SharedRuntime::_deopt_blob;
  90 SafepointBlob*      SharedRuntime::_polling_page_vectors_safepoint_handler_blob;
  91 SafepointBlob*      SharedRuntime::_polling_page_safepoint_handler_blob;
  92 SafepointBlob*      SharedRuntime::_polling_page_return_handler_blob;
  93 
  94 #ifdef COMPILER2
  95 UncommonTrapBlob*   SharedRuntime::_uncommon_trap_blob;
  96 #endif // COMPILER2
  97 
  98 

 991       (char *) kname->bytes(), kname->utf8_length(),
 992       (char *) name->bytes(), name->utf8_length(),
 993       (char *) sig->bytes(), sig->utf8_length());
 994   return 0;
 995 JRT_END
 996 
 997 JRT_LEAF(int, SharedRuntime::dtrace_method_exit(
 998     JavaThread* thread, Method* method))
 999   assert(DTraceMethodProbes, "wrong call");
1000   Symbol* kname = method->klass_name();
1001   Symbol* name = method->name();
1002   Symbol* sig = method->signature();
1003   HOTSPOT_METHOD_RETURN(
1004       get_java_tid(thread),
1005       (char *) kname->bytes(), kname->utf8_length(),
1006       (char *) name->bytes(), name->utf8_length(),
1007       (char *) sig->bytes(), sig->utf8_length());
1008   return 0;
1009 JRT_END
1010 










































































































































































1011 
1012 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode)
1013 // for a call current in progress, i.e., arguments has been pushed on stack
1014 // put callee has not been invoked yet.  Used by: resolve virtual/static,
1015 // vtable updates, etc.  Caller frame must be compiled.
1016 Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
1017   ResourceMark rm(THREAD);
1018 
1019   // last java frame on stack (which includes native call frames)
1020   vframeStream vfst(thread, true);  // Do not skip and javaCalls
1021 
1022   return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
1023 }
1024 
1025 Method* SharedRuntime::extract_attached_method(vframeStream& vfst) {
1026   CompiledMethod* caller = vfst.nm();
1027 
1028   nmethodLocker caller_lock(caller);
1029 
1030   address pc = vfst.frame_pc();

  59 #include "runtime/biasedLocking.hpp"
  60 #include "runtime/frame.inline.hpp"
  61 #include "runtime/handles.inline.hpp"
  62 #include "runtime/init.hpp"
  63 #include "runtime/interfaceSupport.inline.hpp"
  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/sharedRuntime.hpp"
  67 #include "runtime/stubRoutines.hpp"
  68 #include "runtime/vframe.inline.hpp"
  69 #include "runtime/vframeArray.hpp"
  70 #include "utilities/copy.hpp"
  71 #include "utilities/dtrace.hpp"
  72 #include "utilities/events.hpp"
  73 #include "utilities/hashtable.inline.hpp"
  74 #include "utilities/macros.hpp"
  75 #include "utilities/xmlstream.hpp"
  76 #ifdef COMPILER1
  77 #include "c1/c1_Runtime1.hpp"
  78 #endif
  79 #if INCLUDE_TSAN
  80 #include "tsan/tsanExternalDecls.hpp"
  81 #include "tsan/tsanOopMap.hpp"
  82 #endif
  83 
  84 // Shared stub locations
  85 RuntimeStub*        SharedRuntime::_wrong_method_blob;
  86 RuntimeStub*        SharedRuntime::_wrong_method_abstract_blob;
  87 RuntimeStub*        SharedRuntime::_ic_miss_blob;
  88 RuntimeStub*        SharedRuntime::_resolve_opt_virtual_call_blob;
  89 RuntimeStub*        SharedRuntime::_resolve_virtual_call_blob;
  90 RuntimeStub*        SharedRuntime::_resolve_static_call_blob;
  91 address             SharedRuntime::_resolve_static_call_entry;
  92 
  93 DeoptimizationBlob* SharedRuntime::_deopt_blob;
  94 SafepointBlob*      SharedRuntime::_polling_page_vectors_safepoint_handler_blob;
  95 SafepointBlob*      SharedRuntime::_polling_page_safepoint_handler_blob;
  96 SafepointBlob*      SharedRuntime::_polling_page_return_handler_blob;
  97 
  98 #ifdef COMPILER2
  99 UncommonTrapBlob*   SharedRuntime::_uncommon_trap_blob;
 100 #endif // COMPILER2
 101 
 102 

 995       (char *) kname->bytes(), kname->utf8_length(),
 996       (char *) name->bytes(), name->utf8_length(),
 997       (char *) sig->bytes(), sig->utf8_length());
 998   return 0;
 999 JRT_END
1000 
1001 JRT_LEAF(int, SharedRuntime::dtrace_method_exit(
1002     JavaThread* thread, Method* method))
1003   assert(DTraceMethodProbes, "wrong call");
1004   Symbol* kname = method->klass_name();
1005   Symbol* name = method->name();
1006   Symbol* sig = method->signature();
1007   HOTSPOT_METHOD_RETURN(
1008       get_java_tid(thread),
1009       (char *) kname->bytes(), kname->utf8_length(),
1010       (char *) name->bytes(), name->utf8_length(),
1011       (char *) sig->bytes(), sig->utf8_length());
1012   return 0;
1013 JRT_END
1014 
1015 #if INCLUDE_TSAN
1016 
1017 JRT_LEAF(void, SharedRuntime::verify_oop_index(oopDesc* obj, int index))
1018   assert(oopDesc::is_oop(obj), "invalid oop");
1019   assert(index >= 0, "index is less than 0");
1020   int obj_size_in_bytes = obj->size() * HeapWordSize;
1021   assert(index < obj_size_in_bytes, "index %d >= obj size %d", index, obj_size_in_bytes);
1022 JRT_END
1023 
1024 // TSAN: method entry callback from interpreter
1025 // (1) In order to have the line numbers in the call stack, we use the caller
1026 //     address instead of the method that's being called. This also matches
1027 //     the entry/exit convention that TSAN uses for C++.
1028 // We use JRT_ENTRY since call_VM_leaf doesn't set _last_Java_sp that we need.
1029 JRT_ENTRY(void, SharedRuntime::tsan_interp_method_entry(JavaThread *thread))
1030   DEBUG_ONLY(NoSafepointVerifier nsv;)
1031   DEBUG_ONLY(NoHandleMark nhm;)
1032   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1033 
1034   RegisterMap unused_reg_map(thread, false);
1035 
1036   // These asserts should be removed once
1037   // we support more than just the interpreter for TSAN.
1038   assert(!thread->last_frame().is_compiled_frame(),
1039          "Current frame should not be a compiled frame");
1040   const frame sender = thread->last_frame().real_sender(&unused_reg_map);
1041   assert(!sender.is_compiled_frame(), "Sender should not be a compiled frame");
1042 
1043   jmethodID jmethod_id = 0;
1044   u2 bci = 0;
1045   // TODO: is (0, 0) really the best we can do
1046   // when the sender isn't an interpreted frame?
1047   if (sender.is_interpreted_frame()) {
1048     jmethod_id = sender.interpreter_frame_method()->find_jmethod_id_or_null();
1049     bci = sender.interpreter_frame_bci();
1050   }
1051   __tsan_func_entry(tsan_code_location(jmethod_id, bci));
1052 JRT_END
1053 
1054 // TSAN: method exit callback from interpreter
1055 JRT_LEAF(void, SharedRuntime::tsan_interp_method_exit())
1056   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1057   __tsan_func_exit();
1058 JRT_END
1059 
1060 void SharedRuntime::tsan_oop_lock(Thread* thread, oop obj) {
1061   DEBUG_ONLY(NoSafepointVerifier nsv;)
1062   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1063   assert(thread != NULL, "null thread");
1064   assert(obj != NULL, "null oop");
1065   assert(oopDesc::is_oop(obj), "invalid oop");
1066 
1067   TsanOopMap::add_oop(obj);
1068   __tsan_java_mutex_lock((julong)(oopDesc*)obj);
1069 }
1070 
1071 void SharedRuntime::tsan_oop_unlock(Thread *thread, oop obj) {
1072   DEBUG_ONLY(NoSafepointVerifier nsv;)
1073   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1074   assert(thread != NULL, "null thread");
1075   assert(obj != NULL, "null oop");
1076   assert(oopDesc::is_oop(obj), "invalid oop");
1077   assert(TsanOopMap::exists(obj), "oop seen in unlock but not tracked");
1078 
1079   __tsan_java_mutex_unlock((julong)(oopDesc*)obj);
1080 }
1081 
1082 void SharedRuntime::tsan_oop_rec_lock(Thread* thread, oop obj, int rec) {
1083   DEBUG_ONLY(NoSafepointVerifier nsv;)
1084   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1085   assert(thread != NULL, "null thread");
1086   assert(obj != NULL, "null oop");
1087   assert(oopDesc::is_oop(obj), "invalid oop");
1088 
1089   TsanOopMap::add_oop(obj);
1090   __tsan_java_mutex_lock_rec((julong)(oopDesc*)obj, rec);
1091 }
1092 
1093 int SharedRuntime::tsan_oop_rec_unlock(Thread *thread, oop obj) {
1094   DEBUG_ONLY(NoSafepointVerifier nsv;)
1095   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1096   assert(thread != NULL, "null thread");
1097   assert(obj != NULL, "null oop");
1098   assert(oopDesc::is_oop(obj), "invalid oop");
1099   assert(TsanOopMap::exists(obj), "oop seen in unlock but not tracked");
1100 
1101   return __tsan_java_mutex_unlock_rec((julong)(oopDesc*)obj);
1102 }
1103 
1104 JRT_LEAF(void, SharedRuntime::tsan_interp_lock(JavaThread* thread,
1105                                                BasicObjectLock* elem))
1106   DEBUG_ONLY(thread->last_frame().interpreter_frame_verify_monitor(elem);)
1107   assert(elem != NULL, "null elem");
1108 
1109   oop obj = elem->obj();
1110   tsan_oop_lock(thread, obj);
1111 
1112   assert(obj == elem->obj(), "oop changed");
1113   DEBUG_ONLY(thread->last_frame().interpreter_frame_verify_monitor(elem);)
1114 JRT_END
1115 
1116 JRT_LEAF(void, SharedRuntime::tsan_interp_unlock(JavaThread* thread,
1117                                                  BasicObjectLock* elem))
1118   DEBUG_ONLY(thread->last_frame().interpreter_frame_verify_monitor(elem);)
1119   assert(elem != NULL, "null elem");
1120 
1121   oop obj = elem->obj();
1122   tsan_oop_unlock(thread, obj);
1123 
1124   assert(obj == elem->obj(), "oop changed");
1125   DEBUG_ONLY(thread->last_frame().interpreter_frame_verify_monitor(elem);)
1126 JRT_END
1127 
1128 // Should be JRT_LEAF, but this is called very early during VM startup, so we
1129 // are sometimes in '_thread_in_vm' state.
1130 // NOTE: DO NOT add operations that can safepoint, enter GC, or throw an
1131 // exception!
1132 void SharedRuntime::tsan_track_obj_with_size(oopDesc* obj, int size) {
1133   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1134   assert(oopDesc::is_oop(obj), "Bad oopDesc passed to tsan_track_obj_with_size().");
1135   TsanOopMap::add_oop_with_size(obj, size);
1136 }
1137 
1138 JRT_LEAF(void, SharedRuntime::tsan_track_obj(oopDesc* obj))
1139   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1140   assert(oopDesc::is_oop(obj), "Bad oopDesc passed to tsan_track_obj().");
1141   TsanOopMap::add_oop(obj);
1142 JRT_END
1143 
1144 // TODO: Make tsan_acquire/release JRT_LEAF
1145 // Currently it can't be JRT_LEAF because there are calls from the VM
1146 // (instanceKlass.cpp), and JRT_LEAF only allows calls from Java/native code.
1147 // We need to figure out a better way of being able to call TSAN functions from
1148 // the VM.
1149 void SharedRuntime::tsan_acquire(void* address) {
1150   DEBUG_ONLY(NoSafepointVerifier nsv;)
1151   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1152   assert(address != NULL, "Cannot acquire at address 0");
1153   __tsan_java_acquire(address);
1154 }
1155 
1156 void SharedRuntime::tsan_release(void* address) {
1157   DEBUG_ONLY(NoSafepointVerifier nsv;)
1158   assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");
1159   assert(address != NULL, "Cannot release at address 0");
1160   __tsan_java_release(address);
1161 }
1162 
1163 #define TSAN_MEMORY_ACCESS(name)                                               \
1164   JRT_LEAF(void, SharedRuntime::tsan_##name(                                   \
1165       void* addr,                                                              \
1166       Method* method,                                                          \
1167       address bcp))                                                            \
1168     assert(ThreadSanitizer, "Need -XX:+ThreadSanitizer");                      \
1169     assert(ThreadSanitizerJavaMemory, "Need -XX:+ThreadSanitizerJavaMemory");  \
1170     jmethodID mid = method->find_jmethod_id_or_null();                         \
1171     int bci = method->bci_from(bcp);                                           \
1172     __tsan_##name##_pc(addr, tsan_code_location(mid, bci));                    \
1173   JRT_END
1174 
1175 TSAN_MEMORY_ACCESS(read1)
1176 TSAN_MEMORY_ACCESS(read2)
1177 TSAN_MEMORY_ACCESS(read4)
1178 TSAN_MEMORY_ACCESS(read8)
1179 TSAN_MEMORY_ACCESS(write1)
1180 TSAN_MEMORY_ACCESS(write2)
1181 TSAN_MEMORY_ACCESS(write4)
1182 TSAN_MEMORY_ACCESS(write8)
1183 
1184 #endif // INCLUDE_TSAN
1185 
1186 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode)
1187 // for a call current in progress, i.e., arguments has been pushed on stack
1188 // put callee has not been invoked yet.  Used by: resolve virtual/static,
1189 // vtable updates, etc.  Caller frame must be compiled.
1190 Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
1191   ResourceMark rm(THREAD);
1192 
1193   // last java frame on stack (which includes native call frames)
1194   vframeStream vfst(thread, true);  // Do not skip and javaCalls
1195 
1196   return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
1197 }
1198 
1199 Method* SharedRuntime::extract_attached_method(vframeStream& vfst) {
1200   CompiledMethod* caller = vfst.nm();
1201 
1202   nmethodLocker caller_lock(caller);
1203 
1204   address pc = vfst.frame_pc();
< prev index next >