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




 344     } else {
 345       if (thread == NULL) {
 346           // don't use Thread::current(), since it is possible that
 347           // the calling thread has yet to attach to VM 'Thread',
 348           // which will result assertion failure
 349           thread = ThreadLocalStorage::thread();
 350       }
 351     }
 352 
 353     if (thread != NULL) {
 354 #ifdef ASSERT
 355       // cause assertion on stack base. This ensures that threads call
 356       // Thread::record_stack_base_and_size() method, which will create
 357       // thread native stack records.
 358       thread->stack_base();
 359 #endif
 360       // for a JavaThread, if it is running in native state, we need to transition it to
 361       // VM state, so it can stop at safepoint. JavaThread running in VM state does not
 362       // need lock to write records.
 363       if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) {




 364         if (((JavaThread*)thread)->thread_state() == _thread_in_native) {
 365           ThreadInVMfromNative trans((JavaThread*)thread);
 366           create_record_in_recorder(addr, flags, size, pc, thread);
 367         } else {
 368           create_record_in_recorder(addr, flags, size, pc, thread);
 369         }
 370       } else {
 371         // other threads, such as worker and watcher threads, etc. need to
 372         // take ThreadCritical to write to global recorder
 373         ThreadCritical tc;
 374         create_record_in_recorder(addr, flags, size, pc, NULL);
 375       }
 376     } else {
 377       if (_state == NMT_bootstrapping_single_thread) {
 378         // single thread, no lock needed
 379         create_record_in_recorder(addr, flags, size, pc, NULL);
 380       } else {
 381         // for thread has yet to attach VM 'Thread', we can not use VM mutex.
 382         // use native thread critical instead
 383         ThreadCritical tc;


 469 
 470     {
 471       // This method is running at safepoint, with ThreadCritical lock,
 472       // it should guarantee that NMT is fully sync-ed.
 473       ThreadCritical tc;
 474       if (_global_recorder != NULL) {
 475         _global_recorder->set_next(pending_recorders);
 476         pending_recorders = _global_recorder;
 477         _global_recorder = NULL;
 478       }
 479       SequenceGenerator::reset();
 480       // check _worker_thread with lock to avoid racing condition
 481       if (_worker_thread != NULL) {
 482         _worker_thread->at_sync_point(pending_recorders);
 483       }
 484     }
 485   }
 486 
 487   // now, it is the time to shut whole things off
 488   if (_state == NMT_final_shutdown) {
 489     _tracking_level = NMT_off;
 490 
 491     // walk all JavaThreads to delete all recorders
 492     SyncThreadRecorderClosure stc;
 493     Threads::threads_do(&stc);
 494     // delete global recorder
 495     {
 496       ThreadCritical tc;
 497       if (_global_recorder != NULL) {
 498         delete _global_recorder;
 499         _global_recorder = NULL;
 500       }
 501     }
 502 






 503     _state = NMT_shutdown;

 504   }

 505 }
 506 
 507 /*
 508  * Start worker thread.
 509  */
 510 bool MemTracker::start_worker() {
 511   assert(_worker_thread == NULL, "Just Check");
 512   _worker_thread = new (std::nothrow) MemTrackWorker();
 513   if (_worker_thread == NULL || _worker_thread->has_error()) {
 514     shutdown(NMT_initialization);
 515     return false;
 516   }
 517   _worker_thread->start();
 518   return true;
 519 }
 520 
 521 /*
 522  * We need to collect a JavaThread's per-thread recorder
 523  * before it exits.
 524  */




 344     } else {
 345       if (thread == NULL) {
 346           // don't use Thread::current(), since it is possible that
 347           // the calling thread has yet to attach to VM 'Thread',
 348           // which will result assertion failure
 349           thread = ThreadLocalStorage::thread();
 350       }
 351     }
 352 
 353     if (thread != NULL) {
 354 #ifdef ASSERT
 355       // cause assertion on stack base. This ensures that threads call
 356       // Thread::record_stack_base_and_size() method, which will create
 357       // thread native stack records.
 358       thread->stack_base();
 359 #endif
 360       // for a JavaThread, if it is running in native state, we need to transition it to
 361       // VM state, so it can stop at safepoint. JavaThread running in VM state does not
 362       // need lock to write records.
 363       if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) {
 364         assert(!(SafepointSynchronize::is_at_safepoint() && 
 365           ((JavaThread*)thread)->thread_state() == _thread_blocked),
 366            "_thread_blocked allocate/deallocation memory at safepoint");
 367 
 368         if (((JavaThread*)thread)->thread_state() == _thread_in_native) {
 369           ThreadInVMfromNative trans((JavaThread*)thread);
 370           create_record_in_recorder(addr, flags, size, pc, thread);
 371         } else {
 372           create_record_in_recorder(addr, flags, size, pc, thread);
 373         }
 374       } else {
 375         // other threads, such as worker and watcher threads, etc. need to
 376         // take ThreadCritical to write to global recorder
 377         ThreadCritical tc;
 378         create_record_in_recorder(addr, flags, size, pc, NULL);
 379       }
 380     } else {
 381       if (_state == NMT_bootstrapping_single_thread) {
 382         // single thread, no lock needed
 383         create_record_in_recorder(addr, flags, size, pc, NULL);
 384       } else {
 385         // for thread has yet to attach VM 'Thread', we can not use VM mutex.
 386         // use native thread critical instead
 387         ThreadCritical tc;


 473 
 474     {
 475       // This method is running at safepoint, with ThreadCritical lock,
 476       // it should guarantee that NMT is fully sync-ed.
 477       ThreadCritical tc;
 478       if (_global_recorder != NULL) {
 479         _global_recorder->set_next(pending_recorders);
 480         pending_recorders = _global_recorder;
 481         _global_recorder = NULL;
 482       }
 483       SequenceGenerator::reset();
 484       // check _worker_thread with lock to avoid racing condition
 485       if (_worker_thread != NULL) {
 486         _worker_thread->at_sync_point(pending_recorders);
 487       }
 488     }
 489   }
 490 
 491   // now, it is the time to shut whole things off
 492   if (_state == NMT_final_shutdown) {


 493     // walk all JavaThreads to delete all recorders
 494     SyncThreadRecorderClosure stc;
 495     Threads::threads_do(&stc);
 496     // delete global recorder
 497     {
 498       ThreadCritical tc;
 499       if (_global_recorder != NULL) {
 500         delete _global_recorder;
 501         _global_recorder = NULL;
 502       }
 503     }
 504     MemRecorder* pending_recorders = get_pending_recorders();
 505     if (pending_recorders != NULL) {
 506       delete pending_recorders;
 507     }
 508     // wait until MemRecorder instance drops to zero to
 509     // completely shutdown NMT
 510     if (MemRecorder::_instance_count == 0) {
 511       _state = NMT_shutdown;
 512       _tracking_level = NMT_off;
 513     }
 514   }
 515 }
 516 
 517 /*
 518  * Start worker thread.
 519  */
 520 bool MemTracker::start_worker() {
 521   assert(_worker_thread == NULL, "Just Check");
 522   _worker_thread = new (std::nothrow) MemTrackWorker();
 523   if (_worker_thread == NULL || _worker_thread->has_error()) {
 524     shutdown(NMT_initialization);
 525     return false;
 526   }
 527   _worker_thread->start();
 528   return true;
 529 }
 530 
 531 /*
 532  * We need to collect a JavaThread's per-thread recorder
 533  * before it exits.
 534  */


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