Mon, 12 Aug 2013 17:37:02 +0200
8015107: NPG: Use consistent naming for metaspace concepts
Reviewed-by: coleenp, mgerdin, hseigel
coleenp@4037 | 1 | /* |
katleman@4376 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
coleenp@4037 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
coleenp@4037 | 4 | * |
coleenp@4037 | 5 | * This code is free software; you can redistribute it and/or modify it |
coleenp@4037 | 6 | * under the terms of the GNU General Public License version 2 only, as |
coleenp@4037 | 7 | * published by the Free Software Foundation. |
coleenp@4037 | 8 | * |
coleenp@4037 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
coleenp@4037 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
coleenp@4037 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
coleenp@4037 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
coleenp@4037 | 13 | * accompanied this code). |
coleenp@4037 | 14 | * |
coleenp@4037 | 15 | * You should have received a copy of the GNU General Public License version |
coleenp@4037 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
coleenp@4037 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
coleenp@4037 | 18 | * |
coleenp@4037 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
coleenp@4037 | 20 | * or visit www.oracle.com if you need additional information or have any |
coleenp@4037 | 21 | * questions. |
coleenp@4037 | 22 | * |
coleenp@4037 | 23 | */ |
coleenp@4037 | 24 | |
coleenp@4037 | 25 | #include "precompiled.hpp" |
coleenp@4037 | 26 | #include "memory/metaspaceCounters.hpp" |
coleenp@4037 | 27 | #include "memory/resourceArea.hpp" |
ehelin@5531 | 28 | #include "runtime/globals.hpp" |
ehelin@5531 | 29 | #include "runtime/perfData.hpp" |
ehelin@4680 | 30 | #include "utilities/exceptions.hpp" |
coleenp@4037 | 31 | |
ehelin@5531 | 32 | class MetaspacePerfCounters: public CHeapObj<mtInternal> { |
ehelin@5531 | 33 | friend class VMStructs; |
ehelin@5531 | 34 | PerfVariable* _capacity; |
ehelin@5531 | 35 | PerfVariable* _used; |
ehelin@5531 | 36 | PerfVariable* _max_capacity; |
coleenp@4037 | 37 | |
ehelin@5531 | 38 | PerfVariable* create_variable(const char *ns, const char *name, size_t value, TRAPS) { |
ehelin@5531 | 39 | const char *path = PerfDataManager::counter_name(ns, name); |
ehelin@5531 | 40 | return PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, THREAD); |
ehelin@5531 | 41 | } |
ehelin@5531 | 42 | |
ehelin@5531 | 43 | void create_constant(const char *ns, const char *name, size_t value, TRAPS) { |
ehelin@5531 | 44 | const char *path = PerfDataManager::counter_name(ns, name); |
ehelin@5531 | 45 | PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, THREAD); |
ehelin@5531 | 46 | } |
ehelin@5531 | 47 | |
ehelin@5531 | 48 | public: |
ehelin@5531 | 49 | MetaspacePerfCounters(const char* ns, size_t min_capacity, size_t curr_capacity, size_t max_capacity, size_t used) { |
ehelin@5531 | 50 | EXCEPTION_MARK; |
ehelin@5531 | 51 | ResourceMark rm; |
ehelin@5531 | 52 | |
ehelin@5531 | 53 | create_constant(ns, "minCapacity", min_capacity, THREAD); |
ehelin@5531 | 54 | _capacity = create_variable(ns, "capacity", curr_capacity, THREAD); |
ehelin@5531 | 55 | _max_capacity = create_variable(ns, "maxCapacity", max_capacity, THREAD); |
ehelin@5531 | 56 | _used = create_variable(ns, "used", used, THREAD); |
ehelin@5531 | 57 | } |
ehelin@5531 | 58 | |
ehelin@5531 | 59 | void update(size_t capacity, size_t max_capacity, size_t used) { |
ehelin@5531 | 60 | _capacity->set_value(capacity); |
ehelin@5531 | 61 | _max_capacity->set_value(max_capacity); |
ehelin@5531 | 62 | _used->set_value(used); |
ehelin@5531 | 63 | } |
ehelin@5531 | 64 | }; |
ehelin@5531 | 65 | |
ehelin@5531 | 66 | MetaspacePerfCounters* MetaspaceCounters::_perf_counters = NULL; |
ehelin@5531 | 67 | |
ehelin@5531 | 68 | size_t MetaspaceCounters::calculate_capacity() { |
jmasa@5015 | 69 | // The total capacity is the sum of |
jmasa@5015 | 70 | // 1) capacity of Metachunks in use by all Metaspaces |
jmasa@5015 | 71 | // 2) unused space at the end of each Metachunk |
jmasa@5015 | 72 | // 3) space in the freelist |
jmasa@5015 | 73 | size_t total_capacity = MetaspaceAux::allocated_capacity_bytes() |
jmasa@5015 | 74 | + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_in_bytes(); |
jmasa@5015 | 75 | return total_capacity; |
jmasa@5015 | 76 | } |
jmasa@5015 | 77 | |
ehelin@5531 | 78 | void MetaspaceCounters::initialize_performance_counters() { |
coleenp@4037 | 79 | if (UsePerfData) { |
ehelin@5531 | 80 | assert(_perf_counters == NULL, "Should only be initialized once"); |
ehelin@5531 | 81 | |
coleenp@4037 | 82 | size_t min_capacity = MetaspaceAux::min_chunk_size(); |
ehelin@5531 | 83 | size_t capacity = calculate_capacity(); |
coleenp@4037 | 84 | size_t max_capacity = MetaspaceAux::reserved_in_bytes(); |
jmasa@5015 | 85 | size_t used = MetaspaceAux::allocated_used_bytes(); |
coleenp@4037 | 86 | |
ehelin@5531 | 87 | _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, capacity, max_capacity, used); |
coleenp@4037 | 88 | } |
coleenp@4037 | 89 | } |
coleenp@4037 | 90 | |
coleenp@4037 | 91 | void MetaspaceCounters::update_performance_counters() { |
coleenp@4037 | 92 | if (UsePerfData) { |
ehelin@5531 | 93 | assert(_perf_counters != NULL, "Should be initialized"); |
ehelin@5531 | 94 | |
ehelin@5531 | 95 | size_t capacity = calculate_capacity(); |
ehelin@5531 | 96 | size_t max_capacity = MetaspaceAux::reserved_in_bytes(); |
ehelin@5531 | 97 | size_t used = MetaspaceAux::allocated_used_bytes(); |
ehelin@5531 | 98 | |
ehelin@5531 | 99 | _perf_counters->update(capacity, max_capacity, used); |
coleenp@4037 | 100 | } |
coleenp@4037 | 101 | } |
coleenp@4037 | 102 | |
ehelin@5531 | 103 | MetaspacePerfCounters* CompressedClassSpaceCounters::_perf_counters = NULL; |
ehelin@5531 | 104 | |
ehelin@5531 | 105 | size_t CompressedClassSpaceCounters::calculate_capacity() { |
ehelin@5531 | 106 | return MetaspaceAux::allocated_capacity_bytes(_class_type) + |
ehelin@5531 | 107 | MetaspaceAux::free_bytes(_class_type) + |
ehelin@5531 | 108 | MetaspaceAux::free_chunks_total_in_bytes(_class_type); |
ehelin@5531 | 109 | } |
ehelin@5531 | 110 | |
ehelin@5531 | 111 | void CompressedClassSpaceCounters::update_performance_counters() { |
ehelin@5694 | 112 | if (UsePerfData && UseCompressedClassPointers) { |
ehelin@5531 | 113 | assert(_perf_counters != NULL, "Should be initialized"); |
ehelin@5531 | 114 | |
ehelin@5531 | 115 | size_t capacity = calculate_capacity(); |
ehelin@5531 | 116 | size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); |
ehelin@5531 | 117 | size_t used = MetaspaceAux::allocated_used_bytes(_class_type); |
ehelin@5531 | 118 | |
ehelin@5531 | 119 | _perf_counters->update(capacity, max_capacity, used); |
ehelin@5531 | 120 | } |
ehelin@5531 | 121 | } |
ehelin@5531 | 122 | |
ehelin@5531 | 123 | void CompressedClassSpaceCounters::initialize_performance_counters() { |
ehelin@5531 | 124 | if (UsePerfData) { |
ehelin@5531 | 125 | assert(_perf_counters == NULL, "Should only be initialized once"); |
ehelin@5531 | 126 | const char* ns = "compressedclassspace"; |
ehelin@5531 | 127 | |
ehelin@5694 | 128 | if (UseCompressedClassPointers) { |
ehelin@5531 | 129 | size_t min_capacity = MetaspaceAux::min_chunk_size(); |
ehelin@5531 | 130 | size_t capacity = calculate_capacity(); |
ehelin@5531 | 131 | size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); |
ehelin@5531 | 132 | size_t used = MetaspaceAux::allocated_used_bytes(_class_type); |
ehelin@5531 | 133 | |
ehelin@5531 | 134 | _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity, max_capacity, used); |
ehelin@5531 | 135 | } else { |
ehelin@5531 | 136 | _perf_counters = new MetaspacePerfCounters(ns, 0, 0, 0, 0); |
ehelin@5531 | 137 | } |
ehelin@5531 | 138 | } |
ehelin@5531 | 139 | } |