Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceContext.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_METASPACECONTEXT_HPP26#define SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP2728#include "memory/allocation.hpp"29#include "memory/virtualspace.hpp"30#include "utilities/debug.hpp"3132class outputStream;3334namespace metaspace {3536class ChunkManager;37class VirtualSpaceList;38class CommitLimiter;3940// MetaspaceContext is a convenience bracket around:41//42// - a VirtualSpaceList managing a memory area used for Metaspace43// - a ChunkManager sitting atop of that which manages chunk freelists44//45// In a normal VM only one or two of these contexts ever exist: one for the metaspace, and46// optionally another one for the compressed class space.47//48// For tests more contexts may be created, and this would also be a way to use Metaspace49// for things other than class metadata. We would have to work on the naming then.50//51// - (Future TODO): Context should own a lock to guard it. Currently this stuff is guarded52// by one global lock, the slightly misnamed Metaspace_expandlock, but that one53// should be split into one per context.54// - (Future TODO): Context can/should have its own allocation alignment. That way we55// can have different alignment between class space and non-class metaspace. That could56// help optimize compressed class pointer encoding, see discussion for JDK-8244943).5758class MetaspaceContext : public CHeapObj<mtMetaspace> {5960const char* const _name;61VirtualSpaceList* const _vslist;62ChunkManager* const _cm;6364MetaspaceContext(const char* name, VirtualSpaceList* vslist, ChunkManager* cm) :65_name(name),66_vslist(vslist),67_cm(cm)68{}6970static MetaspaceContext* _nonclass_space_context;71static MetaspaceContext* _class_space_context;7273public:7475// Destroys the context: deletes chunkmanager and virtualspacelist.76// If this is a non-expandable context over an existing space, that space remains77// untouched, otherwise all memory is unmapped.78~MetaspaceContext();7980VirtualSpaceList* vslist() { return _vslist; }81ChunkManager* cm() { return _cm; }8283// Create a new, empty, expandable metaspace context.84static MetaspaceContext* create_expandable_context(const char* name, CommitLimiter* commit_limiter);8586// Create a new, empty, non-expandable metaspace context atop of an externally provided space.87static MetaspaceContext* create_nonexpandable_context(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter);8889void print_on(outputStream* st) const;9091DEBUG_ONLY(void verify() const;)9293static void initialize_class_space_context(ReservedSpace rs);94static void initialize_nonclass_space_context();9596// Returns pointer to the global metaspace context.97// If compressed class space is active, this contains the non-class-space allocations.98// If compressed class space is inactive, this contains all metaspace allocations.99static MetaspaceContext* context_nonclass() { return _nonclass_space_context; }100101// Returns pointer to the global class space context, if compressed class space is active,102// NULL otherwise.103static MetaspaceContext* context_class() { return _class_space_context; }104105};106107} // end namespace108109#endif // SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP110111112113