annotate src/share/vm/services/memoryService.cpp @ 9038:4b8584c24ff4

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