Path: blob/master/src/hotspot/share/memory/metaspace/metachunkList.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/metachunkList.hpp"27#include "memory/metaspace/metaspaceCommon.hpp"28#include "utilities/debug.hpp"29#include "utilities/globalDefinitions.hpp"30#include "utilities/ostream.hpp"3132namespace metaspace {3334#ifdef ASSERT3536void MetachunkList::verify_does_not_contain(const Metachunk* c) const {37SOMETIMES(assert(contains(c) == false, "List contains this chunk.");)38}3940bool MetachunkList::contains(const Metachunk* c) const {41for (Metachunk* c2 = _first; c2 != NULL; c2 = c2->next()) {42if (c == c2) {43return true;44}45}46return false;47}4849void MetachunkList::verify() const {50int num = 0;51const Metachunk* last_c = NULL;52for (const Metachunk* c = _first; c != NULL; c = c->next()) {53num++;54assert(c->prev() != c && c->next() != c, "circularity");55assert(c->prev() == last_c,56"Broken link to predecessor. Chunk " METACHUNK_FULL_FORMAT ".",57METACHUNK_FULL_FORMAT_ARGS(c));58c->verify();59last_c = c;60}61_num_chunks.check(num);62}6364#endif // ASSERT6566size_t MetachunkList::calc_committed_word_size() const {67if (_first != NULL && _first->is_dead()) {68// list used for chunk header pool; dead chunks have no size.69return 0;70}71size_t s = 0;72for (Metachunk* c = _first; c != NULL; c = c->next()) {73assert(c->is_dead() == false, "Sanity");74s += c->committed_words();75}76return s;77}7879size_t MetachunkList::calc_word_size() const {80if (_first != NULL && _first->is_dead()) {81// list used for chunk header pool; dead chunks have no size.82return 0;83}84size_t s = 0;85for (Metachunk* c = _first; c != NULL; c = c->next()) {86assert(c->is_dead() == false, "Sanity");87s += c->committed_words();88}89return s;90}9192void MetachunkList::print_on(outputStream* st) const {93if (_num_chunks.get() > 0) {94for (const Metachunk* c = _first; c != NULL; c = c->next()) {95st->print(" - <");96c->print_on(st);97st->print(">");98}99st->print(" - total : %d chunks.", _num_chunks.get());100} else {101st->print("empty");102}103}104105} // namespace metaspace106107108109