< prev index next >

src/hotspot/share/runtime/javaThread.cpp

Print this page

 140   if (_on_thread_list) {
 141     ThreadsSMRSupport::smr_delete(this);
 142   } else {
 143     delete this;
 144   }
 145 }
 146 
 147 // Initialized by VMThread at vm_global_init
 148 OopStorage* JavaThread::_thread_oop_storage = NULL;
 149 
 150 OopStorage* JavaThread::thread_oop_storage() {
 151   assert(_thread_oop_storage != NULL, "not yet initialized");
 152   return _thread_oop_storage;
 153 }
 154 
 155 void JavaThread::set_threadOopHandles(oop p) {
 156   assert(_thread_oop_storage != NULL, "not yet initialized");
 157   _threadObj   = OopHandle(_thread_oop_storage, p);
 158   _vthread     = OopHandle(_thread_oop_storage, p);
 159   _jvmti_vthread = OopHandle(_thread_oop_storage, NULL);
 160   _extentLocalCache = OopHandle(_thread_oop_storage, NULL);
 161 }
 162 
 163 oop JavaThread::threadObj() const {
 164   // Ideally we would verify the current thread is oop_safe when this is called, but as we can
 165   // be called from a signal handler we would have to use Thread::current_or_null_safe(). That
 166   // has overhead and also interacts poorly with GetLastError on Windows due to the use of TLS.
 167   // Instead callers must verify oop safe access.
 168   return _threadObj.resolve();
 169 }
 170 
 171 oop JavaThread::vthread() const {
 172   return _vthread.resolve();
 173 }
 174 
 175 void JavaThread::set_vthread(oop p) {
 176   assert(_thread_oop_storage != NULL, "not yet initialized");
 177   _vthread.replace(p);
 178 }
 179 
 180 oop JavaThread::jvmti_vthread() const {
 181   return _jvmti_vthread.resolve();
 182 }
 183 
 184 void JavaThread::set_jvmti_vthread(oop p) {
 185   assert(_thread_oop_storage != NULL, "not yet initialized");
 186   _jvmti_vthread.replace(p);
 187 }
 188 
 189 oop JavaThread::extentLocalCache() const {
 190   return _extentLocalCache.resolve();
 191 }
 192 
 193 void JavaThread::set_extentLocalCache(oop p) {
 194   assert(_thread_oop_storage != NULL, "not yet initialized");
 195   _extentLocalCache.replace(p);








 196 }
 197 
 198 void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name,
 199                                     bool daemon, TRAPS) {
 200   assert(thread_group.not_null(), "thread group should be specified");
 201   assert(threadObj() == NULL, "should only create Java thread object once");
 202 
 203   InstanceKlass* ik = vmClasses::Thread_klass();
 204   assert(ik->is_initialized(), "must be");
 205   instanceHandle thread_oop = ik->allocate_instance_handle(CHECK);
 206 
 207   // We are called from jni_AttachCurrentThread/jni_AttachCurrentThreadAsDaemon.
 208   // We cannot use JavaCalls::construct_new_instance because the java.lang.Thread
 209   // constructor calls Thread.current(), which must be set here.
 210   java_lang_Thread::set_thread(thread_oop(), this);
 211   set_threadOopHandles(thread_oop());
 212 
 213   JavaValue result(T_VOID);
 214   if (thread_name != NULL) {
 215     Handle name = java_lang_String::create_from_str(thread_name, CHECK);

1048     frame f = last_frame();
1049     if (f.is_runtime_frame()) {
1050       // If the topmost frame is a runtime stub, then we are calling into
1051       // OptoRuntime from compiled code. Some runtime stubs (new, monitor_exit..)
1052       // must deoptimize the caller before continuing, as the compiled exception
1053       // handler table may not be valid.
1054       RegisterMap reg_map(this,
1055                           RegisterMap::UpdateMap::skip,
1056                           RegisterMap::ProcessFrames::include,
1057                           RegisterMap::WalkContinuation::skip);
1058       frame compiled_frame = f.sender(&reg_map);
1059       if (!StressCompiledExceptionHandlers && compiled_frame.can_be_deoptimized()) {
1060         Deoptimization::deoptimize(this, compiled_frame);
1061       }
1062     }
1063   }
1064 
1065   // We cannot call Exceptions::_throw(...) here because we cannot block
1066   set_pending_exception(java_throwable, __FILE__, __LINE__);
1067 
1068   // Clear any extent-local bindings
1069   set_extentLocalCache(NULL);
1070   oop threadOop = threadObj();
1071   assert(threadOop != NULL, "must be");
1072   java_lang_Thread::clear_extentLocalBindings(threadOop);
1073 
1074   LogTarget(Info, exceptions) lt;
1075   if (lt.is_enabled()) {
1076     ResourceMark rm;
1077     LogStream ls(lt);
1078     ls.print("Async. exception installed at runtime exit (" INTPTR_FORMAT ")", p2i(this));
1079     if (has_last_Java_frame()) {
1080       frame f = last_frame();
1081       ls.print(" (pc: " INTPTR_FORMAT " sp: " INTPTR_FORMAT " )", p2i(f.pc()), p2i(f.sp()));
1082     }
1083     ls.print_cr(" of type: %s", java_throwable->klass()->external_name());
1084   }
1085 }
1086 
1087 void JavaThread::install_async_exception(AsyncExceptionHandshake* aeh) {
1088   // Do not throw asynchronous exceptions against the compiler thread
1089   // or if the thread is already exiting.
1090   if (!can_call_java() || is_exiting()) {
1091     delete aeh;
1092     return;

2114     MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
2115     list = _oop_handle_list;
2116     _oop_handle_list = nullptr;
2117   }
2118   assert(!SafepointSynchronize::is_at_safepoint(), "cannot be called at a safepoint");
2119 
2120   while (list != nullptr) {
2121     OopHandleList* l = list;
2122     list = l->next();
2123     delete l;
2124   }
2125 }
2126 
2127 // Add our OopHandles for later release.
2128 void JavaThread::add_oop_handles_for_release() {
2129   MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
2130   OopHandleList* new_head = new OopHandleList(_oop_handle_list);
2131   new_head->add(_threadObj);
2132   new_head->add(_vthread);
2133   new_head->add(_jvmti_vthread);
2134   new_head->add(_extentLocalCache);
2135   _oop_handle_list = new_head;
2136   Service_lock->notify_all();
2137 }

 140   if (_on_thread_list) {
 141     ThreadsSMRSupport::smr_delete(this);
 142   } else {
 143     delete this;
 144   }
 145 }
 146 
 147 // Initialized by VMThread at vm_global_init
 148 OopStorage* JavaThread::_thread_oop_storage = NULL;
 149 
 150 OopStorage* JavaThread::thread_oop_storage() {
 151   assert(_thread_oop_storage != NULL, "not yet initialized");
 152   return _thread_oop_storage;
 153 }
 154 
 155 void JavaThread::set_threadOopHandles(oop p) {
 156   assert(_thread_oop_storage != NULL, "not yet initialized");
 157   _threadObj   = OopHandle(_thread_oop_storage, p);
 158   _vthread     = OopHandle(_thread_oop_storage, p);
 159   _jvmti_vthread = OopHandle(_thread_oop_storage, NULL);
 160   _scopedValueCache = OopHandle(_thread_oop_storage, NULL);
 161 }
 162 
 163 oop JavaThread::threadObj() const {
 164   // Ideally we would verify the current thread is oop_safe when this is called, but as we can
 165   // be called from a signal handler we would have to use Thread::current_or_null_safe(). That
 166   // has overhead and also interacts poorly with GetLastError on Windows due to the use of TLS.
 167   // Instead callers must verify oop safe access.
 168   return _threadObj.resolve();
 169 }
 170 
 171 oop JavaThread::vthread() const {
 172   return _vthread.resolve();
 173 }
 174 
 175 void JavaThread::set_vthread(oop p) {
 176   assert(_thread_oop_storage != NULL, "not yet initialized");
 177   _vthread.replace(p);
 178 }
 179 
 180 oop JavaThread::jvmti_vthread() const {
 181   return _jvmti_vthread.resolve();
 182 }
 183 
 184 void JavaThread::set_jvmti_vthread(oop p) {
 185   assert(_thread_oop_storage != NULL, "not yet initialized");
 186   _jvmti_vthread.replace(p);
 187 }
 188 
 189 oop JavaThread::scopedValueCache() const {
 190   return _scopedValueCache.resolve();
 191 }
 192 
 193 void JavaThread::set_scopedValueCache(oop p) {
 194   if (_scopedValueCache.ptr_raw() != NULL) { // i.e. if the OopHandle has been allocated
 195     _scopedValueCache.replace(p);
 196   } else {
 197     assert(p == NULL, "not yet initialized");
 198   }
 199 }
 200 
 201 void JavaThread::clear_scopedValueBindings() {
 202   set_scopedValueCache(NULL);
 203   java_lang_Thread::clear_scopedValueBindings(vthread());
 204 }
 205 
 206 void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name,
 207                                     bool daemon, TRAPS) {
 208   assert(thread_group.not_null(), "thread group should be specified");
 209   assert(threadObj() == NULL, "should only create Java thread object once");
 210 
 211   InstanceKlass* ik = vmClasses::Thread_klass();
 212   assert(ik->is_initialized(), "must be");
 213   instanceHandle thread_oop = ik->allocate_instance_handle(CHECK);
 214 
 215   // We are called from jni_AttachCurrentThread/jni_AttachCurrentThreadAsDaemon.
 216   // We cannot use JavaCalls::construct_new_instance because the java.lang.Thread
 217   // constructor calls Thread.current(), which must be set here.
 218   java_lang_Thread::set_thread(thread_oop(), this);
 219   set_threadOopHandles(thread_oop());
 220 
 221   JavaValue result(T_VOID);
 222   if (thread_name != NULL) {
 223     Handle name = java_lang_String::create_from_str(thread_name, CHECK);

1056     frame f = last_frame();
1057     if (f.is_runtime_frame()) {
1058       // If the topmost frame is a runtime stub, then we are calling into
1059       // OptoRuntime from compiled code. Some runtime stubs (new, monitor_exit..)
1060       // must deoptimize the caller before continuing, as the compiled exception
1061       // handler table may not be valid.
1062       RegisterMap reg_map(this,
1063                           RegisterMap::UpdateMap::skip,
1064                           RegisterMap::ProcessFrames::include,
1065                           RegisterMap::WalkContinuation::skip);
1066       frame compiled_frame = f.sender(&reg_map);
1067       if (!StressCompiledExceptionHandlers && compiled_frame.can_be_deoptimized()) {
1068         Deoptimization::deoptimize(this, compiled_frame);
1069       }
1070     }
1071   }
1072 
1073   // We cannot call Exceptions::_throw(...) here because we cannot block
1074   set_pending_exception(java_throwable, __FILE__, __LINE__);
1075 
1076   clear_scopedValueBindings();




1077 
1078   LogTarget(Info, exceptions) lt;
1079   if (lt.is_enabled()) {
1080     ResourceMark rm;
1081     LogStream ls(lt);
1082     ls.print("Async. exception installed at runtime exit (" INTPTR_FORMAT ")", p2i(this));
1083     if (has_last_Java_frame()) {
1084       frame f = last_frame();
1085       ls.print(" (pc: " INTPTR_FORMAT " sp: " INTPTR_FORMAT " )", p2i(f.pc()), p2i(f.sp()));
1086     }
1087     ls.print_cr(" of type: %s", java_throwable->klass()->external_name());
1088   }
1089 }
1090 
1091 void JavaThread::install_async_exception(AsyncExceptionHandshake* aeh) {
1092   // Do not throw asynchronous exceptions against the compiler thread
1093   // or if the thread is already exiting.
1094   if (!can_call_java() || is_exiting()) {
1095     delete aeh;
1096     return;

2118     MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
2119     list = _oop_handle_list;
2120     _oop_handle_list = nullptr;
2121   }
2122   assert(!SafepointSynchronize::is_at_safepoint(), "cannot be called at a safepoint");
2123 
2124   while (list != nullptr) {
2125     OopHandleList* l = list;
2126     list = l->next();
2127     delete l;
2128   }
2129 }
2130 
2131 // Add our OopHandles for later release.
2132 void JavaThread::add_oop_handles_for_release() {
2133   MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
2134   OopHandleList* new_head = new OopHandleList(_oop_handle_list);
2135   new_head->add(_threadObj);
2136   new_head->add(_vthread);
2137   new_head->add(_jvmti_vthread);
2138   new_head->add(_scopedValueCache);
2139   _oop_handle_list = new_head;
2140   Service_lock->notify_all();
2141 }
< prev index next >