49 #include "runtime/arguments.hpp"
50 #include "runtime/atomic.inline.hpp"
51 #include "runtime/biasedLocking.hpp"
52 #include "runtime/deoptimization.hpp"
53 #include "runtime/fprofiler.hpp"
54 #include "runtime/frame.inline.hpp"
55 #include "runtime/init.hpp"
56 #include "runtime/interfaceSupport.hpp"
57 #include "runtime/java.hpp"
58 #include "runtime/javaCalls.hpp"
59 #include "runtime/jniPeriodicChecker.hpp"
60 #include "runtime/memprofiler.hpp"
61 #include "runtime/mutexLocker.hpp"
62 #include "runtime/objectMonitor.hpp"
63 #include "runtime/orderAccess.inline.hpp"
64 #include "runtime/osThread.hpp"
65 #include "runtime/safepoint.hpp"
66 #include "runtime/sharedRuntime.hpp"
67 #include "runtime/statSampler.hpp"
68 #include "runtime/stubRoutines.hpp"
69 #include "runtime/task.hpp"
70 #include "runtime/thread.inline.hpp"
71 #include "runtime/threadCritical.hpp"
72 #include "runtime/threadLocalStorage.hpp"
73 #include "runtime/vframe.hpp"
74 #include "runtime/vframeArray.hpp"
75 #include "runtime/vframe_hp.hpp"
76 #include "runtime/vmThread.hpp"
77 #include "runtime/vm_operations.hpp"
78 #include "runtime/vm_version.hpp"
79 #include "services/attachListener.hpp"
80 #include "services/management.hpp"
81 #include "services/memTracker.hpp"
82 #include "services/threadService.hpp"
83 #include "trace/tracing.hpp"
84 #include "trace/traceMacros.hpp"
85 #include "utilities/defaultStream.hpp"
86 #include "utilities/dtrace.hpp"
87 #include "utilities/events.hpp"
88 #include "utilities/preserveException.hpp"
1533 return true;
1534 }
1535
1536 bool JavaThread::reguard_stack(void) {
1537 return reguard_stack(os::current_stack_pointer());
1538 }
1539
1540
1541 void JavaThread::block_if_vm_exited() {
1542 if (_terminated == _vm_exited) {
1543 // _vm_exited is set at safepoint, and Threads_lock is never released
1544 // we will block here forever
1545 Threads_lock->lock_without_safepoint_check();
1546 ShouldNotReachHere();
1547 }
1548 }
1549
1550
1551 // Remove this ifdef when C1 is ported to the compiler interface.
1552 static void compiler_thread_entry(JavaThread* thread, TRAPS);
1553
1554 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
1555 Thread()
1556 #if INCLUDE_ALL_GCS
1557 , _satb_mark_queue(&_satb_mark_queue_set),
1558 _dirty_card_queue(&_dirty_card_queue_set)
1559 #endif // INCLUDE_ALL_GCS
1560 {
1561 if (TraceThreadEvents) {
1562 tty->print_cr("creating thread %p", this);
1563 }
1564 initialize();
1565 _jni_attach_state = _not_attaching_via_jni;
1566 set_entry_point(entry_point);
1567 // Create the native thread itself.
1568 // %note runtime_23
1569 os::ThreadType thr_type = os::java_thread;
1570 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread :
1571 os::java_thread;
1572 os::create_thread(this, thr_type, stack_sz);
3152 if (vf->is_java_frame()) return javaVFrame::cast(vf);
3153 }
3154 return NULL;
3155 }
3156
3157
3158 Klass* JavaThread::security_get_caller_class(int depth) {
3159 vframeStream vfst(this);
3160 vfst.security_get_caller_frame(depth);
3161 if (!vfst.at_end()) {
3162 return vfst.method()->method_holder();
3163 }
3164 return NULL;
3165 }
3166
3167 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
3168 assert(thread->is_Compiler_thread(), "must be compiler thread");
3169 CompileBroker::compiler_thread_loop();
3170 }
3171
3172 // Create a CompilerThread
3173 CompilerThread::CompilerThread(CompileQueue* queue,
3174 CompilerCounters* counters)
3175 : JavaThread(&compiler_thread_entry) {
3176 _env = NULL;
3177 _log = NULL;
3178 _task = NULL;
3179 _queue = queue;
3180 _counters = counters;
3181 _buffer_blob = NULL;
3182 _scanned_nmethod = NULL;
3183 _compiler = NULL;
3184
3185 #ifndef PRODUCT
3186 _ideal_graph_printer = NULL;
3187 #endif
3188 }
3189
3190 void CompilerThread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
3191 JavaThread::oops_do(f, cld_f, cf);
3192 if (_scanned_nmethod != NULL && cf != NULL) {
3193 // Safepoints can occur when the sweeper is scanning an nmethod so
3194 // process it here to make sure it isn't unloaded in the middle of
3195 // a scan.
3196 cf->do_code_blob(_scanned_nmethod);
3197 }
3198 }
3199
3200
3201 // ======= Threads ========
3202
3203 // The Threads class links together all active threads, and provides
3204 // operations over all threads. It is protected by its own Mutex
3205 // lock, which is also used in other contexts to protect thread
3206 // operations from having the thread being operated on from exiting
3207 // and going away unexpectedly (e.g., safepoint synchronization)
3208
3209 JavaThread* Threads::_thread_list = NULL;
3210 int Threads::_number_of_threads = 0;
|
49 #include "runtime/arguments.hpp"
50 #include "runtime/atomic.inline.hpp"
51 #include "runtime/biasedLocking.hpp"
52 #include "runtime/deoptimization.hpp"
53 #include "runtime/fprofiler.hpp"
54 #include "runtime/frame.inline.hpp"
55 #include "runtime/init.hpp"
56 #include "runtime/interfaceSupport.hpp"
57 #include "runtime/java.hpp"
58 #include "runtime/javaCalls.hpp"
59 #include "runtime/jniPeriodicChecker.hpp"
60 #include "runtime/memprofiler.hpp"
61 #include "runtime/mutexLocker.hpp"
62 #include "runtime/objectMonitor.hpp"
63 #include "runtime/orderAccess.inline.hpp"
64 #include "runtime/osThread.hpp"
65 #include "runtime/safepoint.hpp"
66 #include "runtime/sharedRuntime.hpp"
67 #include "runtime/statSampler.hpp"
68 #include "runtime/stubRoutines.hpp"
69 #include "runtime/sweeper.hpp"
70 #include "runtime/task.hpp"
71 #include "runtime/thread.inline.hpp"
72 #include "runtime/threadCritical.hpp"
73 #include "runtime/threadLocalStorage.hpp"
74 #include "runtime/vframe.hpp"
75 #include "runtime/vframeArray.hpp"
76 #include "runtime/vframe_hp.hpp"
77 #include "runtime/vmThread.hpp"
78 #include "runtime/vm_operations.hpp"
79 #include "runtime/vm_version.hpp"
80 #include "services/attachListener.hpp"
81 #include "services/management.hpp"
82 #include "services/memTracker.hpp"
83 #include "services/threadService.hpp"
84 #include "trace/tracing.hpp"
85 #include "trace/traceMacros.hpp"
86 #include "utilities/defaultStream.hpp"
87 #include "utilities/dtrace.hpp"
88 #include "utilities/events.hpp"
89 #include "utilities/preserveException.hpp"
1534 return true;
1535 }
1536
1537 bool JavaThread::reguard_stack(void) {
1538 return reguard_stack(os::current_stack_pointer());
1539 }
1540
1541
1542 void JavaThread::block_if_vm_exited() {
1543 if (_terminated == _vm_exited) {
1544 // _vm_exited is set at safepoint, and Threads_lock is never released
1545 // we will block here forever
1546 Threads_lock->lock_without_safepoint_check();
1547 ShouldNotReachHere();
1548 }
1549 }
1550
1551
1552 // Remove this ifdef when C1 is ported to the compiler interface.
1553 static void compiler_thread_entry(JavaThread* thread, TRAPS);
1554 static void sweeper_thread_entry(JavaThread* thread, TRAPS);
1555
1556 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
1557 Thread()
1558 #if INCLUDE_ALL_GCS
1559 , _satb_mark_queue(&_satb_mark_queue_set),
1560 _dirty_card_queue(&_dirty_card_queue_set)
1561 #endif // INCLUDE_ALL_GCS
1562 {
1563 if (TraceThreadEvents) {
1564 tty->print_cr("creating thread %p", this);
1565 }
1566 initialize();
1567 _jni_attach_state = _not_attaching_via_jni;
1568 set_entry_point(entry_point);
1569 // Create the native thread itself.
1570 // %note runtime_23
1571 os::ThreadType thr_type = os::java_thread;
1572 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread :
1573 os::java_thread;
1574 os::create_thread(this, thr_type, stack_sz);
3154 if (vf->is_java_frame()) return javaVFrame::cast(vf);
3155 }
3156 return NULL;
3157 }
3158
3159
3160 Klass* JavaThread::security_get_caller_class(int depth) {
3161 vframeStream vfst(this);
3162 vfst.security_get_caller_frame(depth);
3163 if (!vfst.at_end()) {
3164 return vfst.method()->method_holder();
3165 }
3166 return NULL;
3167 }
3168
3169 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
3170 assert(thread->is_Compiler_thread(), "must be compiler thread");
3171 CompileBroker::compiler_thread_loop();
3172 }
3173
3174 static void sweeper_thread_entry(JavaThread* thread, TRAPS) {
3175 NMethodSweeper::sweeper_loop();
3176 }
3177
3178 // Create a CompilerThread
3179 CompilerThread::CompilerThread(CompileQueue* queue,
3180 CompilerCounters* counters)
3181 : JavaThread(&compiler_thread_entry) {
3182 _env = NULL;
3183 _log = NULL;
3184 _task = NULL;
3185 _queue = queue;
3186 _counters = counters;
3187 _buffer_blob = NULL;
3188 _compiler = NULL;
3189
3190 #ifndef PRODUCT
3191 _ideal_graph_printer = NULL;
3192 #endif
3193 }
3194
3195 // Create sweeper thread
3196 CodeCacheSweeperThread::CodeCacheSweeperThread()
3197 : JavaThread(&sweeper_thread_entry) {
3198 _scanned_nmethod = NULL;
3199 }
3200 void CodeCacheSweeperThread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
3201 JavaThread::oops_do(f, cld_f, cf);
3202 if (_scanned_nmethod != NULL && cf != NULL) {
3203 // Safepoints can occur when the sweeper is scanning an nmethod so
3204 // process it here to make sure it isn't unloaded in the middle of
3205 // a scan.
3206 cf->do_code_blob(_scanned_nmethod);
3207 }
3208 }
3209
3210
3211 // ======= Threads ========
3212
3213 // The Threads class links together all active threads, and provides
3214 // operations over all threads. It is protected by its own Mutex
3215 // lock, which is also used in other contexts to protect thread
3216 // operations from having the thread being operated on from exiting
3217 // and going away unexpectedly (e.g., safepoint synchronization)
3218
3219 JavaThread* Threads::_thread_list = NULL;
3220 int Threads::_number_of_threads = 0;
|