src/hotspot/share/runtime/thread.cpp
changeset 52569 1a534c7926cc
parent 52431 b0af758a092c
child 52596 dfa02b3f728c
equal deleted inserted replaced
52568:40474b7105f4 52569:1a534c7926cc
    39 #include "gc/shared/workgroup.hpp"
    39 #include "gc/shared/workgroup.hpp"
    40 #include "interpreter/interpreter.hpp"
    40 #include "interpreter/interpreter.hpp"
    41 #include "interpreter/linkResolver.hpp"
    41 #include "interpreter/linkResolver.hpp"
    42 #include "interpreter/oopMapCache.hpp"
    42 #include "interpreter/oopMapCache.hpp"
    43 #include "jfr/jfrEvents.hpp"
    43 #include "jfr/jfrEvents.hpp"
    44 #include "jfr/support/jfrThreadId.hpp"
       
    45 #include "jvmtifiles/jvmtiEnv.hpp"
    44 #include "jvmtifiles/jvmtiEnv.hpp"
    46 #include "logging/log.hpp"
    45 #include "logging/log.hpp"
    47 #include "logging/logConfiguration.hpp"
    46 #include "logging/logConfiguration.hpp"
    48 #include "logging/logStream.hpp"
    47 #include "logging/logStream.hpp"
    49 #include "memory/allocation.inline.hpp"
    48 #include "memory/allocation.inline.hpp"
   367   // At this point, Thread object should be fully initialized and
   366   // At this point, Thread object should be fully initialized and
   368   // Thread::current() should be set.
   367   // Thread::current() should be set.
   369 
   368 
   370   register_thread_stack_with_NMT();
   369   register_thread_stack_with_NMT();
   371 
   370 
       
   371   JFR_ONLY(Jfr::on_thread_start(this);)
       
   372 
   372   log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: "
   373   log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: "
   373     PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).",
   374     PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).",
   374     os::current_thread_id(), p2i(stack_base() - stack_size()),
   375     os::current_thread_id(), p2i(stack_base() - stack_size()),
   375     p2i(stack_base()), stack_size()/1024);
   376     p2i(stack_base()), stack_size()/1024);
   376 
   377 
   391   }
   392   }
   392 
   393 
   393 }
   394 }
   394 
   395 
   395 Thread::~Thread() {
   396 Thread::~Thread() {
   396   JFR_ONLY(Jfr::on_thread_destruct(this);)
       
   397 
       
   398   // Notify the barrier set that a thread is being destroyed. Note that a barrier
   397   // Notify the barrier set that a thread is being destroyed. Note that a barrier
   399   // set might not be available if we encountered errors during bootstrapping.
   398   // set might not be available if we encountered errors during bootstrapping.
   400   BarrierSet* const barrier_set = BarrierSet::barrier_set();
   399   BarrierSet* const barrier_set = BarrierSet::barrier_set();
   401   if (barrier_set != NULL) {
   400   if (barrier_set != NULL) {
   402     barrier_set->on_thread_destroy(this);
   401     barrier_set->on_thread_destroy(this);
   403   }
   402   }
   404 
       
   405 
   403 
   406   // stack_base can be NULL if the thread is never started or exited before
   404   // stack_base can be NULL if the thread is never started or exited before
   407   // record_stack_base_and_size called. Although, we would like to ensure
   405   // record_stack_base_and_size called. Although, we would like to ensure
   408   // that all started threads do call record_stack_base_and_size(), there is
   406   // that all started threads do call record_stack_base_and_size(), there is
   409   // not proper way to enforce that.
   407   // not proper way to enforce that.
  1256   _next = _the_list._head;
  1254   _next = _the_list._head;
  1257   OrderAccess::release_store(&_the_list._head, this);
  1255   OrderAccess::release_store(&_the_list._head, this);
  1258 }
  1256 }
  1259 
  1257 
  1260 NonJavaThread::~NonJavaThread() {
  1258 NonJavaThread::~NonJavaThread() {
       
  1259   JFR_ONLY(Jfr::on_thread_exit(this);)
  1261   // Remove this thread from _the_list.
  1260   // Remove this thread from _the_list.
  1262   MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
  1261   MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
  1263   NonJavaThread* volatile* p = &_the_list._head;
  1262   NonJavaThread* volatile* p = &_the_list._head;
  1264   for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
  1263   for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
  1265     if (t == this) {
  1264     if (t == this) {
  1778   // been completed.
  1777   // been completed.
  1779   this->set_active_handles(JNIHandleBlock::allocate_block());
  1778   this->set_active_handles(JNIHandleBlock::allocate_block());
  1780 
  1779 
  1781   if (JvmtiExport::should_post_thread_life()) {
  1780   if (JvmtiExport::should_post_thread_life()) {
  1782     JvmtiExport::post_thread_start(this);
  1781     JvmtiExport::post_thread_start(this);
  1783   }
  1782 
  1784 
       
  1785   EventThreadStart event;
       
  1786   if (event.should_commit()) {
       
  1787     event.set_thread(JFR_THREAD_ID(this));
       
  1788     event.commit();
       
  1789   }
  1783   }
  1790 
  1784 
  1791   // We call another function to do the rest so we are sure that the stack addresses used
  1785   // We call another function to do the rest so we are sure that the stack addresses used
  1792   // from there will be lower than the stack base just computed
  1786   // from there will be lower than the stack base just computed
  1793   thread_main_inner();
  1787   thread_main_inner();
  1887                     pending_exception()->klass()->external_name(),
  1881                     pending_exception()->klass()->external_name(),
  1888                     get_thread_name());
  1882                     get_thread_name());
  1889         CLEAR_PENDING_EXCEPTION;
  1883         CLEAR_PENDING_EXCEPTION;
  1890       }
  1884       }
  1891     }
  1885     }
  1892 
  1886     JFR_ONLY(Jfr::on_java_thread_dismantle(this);)
  1893     // Called before the java thread exit since we want to read info
       
  1894     // from java_lang_Thread object
       
  1895     EventThreadEnd event;
       
  1896     if (event.should_commit()) {
       
  1897       event.set_thread(JFR_THREAD_ID(this));
       
  1898       event.commit();
       
  1899     }
       
  1900 
       
  1901     // Call after last event on thread
       
  1902     JFR_ONLY(Jfr::on_thread_exit(this);)
       
  1903 
  1887 
  1904     // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
  1888     // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
  1905     // the execution of the method. If that is not enough, then we don't really care. Thread.stop
  1889     // the execution of the method. If that is not enough, then we don't really care. Thread.stop
  1906     // is deprecated anyhow.
  1890     // is deprecated anyhow.
  1907     if (!is_Compiler_thread()) {
  1891     if (!is_Compiler_thread()) {
  1986     assert(!this->has_pending_exception(), "release_monitors should have cleared");
  1970     assert(!this->has_pending_exception(), "release_monitors should have cleared");
  1987   }
  1971   }
  1988 
  1972 
  1989   // These things needs to be done while we are still a Java Thread. Make sure that thread
  1973   // These things needs to be done while we are still a Java Thread. Make sure that thread
  1990   // is in a consistent state, in case GC happens
  1974   // is in a consistent state, in case GC happens
       
  1975   JFR_ONLY(Jfr::on_thread_exit(this);)
  1991 
  1976 
  1992   if (active_handles() != NULL) {
  1977   if (active_handles() != NULL) {
  1993     JNIHandleBlock* block = active_handles();
  1978     JNIHandleBlock* block = active_handles();
  1994     set_active_handles(NULL);
  1979     set_active_handles(NULL);
  1995     JNIHandleBlock::release_block(block);
  1980     JNIHandleBlock::release_block(block);