< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page




1977     JNIHandleBlock::release_block(block);
1978   }
1979 
1980   if (free_handle_block() != NULL) {
1981     JNIHandleBlock* block = free_handle_block();
1982     set_free_handle_block(NULL);
1983     JNIHandleBlock::release_block(block);
1984   }
1985 
1986   // These have to be removed while this is still a valid thread.
1987   remove_stack_guard_pages();
1988 
1989   if (UseTLAB) {
1990     tlab().make_parsable(true);  // retire TLAB
1991   }
1992 
1993   if (JvmtiEnv::environments_might_exist()) {
1994     JvmtiExport::cleanup_thread(this);
1995   }
1996 
1997   // We must flush any deferred card marks and other various GC barrier
1998   // related buffers (e.g. G1 SATB buffer and G1 dirty card queue buffer)
1999   // before removing a thread from the list of active threads.
2000   BarrierSet::barrier_set()->flush_deferred_barriers(this);
2001 
2002   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
2003     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
2004     os::current_thread_id());
2005 
2006   if (log_is_enabled(Debug, os, thread, timer)) {
2007     _timer_exit_phase3.stop();
2008     _timer_exit_phase4.start();
2009   }
2010   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
2011   Threads::remove(this);
2012 
2013   if (log_is_enabled(Debug, os, thread, timer)) {
2014     _timer_exit_phase4.stop();
2015     ResourceMark rm(this);
2016     log_debug(os, thread, timer)("name='%s'"
2017                                  ", exit-phase1=" JLONG_FORMAT
2018                                  ", exit-phase2=" JLONG_FORMAT
2019                                  ", exit-phase3=" JLONG_FORMAT
2020                                  ", exit-phase4=" JLONG_FORMAT,
2021                                  get_thread_name(),
2022                                  _timer_exit_phase1.milliseconds(),
2023                                  _timer_exit_phase2.milliseconds(),
2024                                  _timer_exit_phase3.milliseconds(),
2025                                  _timer_exit_phase4.milliseconds());
2026   }
2027 }
2028 
2029 #if INCLUDE_ALL_GCS
2030 void JavaThread::initialize_queues() {
2031   assert(!SafepointSynchronize::is_at_safepoint(),
2032          "we should not be at a safepoint");
2033 
2034   SATBMarkQueue& satb_queue = satb_mark_queue();
2035   SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set();
2036   // The SATB queue should have been constructed with its active
2037   // field set to false.
2038   assert(!satb_queue.is_active(), "SATB queue should not be active");
2039   assert(satb_queue.is_empty(), "SATB queue should be empty");
2040   // If we are creating the thread during a marking cycle, we should
2041   // set the active field of the SATB queue to true.
2042   if (satb_queue_set.is_active()) {
2043     satb_queue.set_active(true);
2044   }
2045 
2046   DirtyCardQueue& dirty_queue = dirty_card_queue();
2047   // The dirty card queue should have been constructed with its
2048   // active field set to true.
2049   assert(dirty_queue.is_active(), "dirty card queue should be active");
2050 }
2051 #endif // INCLUDE_ALL_GCS
2052 
2053 void JavaThread::cleanup_failed_attach_current_thread() {
2054   if (active_handles() != NULL) {
2055     JNIHandleBlock* block = active_handles();
2056     set_active_handles(NULL);
2057     JNIHandleBlock::release_block(block);
2058   }
2059 
2060   if (free_handle_block() != NULL) {
2061     JNIHandleBlock* block = free_handle_block();
2062     set_free_handle_block(NULL);
2063     JNIHandleBlock::release_block(block);
2064   }
2065 
2066   // These have to be removed while this is still a valid thread.
2067   remove_stack_guard_pages();
2068 
2069   if (UseTLAB) {
2070     tlab().make_parsable(true);  // retire TLAB, if any
2071   }
2072 
2073   BarrierSet::barrier_set()->flush_deferred_barriers(this);
2074 
2075   Threads::remove(this);
2076   this->smr_delete();
2077 }
2078 
2079 
2080 
2081 
2082 JavaThread* JavaThread::active() {
2083   Thread* thread = Thread::current();
2084   if (thread->is_Java_thread()) {
2085     return (JavaThread*) thread;
2086   } else {
2087     assert(thread->is_VM_thread(), "this must be a vm thread");
2088     VM_Operation* op = ((VMThread*) thread)->vm_operation();
2089     JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread();
2090     assert(ret->is_Java_thread(), "must be a Java thread");
2091     return ret;
2092   }
2093 }
2094 
2095 bool JavaThread::is_lock_owned(address adr) const {
2096   if (Thread::is_lock_owned(adr)) return true;
2097 
2098   for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
2099     if (chunk->contains(adr)) return true;
2100   }
2101 


4315   if (version == JNI_VERSION_1_1) return JNI_TRUE;
4316   return is_supported_jni_version(version);
4317 }
4318 
4319 
4320 jboolean Threads::is_supported_jni_version(jint version) {
4321   if (version == JNI_VERSION_1_2) return JNI_TRUE;
4322   if (version == JNI_VERSION_1_4) return JNI_TRUE;
4323   if (version == JNI_VERSION_1_6) return JNI_TRUE;
4324   if (version == JNI_VERSION_1_8) return JNI_TRUE;
4325   if (version == JNI_VERSION_9) return JNI_TRUE;
4326   if (version == JNI_VERSION_10) return JNI_TRUE;
4327   return JNI_FALSE;
4328 }
4329 
4330 
4331 void Threads::add(JavaThread* p, bool force_daemon) {
4332   // The threads lock must be owned at this point
4333   assert_locked_or_safepoint(Threads_lock);
4334 
4335   // See the comment for this method in thread.hpp for its purpose and
4336   // why it is called here.
4337   p->initialize_queues();
4338   p->set_next(_thread_list);
4339   _thread_list = p;
4340 
4341   // Once a JavaThread is added to the Threads list, smr_delete() has
4342   // to be used to delete it. Otherwise we can just delete it directly.
4343   p->set_on_thread_list();
4344 
4345   _number_of_threads++;
4346   oop threadObj = p->threadObj();
4347   bool daemon = true;
4348   // Bootstrapping problem: threadObj can be null for initial
4349   // JavaThread (or for threads attached via JNI)
4350   if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) {
4351     _number_of_non_daemon_threads++;
4352     daemon = false;
4353   }
4354 
4355   ThreadService::add_thread(p, daemon);
4356 
4357   // Maintain fast thread list




1977     JNIHandleBlock::release_block(block);
1978   }
1979 
1980   if (free_handle_block() != NULL) {
1981     JNIHandleBlock* block = free_handle_block();
1982     set_free_handle_block(NULL);
1983     JNIHandleBlock::release_block(block);
1984   }
1985 
1986   // These have to be removed while this is still a valid thread.
1987   remove_stack_guard_pages();
1988 
1989   if (UseTLAB) {
1990     tlab().make_parsable(true);  // retire TLAB
1991   }
1992 
1993   if (JvmtiEnv::environments_might_exist()) {
1994     JvmtiExport::cleanup_thread(this);
1995   }
1996 
1997   BarrierSet::barrier_set()->on_thread_detach(this);



1998 
1999   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
2000     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
2001     os::current_thread_id());
2002 
2003   if (log_is_enabled(Debug, os, thread, timer)) {
2004     _timer_exit_phase3.stop();
2005     _timer_exit_phase4.start();
2006   }
2007   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
2008   Threads::remove(this);
2009 
2010   if (log_is_enabled(Debug, os, thread, timer)) {
2011     _timer_exit_phase4.stop();
2012     ResourceMark rm(this);
2013     log_debug(os, thread, timer)("name='%s'"
2014                                  ", exit-phase1=" JLONG_FORMAT
2015                                  ", exit-phase2=" JLONG_FORMAT
2016                                  ", exit-phase3=" JLONG_FORMAT
2017                                  ", exit-phase4=" JLONG_FORMAT,
2018                                  get_thread_name(),
2019                                  _timer_exit_phase1.milliseconds(),
2020                                  _timer_exit_phase2.milliseconds(),
2021                                  _timer_exit_phase3.milliseconds(),
2022                                  _timer_exit_phase4.milliseconds());
2023   }
2024 }
2025 
























2026 void JavaThread::cleanup_failed_attach_current_thread() {
2027   if (active_handles() != NULL) {
2028     JNIHandleBlock* block = active_handles();
2029     set_active_handles(NULL);
2030     JNIHandleBlock::release_block(block);
2031   }
2032 
2033   if (free_handle_block() != NULL) {
2034     JNIHandleBlock* block = free_handle_block();
2035     set_free_handle_block(NULL);
2036     JNIHandleBlock::release_block(block);
2037   }
2038 
2039   // These have to be removed while this is still a valid thread.
2040   remove_stack_guard_pages();
2041 
2042   if (UseTLAB) {
2043     tlab().make_parsable(true);  // retire TLAB, if any
2044   }
2045 
2046   BarrierSet::barrier_set()->on_thread_detach(this);
2047 
2048   Threads::remove(this);
2049   this->smr_delete();
2050 }
2051 



2052 JavaThread* JavaThread::active() {
2053   Thread* thread = Thread::current();
2054   if (thread->is_Java_thread()) {
2055     return (JavaThread*) thread;
2056   } else {
2057     assert(thread->is_VM_thread(), "this must be a vm thread");
2058     VM_Operation* op = ((VMThread*) thread)->vm_operation();
2059     JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread();
2060     assert(ret->is_Java_thread(), "must be a Java thread");
2061     return ret;
2062   }
2063 }
2064 
2065 bool JavaThread::is_lock_owned(address adr) const {
2066   if (Thread::is_lock_owned(adr)) return true;
2067 
2068   for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
2069     if (chunk->contains(adr)) return true;
2070   }
2071 


4285   if (version == JNI_VERSION_1_1) return JNI_TRUE;
4286   return is_supported_jni_version(version);
4287 }
4288 
4289 
4290 jboolean Threads::is_supported_jni_version(jint version) {
4291   if (version == JNI_VERSION_1_2) return JNI_TRUE;
4292   if (version == JNI_VERSION_1_4) return JNI_TRUE;
4293   if (version == JNI_VERSION_1_6) return JNI_TRUE;
4294   if (version == JNI_VERSION_1_8) return JNI_TRUE;
4295   if (version == JNI_VERSION_9) return JNI_TRUE;
4296   if (version == JNI_VERSION_10) return JNI_TRUE;
4297   return JNI_FALSE;
4298 }
4299 
4300 
4301 void Threads::add(JavaThread* p, bool force_daemon) {
4302   // The threads lock must be owned at this point
4303   assert_locked_or_safepoint(Threads_lock);
4304 
4305   BarrierSet::barrier_set()->on_thread_attach(p);
4306 

4307   p->set_next(_thread_list);
4308   _thread_list = p;
4309 
4310   // Once a JavaThread is added to the Threads list, smr_delete() has
4311   // to be used to delete it. Otherwise we can just delete it directly.
4312   p->set_on_thread_list();
4313 
4314   _number_of_threads++;
4315   oop threadObj = p->threadObj();
4316   bool daemon = true;
4317   // Bootstrapping problem: threadObj can be null for initial
4318   // JavaThread (or for threads attached via JNI)
4319   if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) {
4320     _number_of_non_daemon_threads++;
4321     daemon = false;
4322   }
4323 
4324   ThreadService::add_thread(p, daemon);
4325 
4326   // Maintain fast thread list


< prev index next >