1.1 --- a/src/share/vm/services/memTracker.cpp Wed Jul 04 15:55:45 2012 -0400 1.2 +++ b/src/share/vm/services/memTracker.cpp Thu Jul 19 09:05:42 2012 -0400 1.3 @@ -351,21 +351,17 @@ 1.4 } 1.5 1.6 if (thread != NULL) { 1.7 -#ifdef ASSERT 1.8 - // cause assertion on stack base. This ensures that threads call 1.9 - // Thread::record_stack_base_and_size() method, which will create 1.10 - // thread native stack records. 1.11 - thread->stack_base(); 1.12 -#endif 1.13 - // for a JavaThread, if it is running in native state, we need to transition it to 1.14 - // VM state, so it can stop at safepoint. JavaThread running in VM state does not 1.15 - // need lock to write records. 1.16 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { 1.17 - if (((JavaThread*)thread)->thread_state() == _thread_in_native) { 1.18 - ThreadInVMfromNative trans((JavaThread*)thread); 1.19 - create_record_in_recorder(addr, flags, size, pc, thread); 1.20 + JavaThread* java_thread = static_cast<JavaThread*>(thread); 1.21 + JavaThreadState state = java_thread->thread_state(); 1.22 + if (SafepointSynchronize::safepoint_safe(java_thread, state)) { 1.23 + // JavaThreads that are safepoint safe, can run through safepoint, 1.24 + // so ThreadCritical is needed to ensure no threads at safepoint create 1.25 + // new records while the records are being gathered and the sequence number is changing 1.26 + ThreadCritical tc; 1.27 + create_record_in_recorder(addr, flags, size, pc, java_thread); 1.28 } else { 1.29 - create_record_in_recorder(addr, flags, size, pc, thread); 1.30 + create_record_in_recorder(addr, flags, size, pc, java_thread); 1.31 } 1.32 } else { 1.33 // other threads, such as worker and watcher threads, etc. need to 1.34 @@ -390,10 +386,9 @@ 1.35 // write a record to proper recorder. No lock can be taken from this method 1.36 // down. 1.37 void MemTracker::create_record_in_recorder(address addr, MEMFLAGS flags, 1.38 - size_t size, address pc, Thread* thread) { 1.39 - assert(thread == NULL || thread->is_Java_thread(), "wrong thread"); 1.40 + size_t size, address pc, JavaThread* thread) { 1.41 1.42 - MemRecorder* rc = get_thread_recorder((JavaThread*)thread); 1.43 + MemRecorder* rc = get_thread_recorder(thread); 1.44 if (rc != NULL) { 1.45 rc->record(addr, flags, size, pc); 1.46 } 1.47 @@ -460,17 +455,18 @@ 1.48 } 1.49 } 1.50 _sync_point_skip_count = 0; 1.51 - // walk all JavaThreads to collect recorders 1.52 - SyncThreadRecorderClosure stc; 1.53 - Threads::threads_do(&stc); 1.54 - 1.55 - _thread_count = stc.get_thread_count(); 1.56 - MemRecorder* pending_recorders = get_pending_recorders(); 1.57 - 1.58 { 1.59 // This method is running at safepoint, with ThreadCritical lock, 1.60 // it should guarantee that NMT is fully sync-ed. 1.61 ThreadCritical tc; 1.62 + 1.63 + // walk all JavaThreads to collect recorders 1.64 + SyncThreadRecorderClosure stc; 1.65 + Threads::threads_do(&stc); 1.66 + 1.67 + _thread_count = stc.get_thread_count(); 1.68 + MemRecorder* pending_recorders = get_pending_recorders(); 1.69 + 1.70 if (_global_recorder != NULL) { 1.71 _global_recorder->set_next(pending_recorders); 1.72 pending_recorders = _global_recorder; 1.73 @@ -486,8 +482,6 @@ 1.74 1.75 // now, it is the time to shut whole things off 1.76 if (_state == NMT_final_shutdown) { 1.77 - _tracking_level = NMT_off; 1.78 - 1.79 // walk all JavaThreads to delete all recorders 1.80 SyncThreadRecorderClosure stc; 1.81 Threads::threads_do(&stc); 1.82 @@ -499,8 +493,16 @@ 1.83 _global_recorder = NULL; 1.84 } 1.85 } 1.86 - 1.87 - _state = NMT_shutdown; 1.88 + MemRecorder* pending_recorders = get_pending_recorders(); 1.89 + if (pending_recorders != NULL) { 1.90 + delete pending_recorders; 1.91 + } 1.92 + // try at a later sync point to ensure MemRecorder instance drops to zero to 1.93 + // completely shutdown NMT 1.94 + if (MemRecorder::_instance_count == 0) { 1.95 + _state = NMT_shutdown; 1.96 + _tracking_level = NMT_off; 1.97 + } 1.98 } 1.99 } 1.100