Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceSettings.cpp
40957 views
/*1* Copyright (c) 2020, 2021, 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#include "precompiled.hpp"26#include "logging/log.hpp"27#include "logging/logStream.hpp"28#include "memory/metaspace/metaspaceSettings.hpp"29#include "runtime/globals.hpp"30#include "runtime/java.hpp"31#include "runtime/os.hpp"32#include "utilities/debug.hpp"33#include "utilities/globalDefinitions.hpp"34#include "utilities/powerOfTwo.hpp"3536namespace metaspace {3738size_t Settings::_commit_granule_bytes = 0;39size_t Settings::_commit_granule_words = 0;4041bool Settings::_new_chunks_are_fully_committed = false;42bool Settings::_uncommit_free_chunks = false;4344DEBUG_ONLY(bool Settings::_use_allocation_guard = false;)45DEBUG_ONLY(bool Settings::_handle_deallocations = true;)4647void Settings::ergo_initialize() {48if (strcmp(MetaspaceReclaimPolicy, "none") == 0) {49log_info(metaspace)("Initialized with strategy: no reclaim.");50_commit_granule_bytes = MAX2((size_t)os::vm_page_size(), 64 * K);51_commit_granule_words = _commit_granule_bytes / BytesPerWord;52// In "none" reclamation mode, we do not uncommit, and we commit new chunks fully;53// that very closely mimicks the behaviour of old Metaspace.54_new_chunks_are_fully_committed = true;55_uncommit_free_chunks = false;56} else if (strcmp(MetaspaceReclaimPolicy, "aggressive") == 0) {57log_info(metaspace)("Initialized with strategy: aggressive reclaim.");58// Set the granule size rather small; may increase59// mapping fragmentation but also increase chance to uncommit.60_commit_granule_bytes = MAX2((size_t)os::vm_page_size(), 16 * K);61_commit_granule_words = _commit_granule_bytes / BytesPerWord;62_new_chunks_are_fully_committed = false;63_uncommit_free_chunks = true;64} else if (strcmp(MetaspaceReclaimPolicy, "balanced") == 0) {65log_info(metaspace)("Initialized with strategy: balanced reclaim.");66_commit_granule_bytes = MAX2((size_t)os::vm_page_size(), 64 * K);67_commit_granule_words = _commit_granule_bytes / BytesPerWord;68_new_chunks_are_fully_committed = false;69_uncommit_free_chunks = true;70} else {71vm_exit_during_initialization("Invalid value for MetaspaceReclaimPolicy: \"%s\".", MetaspaceReclaimPolicy);72}7374// Sanity checks.75assert(commit_granule_words() <= chunklevel::MAX_CHUNK_WORD_SIZE, "Too large granule size");76assert(is_power_of_2(commit_granule_words()), "granule size must be a power of 2");7778#ifdef ASSERT79// Off for release builds, and by default for debug builds, but can be switched on manually to aid80// error analysis.81_use_allocation_guard = MetaspaceGuardAllocations;8283// Deallocations can be manually switched off to aid error analysis, since this removes one layer of complexity84// from allocation.85_handle_deallocations = MetaspaceHandleDeallocations;8687// We also switch it off automatically if we use allocation guards. This is to keep prefix handling in MetaspaceArena simple.88if (_use_allocation_guard) {89_handle_deallocations = false;90}91#endif92LogStream ls(Log(metaspace)::info());93Settings::print_on(&ls);94}9596void Settings::print_on(outputStream* st) {97st->print_cr(" - commit_granule_bytes: " SIZE_FORMAT ".", commit_granule_bytes());98st->print_cr(" - commit_granule_words: " SIZE_FORMAT ".", commit_granule_words());99st->print_cr(" - virtual_space_node_default_size: " SIZE_FORMAT ".", virtual_space_node_default_word_size());100st->print_cr(" - enlarge_chunks_in_place: %d.", (int)enlarge_chunks_in_place());101st->print_cr(" - new_chunks_are_fully_committed: %d.", (int)new_chunks_are_fully_committed());102st->print_cr(" - uncommit_free_chunks: %d.", (int)uncommit_free_chunks());103st->print_cr(" - use_allocation_guard: %d.", (int)use_allocation_guard());104st->print_cr(" - handle_deallocations: %d.", (int)handle_deallocations());105}106107} // namespace metaspace108109110111