362 } |
362 } |
363 } |
363 } |
364 |
364 |
365 if (thread != NULL) { |
365 if (thread != NULL) { |
366 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { |
366 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { |
367 JavaThread* java_thread = static_cast<JavaThread*>(thread); |
367 JavaThread* java_thread = (JavaThread*)thread; |
368 JavaThreadState state = java_thread->thread_state(); |
368 JavaThreadState state = java_thread->thread_state(); |
369 if (SafepointSynchronize::safepoint_safe(java_thread, state)) { |
369 if (SafepointSynchronize::safepoint_safe(java_thread, state)) { |
370 // JavaThreads that are safepoint safe, can run through safepoint, |
370 // JavaThreads that are safepoint safe, can run through safepoint, |
371 // so ThreadCritical is needed to ensure no threads at safepoint create |
371 // so ThreadCritical is needed to ensure no threads at safepoint create |
372 // new records while the records are being gathered and the sequence number is changing |
372 // new records while the records are being gathered and the sequence number is changing |
470 { |
470 { |
471 // This method is running at safepoint, with ThreadCritical lock, |
471 // This method is running at safepoint, with ThreadCritical lock, |
472 // it should guarantee that NMT is fully sync-ed. |
472 // it should guarantee that NMT is fully sync-ed. |
473 ThreadCritical tc; |
473 ThreadCritical tc; |
474 |
474 |
|
475 SequenceGenerator::reset(); |
|
476 |
475 // walk all JavaThreads to collect recorders |
477 // walk all JavaThreads to collect recorders |
476 SyncThreadRecorderClosure stc; |
478 SyncThreadRecorderClosure stc; |
477 Threads::threads_do(&stc); |
479 Threads::threads_do(&stc); |
478 |
480 |
479 _thread_count = stc.get_thread_count(); |
481 _thread_count = stc.get_thread_count(); |
482 if (_global_recorder != NULL) { |
484 if (_global_recorder != NULL) { |
483 _global_recorder->set_next(pending_recorders); |
485 _global_recorder->set_next(pending_recorders); |
484 pending_recorders = _global_recorder; |
486 pending_recorders = _global_recorder; |
485 _global_recorder = NULL; |
487 _global_recorder = NULL; |
486 } |
488 } |
487 SequenceGenerator::reset(); |
|
488 // check _worker_thread with lock to avoid racing condition |
489 // check _worker_thread with lock to avoid racing condition |
489 if (_worker_thread != NULL) { |
490 if (_worker_thread != NULL) { |
490 _worker_thread->at_sync_point(pending_recorders); |
491 _worker_thread->at_sync_point(pending_recorders); |
491 } |
492 } |
|
493 |
|
494 assert(SequenceGenerator::peek() == 1, "Should not have memory activities during sync-point"); |
492 } |
495 } |
493 } |
496 } |
494 |
497 |
495 // now, it is the time to shut whole things off |
498 // now, it is the time to shut whole things off |
496 if (_state == NMT_final_shutdown) { |
499 if (_state == NMT_final_shutdown) { |