Path: blob/master/src/hotspot/share/memory/metaspace/chunkHeaderPool.cpp
40957 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "memory/metaspace/chunkHeaderPool.hpp"27#include "runtime/os.hpp"28#include "utilities/debug.hpp"29#include "utilities/globalDefinitions.hpp"3031namespace metaspace {3233// Returns reference to the one global chunk header pool.34ChunkHeaderPool* ChunkHeaderPool::_chunkHeaderPool = NULL;3536ChunkHeaderPool::ChunkHeaderPool() :37_num_slabs(),38_first_slab(NULL),39_current_slab(NULL)40{}4142// Note: the global chunk header pool gets never deleted; so this destructor only43// exists for the sake of tests.44ChunkHeaderPool::~ChunkHeaderPool() {45Slab* s = _first_slab;46while (s != NULL) {47Slab* next_slab = s->_next;48os::free(s);49s = next_slab;50}51}5253void ChunkHeaderPool::allocate_new_slab() {54Slab* slab = new Slab();55if (_current_slab != NULL) {56_current_slab->_next = slab;57}58_current_slab = slab;59if (_first_slab == NULL) {60_first_slab = slab;61}62_num_slabs.increment();63}6465// Returns size of memory used.66size_t ChunkHeaderPool::memory_footprint_words() const {67return (_num_slabs.get() * sizeof(Slab)) / BytesPerWord;68}6970void ChunkHeaderPool::initialize() {71assert(_chunkHeaderPool == NULL, "only once");72_chunkHeaderPool = new ChunkHeaderPool();73}7475#ifdef ASSERT76void ChunkHeaderPool::verify() const {77const Slab* s = _first_slab;78int num = 0;79while (s != NULL) {80assert(s->_top >= 0 && s->_top <= SlabCapacity,81"invalid slab at " PTR_FORMAT ", top: %d, slab cap: %d",82p2i(s), s->_top, SlabCapacity );83s = s->_next;84num++;85}86_num_slabs.check(num);87}88#endif8990} // namespace metaspace91929394