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