Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceArenaGrowthPolicy.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_METASPACEARENAGROWTHPOLICY_HPP26#define SHARE_MEMORY_METASPACE_METASPACEARENAGROWTHPOLICY_HPP2728#include "memory/metaspace.hpp" // For Metaspace::MetaspaceType29#include "memory/metaspace/chunklevel.hpp"30#include "utilities/debug.hpp"3132namespace metaspace {3334// ArenaGrowthPolicy encodes the growth policy of a MetaspaceArena.35//36// These arenas grow in steps (by allocating new chunks). The coarseness of growth37// (chunk size, level) depends on what the arena is used for. Used for a class loader38// which is expected to load only one or very few classes should grow in tiny steps.39// For normal classloaders, it can grow in coarser steps, and arenas used by40// the boot loader will grow in even larger steps since we expect it to load a lot of41// classes.42// Note that when growing in large steps (in steps larger than a commit granule,43// by default 64K), costs diminish somewhat since we do not commit the whole space44// immediately.4546class ArenaGrowthPolicy {4748// const array specifying chunk level allocation progression (growth steps). Last49// chunk is to be an endlessly repeated allocation.50const chunklevel_t* const _entries;51const int _num_entries;5253public:5455ArenaGrowthPolicy(const chunklevel_t* array, int num_entries) :56_entries(array),57_num_entries(num_entries)58{59assert(_num_entries > 0, "must not be empty.");60}6162chunklevel_t get_level_at_step(int num_allocated) const {63if (num_allocated >= _num_entries) {64// Caller shall repeat last allocation65return _entries[_num_entries - 1];66}67return _entries[num_allocated];68}6970// Given a space type, return the correct policy to use.71// The returned object is static and read only.72static const ArenaGrowthPolicy* policy_for_space_type(Metaspace::MetaspaceType space_type, bool is_class);7374};7576} // namespace metaspace7778#endif // SHARE_MEMORY_METASPACE_METASPACEARENAGROWTHPOLICY_HPP798081