Path: blob/master/src/hotspot/share/memory/metaspaceUtils.hpp
40949 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 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_METASPACEUTILS_HPP25#define SHARE_MEMORY_METASPACEUTILS_HPP2627#include "memory/metaspace.hpp"28#include "memory/metaspaceChunkFreeListSummary.hpp"29#include "memory/metaspaceStats.hpp"3031class outputStream;3233// Metaspace are deallocated when their class loader are GC'ed.34// This class implements a policy for inducing GC's to recover35// Metaspaces.3637class MetaspaceGCThresholdUpdater : public AllStatic {38public:39enum Type {40ComputeNewSize,41ExpandAndAllocate,42Last43};4445static const char* to_string(MetaspaceGCThresholdUpdater::Type updater) {46switch (updater) {47case ComputeNewSize:48return "compute_new_size";49case ExpandAndAllocate:50return "expand_and_allocate";51default:52assert(false, "Got bad updater: %d", (int) updater);53return NULL;54};55}56};5758class MetaspaceGC : public AllStatic {5960// The current high-water-mark for inducing a GC.61// When committed memory of all metaspaces reaches this value,62// a GC is induced and the value is increased. Size is in bytes.63static volatile size_t _capacity_until_GC;64static uint _shrink_factor;6566static size_t shrink_factor() { return _shrink_factor; }67void set_shrink_factor(uint v) { _shrink_factor = v; }6869public:7071static void initialize();72static void post_initialize();7374static size_t capacity_until_GC();75static bool inc_capacity_until_GC(size_t v,76size_t* new_cap_until_GC = NULL,77size_t* old_cap_until_GC = NULL,78bool* can_retry = NULL);79static size_t dec_capacity_until_GC(size_t v);8081// The amount to increase the high-water-mark (_capacity_until_GC)82static size_t delta_capacity_until_GC(size_t bytes);8384// Tells if we have can expand metaspace without hitting set limits.85static bool can_expand(size_t words, bool is_class);8687// Returns amount that we can expand without hitting a GC,88// measured in words.89static size_t allowed_expansion();9091// Calculate the new high-water mark at which to induce92// a GC.93static void compute_new_size();94};9596class MetaspaceUtils : AllStatic {97public:9899// Committed space actually in use by Metadata100static size_t used_words();101static size_t used_words(Metaspace::MetadataType mdtype);102103// Space committed for Metaspace104static size_t committed_words();105static size_t committed_words(Metaspace::MetadataType mdtype);106107// Space reserved for Metaspace108static size_t reserved_words();109static size_t reserved_words(Metaspace::MetadataType mdtype);110111// _bytes() variants for convenience...112static size_t used_bytes() { return used_words() * BytesPerWord; }113static size_t used_bytes(Metaspace::MetadataType mdtype) { return used_words(mdtype) * BytesPerWord; }114static size_t committed_bytes() { return committed_words() * BytesPerWord; }115static size_t committed_bytes(Metaspace::MetadataType mdtype) { return committed_words(mdtype) * BytesPerWord; }116static size_t reserved_bytes() { return reserved_words() * BytesPerWord; }117static size_t reserved_bytes(Metaspace::MetadataType mdtype) { return reserved_words(mdtype) * BytesPerWord; }118119// Retrieve all statistics in one go; make sure the values are consistent.120static MetaspaceStats get_statistics(Metaspace::MetadataType mdtype);121static MetaspaceCombinedStats get_combined_statistics();122123// (See JDK-8251342). Implement or Consolidate.124static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype) {125return MetaspaceChunkFreeListSummary(0,0,0,0,0,0,0,0);126}127128// Log change in used metadata.129static void print_metaspace_change(const MetaspaceCombinedStats& pre_meta_values);130131// This will print out a basic metaspace usage report but132// unlike print_report() is guaranteed not to lock or to walk the CLDG.133static void print_basic_report(outputStream* st, size_t scale = 0);134135// Prints a report about the current metaspace state.136// Function will walk the CLDG and will lock the expand lock; if that is not137// convenient, use print_basic_report() instead.138static void print_report(outputStream* out, size_t scale = 0);139140static void print_on(outputStream * out);141142DEBUG_ONLY(static void verify();)143144};145146#endif // SHARE_MEMORY_METASPACEUTILS_HPP147148149