Path: blob/master/src/hotspot/share/memory/metaspace/commitLimiter.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_COMMITLIMITER_HPP26#define SHARE_MEMORY_METASPACE_COMMITLIMITER_HPP2728#include "memory/allocation.hpp"29#include "memory/metaspace/counters.hpp"3031namespace metaspace {3233// The CommitLimiter encapsulates a limit we may want to impose on how much34// memory can be committed. This is a matter of separation of concerns:35//36// In metaspace, we have two limits to committing memory: the absolute limit,37// MaxMetaspaceSize; and the GC threshold. In both cases an allocation should38// fail if it would require committing memory and hit one of these limits.39//40// However, the actual Metaspace allocator is a generic one and this41// GC- and classloading specific logic should be kept separate. Therefore42// it is hidden inside this interface.43//44// This allows us to:45// - more easily write tests for metaspace, by providing a different implementation46// of the commit limiter, thus keeping test logic separate from VM state.47// - (potentially) use the metaspace for things other than class metadata,48// where different commit rules would apply.49//50class CommitLimiter : public CHeapObj<mtMetaspace> {5152// Counts total words committed for metaspace53SizeCounter _cnt;5455// Purely for testing purposes: cap, in words.56const size_t _cap;5758public:5960// Create a commit limiter. This is only useful for testing, with a cap != 0,61// since normal code should use the global commit limiter.62// If cap != 0 (word size), the cap replaces the internal logic of limiting.63CommitLimiter(size_t cap = 0) : _cnt(), _cap(cap) {}6465// Returns the size, in words, by which we may expand the metaspace committed area without:66// - _cap == 0: hitting GC threshold or the MaxMetaspaceSize67// - _cap > 0: hitting cap (this is just for testing purposes)68size_t possible_expansion_words() const;6970void increase_committed(size_t word_size) { _cnt.increment_by(word_size); }71void decrease_committed(size_t word_size) { _cnt.decrement_by(word_size); }7273size_t committed_words() const { return _cnt.get(); }74size_t cap() const { return _cap; }7576// Returns the global metaspace commit counter77static CommitLimiter* globalLimiter();7879};8081} // namespace metaspace8283#endif // SHARE_MEMORY_METASPACE_COMMITLIMITER_HPP848586