31 #include "compiler/compileBroker.hpp" |
31 #include "compiler/compileBroker.hpp" |
32 #include "interpreter/interpreter.hpp" |
32 #include "interpreter/interpreter.hpp" |
33 #include "interpreter/linkResolver.hpp" |
33 #include "interpreter/linkResolver.hpp" |
34 #include "interpreter/oopMapCache.hpp" |
34 #include "interpreter/oopMapCache.hpp" |
35 #include "jfr/jfrEvents.hpp" |
35 #include "jfr/jfrEvents.hpp" |
36 #include "jfr/support/jfrThreadId.hpp" |
|
37 #include "jvmtifiles/jvmtiEnv.hpp" |
36 #include "jvmtifiles/jvmtiEnv.hpp" |
38 #include "memory/gcLocker.inline.hpp" |
37 #include "memory/gcLocker.inline.hpp" |
39 #include "memory/metaspaceShared.hpp" |
38 #include "memory/metaspaceShared.hpp" |
40 #include "memory/oopFactory.hpp" |
39 #include "memory/oopFactory.hpp" |
41 #include "memory/universe.inline.hpp" |
40 #include "memory/universe.inline.hpp" |
343 |
342 |
344 Thread::~Thread() { |
343 Thread::~Thread() { |
345 // Reclaim the objectmonitors from the omFreeList of the moribund thread. |
344 // Reclaim the objectmonitors from the omFreeList of the moribund thread. |
346 ObjectSynchronizer::omFlush (this) ; |
345 ObjectSynchronizer::omFlush (this) ; |
347 |
346 |
348 JFR_ONLY(Jfr::on_thread_destruct(this);) |
|
349 |
|
350 // stack_base can be NULL if the thread is never started or exited before |
347 // stack_base can be NULL if the thread is never started or exited before |
351 // record_stack_base_and_size called. Although, we would like to ensure |
348 // record_stack_base_and_size called. Although, we would like to ensure |
352 // that all started threads do call record_stack_base_and_size(), there is |
349 // that all started threads do call record_stack_base_and_size(), there is |
353 // not proper way to enforce that. |
350 // not proper way to enforce that. |
354 #if INCLUDE_NMT |
351 #if INCLUDE_NMT |
1213 _name = NULL; |
1210 _name = NULL; |
1214 _processed_thread = NULL; |
1211 _processed_thread = NULL; |
1215 } |
1212 } |
1216 |
1213 |
1217 NamedThread::~NamedThread() { |
1214 NamedThread::~NamedThread() { |
|
1215 JFR_ONLY(Jfr::on_thread_exit(this);) |
1218 if (_name != NULL) { |
1216 if (_name != NULL) { |
1219 FREE_C_HEAP_ARRAY(char, _name, mtThread); |
1217 FREE_C_HEAP_ARRAY(char, _name, mtThread); |
1220 _name = NULL; |
1218 _name = NULL; |
1221 } |
1219 } |
1222 } |
1220 } |
1670 |
1668 |
1671 if (JvmtiExport::should_post_thread_life()) { |
1669 if (JvmtiExport::should_post_thread_life()) { |
1672 JvmtiExport::post_thread_start(this); |
1670 JvmtiExport::post_thread_start(this); |
1673 } |
1671 } |
1674 |
1672 |
1675 EventThreadStart event; |
1673 JFR_ONLY(Jfr::on_thread_start(this);) |
1676 if (event.should_commit()) { |
|
1677 event.set_thread(JFR_THREAD_ID(this)); |
|
1678 event.commit(); |
|
1679 } |
|
1680 |
1674 |
1681 // We call another function to do the rest so we are sure that the stack addresses used |
1675 // We call another function to do the rest so we are sure that the stack addresses used |
1682 // from there will be lower than the stack base just computed |
1676 // from there will be lower than the stack base just computed |
1683 thread_main_inner(); |
1677 thread_main_inner(); |
1684 |
1678 |
1801 get_thread_name()); |
1795 get_thread_name()); |
1802 CLEAR_PENDING_EXCEPTION; |
1796 CLEAR_PENDING_EXCEPTION; |
1803 } |
1797 } |
1804 } |
1798 } |
1805 } |
1799 } |
1806 |
1800 JFR_ONLY(Jfr::on_java_thread_dismantle(this);) |
1807 // Called before the java thread exit since we want to read info |
|
1808 // from java_lang_Thread object |
|
1809 EventThreadEnd event; |
|
1810 if (event.should_commit()) { |
|
1811 event.set_thread(JFR_THREAD_ID(this)); |
|
1812 event.commit(); |
|
1813 } |
|
1814 |
|
1815 // Call after last event on thread |
|
1816 JFR_ONLY(Jfr::on_thread_exit(this);) |
|
1817 |
1801 |
1818 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during |
1802 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during |
1819 // the execution of the method. If that is not enough, then we don't really care. Thread.stop |
1803 // the execution of the method. If that is not enough, then we don't really care. Thread.stop |
1820 // is deprecated anyhow. |
1804 // is deprecated anyhow. |
1821 if (!is_Compiler_thread()) { |
1805 if (!is_Compiler_thread()) { |
1888 } |
1872 } |
1889 |
1873 |
1890 // These things needs to be done while we are still a Java Thread. Make sure that thread |
1874 // These things needs to be done while we are still a Java Thread. Make sure that thread |
1891 // is in a consistent state, in case GC happens |
1875 // is in a consistent state, in case GC happens |
1892 assert(_privileged_stack_top == NULL, "must be NULL when we get here"); |
1876 assert(_privileged_stack_top == NULL, "must be NULL when we get here"); |
|
1877 JFR_ONLY(Jfr::on_thread_exit(this);) |
1893 |
1878 |
1894 if (active_handles() != NULL) { |
1879 if (active_handles() != NULL) { |
1895 JNIHandleBlock* block = active_handles(); |
1880 JNIHandleBlock* block = active_handles(); |
1896 set_active_handles(NULL); |
1881 set_active_handles(NULL); |
1897 JNIHandleBlock::release_block(block); |
1882 JNIHandleBlock::release_block(block); |