| File: | jdk/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp |
| Warning: | line 83, column 21 Value stored to 'vsn2' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | * Copyright (c) 2018, 2021 SAP SE. 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 "logging/log.hpp" |
| 28 | #include "memory/metaspace.hpp" |
| 29 | #include "memory/metaspace/chunkManager.hpp" |
| 30 | #include "memory/metaspace/commitLimiter.hpp" |
| 31 | #include "memory/metaspace/counters.hpp" |
| 32 | #include "memory/metaspace/freeChunkList.hpp" |
| 33 | #include "memory/metaspace/metaspaceContext.hpp" |
| 34 | #include "memory/metaspace/metaspaceCommon.hpp" |
| 35 | #include "memory/metaspace/virtualSpaceList.hpp" |
| 36 | #include "memory/metaspace/virtualSpaceNode.hpp" |
| 37 | #include "runtime/atomic.hpp" |
| 38 | #include "runtime/mutexLocker.hpp" |
| 39 | |
| 40 | namespace metaspace { |
| 41 | |
| 42 | #define LOGFMT"VsList @" "0x%016" "l" "x" " (%s)" "VsList @" PTR_FORMAT"0x%016" "l" "x" " (%s)" |
| 43 | #define LOGFMT_ARGSp2i(this), this->_name p2i(this), this->_name |
| 44 | |
| 45 | // Create a new, empty, expandable list. |
| 46 | VirtualSpaceList::VirtualSpaceList(const char* name, CommitLimiter* commit_limiter) : |
| 47 | _name(name), |
| 48 | _first_node(NULL__null), |
| 49 | _can_expand(true), |
| 50 | _commit_limiter(commit_limiter), |
| 51 | _reserved_words_counter(), |
| 52 | _committed_words_counter() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | // Create a new list. The list will contain one node only, which uses the given ReservedSpace. |
| 57 | // It will be not expandable beyond that first node. |
| 58 | VirtualSpaceList::VirtualSpaceList(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter) : |
| 59 | _name(name), |
| 60 | _first_node(NULL__null), |
| 61 | _can_expand(false), |
| 62 | _commit_limiter(commit_limiter), |
| 63 | _reserved_words_counter(), |
| 64 | _committed_words_counter() |
| 65 | { |
| 66 | // Create the first node spanning the existing ReservedSpace. This will be the only node created |
| 67 | // for this list since we cannot expand. |
| 68 | VirtualSpaceNode* vsn = VirtualSpaceNode::create_node(rs, _commit_limiter, |
| 69 | &_reserved_words_counter, &_committed_words_counter); |
| 70 | assert(vsn != NULL, "node creation failed")do { if (!(vsn != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp" , 70, "assert(" "vsn != __null" ") failed", "node creation failed" ); ::breakpoint(); } } while (0); |
| 71 | _first_node = vsn; |
| 72 | _first_node->set_next(NULL__null); |
| 73 | _nodes_counter.increment(); |
| 74 | } |
| 75 | |
| 76 | VirtualSpaceList::~VirtualSpaceList() { |
| 77 | assert_lock_strong(Metaspace_lock); |
| 78 | // Delete every single mapping in this list. |
| 79 | // Please note that this only gets executed during gtests under controlled |
| 80 | // circumstances, so we do not have any concurrency issues here. The "real" |
| 81 | // lists in metaspace are immortal. |
| 82 | VirtualSpaceNode* vsn = _first_node; |
| 83 | VirtualSpaceNode* vsn2 = vsn; |
Value stored to 'vsn2' during its initialization is never read | |
| 84 | while (vsn != NULL__null) { |
| 85 | vsn2 = vsn->next(); |
| 86 | delete vsn; |
| 87 | vsn = vsn2; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Create a new node and append it to the list. After |
| 92 | // this function, _current_node shall point to a new empty node. |
| 93 | // List must be expandable for this to work. |
| 94 | void VirtualSpaceList::create_new_node() { |
| 95 | assert(_can_expand, "List is not expandable")do { if (!(_can_expand)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp" , 95, "assert(" "_can_expand" ") failed", "List is not expandable" ); ::breakpoint(); } } while (0); |
| 96 | assert_lock_strong(Metaspace_lock); |
| 97 | |
| 98 | VirtualSpaceNode* vsn = VirtualSpaceNode::create_node(Settings::virtual_space_node_default_word_size(), |
| 99 | _commit_limiter, |
| 100 | &_reserved_words_counter, &_committed_words_counter); |
| 101 | vsn->set_next(_first_node); |
| 102 | Atomic::release_store(&_first_node, vsn); |
| 103 | _nodes_counter.increment(); |
| 104 | } |
| 105 | |
| 106 | // Allocate a root chunk from this list. |
| 107 | // Note: this just returns a chunk whose memory is reserved; no memory is committed yet. |
| 108 | // Hence, before using this chunk, it must be committed. |
| 109 | // Also, no limits are checked, since no committing takes place. |
| 110 | Metachunk* VirtualSpaceList::allocate_root_chunk() { |
| 111 | assert_lock_strong(Metaspace_lock); |
| 112 | |
| 113 | if (_first_node == NULL__null || |
| 114 | _first_node->free_words() < chunklevel::MAX_CHUNK_WORD_SIZE) { |
| 115 | |
| 116 | #ifdef ASSERT1 |
| 117 | // Since all allocations from a VirtualSpaceNode happen in |
| 118 | // root-chunk-size units, and the node size must be root-chunk-size aligned, |
| 119 | // we should never have left-over space. |
| 120 | if (_first_node != NULL__null) { |
| 121 | assert(_first_node->free_words() == 0, "Sanity")do { if (!(_first_node->free_words() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp" , 121, "assert(" "_first_node->free_words() == 0" ") failed" , "Sanity"); ::breakpoint(); } } while (0); |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | if (_can_expand) { |
| 126 | create_new_node(); |
| 127 | UL2(debug, "added new node (now: %d).", num_nodes())(!(LogImpl<(LogTag::_metaspace), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_metaspace), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("VsList @" "0x%016" "l" "x" " (%s)" ": " "added new node (now: %d).", p2i(this), this-> _name, num_nodes());; |
| 128 | } else { |
| 129 | UL(debug, "list cannot expand.")(!(LogImpl<(LogTag::_metaspace), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_metaspace), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("VsList @" "0x%016" "l" "x" " (%s)" ": " "list cannot expand.", p2i(this), this->_name );; |
| 130 | return NULL__null; // We cannot expand this list. |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | Metachunk* c = _first_node->allocate_root_chunk(); |
| 135 | assert(c != NULL, "This should have worked")do { if (!(c != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp" , 135, "assert(" "c != __null" ") failed", "This should have worked" ); ::breakpoint(); } } while (0); |
| 136 | |
| 137 | return c; |
| 138 | } |
| 139 | |
| 140 | // Print all nodes in this space list. |
| 141 | void VirtualSpaceList::print_on(outputStream* st) const { |
| 142 | MutexLocker fcl(Metaspace_lock, Mutex::_no_safepoint_check_flag); |
| 143 | |
| 144 | st->print_cr("vsl %s:", _name); |
| 145 | const VirtualSpaceNode* vsn = _first_node; |
| 146 | int n = 0; |
| 147 | while (vsn != NULL__null) { |
| 148 | st->print("- node #%d: ", n); |
| 149 | vsn->print_on(st); |
| 150 | vsn = vsn->next(); |
| 151 | n++; |
| 152 | } |
| 153 | st->print_cr("- total %d nodes, " SIZE_FORMAT"%" "l" "u" " reserved words, " SIZE_FORMAT"%" "l" "u" " committed words.", |
| 154 | n, reserved_words(), committed_words()); |
| 155 | } |
| 156 | |
| 157 | #ifdef ASSERT1 |
| 158 | void VirtualSpaceList::verify_locked() const { |
| 159 | assert_lock_strong(Metaspace_lock); |
| 160 | assert(_name != NULL, "Sanity")do { if (!(_name != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp" , 160, "assert(" "_name != __null" ") failed", "Sanity"); ::breakpoint (); } } while (0); |
| 161 | |
| 162 | int n = 0; |
| 163 | |
| 164 | if (_first_node != NULL__null) { |
| 165 | size_t total_reserved_words = 0; |
| 166 | size_t total_committed_words = 0; |
| 167 | const VirtualSpaceNode* vsn = _first_node; |
| 168 | while (vsn != NULL__null) { |
| 169 | n++; |
| 170 | vsn->verify_locked(); |
| 171 | total_reserved_words += vsn->word_size(); |
| 172 | total_committed_words += vsn->committed_words(); |
| 173 | vsn = vsn->next(); |
| 174 | } |
| 175 | _nodes_counter.check(n); |
| 176 | _reserved_words_counter.check(total_reserved_words); |
| 177 | _committed_words_counter.check(total_committed_words); |
| 178 | } else { |
| 179 | _reserved_words_counter.check(0); |
| 180 | _committed_words_counter.check(0); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void VirtualSpaceList::verify() const { |
| 185 | MutexLocker fcl(Metaspace_lock, Mutex::_no_safepoint_check_flag); |
| 186 | verify_locked(); |
| 187 | } |
| 188 | #endif |
| 189 | |
| 190 | // Returns true if this pointer is contained in one of our nodes. |
| 191 | bool VirtualSpaceList::contains(const MetaWord* p) const { |
| 192 | // Note: needs to work without locks. |
| 193 | const VirtualSpaceNode* vsn = Atomic::load_acquire(&_first_node); |
| 194 | while (vsn != NULL__null) { |
| 195 | if (vsn->contains(p)) { |
| 196 | return true; |
| 197 | } |
| 198 | vsn = vsn->next(); |
| 199 | } |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | // Convenience methods to return the global class-space chunkmanager |
| 204 | // and non-class chunkmanager, respectively. |
| 205 | VirtualSpaceList* VirtualSpaceList::vslist_class() { |
| 206 | return MetaspaceContext::context_class() == NULL__null ? NULL__null : MetaspaceContext::context_class()->vslist(); |
| 207 | } |
| 208 | |
| 209 | VirtualSpaceList* VirtualSpaceList::vslist_nonclass() { |
| 210 | return MetaspaceContext::context_nonclass() == NULL__null ? NULL__null : MetaspaceContext::context_nonclass()->vslist(); |
| 211 | } |
| 212 | |
| 213 | } // namespace metaspace |