1 /* 2 * Copyright (c) 2013, 2019, Red Hat, Inc. All rights reserved. 3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "gc/shenandoah/shenandoahMemoryPool.hpp" 28 #include "gc/shenandoah/shenandoahYoungGeneration.hpp" 29 #include "gc/shenandoah/shenandoahOldGeneration.hpp" 30 31 ShenandoahMemoryPool::ShenandoahMemoryPool(ShenandoahHeap* heap, 32 const char* name) : 33 CollectedMemoryPool(name, 34 heap->initial_capacity(), 35 heap->max_capacity(), 36 true /* support_usage_threshold */), 37 _heap(heap) {} 38 39 ShenandoahMemoryPool::ShenandoahMemoryPool(ShenandoahHeap* heap, 40 const char* name, 41 size_t initial_capacity, 42 size_t max_capacity) : 43 CollectedMemoryPool(name, 44 initial_capacity, 45 max_capacity, 46 true /* support_usage_threshold */), 47 _heap(heap) {} 48 49 50 MemoryUsage ShenandoahMemoryPool::get_memory_usage() { 51 size_t initial = initial_size(); 52 size_t max = max_size(); 53 size_t used = used_in_bytes(); 54 size_t committed = _heap->committed(); 55 56 // These asserts can never fail: max is stable, and all updates to other values never overflow max. 57 assert(initial <= max, "initial: " SIZE_FORMAT ", max: " SIZE_FORMAT, initial, max); 58 assert(used <= max, "used: " SIZE_FORMAT ", max: " SIZE_FORMAT, used, max); 59 assert(committed <= max, "committed: " SIZE_FORMAT ", max: " SIZE_FORMAT, committed, max); 60 61 // Committed and used are updated concurrently and independently. They can momentarily break 62 // the assert below, which would also fail in downstream code. To avoid that, adjust values 63 // to make sense under the race. See JDK-8207200. 64 committed = MAX2(used, committed); 65 assert(used <= committed, "used: " SIZE_FORMAT ", committed: " SIZE_FORMAT, used, committed); 66 67 return MemoryUsage(initial, used, committed, max); 68 } 69 70 size_t ShenandoahMemoryPool::used_in_bytes() { 71 return _heap->used(); 72 } 73 74 size_t ShenandoahMemoryPool::max_size() const { 75 return _heap->max_capacity(); 76 } 77 78 ShenandoahGenerationalMemoryPool::ShenandoahGenerationalMemoryPool(ShenandoahHeap* heap, const char* name, 79 ShenandoahGeneration* generation) : 80 ShenandoahMemoryPool(heap, name, 0, heap->max_capacity()), 81 _generation(generation) { } 82 83 MemoryUsage ShenandoahGenerationalMemoryPool::get_memory_usage() { 84 size_t initial = initial_size(); 85 size_t max = max_size(); 86 size_t used = used_in_bytes(); 87 size_t committed = _generation->used_regions_size(); 88 89 return MemoryUsage(initial, used, committed, max); 90 } 91 92 size_t ShenandoahGenerationalMemoryPool::used_in_bytes() { 93 return _generation->used(); 94 } 95 96 size_t ShenandoahGenerationalMemoryPool::max_size() const { 97 return _generation->max_capacity(); 98 } 99 100 101 ShenandoahYoungGenMemoryPool::ShenandoahYoungGenMemoryPool(ShenandoahHeap* heap) : 102 ShenandoahGenerationalMemoryPool(heap, 103 "Shenandoah Young Gen", 104 heap->young_generation()) { } 105 106 ShenandoahOldGenMemoryPool::ShenandoahOldGenMemoryPool(ShenandoahHeap* heap) : 107 ShenandoahGenerationalMemoryPool(heap, 108 "Shenandoah Old Gen", 109 heap->old_generation()) { }