66 MemTracker::ShutdownReason MemTracker::_reason = NMT_shutdown_none; |
66 MemTracker::ShutdownReason MemTracker::_reason = NMT_shutdown_none; |
67 int MemTracker::_thread_count = 255; |
67 int MemTracker::_thread_count = 255; |
68 volatile jint MemTracker::_pooled_recorder_count = 0; |
68 volatile jint MemTracker::_pooled_recorder_count = 0; |
69 volatile unsigned long MemTracker::_processing_generation = 0; |
69 volatile unsigned long MemTracker::_processing_generation = 0; |
70 volatile bool MemTracker::_worker_thread_idle = false; |
70 volatile bool MemTracker::_worker_thread_idle = false; |
|
71 volatile bool MemTracker::_slowdown_calling_thread = false; |
71 debug_only(intx MemTracker::_main_thread_tid = 0;) |
72 debug_only(intx MemTracker::_main_thread_tid = 0;) |
72 NOT_PRODUCT(volatile jint MemTracker::_pending_recorder_count = 0;) |
73 NOT_PRODUCT(volatile jint MemTracker::_pending_recorder_count = 0;) |
73 |
74 |
74 void MemTracker::init_tracking_options(const char* option_line) { |
75 void MemTracker::init_tracking_options(const char* option_line) { |
75 _tracking_level = NMT_off; |
76 _tracking_level = NMT_off; |
362 thread = ThreadLocalStorage::thread(); |
363 thread = ThreadLocalStorage::thread(); |
363 } |
364 } |
364 } |
365 } |
365 |
366 |
366 if (thread != NULL) { |
367 if (thread != NULL) { |
|
368 // slow down all calling threads except NMT worker thread, so it |
|
369 // can catch up. |
|
370 if (_slowdown_calling_thread && thread != _worker_thread) { |
|
371 os::yield_all(); |
|
372 } |
|
373 |
367 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { |
374 if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) { |
368 JavaThread* java_thread = (JavaThread*)thread; |
375 JavaThread* java_thread = (JavaThread*)thread; |
369 JavaThreadState state = java_thread->thread_state(); |
376 JavaThreadState state = java_thread->thread_state(); |
370 if (SafepointSynchronize::safepoint_safe(java_thread, state)) { |
377 if (SafepointSynchronize::safepoint_safe(java_thread, state)) { |
371 // JavaThreads that are safepoint safe, can run through safepoint, |
378 // JavaThreads that are safepoint safe, can run through safepoint, |
440 * 5. call worker's sync |
447 * 5. call worker's sync |
441 */ |
448 */ |
442 #define MAX_SAFEPOINTS_TO_SKIP 128 |
449 #define MAX_SAFEPOINTS_TO_SKIP 128 |
443 #define SAFE_SEQUENCE_THRESHOLD 30 |
450 #define SAFE_SEQUENCE_THRESHOLD 30 |
444 #define HIGH_GENERATION_THRESHOLD 60 |
451 #define HIGH_GENERATION_THRESHOLD 60 |
|
452 #define MAX_RECORDER_THREAD_RATIO 30 |
445 |
453 |
446 void MemTracker::sync() { |
454 void MemTracker::sync() { |
447 assert(_tracking_level > NMT_off, "NMT is not enabled"); |
455 assert(_tracking_level > NMT_off, "NMT is not enabled"); |
448 assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required"); |
456 assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required"); |
449 |
457 |
485 if (_global_recorder != NULL) { |
493 if (_global_recorder != NULL) { |
486 _global_recorder->set_next(pending_recorders); |
494 _global_recorder->set_next(pending_recorders); |
487 pending_recorders = _global_recorder; |
495 pending_recorders = _global_recorder; |
488 _global_recorder = NULL; |
496 _global_recorder = NULL; |
489 } |
497 } |
|
498 |
|
499 // see if NMT has too many outstanding recorder instances, it usually |
|
500 // means that worker thread is lagging behind in processing them. |
|
501 if (!AutoShutdownNMT) { |
|
502 _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count); |
|
503 } |
|
504 |
490 // check _worker_thread with lock to avoid racing condition |
505 // check _worker_thread with lock to avoid racing condition |
491 if (_worker_thread != NULL) { |
506 if (_worker_thread != NULL) { |
492 _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes()); |
507 _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes()); |
493 } |
508 } |
494 |
509 |