src/share/vm/runtime/thread.cpp

changeset 9858
b985cbb00e68
parent 9676
bf1c9a3312a4
child 9864
f066260954ae
equal deleted inserted replaced
9727:c7a3e57fdf4a 9858:b985cbb00e68
30 #include "code/scopeDesc.hpp" 30 #include "code/scopeDesc.hpp"
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"
36 #include "jfr/support/jfrThreadId.hpp"
35 #include "jvmtifiles/jvmtiEnv.hpp" 37 #include "jvmtifiles/jvmtiEnv.hpp"
36 #include "memory/gcLocker.inline.hpp" 38 #include "memory/gcLocker.inline.hpp"
37 #include "memory/metaspaceShared.hpp" 39 #include "memory/metaspaceShared.hpp"
38 #include "memory/oopFactory.hpp" 40 #include "memory/oopFactory.hpp"
39 #include "memory/universe.inline.hpp" 41 #include "memory/universe.inline.hpp"
75 #include "runtime/vm_operations.hpp" 77 #include "runtime/vm_operations.hpp"
76 #include "services/attachListener.hpp" 78 #include "services/attachListener.hpp"
77 #include "services/management.hpp" 79 #include "services/management.hpp"
78 #include "services/memTracker.hpp" 80 #include "services/memTracker.hpp"
79 #include "services/threadService.hpp" 81 #include "services/threadService.hpp"
80 #include "trace/tracing.hpp"
81 #include "trace/traceMacros.hpp"
82 #include "utilities/defaultStream.hpp" 82 #include "utilities/defaultStream.hpp"
83 #include "utilities/dtrace.hpp" 83 #include "utilities/dtrace.hpp"
84 #include "utilities/events.hpp" 84 #include "utilities/events.hpp"
85 #include "utilities/preserveException.hpp" 85 #include "utilities/preserveException.hpp"
86 #include "utilities/macros.hpp" 86 #include "utilities/macros.hpp"
109 #include "opto/idealGraphPrinter.hpp" 109 #include "opto/idealGraphPrinter.hpp"
110 #endif 110 #endif
111 #if INCLUDE_RTM_OPT 111 #if INCLUDE_RTM_OPT
112 #include "runtime/rtmLocking.hpp" 112 #include "runtime/rtmLocking.hpp"
113 #endif 113 #endif
114 #if INCLUDE_JFR
115 #include "jfr/jfr.hpp"
116 #endif
114 117
115 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 118 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
116 119
117 #ifdef DTRACE_ENABLED 120 #ifdef DTRACE_ENABLED
118 121
340 343
341 Thread::~Thread() { 344 Thread::~Thread() {
342 // Reclaim the objectmonitors from the omFreeList of the moribund thread. 345 // Reclaim the objectmonitors from the omFreeList of the moribund thread.
343 ObjectSynchronizer::omFlush (this) ; 346 ObjectSynchronizer::omFlush (this) ;
344 347
345 EVENT_THREAD_DESTRUCT(this); 348 JFR_ONLY(Jfr::on_thread_destruct(this);)
346 349
347 // stack_base can be NULL if the thread is never started or exited before 350 // stack_base can be NULL if the thread is never started or exited before
348 // record_stack_base_and_size called. Although, we would like to ensure 351 // record_stack_base_and_size called. Although, we would like to ensure
349 // that all started threads do call record_stack_base_and_size(), there is 352 // that all started threads do call record_stack_base_and_size(), there is
350 // not proper way to enforce that. 353 // not proper way to enforce that.
1669 JvmtiExport::post_thread_start(this); 1672 JvmtiExport::post_thread_start(this);
1670 } 1673 }
1671 1674
1672 EventThreadStart event; 1675 EventThreadStart event;
1673 if (event.should_commit()) { 1676 if (event.should_commit()) {
1674 event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj())); 1677 event.set_thread(JFR_THREAD_ID(this));
1675 event.commit(); 1678 event.commit();
1676 } 1679 }
1677 1680
1678 // We call another function to do the rest so we are sure that the stack addresses used 1681 // We call another function to do the rest so we are sure that the stack addresses used
1679 // from there will be lower than the stack base just computed 1682 // from there will be lower than the stack base just computed
1803 1806
1804 // Called before the java thread exit since we want to read info 1807 // Called before the java thread exit since we want to read info
1805 // from java_lang_Thread object 1808 // from java_lang_Thread object
1806 EventThreadEnd event; 1809 EventThreadEnd event;
1807 if (event.should_commit()) { 1810 if (event.should_commit()) {
1808 event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj())); 1811 event.set_thread(JFR_THREAD_ID(this));
1809 event.commit(); 1812 event.commit();
1810 } 1813 }
1811 1814
1812 // Call after last event on thread 1815 // Call after last event on thread
1813 EVENT_THREAD_EXIT(this); 1816 JFR_ONLY(Jfr::on_thread_exit(this);)
1814 1817
1815 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during 1818 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
1816 // the execution of the method. If that is not enough, then we don't really care. Thread.stop 1819 // the execution of the method. If that is not enough, then we don't really care. Thread.stop
1817 // is deprecated anyhow. 1820 // is deprecated anyhow.
1818 if (!is_Compiler_thread()) { 1821 if (!is_Compiler_thread()) {
2184 } 2187 }
2185 2188
2186 if (check_asyncs) { 2189 if (check_asyncs) {
2187 check_and_handle_async_exceptions(); 2190 check_and_handle_async_exceptions();
2188 } 2191 }
2192
2193 JFR_ONLY(SUSPEND_THREAD_CONDITIONAL(this);)
2189 } 2194 }
2190 2195
2191 void JavaThread::send_thread_stop(oop java_throwable) { 2196 void JavaThread::send_thread_stop(oop java_throwable) {
2192 assert(Thread::current()->is_VM_thread(), "should be in the vm thread"); 2197 assert(Thread::current()->is_VM_thread(), "should be in the vm thread");
2193 assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code"); 2198 assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code");
2422 f.deoptimize(thread); 2427 f.deoptimize(thread);
2423 } else { 2428 } else {
2424 fatal("missed deoptimization!"); 2429 fatal("missed deoptimization!");
2425 } 2430 }
2426 } 2431 }
2432
2433 JFR_ONLY(SUSPEND_THREAD_CONDITIONAL(thread);)
2427 } 2434 }
2428 2435
2429 // Slow path when the native==>VM/Java barriers detect a safepoint is in 2436 // Slow path when the native==>VM/Java barriers detect a safepoint is in
2430 // progress or when _suspend_flags is non-zero. 2437 // progress or when _suspend_flags is non-zero.
2431 // Current thread needs to self-suspend if there is a suspend request and/or 2438 // Current thread needs to self-suspend if there is a suspend request and/or
3310 // Terminator_lock, but we can't do that without violating the lock rank 3317 // Terminator_lock, but we can't do that without violating the lock rank
3311 // checking in some cases. 3318 // checking in some cases.
3312 if (wt != NULL) 3319 if (wt != NULL)
3313 tc->do_thread(wt); 3320 tc->do_thread(wt);
3314 3321
3322 #if INCLUDE_JFR
3323 Thread* sampler_thread = Jfr::sampler_thread();
3324 if (sampler_thread != NULL) {
3325 tc->do_thread(sampler_thread);
3326 }
3327
3328 #endif
3329
3315 // If CompilerThreads ever become non-JavaThreads, add them here 3330 // If CompilerThreads ever become non-JavaThreads, add them here
3316 } 3331 }
3317 3332
3318 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { 3333 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
3319 3334
3435 if (status != JNI_OK) { 3450 if (status != JNI_OK) {
3436 delete main_thread; 3451 delete main_thread;
3437 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again 3452 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
3438 return status; 3453 return status;
3439 } 3454 }
3455
3456 JFR_ONLY(Jfr::on_vm_init();)
3440 3457
3441 // Should be done after the heap is fully created 3458 // Should be done after the heap is fully created
3442 main_thread->cache_global_variables(); 3459 main_thread->cache_global_variables();
3443 3460
3444 HandleMark hm; 3461 HandleMark hm;
3563 // This should also be taken out as soon as 4211383 gets fixed. 3580 // This should also be taken out as soon as 4211383 gets fixed.
3564 reset_vm_info_property(CHECK_0); 3581 reset_vm_info_property(CHECK_0);
3565 3582
3566 quicken_jni_functions(); 3583 quicken_jni_functions();
3567 3584
3568 // Must be run after init_ft which initializes ft_enabled
3569 if (TRACE_INITIALIZE() != JNI_OK) {
3570 vm_exit_during_initialization("Failed to initialize tracing backend");
3571 }
3572
3573 // Set flag that basic initialization has completed. Used by exceptions and various 3585 // Set flag that basic initialization has completed. Used by exceptions and various
3574 // debug stuff, that does not work until all basic classes have been initialized. 3586 // debug stuff, that does not work until all basic classes have been initialized.
3575 set_init_completed(); 3587 set_init_completed();
3576 3588
3577 Metaspace::post_initialize(); 3589 Metaspace::post_initialize();
3636 } 3648 }
3637 3649
3638 // Notify JVMTI agents that VM initialization is complete - nop if no agents. 3650 // Notify JVMTI agents that VM initialization is complete - nop if no agents.
3639 JvmtiExport::post_vm_initialized(); 3651 JvmtiExport::post_vm_initialized();
3640 3652
3641 if (TRACE_START() != JNI_OK) { 3653 JFR_ONLY(Jfr::on_vm_start();)
3642 vm_exit_during_initialization("Failed to start tracing backend.");
3643 }
3644 3654
3645 if (CleanChunkPoolAsync) { 3655 if (CleanChunkPoolAsync) {
3646 Chunk::start_chunk_pool_cleaner_task(); 3656 Chunk::start_chunk_pool_cleaner_task();
3647 } 3657 }
3648 3658

mercurial