1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "gc_implementation/shared/mutableSpace.hpp"
  29 #include "memory/collectorPolicy.hpp"
  30 #include "memory/defNewGeneration.hpp"
  31 #include "memory/genCollectedHeap.hpp"
  32 #include "memory/generation.hpp"
  33 #include "memory/generationSpec.hpp"
  34 #include "memory/heap.hpp"
  35 #include "memory/memRegion.hpp"
  36 #include "memory/tenuredGeneration.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/javaCalls.hpp"
  39 #include "services/classLoadingService.hpp"
  40 #include "services/lowMemoryDetector.hpp"
  41 #include "services/management.hpp"
  42 #include "services/memoryManager.hpp"
  43 #include "services/memoryPool.hpp"
  44 #include "services/memoryService.hpp"
  45 #include "utilities/growableArray.hpp"
  46 #include "utilities/macros.hpp"
  47 #if INCLUDE_ALL_GCS
  48 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp"
  49 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  50 #include "gc_implementation/parNew/parNewGeneration.hpp"
  51 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  52 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
  53 #include "gc_implementation/parallelScavenge/psYoungGen.hpp"
  54 #include "services/g1MemoryPool.hpp"
  55 #include "services/psMemoryPool.hpp"
  56 #endif // INCLUDE_ALL_GCS
  57 
  58 GrowableArray<MemoryPool*>* MemoryService::_pools_list =
  59   new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_pools_list_size, true);
  60 GrowableArray<MemoryManager*>* MemoryService::_managers_list =
  61   new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryManager*>(init_managers_list_size, true);
  62 
  63 GCMemoryManager* MemoryService::_minor_gc_manager = NULL;
  64 GCMemoryManager* MemoryService::_major_gc_manager = NULL;
  65 MemoryPool*      MemoryService::_code_heap_pool   = NULL;
  66 
  67 class GcThreadCountClosure: public ThreadClosure {
  68  private:
  69   int _count;
  70  public:
  71   GcThreadCountClosure() : _count(0) {};
  72   void do_thread(Thread* thread);
  73   int count() { return _count; }
  74 };
  75 
  76 void GcThreadCountClosure::do_thread(Thread* thread) {
  77   _count++;
  78 }
  79 
  80 void MemoryService::set_universe_heap(CollectedHeap* heap) {
  81   CollectedHeap::Name kind = heap->kind();
  82   switch (kind) {
  83     case CollectedHeap::GenCollectedHeap : {
  84       add_gen_collected_heap_info(GenCollectedHeap::heap());
  85       break;
  86     }
  87 #if INCLUDE_ALL_GCS
  88     case CollectedHeap::ParallelScavengeHeap : {
  89       add_parallel_scavenge_heap_info(ParallelScavengeHeap::heap());
  90       break;
  91     }
  92     case CollectedHeap::G1CollectedHeap : {
  93       add_g1_heap_info(G1CollectedHeap::heap());
  94       break;
  95     }
  96 #endif // INCLUDE_ALL_GCS
  97     default: {
  98       guarantee(false, "Unrecognized kind of heap");
  99     }
 100   }
 101 
 102   // set the GC thread count
 103   GcThreadCountClosure gctcc;
 104   heap->gc_threads_do(&gctcc);
 105   int count = gctcc.count();
 106   if (count > 0) {
 107     _minor_gc_manager->set_num_gc_threads(count);
 108     _major_gc_manager->set_num_gc_threads(count);
 109   }
 110 
 111   // All memory pools and memory managers are initialized.
 112   //
 113   _minor_gc_manager->initialize_gc_stat_info();
 114   _major_gc_manager->initialize_gc_stat_info();
 115 }
 116 
 117 // Add memory pools for GenCollectedHeap
 118 // This function currently only supports two generations collected heap.
 119 // The collector for GenCollectedHeap will have two memory managers.
 120 void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) {
 121   CollectorPolicy* policy = heap->collector_policy();
 122 
 123   assert(policy->is_two_generation_policy(), "Only support two generations");
 124   guarantee(heap->n_gens() == 2, "Only support two-generation heap");
 125 
 126   TwoGenerationCollectorPolicy* two_gen_policy = policy->as_two_generation_policy();
 127   if (two_gen_policy != NULL) {
 128     GenerationSpec** specs = two_gen_policy->generations();
 129     Generation::Name kind = specs[0]->name();
 130     switch (kind) {
 131       case Generation::DefNew:
 132         _minor_gc_manager = MemoryManager::get_copy_memory_manager();
 133         break;
 134 #if INCLUDE_ALL_GCS
 135       case Generation::ParNew:
 136       case Generation::ASParNew:
 137         _minor_gc_manager = MemoryManager::get_parnew_memory_manager();
 138         break;
 139 #endif // INCLUDE_ALL_GCS
 140       default:
 141         guarantee(false, "Unrecognized generation spec");
 142         break;
 143     }
 144     if (policy->is_mark_sweep_policy()) {
 145       _major_gc_manager = MemoryManager::get_msc_memory_manager();
 146 #if INCLUDE_ALL_GCS
 147     } else if (policy->is_concurrent_mark_sweep_policy()) {
 148       _major_gc_manager = MemoryManager::get_cms_memory_manager();
 149 #endif // INCLUDE_ALL_GCS
 150     } else {
 151       guarantee(false, "Unknown two-gen policy");
 152     }
 153   } else {
 154     guarantee(false, "Non two-gen policy");
 155   }
 156   _managers_list->append(_minor_gc_manager);
 157   _managers_list->append(_major_gc_manager);
 158 
 159   add_generation_memory_pool(heap->get_gen(minor), _major_gc_manager, _minor_gc_manager);
 160   add_generation_memory_pool(heap->get_gen(major), _major_gc_manager);
 161 }
 162 
 163 #if INCLUDE_ALL_GCS
 164 // Add memory pools for ParallelScavengeHeap
 165 // This function currently only supports two generations collected heap.
 166 // The collector for ParallelScavengeHeap will have two memory managers.
 167 void MemoryService::add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap) {
 168   // Two managers to keep statistics about _minor_gc_manager and _major_gc_manager GC.
 169   _minor_gc_manager = MemoryManager::get_psScavenge_memory_manager();
 170   _major_gc_manager = MemoryManager::get_psMarkSweep_memory_manager();
 171   _managers_list->append(_minor_gc_manager);
 172   _managers_list->append(_major_gc_manager);
 173 
 174   add_psYoung_memory_pool(heap->young_gen(), _major_gc_manager, _minor_gc_manager);
 175   add_psOld_memory_pool(heap->old_gen(), _major_gc_manager);
 176 }
 177 
 178 void MemoryService::add_g1_heap_info(G1CollectedHeap* g1h) {
 179   assert(UseG1GC, "sanity");
 180 
 181   _minor_gc_manager = MemoryManager::get_g1YoungGen_memory_manager();
 182   _major_gc_manager = MemoryManager::get_g1OldGen_memory_manager();
 183   _managers_list->append(_minor_gc_manager);
 184   _managers_list->append(_major_gc_manager);
 185 
 186   add_g1YoungGen_memory_pool(g1h, _major_gc_manager, _minor_gc_manager);
 187   add_g1OldGen_memory_pool(g1h, _major_gc_manager);
 188 }
 189 #endif // INCLUDE_ALL_GCS
 190 
 191 MemoryPool* MemoryService::add_gen(Generation* gen,
 192                                    const char* name,
 193                                    bool is_heap,
 194                                    bool support_usage_threshold) {
 195 
 196   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 197   GenerationPool* pool = new GenerationPool(gen, name, type, support_usage_threshold);
 198   _pools_list->append(pool);
 199   return (MemoryPool*) pool;
 200 }
 201 
 202 MemoryPool* MemoryService::add_space(ContiguousSpace* space,
 203                                      const char* name,
 204                                      bool is_heap,
 205                                      size_t max_size,
 206                                      bool support_usage_threshold) {
 207   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 208   ContiguousSpacePool* pool = new ContiguousSpacePool(space, name, type, max_size, support_usage_threshold);
 209 
 210   _pools_list->append(pool);
 211   return (MemoryPool*) pool;
 212 }
 213 
 214 MemoryPool* MemoryService::add_survivor_spaces(DefNewGeneration* gen,
 215                                                const char* name,
 216                                                bool is_heap,
 217                                                size_t max_size,
 218                                                bool support_usage_threshold) {
 219   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 220   SurvivorContiguousSpacePool* pool = new SurvivorContiguousSpacePool(gen, name, type, max_size, support_usage_threshold);
 221 
 222   _pools_list->append(pool);
 223   return (MemoryPool*) pool;
 224 }
 225 
 226 #if INCLUDE_ALL_GCS
 227 MemoryPool* MemoryService::add_cms_space(CompactibleFreeListSpace* space,
 228                                          const char* name,
 229                                          bool is_heap,
 230                                          size_t max_size,
 231                                          bool support_usage_threshold) {
 232   MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap);
 233   CompactibleFreeListSpacePool* pool = new CompactibleFreeListSpacePool(space, name, type, max_size, support_usage_threshold);
 234   _pools_list->append(pool);
 235   return (MemoryPool*) pool;
 236 }
 237 #endif // INCLUDE_ALL_GCS
 238 
 239 // Add memory pool(s) for one generation
 240 void MemoryService::add_generation_memory_pool(Generation* gen,
 241                                                MemoryManager* major_mgr,
 242                                                MemoryManager* minor_mgr) {
 243   assert(gen != NULL, "No generation for memory pool");
 244   if (gen == NULL) {
 245     ShouldNotReachHere();
 246     return;
 247   }
 248   Generation::Name kind = gen->kind();
 249   int index = _pools_list->length();
 250 
 251   switch (kind) {
 252     case Generation::DefNew: {
 253       assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
 254       DefNewGeneration* young_gen = (DefNewGeneration*) gen;
 255       // Add a memory pool for each space and young gen doesn't
 256       // support low memory detection as it is expected to get filled up.
 257       MemoryPool* eden = add_space(young_gen->eden(),
 258                                    "Eden Space",
 259                                    true, /* is_heap */
 260                                    young_gen->max_eden_size(),
 261                                    false /* support_usage_threshold */);
 262       MemoryPool* survivor = add_survivor_spaces(young_gen,
 263                                                  "Survivor Space",
 264                                                  true, /* is_heap */
 265                                                  young_gen->max_survivor_size(),
 266                                                  false /* support_usage_threshold */);
 267       break;
 268     }
 269 
 270 #if INCLUDE_ALL_GCS
 271     case Generation::ParNew:
 272     case Generation::ASParNew:
 273     {
 274       assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
 275       // Add a memory pool for each space and young gen doesn't
 276       // support low memory detection as it is expected to get filled up.
 277       ParNewGeneration* parnew_gen = (ParNewGeneration*) gen;
 278       MemoryPool* eden = add_space(parnew_gen->eden(),
 279                                    "Par Eden Space",
 280                                    true /* is_heap */,
 281                                    parnew_gen->max_eden_size(),
 282                                    false /* support_usage_threshold */);
 283       MemoryPool* survivor = add_survivor_spaces(parnew_gen,
 284                                                  "Par Survivor Space",
 285                                                  true, /* is_heap */
 286                                                  parnew_gen->max_survivor_size(),
 287                                                  false /* support_usage_threshold */);
 288 
 289       break;
 290     }
 291 #endif // INCLUDE_ALL_GCS
 292 
 293     case Generation::MarkSweepCompact: {
 294       assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager");
 295       add_gen(gen,
 296               "Tenured Gen",
 297               true, /* is_heap */
 298               true  /* support_usage_threshold */);
 299       break;
 300     }
 301 
 302 #if INCLUDE_ALL_GCS
 303     case Generation::ConcurrentMarkSweep:
 304     case Generation::ASConcurrentMarkSweep:
 305     {
 306       assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager");
 307       ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*) gen;
 308       MemoryPool* pool = add_cms_space(cms->cmsSpace(),
 309                                        "CMS Old Gen",
 310                                        true, /* is_heap */
 311                                        cms->reserved().byte_size(),
 312                                        true  /* support_usage_threshold */);
 313       break;
 314     }
 315 #endif // INCLUDE_ALL_GCS
 316 
 317     default:
 318       assert(false, "should not reach here");
 319       // no memory pool added for others
 320       break;
 321   }
 322 
 323   assert(major_mgr != NULL, "Should have at least one manager");
 324   // Link managers and the memory pools together
 325   for (int i = index; i < _pools_list->length(); i++) {
 326     MemoryPool* pool = _pools_list->at(i);
 327     major_mgr->add_pool(pool);
 328     if (minor_mgr != NULL) {
 329       minor_mgr->add_pool(pool);
 330     }
 331   }
 332 }
 333 
 334 
 335 #if INCLUDE_ALL_GCS
 336 void MemoryService::add_psYoung_memory_pool(PSYoungGen* gen, MemoryManager* major_mgr, MemoryManager* minor_mgr) {
 337   assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers");
 338 
 339   // Add a memory pool for each space and young gen doesn't
 340   // support low memory detection as it is expected to get filled up.
 341   EdenMutableSpacePool* eden = new EdenMutableSpacePool(gen,
 342                                                         gen->eden_space(),
 343                                                         "PS Eden Space",
 344                                                         MemoryPool::Heap,
 345                                                         false /* support_usage_threshold */);
 346 
 347   SurvivorMutableSpacePool* survivor = new SurvivorMutableSpacePool(gen,
 348                                                                     "PS Survivor Space",
 349                                                                     MemoryPool::Heap,
 350                                                                     false /* support_usage_threshold */);
 351 
 352   major_mgr->add_pool(eden);
 353   major_mgr->add_pool(survivor);
 354   minor_mgr->add_pool(eden);
 355   minor_mgr->add_pool(survivor);
 356   _pools_list->append(eden);
 357   _pools_list->append(survivor);
 358 }
 359 
 360 void MemoryService::add_psOld_memory_pool(PSOldGen* gen, MemoryManager* mgr) {
 361   PSGenerationPool* old_gen = new PSGenerationPool(gen,
 362                                                    "PS Old Gen",
 363                                                    MemoryPool::Heap,
 364                                                    true /* support_usage_threshold */);
 365   mgr->add_pool(old_gen);
 366   _pools_list->append(old_gen);
 367 }
 368 
 369 void MemoryService::add_g1YoungGen_memory_pool(G1CollectedHeap* g1h,
 370                                                MemoryManager* major_mgr,
 371                                                MemoryManager* minor_mgr) {
 372   assert(major_mgr != NULL && minor_mgr != NULL, "should have two managers");
 373 
 374   G1EdenPool* eden = new G1EdenPool(g1h);
 375   G1SurvivorPool* survivor = new G1SurvivorPool(g1h);
 376 
 377   major_mgr->add_pool(eden);
 378   major_mgr->add_pool(survivor);
 379   minor_mgr->add_pool(eden);
 380   minor_mgr->add_pool(survivor);
 381   _pools_list->append(eden);
 382   _pools_list->append(survivor);
 383 }
 384 
 385 void MemoryService::add_g1OldGen_memory_pool(G1CollectedHeap* g1h,
 386                                              MemoryManager* mgr) {
 387   assert(mgr != NULL, "should have one manager");
 388 
 389   G1OldGenPool* old_gen = new G1OldGenPool(g1h);
 390   mgr->add_pool(old_gen);
 391   _pools_list->append(old_gen);
 392 }
 393 #endif // INCLUDE_ALL_GCS
 394 
 395 void MemoryService::add_code_heap_memory_pool(CodeHeap* heap) {
 396   _code_heap_pool = new CodeHeapPool(heap,
 397                                      "Code Cache",
 398                                      true /* support_usage_threshold */);
 399   MemoryManager* mgr = MemoryManager::get_code_cache_memory_manager();
 400   mgr->add_pool(_code_heap_pool);
 401 
 402   _pools_list->append(_code_heap_pool);
 403   _managers_list->append(mgr);
 404 }
 405 
 406 MemoryManager* MemoryService::get_memory_manager(instanceHandle mh) {
 407   for (int i = 0; i < _managers_list->length(); i++) {
 408     MemoryManager* mgr = _managers_list->at(i);
 409     if (mgr->is_manager(mh)) {
 410       return mgr;
 411     }
 412   }
 413   return NULL;
 414 }
 415 
 416 MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) {
 417   for (int i = 0; i < _pools_list->length(); i++) {
 418     MemoryPool* pool = _pools_list->at(i);
 419     if (pool->is_pool(ph)) {
 420       return pool;
 421     }
 422   }
 423   return NULL;
 424 }
 425 
 426 void MemoryService::track_memory_usage() {
 427   // Track the peak memory usage
 428   for (int i = 0; i < _pools_list->length(); i++) {
 429     MemoryPool* pool = _pools_list->at(i);
 430     pool->record_peak_memory_usage();
 431   }
 432 
 433   // Detect low memory
 434   LowMemoryDetector::detect_low_memory();
 435 }
 436 
 437 void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
 438   // Track the peak memory usage
 439   pool->record_peak_memory_usage();
 440 
 441   // Detect low memory
 442   if (LowMemoryDetector::is_enabled(pool)) {
 443     LowMemoryDetector::detect_low_memory(pool);
 444   }
 445 }
 446 
 447 void MemoryService::gc_begin(bool fullGC, bool recordGCBeginTime,
 448                              bool recordAccumulatedGCTime,
 449                              bool recordPreGCUsage, bool recordPeakUsage) {
 450 
 451   GCMemoryManager* mgr;
 452   if (fullGC) {
 453     mgr = _major_gc_manager;
 454   } else {
 455     mgr = _minor_gc_manager;
 456   }
 457   assert(mgr->is_gc_memory_manager(), "Sanity check");
 458   mgr->gc_begin(recordGCBeginTime, recordPreGCUsage, recordAccumulatedGCTime);
 459 
 460   // Track the peak memory usage when GC begins
 461   if (recordPeakUsage) {
 462     for (int i = 0; i < _pools_list->length(); i++) {
 463       MemoryPool* pool = _pools_list->at(i);
 464       pool->record_peak_memory_usage();
 465     }
 466   }
 467 }
 468 
 469 void MemoryService::gc_end(bool fullGC, bool recordPostGCUsage,
 470                            bool recordAccumulatedGCTime,
 471                            bool recordGCEndTime, bool countCollection,
 472                            GCCause::Cause cause) {
 473 
 474   GCMemoryManager* mgr;
 475   if (fullGC) {
 476     mgr = (GCMemoryManager*) _major_gc_manager;
 477   } else {
 478     mgr = (GCMemoryManager*) _minor_gc_manager;
 479   }
 480   assert(mgr->is_gc_memory_manager(), "Sanity check");
 481 
 482   // register the GC end statistics and memory usage
 483   mgr->gc_end(recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
 484               countCollection, cause);
 485 }
 486 
 487 void MemoryService::oops_do(OopClosure* f) {
 488   int i;
 489 
 490   for (i = 0; i < _pools_list->length(); i++) {
 491     MemoryPool* pool = _pools_list->at(i);
 492     pool->oops_do(f);
 493   }
 494   for (i = 0; i < _managers_list->length(); i++) {
 495     MemoryManager* mgr = _managers_list->at(i);
 496     mgr->oops_do(f);
 497   }
 498 }
 499 
 500 bool MemoryService::set_verbose(bool verbose) {
 501   MutexLocker m(Management_lock);
 502   // verbose will be set to the previous value
 503   bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, MANAGEMENT);
 504   assert(succeed, "Setting PrintGC flag fails");
 505   ClassLoadingService::reset_trace_class_unloading();
 506 
 507   return verbose;
 508 }
 509 
 510 Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) {
 511   Klass* k = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
 512   instanceKlassHandle ik(THREAD, k);
 513 
 514   instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
 515 
 516   JavaValue result(T_VOID);
 517   JavaCallArguments args(10);
 518   args.push_oop(obj);                         // receiver
 519   args.push_long(usage.init_size_as_jlong()); // Argument 1
 520   args.push_long(usage.used_as_jlong());      // Argument 2
 521   args.push_long(usage.committed_as_jlong()); // Argument 3
 522   args.push_long(usage.max_size_as_jlong());  // Argument 4
 523 
 524   JavaCalls::call_special(&result,
 525                           ik,
 526                           vmSymbols::object_initializer_name(),
 527                           vmSymbols::long_long_long_long_void_signature(),
 528                           &args,
 529                           CHECK_NH);
 530   return obj;
 531 }
 532 //
 533 // GC manager type depends on the type of Generation. Depending on the space
 534 // availablity and vm options the gc uses major gc manager or minor gc
 535 // manager or both. The type of gc manager depends on the generation kind.
 536 // For DefNew, ParNew and ASParNew generation doing scavenge gc uses minor
 537 // gc manager (so _fullGC is set to false ) and for other generation kinds
 538 // doing mark-sweep-compact uses major gc manager (so _fullGC is set
 539 // to true).
 540 TraceMemoryManagerStats::TraceMemoryManagerStats(Generation::Name kind, GCCause::Cause cause) {
 541   switch (kind) {
 542     case Generation::DefNew:
 543 #if INCLUDE_ALL_GCS
 544     case Generation::ParNew:
 545     case Generation::ASParNew:
 546 #endif // INCLUDE_ALL_GCS
 547       _fullGC=false;
 548       break;
 549     case Generation::MarkSweepCompact:
 550 #if INCLUDE_ALL_GCS
 551     case Generation::ConcurrentMarkSweep:
 552     case Generation::ASConcurrentMarkSweep:
 553 #endif // INCLUDE_ALL_GCS
 554       _fullGC=true;
 555       break;
 556     default:
 557       assert(false, "Unrecognized gc generation kind.");
 558   }
 559   // this has to be called in a stop the world pause and represent
 560   // an entire gc pause, start to finish:
 561   initialize(_fullGC, cause,true, true, true, true, true, true, true);
 562 }
 563 TraceMemoryManagerStats::TraceMemoryManagerStats(bool fullGC,
 564                                                  GCCause::Cause cause,
 565                                                  bool recordGCBeginTime,
 566                                                  bool recordPreGCUsage,
 567                                                  bool recordPeakUsage,
 568                                                  bool recordPostGCUsage,
 569                                                  bool recordAccumulatedGCTime,
 570                                                  bool recordGCEndTime,
 571                                                  bool countCollection) {
 572     initialize(fullGC, cause, recordGCBeginTime, recordPreGCUsage, recordPeakUsage,
 573              recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
 574              countCollection);
 575 }
 576 
 577 // for a subclass to create then initialize an instance before invoking
 578 // the MemoryService
 579 void TraceMemoryManagerStats::initialize(bool fullGC,
 580                                          GCCause::Cause cause,
 581                                          bool recordGCBeginTime,
 582                                          bool recordPreGCUsage,
 583                                          bool recordPeakUsage,
 584                                          bool recordPostGCUsage,
 585                                          bool recordAccumulatedGCTime,
 586                                          bool recordGCEndTime,
 587                                          bool countCollection) {
 588   _fullGC = fullGC;
 589   _recordGCBeginTime = recordGCBeginTime;
 590   _recordPreGCUsage = recordPreGCUsage;
 591   _recordPeakUsage = recordPeakUsage;
 592   _recordPostGCUsage = recordPostGCUsage;
 593   _recordAccumulatedGCTime = recordAccumulatedGCTime;
 594   _recordGCEndTime = recordGCEndTime;
 595   _countCollection = countCollection;
 596   _cause = cause;
 597 
 598   MemoryService::gc_begin(_fullGC, _recordGCBeginTime, _recordAccumulatedGCTime,
 599                           _recordPreGCUsage, _recordPeakUsage);
 600 }
 601 
 602 TraceMemoryManagerStats::~TraceMemoryManagerStats() {
 603   MemoryService::gc_end(_fullGC, _recordPostGCUsage, _recordAccumulatedGCTime,
 604                         _recordGCEndTime, _countCollection, _cause);
 605 }
 606