Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceContext.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/chunkManager.hpp"27#include "memory/metaspace/commitLimiter.hpp"28#include "memory/metaspace/metaspaceContext.hpp"29#include "memory/metaspace/virtualSpaceList.hpp"30#include "utilities/debug.hpp"31#include "utilities/globalDefinitions.hpp"32#include "utilities/ostream.hpp"3334namespace metaspace {3536MetaspaceContext* MetaspaceContext::_class_space_context = NULL;37MetaspaceContext* MetaspaceContext::_nonclass_space_context = NULL;3839// Destroys the context: deletes chunkmanager and virtualspacelist.40// If this is a non-expandable context over an existing space, that space remains41// untouched, otherwise all memory is unmapped.42// Note: the standard metaspace contexts (non-class context and class context) are43// never deleted. This code only exists for the sake of tests and for future reuse44// of metaspace contexts in different scenarios.45MetaspaceContext::~MetaspaceContext() {46delete _cm;47delete _vslist;48}4950// Create a new, empty, expandable metaspace context.51MetaspaceContext* MetaspaceContext::create_expandable_context(const char* name, CommitLimiter* commit_limiter) {52VirtualSpaceList* vsl = new VirtualSpaceList(name, commit_limiter);53ChunkManager* cm = new ChunkManager(name, vsl);54return new MetaspaceContext(name, vsl, cm);55}5657// Create a new, empty, non-expandable metaspace context atop of an externally provided space.58MetaspaceContext* MetaspaceContext::create_nonexpandable_context(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter) {59VirtualSpaceList* vsl = new VirtualSpaceList(name, rs, commit_limiter);60ChunkManager* cm = new ChunkManager(name, vsl);61return new MetaspaceContext(name, vsl, cm);62}6364void MetaspaceContext::initialize_class_space_context(ReservedSpace rs) {65_class_space_context = create_nonexpandable_context("class-space", rs, CommitLimiter::globalLimiter());66}6768void MetaspaceContext::initialize_nonclass_space_context() {69_nonclass_space_context = create_expandable_context("non-class-space", CommitLimiter::globalLimiter());70}7172void MetaspaceContext::print_on(outputStream* st) const {73_vslist->print_on(st);74_cm->print_on(st);75}7677#ifdef ASSERT78void MetaspaceContext::verify() const {79_vslist->verify();80_cm->verify();81}82#endif // ASSERT8384} // namespace metaspace85868788