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