src/share/vm/services/memoryService.cpp

Print this page




 492   // Track the peak memory usage
 493   for (int i = 0; i < _pools_list->length(); i++) {
 494     MemoryPool* pool = _pools_list->at(i);
 495     pool->record_peak_memory_usage();
 496   }
 497 
 498   // Detect low memory
 499   LowMemoryDetector::detect_low_memory();
 500 }
 501 
 502 void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
 503   // Track the peak memory usage
 504   pool->record_peak_memory_usage();
 505 
 506   // Detect low memory
 507   if (LowMemoryDetector::is_enabled(pool)) {
 508     LowMemoryDetector::detect_low_memory(pool);
 509   }
 510 }
 511 
 512 void MemoryService::gc_begin(bool fullGC) {



 513   GCMemoryManager* mgr;
 514   if (fullGC) {
 515     mgr = _major_gc_manager;
 516   } else {
 517     mgr = _minor_gc_manager;
 518   }
 519   assert(mgr->is_gc_memory_manager(), "Sanity check");
 520   mgr->gc_begin();
 521 
 522   // Track the peak memory usage when GC begins

 523   for (int i = 0; i < _pools_list->length(); i++) {
 524     MemoryPool* pool = _pools_list->at(i);
 525     pool->record_peak_memory_usage();
 526   }

 527 }
 528 
 529 void MemoryService::gc_end(bool fullGC) {



 530   GCMemoryManager* mgr;
 531   if (fullGC) {
 532     mgr = (GCMemoryManager*) _major_gc_manager;
 533   } else {
 534     mgr = (GCMemoryManager*) _minor_gc_manager;
 535   }
 536   assert(mgr->is_gc_memory_manager(), "Sanity check");
 537 
 538   // register the GC end statistics and memory usage
 539   mgr->gc_end();

 540 }
 541 
 542 void MemoryService::oops_do(OopClosure* f) {
 543   int i;
 544 
 545   for (i = 0; i < _pools_list->length(); i++) {
 546     MemoryPool* pool = _pools_list->at(i);
 547     pool->oops_do(f);
 548   }
 549   for (i = 0; i < _managers_list->length(); i++) {
 550     MemoryManager* mgr = _managers_list->at(i);
 551     mgr->oops_do(f);
 552   }
 553 }
 554 
 555 bool MemoryService::set_verbose(bool verbose) {
 556   MutexLocker m(Management_lock);
 557   // verbose will be set to the previous value
 558   bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, MANAGEMENT);
 559   assert(succeed, "Setting PrintGC flag fails");


 568 
 569   instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
 570 
 571   JavaValue result(T_VOID);
 572   JavaCallArguments args(10);
 573   args.push_oop(obj);                         // receiver
 574   args.push_long(usage.init_size_as_jlong()); // Argument 1
 575   args.push_long(usage.used_as_jlong());      // Argument 2
 576   args.push_long(usage.committed_as_jlong()); // Argument 3
 577   args.push_long(usage.max_size_as_jlong());  // Argument 4
 578 
 579   JavaCalls::call_special(&result,
 580                           ik,
 581                           vmSymbolHandles::object_initializer_name(),
 582                           vmSymbolHandles::long_long_long_long_void_signature(),
 583                           &args,
 584                           CHECK_NH);
 585   return obj;
 586 }
 587 //
 588 // GC manager type depends on the type of Generation. Depending the space
 589 // availablity and vm option the gc uses major gc manager or minor gc
 590 // manager or both. The type of gc manager depends on the generation kind.
 591 // For DefNew, ParNew and ASParNew generation doing scavange gc uses minor
 592 // gc manager (so _fullGC is set to false ) and for other generation kind
 593 // DOing mark-sweep-compact uses major gc manager (so _fullGC is set
 594 // to true).
 595 TraceMemoryManagerStats::TraceMemoryManagerStats(Generation::Name kind) {
 596   switch (kind) {
 597     case Generation::DefNew:
 598 #ifndef SERIALGC
 599     case Generation::ParNew:
 600     case Generation::ASParNew:
 601 #endif // SERIALGC
 602       _fullGC=false;
 603       break;
 604     case Generation::MarkSweepCompact:
 605 #ifndef SERIALGC
 606     case Generation::ConcurrentMarkSweep:
 607     case Generation::ASConcurrentMarkSweep:
 608 #endif // SERIALGC
 609       _fullGC=true;
 610       break;
 611     default:
 612       assert(false, "Unrecognized gc generation kind.");
 613   }
 614   MemoryService::gc_begin(_fullGC);


 615 }
 616 TraceMemoryManagerStats::TraceMemoryManagerStats(bool fullGC) {






















 617   _fullGC = fullGC;
 618   MemoryService::gc_begin(_fullGC);









 619 }
 620 
 621 TraceMemoryManagerStats::~TraceMemoryManagerStats() {
 622   MemoryService::gc_end(_fullGC);

 623 }



 492   // Track the peak memory usage
 493   for (int i = 0; i < _pools_list->length(); i++) {
 494     MemoryPool* pool = _pools_list->at(i);
 495     pool->record_peak_memory_usage();
 496   }
 497 
 498   // Detect low memory
 499   LowMemoryDetector::detect_low_memory();
 500 }
 501 
 502 void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
 503   // Track the peak memory usage
 504   pool->record_peak_memory_usage();
 505 
 506   // Detect low memory
 507   if (LowMemoryDetector::is_enabled(pool)) {
 508     LowMemoryDetector::detect_low_memory(pool);
 509   }
 510 }
 511 
 512 void MemoryService::gc_begin(bool fullGC, bool recordGCBeginTime,
 513                              bool recordAccumulatedGCTime,
 514                              bool recordPreGCUsage, bool recordPeakUsage) {
 515 
 516   GCMemoryManager* mgr;
 517   if (fullGC) {
 518     mgr = _major_gc_manager;
 519   } else {
 520     mgr = _minor_gc_manager;
 521   }
 522   assert(mgr->is_gc_memory_manager(), "Sanity check");
 523   mgr->gc_begin(recordGCBeginTime, recordPreGCUsage, recordAccumulatedGCTime);
 524 
 525   // Track the peak memory usage when GC begins
 526   if (recordPeakUsage) {
 527     for (int i = 0; i < _pools_list->length(); i++) {
 528       MemoryPool* pool = _pools_list->at(i);
 529       pool->record_peak_memory_usage();
 530     }
 531   }
 532 }
 533 
 534 void MemoryService::gc_end(bool fullGC, bool recordPostGCUsage,
 535                            bool recordAccumulatedGCTime,
 536                            bool recordGCEndTime, bool countCollection) {
 537 
 538   GCMemoryManager* mgr;
 539   if (fullGC) {
 540     mgr = (GCMemoryManager*) _major_gc_manager;
 541   } else {
 542     mgr = (GCMemoryManager*) _minor_gc_manager;
 543   }
 544   assert(mgr->is_gc_memory_manager(), "Sanity check");
 545 
 546   // register the GC end statistics and memory usage
 547   mgr->gc_end(recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
 548               countCollection);
 549 }
 550 
 551 void MemoryService::oops_do(OopClosure* f) {
 552   int i;
 553 
 554   for (i = 0; i < _pools_list->length(); i++) {
 555     MemoryPool* pool = _pools_list->at(i);
 556     pool->oops_do(f);
 557   }
 558   for (i = 0; i < _managers_list->length(); i++) {
 559     MemoryManager* mgr = _managers_list->at(i);
 560     mgr->oops_do(f);
 561   }
 562 }
 563 
 564 bool MemoryService::set_verbose(bool verbose) {
 565   MutexLocker m(Management_lock);
 566   // verbose will be set to the previous value
 567   bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, MANAGEMENT);
 568   assert(succeed, "Setting PrintGC flag fails");


 577 
 578   instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
 579 
 580   JavaValue result(T_VOID);
 581   JavaCallArguments args(10);
 582   args.push_oop(obj);                         // receiver
 583   args.push_long(usage.init_size_as_jlong()); // Argument 1
 584   args.push_long(usage.used_as_jlong());      // Argument 2
 585   args.push_long(usage.committed_as_jlong()); // Argument 3
 586   args.push_long(usage.max_size_as_jlong());  // Argument 4
 587 
 588   JavaCalls::call_special(&result,
 589                           ik,
 590                           vmSymbolHandles::object_initializer_name(),
 591                           vmSymbolHandles::long_long_long_long_void_signature(),
 592                           &args,
 593                           CHECK_NH);
 594   return obj;
 595 }
 596 //
 597 // GC manager type depends on the type of Generation. Depending on the space
 598 // availablity and vm options the gc uses major gc manager or minor gc
 599 // manager or both. The type of gc manager depends on the generation kind.
 600 // For DefNew, ParNew and ASParNew generation doing scavenge gc uses minor
 601 // gc manager (so _fullGC is set to false ) and for other generation kinds
 602 // doing mark-sweep-compact uses major gc manager (so _fullGC is set
 603 // to true).
 604 TraceMemoryManagerStats::TraceMemoryManagerStats(Generation::Name kind) {
 605   switch (kind) {
 606     case Generation::DefNew:
 607 #ifndef SERIALGC
 608     case Generation::ParNew:
 609     case Generation::ASParNew:
 610 #endif // SERIALGC
 611       _fullGC=false;
 612       break;
 613     case Generation::MarkSweepCompact:
 614 #ifndef SERIALGC
 615     case Generation::ConcurrentMarkSweep:
 616     case Generation::ASConcurrentMarkSweep:
 617 #endif // SERIALGC
 618       _fullGC=true;
 619       break;
 620     default:
 621       assert(false, "Unrecognized gc generation kind.");
 622   }
 623   // this has to be called in a stop the world pause and represent
 624   // an entire gc pause, start to finish:
 625   initialize(_fullGC, true, true, true, true, true, true, true);
 626 }
 627 TraceMemoryManagerStats::TraceMemoryManagerStats(bool fullGC,
 628                                                  bool recordGCBeginTime,
 629                                                  bool recordPreGCUsage,
 630                                                  bool recordPeakUsage,
 631                                                  bool recordPostGCUsage,
 632                                                  bool recordAccumulatedGCTime,
 633                                                  bool recordGCEndTime,
 634                                                  bool countCollection) {
 635   initialize(fullGC, recordGCBeginTime, recordPreGCUsage, recordPeakUsage,
 636              recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
 637              countCollection);
 638 }
 639 
 640 // for a subclass to create then initialize an instance before invoking
 641 // the MemoryService
 642 void TraceMemoryManagerStats::initialize(bool fullGC,
 643                                          bool recordGCBeginTime,
 644                                          bool recordPreGCUsage, 
 645                                          bool recordPeakUsage,
 646                                          bool recordPostGCUsage,
 647                                          bool recordAccumulatedGCTime,
 648                                          bool recordGCEndTime,
 649                                          bool countCollection) {
 650   _fullGC = fullGC;
 651   _recordGCBeginTime = recordGCBeginTime;
 652   _recordPreGCUsage = recordPreGCUsage;
 653   _recordPeakUsage = recordPeakUsage;
 654   _recordPostGCUsage = recordPostGCUsage;
 655   _recordAccumulatedGCTime = recordAccumulatedGCTime;
 656   _recordGCEndTime = recordGCEndTime;
 657   _countCollection = countCollection;
 658 
 659   MemoryService::gc_begin(_fullGC, _recordGCBeginTime, _recordAccumulatedGCTime,
 660                           _recordPreGCUsage, _recordPeakUsage);
 661 }
 662 
 663 TraceMemoryManagerStats::~TraceMemoryManagerStats() {
 664   MemoryService::gc_end(_fullGC, _recordPostGCUsage, _recordAccumulatedGCTime,
 665                         _recordGCEndTime, _countCollection);
 666 }
 667