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