src/share/vm/services/memTracker.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/services

src/share/vm/services/memTracker.cpp

Print this page




 368     (void*)cur_head)) {
 369     cur_head = const_cast<MemRecorder*>(_merge_pending_queue);
 370     rec->set_next(cur_head);
 371   }
 372   NOT_PRODUCT(Atomic::inc(&_pending_recorder_count);)
 373 }
 374 
 375 /*
 376  * The method is called at global safepoint
 377  * during it synchronization process.
 378  *   1. enqueue all JavaThreads' per-thread recorders
 379  *   2. enqueue global recorder
 380  *   3. retrieve all pending recorders
 381  *   4. reset global sequence number generator
 382  *   5. call worker's sync
 383  */
 384 #define MAX_SAFEPOINTS_TO_SKIP     128
 385 #define SAFE_SEQUENCE_THRESHOLD    30
 386 #define HIGH_GENERATION_THRESHOLD  60
 387 #define MAX_RECORDER_THREAD_RATIO  30

 388 
 389 void MemTracker::sync() {
 390   assert(_tracking_level > NMT_off, "NMT is not enabled");
 391   assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required");
 392 
 393   // Some GC tests hit large number of safepoints in short period of time
 394   // without meaningful activities. We should prevent going to
 395   // sync point in these cases, which can potentially exhaust generation buffer.
 396   // Here is the factots to determine if we should go into sync point:
 397   // 1. not to overflow sequence number
 398   // 2. if we are in danger to overflow generation buffer
 399   // 3. how many safepoints we already skipped sync point
 400   if (_state == NMT_started) {
 401     // worker thread is not ready, no one can manage generation
 402     // buffer, so skip this safepoint
 403     if (_worker_thread == NULL) return;
 404 
 405     if (_sync_point_skip_count < MAX_SAFEPOINTS_TO_SKIP) {
 406       int per_seq_in_use = SequenceGenerator::peek() * 100 / max_jint;
 407       int per_gen_in_use = _worker_thread->generations_in_use() * 100 / MAX_GENERATIONS;


 420         SequenceGenerator::reset();
 421         _sync_point_skip_count = 0;
 422 
 423         // walk all JavaThreads to collect recorders
 424         SyncThreadRecorderClosure stc;
 425         Threads::threads_do(&stc);
 426 
 427         _thread_count = stc.get_thread_count();
 428         MemRecorder* pending_recorders = get_pending_recorders();
 429 
 430         if (_global_recorder != NULL) {
 431           _global_recorder->set_next(pending_recorders);
 432           pending_recorders = _global_recorder;
 433           _global_recorder = NULL;
 434         }
 435 
 436         // see if NMT has too many outstanding recorder instances, it usually
 437         // means that worker thread is lagging behind in processing them.
 438         if (!AutoShutdownNMT) {
 439           _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count);





 440         }
 441 
 442         // check _worker_thread with lock to avoid racing condition
 443         if (_worker_thread != NULL) {
 444           _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes());
 445         }
 446         assert(SequenceGenerator::peek() == 1, "Should not have memory activities during sync-point");
 447       } else {
 448         _sync_point_skip_count ++;
 449       }
 450     }
 451   }
 452 
 453   // now, it is the time to shut whole things off
 454   if (_state == NMT_final_shutdown) {
 455     // walk all JavaThreads to delete all recorders
 456     SyncThreadRecorderClosure stc;
 457     Threads::threads_do(&stc);
 458     // delete global recorder
 459     {




 368     (void*)cur_head)) {
 369     cur_head = const_cast<MemRecorder*>(_merge_pending_queue);
 370     rec->set_next(cur_head);
 371   }
 372   NOT_PRODUCT(Atomic::inc(&_pending_recorder_count);)
 373 }
 374 
 375 /*
 376  * The method is called at global safepoint
 377  * during it synchronization process.
 378  *   1. enqueue all JavaThreads' per-thread recorders
 379  *   2. enqueue global recorder
 380  *   3. retrieve all pending recorders
 381  *   4. reset global sequence number generator
 382  *   5. call worker's sync
 383  */
 384 #define MAX_SAFEPOINTS_TO_SKIP     128
 385 #define SAFE_SEQUENCE_THRESHOLD    30
 386 #define HIGH_GENERATION_THRESHOLD  60
 387 #define MAX_RECORDER_THREAD_RATIO  30
 388 #define MAX_RECORDER_PER_THREAD    100
 389 
 390 void MemTracker::sync() {
 391   assert(_tracking_level > NMT_off, "NMT is not enabled");
 392   assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required");
 393 
 394   // Some GC tests hit large number of safepoints in short period of time
 395   // without meaningful activities. We should prevent going to
 396   // sync point in these cases, which can potentially exhaust generation buffer.
 397   // Here is the factots to determine if we should go into sync point:
 398   // 1. not to overflow sequence number
 399   // 2. if we are in danger to overflow generation buffer
 400   // 3. how many safepoints we already skipped sync point
 401   if (_state == NMT_started) {
 402     // worker thread is not ready, no one can manage generation
 403     // buffer, so skip this safepoint
 404     if (_worker_thread == NULL) return;
 405 
 406     if (_sync_point_skip_count < MAX_SAFEPOINTS_TO_SKIP) {
 407       int per_seq_in_use = SequenceGenerator::peek() * 100 / max_jint;
 408       int per_gen_in_use = _worker_thread->generations_in_use() * 100 / MAX_GENERATIONS;


 421         SequenceGenerator::reset();
 422         _sync_point_skip_count = 0;
 423 
 424         // walk all JavaThreads to collect recorders
 425         SyncThreadRecorderClosure stc;
 426         Threads::threads_do(&stc);
 427 
 428         _thread_count = stc.get_thread_count();
 429         MemRecorder* pending_recorders = get_pending_recorders();
 430 
 431         if (_global_recorder != NULL) {
 432           _global_recorder->set_next(pending_recorders);
 433           pending_recorders = _global_recorder;
 434           _global_recorder = NULL;
 435         }
 436 
 437         // see if NMT has too many outstanding recorder instances, it usually
 438         // means that worker thread is lagging behind in processing them.
 439         if (!AutoShutdownNMT) {
 440           _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count);
 441         } else {
 442           // If auto shutdown is on, enforce MAX_RECORDER_PER_THREAD threshold to prevent OOM
 443           if (MemRecorder::_instance_count >= _thread_count * MAX_RECORDER_PER_THREAD) {
 444             shutdown(NMT_out_of_memory);
 445           } 
 446         }
 447 
 448         // check _worker_thread with lock to avoid racing condition
 449         if (_worker_thread != NULL) {
 450           _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes());
 451         }
 452         assert(SequenceGenerator::peek() == 1, "Should not have memory activities during sync-point");
 453       } else {
 454         _sync_point_skip_count ++;
 455       }
 456     }
 457   }
 458 
 459   // now, it is the time to shut whole things off
 460   if (_state == NMT_final_shutdown) {
 461     // walk all JavaThreads to delete all recorders
 462     SyncThreadRecorderClosure stc;
 463     Threads::threads_do(&stc);
 464     // delete global recorder
 465     {


src/share/vm/services/memTracker.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File