Path: blob/master/src/hotspot/share/memory/metaspace/chunklevel.cpp
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#include "precompiled.hpp"26#include "memory/metaspace/chunklevel.hpp"27#include "utilities/debug.hpp"28#include "utilities/globalDefinitions.hpp"29#include "utilities/ostream.hpp"30#include "utilities/powerOfTwo.hpp"3132namespace metaspace {3334using namespace chunklevel;3536chunklevel_t chunklevel::level_fitting_word_size(size_t word_size) {37assert(MAX_CHUNK_WORD_SIZE >= word_size,38SIZE_FORMAT " - too large allocation size.", word_size * BytesPerWord);39if (word_size <= MIN_CHUNK_WORD_SIZE) {40return HIGHEST_CHUNK_LEVEL;41}42const size_t v_pow2 = round_up_power_of_2(word_size);43const chunklevel_t lvl = (chunklevel_t)(exact_log2(MAX_CHUNK_WORD_SIZE) - exact_log2(v_pow2));44return lvl;45}4647void chunklevel::print_chunk_size(outputStream* st, chunklevel_t lvl) {48if (chunklevel::is_valid_level(lvl)) {49const size_t s = chunklevel::word_size_for_level(lvl) * BytesPerWord;50if (s < 1 * M) {51st->print("%3uk", (unsigned)(s / K));52} else {53st->print("%3um", (unsigned)(s / M));54}55} else {56st->print("?-?");57}58}5960} // namespace metaspace61626364