Path: blob/master/src/hotspot/share/memory/metaspace.hpp
41144 views
/*1* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2017, 2021 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*/24#ifndef SHARE_MEMORY_METASPACE_HPP25#define SHARE_MEMORY_METASPACE_HPP2627#include "memory/allocation.hpp"28#include "runtime/globals.hpp"29#include "utilities/exceptions.hpp"30#include "utilities/globalDefinitions.hpp"3132class ClassLoaderData;33class MetaspaceShared;34class MetaspaceTracer;35class Mutex;36class outputStream;37class ReservedSpace;3839////////////////// Metaspace ///////////////////////4041// Namespace for important central static functions42// (auxiliary stuff goes into MetaspaceUtils)43class Metaspace : public AllStatic {4445friend class MetaspaceShared;4647public:48enum MetadataType {49ClassType,50NonClassType,51MetadataTypeCount52};53enum MetaspaceType {54ZeroMetaspaceType = 0,55StandardMetaspaceType = ZeroMetaspaceType,56BootMetaspaceType = StandardMetaspaceType + 1,57ClassMirrorHolderMetaspaceType = BootMetaspaceType + 1,58ReflectionMetaspaceType = ClassMirrorHolderMetaspaceType + 1,59MetaspaceTypeCount60};6162private:6364static const MetaspaceTracer* _tracer;6566static bool _initialized;6768public:6970static const MetaspaceTracer* tracer() { return _tracer; }7172private:7374#ifdef _LP647576// Reserve a range of memory at an address suitable for en/decoding narrow77// Klass pointers (see: CompressedClassPointers::is_valid_base()).78// The returned address shall both be suitable as a compressed class pointers79// base, and aligned to Metaspace::reserve_alignment (which is equal to or a80// multiple of allocation granularity).81// On error, returns an unreserved space.82static ReservedSpace reserve_address_space_for_compressed_classes(size_t size);8384// Given a prereserved space, use that to set up the compressed class space list.85static void initialize_class_space(ReservedSpace rs);8687// Returns true if class space has been setup (initialize_class_space).88static bool class_space_is_initialized();8990#endif9192public:9394static void ergo_initialize();95static void global_initialize();96static void post_initialize();9798// Alignment, in bytes, of metaspace mappings99static size_t reserve_alignment() { return reserve_alignment_words() * BytesPerWord; }100// Alignment, in words, of metaspace mappings101static size_t reserve_alignment_words();102103// The granularity at which Metaspace is committed and uncommitted.104// (Todo: Why does this have to be exposed?)105static size_t commit_alignment() { return commit_alignment_words() * BytesPerWord; }106static size_t commit_alignment_words();107108// The largest possible single allocation109static size_t max_allocation_word_size();110111static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,112MetaspaceObj::Type type, TRAPS);113114// Non-TRAPS version of allocate which can be called by a non-Java thread, that returns115// NULL on failure.116static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,117MetaspaceObj::Type type);118119static bool contains(const void* ptr);120static bool contains_non_shared(const void* ptr);121122// Free empty virtualspaces123static void purge();124125static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,126MetaspaceObj::Type type, MetadataType mdtype, TRAPS);127128static const char* metadata_type_name(Metaspace::MetadataType mdtype);129130static void print_compressed_class_space(outputStream* st) NOT_LP64({});131132// Return TRUE only if UseCompressedClassPointers is True.133static bool using_class_space() {134return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);135}136137static bool is_class_space_allocation(MetadataType mdType) {138return mdType == ClassType && using_class_space();139}140141static bool initialized();142143};144145146#endif // SHARE_MEMORY_METASPACE_HPP147148149