comparison src/share/vm/runtime/thread.cpp @ 4137:04b9a2566eec

Merge with hsx23/hotspot.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 17 Dec 2011 21:40:27 +0100
parents dc7902820c9b bca17e38de00
children 723df37192d6
comparison
equal deleted inserted replaced
3737:9dc19b7d89a3 4137:04b9a2566eec
88 #endif 88 #endif
89 #ifdef TARGET_OS_FAMILY_windows 89 #ifdef TARGET_OS_FAMILY_windows
90 # include "os_windows.inline.hpp" 90 # include "os_windows.inline.hpp"
91 # include "thread_windows.inline.hpp" 91 # include "thread_windows.inline.hpp"
92 #endif 92 #endif
93 #ifdef TARGET_OS_FAMILY_bsd
94 # include "os_bsd.inline.hpp"
95 # include "thread_bsd.inline.hpp"
96 #endif
93 #ifndef SERIALGC 97 #ifndef SERIALGC
94 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" 98 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
95 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" 99 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
96 #include "gc_implementation/parallelScavenge/pcTasks.hpp" 100 #include "gc_implementation/parallelScavenge/pcTasks.hpp"
97 #endif 101 #endif
105 109
106 #ifdef DTRACE_ENABLED 110 #ifdef DTRACE_ENABLED
107 111
108 // Only bother with this argument setup if dtrace is available 112 // Only bother with this argument setup if dtrace is available
109 113
114 #ifndef USDT2
110 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin); 115 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin);
111 HS_DTRACE_PROBE_DECL(hotspot, vm__init__end); 116 HS_DTRACE_PROBE_DECL(hotspot, vm__init__end);
112 HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t, 117 HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t,
113 intptr_t, intptr_t, bool); 118 intptr_t, intptr_t, bool);
114 HS_DTRACE_PROBE_DECL5(hotspot, thread__stop, char*, intptr_t, 119 HS_DTRACE_PROBE_DECL5(hotspot, thread__stop, char*, intptr_t,
124 name, len, \ 129 name, len, \
125 java_lang_Thread::thread_id((javathread)->threadObj()), \ 130 java_lang_Thread::thread_id((javathread)->threadObj()), \
126 (javathread)->osthread()->thread_id(), \ 131 (javathread)->osthread()->thread_id(), \
127 java_lang_Thread::is_daemon((javathread)->threadObj())); \ 132 java_lang_Thread::is_daemon((javathread)->threadObj())); \
128 } 133 }
134
135 #else /* USDT2 */
136
137 #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_PROBE_START
138 #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_PROBE_STOP
139
140 #define DTRACE_THREAD_PROBE(probe, javathread) \
141 { \
142 ResourceMark rm(this); \
143 int len = 0; \
144 const char* name = (javathread)->get_thread_name(); \
145 len = strlen(name); \
146 HOTSPOT_THREAD_PROBE_##probe( /* probe = start, stop */ \
147 (char *) name, len, \
148 java_lang_Thread::thread_id((javathread)->threadObj()), \
149 (uintptr_t) (javathread)->osthread()->thread_id(), \
150 java_lang_Thread::is_daemon((javathread)->threadObj())); \
151 }
152
153 #endif /* USDT2 */
129 154
130 #else // ndef DTRACE_ENABLED 155 #else // ndef DTRACE_ENABLED
131 156
132 #define DTRACE_THREAD_PROBE(probe, javathread) 157 #define DTRACE_THREAD_PROBE(probe, javathread)
133 158
748 // GC Support 773 // GC Support
749 bool Thread::claim_oops_do_par_case(int strong_roots_parity) { 774 bool Thread::claim_oops_do_par_case(int strong_roots_parity) {
750 jint thread_parity = _oops_do_parity; 775 jint thread_parity = _oops_do_parity;
751 if (thread_parity != strong_roots_parity) { 776 if (thread_parity != strong_roots_parity) {
752 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity); 777 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity);
753 if (res == thread_parity) return true; 778 if (res == thread_parity) {
754 else { 779 return true;
780 } else {
755 guarantee(res == strong_roots_parity, "Or else what?"); 781 guarantee(res == strong_roots_parity, "Or else what?");
756 assert(SharedHeap::heap()->n_par_threads() > 0, 782 assert(SharedHeap::heap()->workers()->active_workers() > 0,
757 "Should only fail when parallel."); 783 "Should only fail when parallel.");
758 return false; 784 return false;
759 } 785 }
760 } 786 }
761 assert(SharedHeap::heap()->n_par_threads() > 0, 787 assert(SharedHeap::heap()->workers()->active_workers() > 0,
762 "Should only fail when parallel."); 788 "Should only fail when parallel.");
763 return false; 789 return false;
764 } 790 }
765 791
766 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) { 792 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
965 } 991 }
966 992
967 // General purpose hook into Java code, run once when the VM is initialized. 993 // General purpose hook into Java code, run once when the VM is initialized.
968 // The Java library method itself may be changed independently from the VM. 994 // The Java library method itself may be changed independently from the VM.
969 static void call_postVMInitHook(TRAPS) { 995 static void call_postVMInitHook(TRAPS) {
970 klassOop k = SystemDictionary::sun_misc_PostVMInitHook_klass(); 996 klassOop k = SystemDictionary::PostVMInitHook_klass();
971 instanceKlassHandle klass (THREAD, k); 997 instanceKlassHandle klass (THREAD, k);
972 if (klass.not_null()) { 998 if (klass.not_null()) {
973 JavaValue result(T_VOID); 999 JavaValue result(T_VOID);
974 JavaCalls::call_static(&result, klass, vmSymbols::run_method_name(), 1000 JavaCalls::call_static(&result, klass, vmSymbols::run_method_name(),
975 vmSymbols::void_method_signature(), 1001 vmSymbols::void_method_signature(),
1274 _stack_guard_state = stack_guard_unused; 1300 _stack_guard_state = stack_guard_unused;
1275 _graal_deopt_info = NULL; 1301 _graal_deopt_info = NULL;
1276 _exception_oop = NULL; 1302 _exception_oop = NULL;
1277 _exception_pc = 0; 1303 _exception_pc = 0;
1278 _exception_handler_pc = 0; 1304 _exception_handler_pc = 0;
1279 _exception_stack_size = 0;
1280 _is_method_handle_return = 0; 1305 _is_method_handle_return = 0;
1281 _jvmti_thread_state= NULL; 1306 _jvmti_thread_state= NULL;
1282 _should_post_on_exceptions_flag = JNI_FALSE; 1307 _should_post_on_exceptions_flag = JNI_FALSE;
1283 _jvmti_get_loaded_classes_closure = NULL; 1308 _jvmti_get_loaded_classes_closure = NULL;
1284 _interp_only_mode = 0; 1309 _interp_only_mode = 0;
1327 #ifndef SERIALGC 1352 #ifndef SERIALGC
1328 SATBMarkQueueSet JavaThread::_satb_mark_queue_set; 1353 SATBMarkQueueSet JavaThread::_satb_mark_queue_set;
1329 DirtyCardQueueSet JavaThread::_dirty_card_queue_set; 1354 DirtyCardQueueSet JavaThread::_dirty_card_queue_set;
1330 #endif // !SERIALGC 1355 #endif // !SERIALGC
1331 1356
1332 JavaThread::JavaThread(bool is_attaching) : 1357 JavaThread::JavaThread(bool is_attaching_via_jni) :
1333 Thread() 1358 Thread()
1334 #ifndef SERIALGC 1359 #ifndef SERIALGC
1335 , _satb_mark_queue(&_satb_mark_queue_set), 1360 , _satb_mark_queue(&_satb_mark_queue_set),
1336 _dirty_card_queue(&_dirty_card_queue_set) 1361 _dirty_card_queue(&_dirty_card_queue_set)
1337 #endif // !SERIALGC 1362 #endif // !SERIALGC
1338 { 1363 {
1339 initialize(); 1364 initialize();
1340 _is_attaching = is_attaching; 1365 if (is_attaching_via_jni) {
1366 _jni_attach_state = _attaching_via_jni;
1367 } else {
1368 _jni_attach_state = _not_attaching_via_jni;
1369 }
1341 assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor"); 1370 assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor");
1342 } 1371 }
1343 1372
1344 bool JavaThread::reguard_stack(address cur_sp) { 1373 bool JavaThread::reguard_stack(address cur_sp) {
1345 if (_stack_guard_state != stack_guard_yellow_disabled) { 1374 if (_stack_guard_state != stack_guard_yellow_disabled) {
1391 { 1420 {
1392 if (TraceThreadEvents) { 1421 if (TraceThreadEvents) {
1393 tty->print_cr("creating thread %p", this); 1422 tty->print_cr("creating thread %p", this);
1394 } 1423 }
1395 initialize(); 1424 initialize();
1396 _is_attaching = false; 1425 _jni_attach_state = _not_attaching_via_jni;
1397 set_entry_point(entry_point); 1426 set_entry_point(entry_point);
1398 // Create the native thread itself. 1427 // Create the native thread itself.
1399 // %note runtime_23 1428 // %note runtime_23
1400 os::ThreadType thr_type = os::java_thread; 1429 os::ThreadType thr_type = os::java_thread;
1401 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread : 1430 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread :
1503 // Execute thread entry point unless this thread has a pending exception 1532 // Execute thread entry point unless this thread has a pending exception
1504 // or has been stopped before starting. 1533 // or has been stopped before starting.
1505 // Note: Due to JVM_StopThread we can have pending exceptions already! 1534 // Note: Due to JVM_StopThread we can have pending exceptions already!
1506 if (!this->has_pending_exception() && 1535 if (!this->has_pending_exception() &&
1507 !java_lang_Thread::is_stillborn(this->threadObj())) { 1536 !java_lang_Thread::is_stillborn(this->threadObj())) {
1537 {
1538 ResourceMark rm(this);
1539 this->set_native_thread_name(this->get_thread_name());
1540 }
1508 HandleMark hm(this); 1541 HandleMark hm(this);
1509 this->entry_point()(this, this); 1542 this->entry_point()(this, this);
1510 } 1543 }
1511 1544
1512 DTRACE_THREAD_PROBE(stop, this); 1545 DTRACE_THREAD_PROBE(stop, this);
2692 } 2725 }
2693 else { 2726 else {
2694 name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen); 2727 name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen);
2695 } 2728 }
2696 } 2729 }
2697 else if (is_attaching()) { // workaround for 6412693 - see 6404306 2730 else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306
2698 name_str = "<no-name - thread is attaching>"; 2731 name_str = "<no-name - thread is attaching>";
2699 } 2732 }
2700 else { 2733 else {
2701 name_str = Thread::name(); 2734 name_str = Thread::name();
2702 } 2735 }
2873 fst.current()->print_value_on(tty,this); 2906 fst.current()->print_value_on(tty,this);
2874 tty->cr(); 2907 tty->cr();
2875 } 2908 }
2876 } 2909 }
2877 2910
2911 class PrintAndVerifyOopClosure: public OopClosure {
2912 protected:
2913 template <class T> inline void do_oop_work(T* p) {
2914 oop obj = oopDesc::load_decode_heap_oop(p);
2915 if (obj == NULL) return;
2916 tty->print(INTPTR_FORMAT ": ", p);
2917 if (obj->is_oop_or_null()) {
2918 if (obj->is_objArray()) {
2919 tty->print_cr("valid objArray: " INTPTR_FORMAT, (oopDesc*) obj);
2920 } else {
2921 obj->print();
2922 }
2923 } else {
2924 tty->print_cr("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj);
2925 }
2926 tty->cr();
2927 }
2928 public:
2929 virtual void do_oop(oop* p) { do_oop_work(p); }
2930 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
2931 };
2932
2933
2934 static void oops_print(frame* f, const RegisterMap *map) {
2935 PrintAndVerifyOopClosure print;
2936 f->print_value();
2937 f->oops_do(&print, NULL, (RegisterMap*)map);
2938 }
2939
2940 // Print our all the locations that contain oops and whether they are
2941 // valid or not. This useful when trying to find the oldest frame
2942 // where an oop has gone bad since the frame walk is from youngest to
2943 // oldest.
2944 void JavaThread::trace_oops() {
2945 tty->print_cr("[Trace oops]");
2946 frames_do(oops_print);
2947 }
2948
2878 2949
2879 #ifdef ASSERT 2950 #ifdef ASSERT
2880 // Print or validate the layout of stack frames 2951 // Print or validate the layout of stack frames
2881 void JavaThread::print_frame_layout(int depth, bool validate_only) { 2952 void JavaThread::print_frame_layout(int depth, bool validate_only) {
2882 ResourceMark rm; 2953 ResourceMark rm;
2889 } 2960 }
2890 if (validate_only) { 2961 if (validate_only) {
2891 values.validate(); 2962 values.validate();
2892 } else { 2963 } else {
2893 tty->print_cr("[Describe stack layout]"); 2964 tty->print_cr("[Describe stack layout]");
2894 values.print(); 2965 values.print(this);
2895 } 2966 }
2896 } 2967 }
2897 #endif 2968 #endif
2898 2969
2899 void JavaThread::trace_stack_from(vframe* start_vf) { 2970 void JavaThread::trace_stack_from(vframe* start_vf) {
3037 3108
3038 if (PauseAtStartup) { 3109 if (PauseAtStartup) {
3039 os::pause(); 3110 os::pause();
3040 } 3111 }
3041 3112
3113 #ifndef USDT2
3042 HS_DTRACE_PROBE(hotspot, vm__init__begin); 3114 HS_DTRACE_PROBE(hotspot, vm__init__begin);
3115 #else /* USDT2 */
3116 HOTSPOT_VM_INIT_BEGIN();
3117 #endif /* USDT2 */
3043 3118
3044 // Record VM creation timing statistics 3119 // Record VM creation timing statistics
3045 TraceVmCreationTime create_vm_timer; 3120 TraceVmCreationTime create_vm_timer;
3046 create_vm_timer.start(); 3121 create_vm_timer.start();
3047 3122
3292 3367
3293 // Set flag that basic initialization has completed. Used by exceptions and various 3368 // Set flag that basic initialization has completed. Used by exceptions and various
3294 // debug stuff, that does not work until all basic classes have been initialized. 3369 // debug stuff, that does not work until all basic classes have been initialized.
3295 set_init_completed(); 3370 set_init_completed();
3296 3371
3372 #ifndef USDT2
3297 HS_DTRACE_PROBE(hotspot, vm__init__end); 3373 HS_DTRACE_PROBE(hotspot, vm__init__end);
3374 #else /* USDT2 */
3375 HOTSPOT_VM_INIT_END();
3376 #endif /* USDT2 */
3298 3377
3299 // record VM initialization completion time 3378 // record VM initialization completion time
3300 Management::record_vm_init_completed(); 3379 Management::record_vm_init_completed();
3301 3380
3302 // Compute system loader. Note that this has to occur after set_init_completed, since 3381 // Compute system loader. Note that this has to occur after set_init_completed, since
3347 } 3426 }
3348 3427
3349 // Notify JVMTI agents that VM initialization is complete - nop if no agents. 3428 // Notify JVMTI agents that VM initialization is complete - nop if no agents.
3350 JvmtiExport::post_vm_initialized(); 3429 JvmtiExport::post_vm_initialized();
3351 3430
3352 Chunk::start_chunk_pool_cleaner_task(); 3431 if (CleanChunkPoolAsync) {
3432 Chunk::start_chunk_pool_cleaner_task();
3433 }
3353 3434
3354 // initialize compiler(s) 3435 // initialize compiler(s)
3355 CompileBroker::compilation_init(); 3436 CompileBroker::compilation_init();
3356 3437
3357 Management::initialize(THREAD); 3438 Management::initialize(THREAD);
3698 // 4945125 The vm thread comes to a safepoint during exit. 3779 // 4945125 The vm thread comes to a safepoint during exit.
3699 // GC vm_operations can get caught at the safepoint, and the 3780 // GC vm_operations can get caught at the safepoint, and the
3700 // heap is unparseable if they are caught. Grab the Heap_lock 3781 // heap is unparseable if they are caught. Grab the Heap_lock
3701 // to prevent this. The GC vm_operations will not be able to 3782 // to prevent this. The GC vm_operations will not be able to
3702 // queue until after the vm thread is dead. 3783 // queue until after the vm thread is dead.
3784 // After this point, we'll never emerge out of the safepoint before
3785 // the VM exits, so concurrent GC threads do not need to be explicitly
3786 // stopped; they remain inactive until the process exits.
3787 // Note: some concurrent G1 threads may be running during a safepoint,
3788 // but these will not be accessing the heap, just some G1-specific side
3789 // data structures that are not accessed by any other threads but them
3790 // after this point in a terminal safepoint.
3791
3703 MutexLocker ml(Heap_lock); 3792 MutexLocker ml(Heap_lock);
3704 3793
3705 VMThread::wait_for_vm_thread_exit(); 3794 VMThread::wait_for_vm_thread_exit();
3706 assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint"); 3795 assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");
3707 VMThread::destroy(); 3796 VMThread::destroy();
3850 void Threads::possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf) { 3939 void Threads::possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf) {
3851 // Introduce a mechanism allowing parallel threads to claim threads as 3940 // Introduce a mechanism allowing parallel threads to claim threads as
3852 // root groups. Overhead should be small enough to use all the time, 3941 // root groups. Overhead should be small enough to use all the time,
3853 // even in sequential code. 3942 // even in sequential code.
3854 SharedHeap* sh = SharedHeap::heap(); 3943 SharedHeap* sh = SharedHeap::heap();
3855 bool is_par = (sh->n_par_threads() > 0); 3944 // Cannot yet substitute active_workers for n_par_threads
3945 // because of G1CollectedHeap::verify() use of
3946 // SharedHeap::process_strong_roots(). n_par_threads == 0 will
3947 // turn off parallelism in process_strong_roots while active_workers
3948 // is being used for parallelism elsewhere.
3949 bool is_par = sh->n_par_threads() > 0;
3950 assert(!is_par ||
3951 (SharedHeap::heap()->n_par_threads() ==
3952 SharedHeap::heap()->workers()->active_workers()), "Mismatch");
3856 int cp = SharedHeap::heap()->strong_roots_parity(); 3953 int cp = SharedHeap::heap()->strong_roots_parity();
3857 ALL_JAVA_THREADS(p) { 3954 ALL_JAVA_THREADS(p) {
3858 if (p->claim_oops_do(is_par, cp)) { 3955 if (p->claim_oops_do(is_par, cp)) {
3859 p->oops_do(f, cf); 3956 p->oops_do(f, cf);
3860 } 3957 }
3861 } 3958 }
3862 VMThread* vmt = VMThread::vm_thread(); 3959 VMThread* vmt = VMThread::vm_thread();
3863 if (vmt->claim_oops_do(is_par, cp)) 3960 if (vmt->claim_oops_do(is_par, cp)) {
3864 vmt->oops_do(f, cf); 3961 vmt->oops_do(f, cf);
3962 }
3865 } 3963 }
3866 3964
3867 #ifndef SERIALGC 3965 #ifndef SERIALGC
3868 // Used by ParallelScavenge 3966 // Used by ParallelScavenge
3869 void Threads::create_thread_roots_tasks(GCTaskQueue* q) { 3967 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {