Path: blob/master/src/hotspot/share/memory/metaspace/metachunkList.hpp
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#ifndef SHARE_MEMORY_METASPACE_METACHUNKLIST_HPP26#define SHARE_MEMORY_METASPACE_METACHUNKLIST_HPP2728#include "memory/metaspace/counters.hpp"29#include "memory/metaspace/metachunk.hpp"30#include "utilities/globalDefinitions.hpp"3132class outputStream;3334namespace metaspace {3536// A simple single-linked list of chunks, used in MetaspaceArena to keep37// a list of retired chunks, as well as in the ChunkHeaderPool to keep38// a cache of unused chunk headers.3940class MetachunkList {4142Metachunk* _first;43IntCounter _num_chunks;4445// Note: The chunks inside this list may be dead (->chunk header pool).46// So, do not call c->word size on them or anything else which may not47// work with dead chunks.4849// Check that list does not contain the given chunk; Note that since that check50// is expensive, it is subject to VerifyMetaspaceInterval.51DEBUG_ONLY(void verify_does_not_contain(const Metachunk* c) const;)5253public:5455MetachunkList() : _first(NULL), _num_chunks() {}5657int count() const { return _num_chunks.get(); }5859void add(Metachunk* c) {60DEBUG_ONLY(verify_does_not_contain(c);)61c->set_next(_first);62if (_first) {63_first->set_prev(c);64}65_first = c;66_num_chunks.increment();67}6869Metachunk* remove_first() {70if (_first) {71Metachunk* c = _first;72_first = _first->next();73if (_first) {74_first->set_prev(NULL);75}76_num_chunks.decrement();77c->set_prev(NULL);78c->set_next(NULL);79return c;80}81return NULL;82}8384Metachunk* first() { return _first; }85const Metachunk* first() const { return _first; }8687#ifdef ASSERT88// Note: linear search89bool contains(const Metachunk* c) const;90void verify() const;91#endif9293size_t calc_committed_word_size() const;94size_t calc_word_size() const;9596void print_on(outputStream* st) const;9798};99100} // namespace metaspace101102#endif // SHARE_MEMORY_METASPACE_METACHUNKLIST_HPP103104105