Path: blob/master/src/hotspot/share/memory/metaspace/chunklevel.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_CHUNKLEVEL_HPP26#define SHARE_MEMORY_METASPACE_CHUNKLEVEL_HPP2728#include "utilities/globalDefinitions.hpp"2930// Constants for the chunk levels and some utility functions.3132class outputStream;3334namespace metaspace {3536// Chunks are managed by a binary buddy allocator.3738// Chunk sizes range from 1K to 4MB (64bit).39//4041// Each chunk has a level; the level corresponds to its position in the tree42// and describes its size.43//44// The largest chunks are called root chunks, of 4MB in size, and have level 0.45// From there on it goes:46//47// size level48// 4MB 049// 2MB 150// 1MB 251// 512K 352// 256K 453// 128K 554// 64K 655// 32K 756// 16K 857// 8K 958// 4K 1059// 2K 1160// 1K 126162// Metachunk level (must be signed)63typedef signed char chunklevel_t;6465#define CHKLVL_FORMAT "lv%.2d"6667namespace chunklevel {6869static const size_t MAX_CHUNK_BYTE_SIZE = 4 * M;70static const int NUM_CHUNK_LEVELS = 13;71static const size_t MIN_CHUNK_BYTE_SIZE = (MAX_CHUNK_BYTE_SIZE >> ((size_t)NUM_CHUNK_LEVELS - 1));7273static const size_t MIN_CHUNK_WORD_SIZE = MIN_CHUNK_BYTE_SIZE / sizeof(MetaWord);74static const size_t MAX_CHUNK_WORD_SIZE = MAX_CHUNK_BYTE_SIZE / sizeof(MetaWord);7576static const chunklevel_t ROOT_CHUNK_LEVEL = 0;7778static const chunklevel_t HIGHEST_CHUNK_LEVEL = NUM_CHUNK_LEVELS - 1;79static const chunklevel_t LOWEST_CHUNK_LEVEL = 0;8081static const chunklevel_t INVALID_CHUNK_LEVEL = (chunklevel_t) -1;8283inline bool is_valid_level(chunklevel_t level) {84return level >= LOWEST_CHUNK_LEVEL &&85level <= HIGHEST_CHUNK_LEVEL;86}8788inline void check_valid_level(chunklevel_t lvl) {89assert(is_valid_level(lvl), "invalid level (%d)", (int)lvl);90}9192// Given a level return the chunk size, in words.93inline size_t word_size_for_level(chunklevel_t level) {94return (MAX_CHUNK_BYTE_SIZE >> level) / BytesPerWord;95}9697// Given an arbitrary word size smaller than the highest chunk size,98// return the highest chunk level able to hold this size.99// Returns INVALID_CHUNK_LEVEL if no fitting level can be found.100chunklevel_t level_fitting_word_size(size_t word_size);101102// Shorthands to refer to exact sizes103static const chunklevel_t CHUNK_LEVEL_4M = ROOT_CHUNK_LEVEL;104static const chunklevel_t CHUNK_LEVEL_2M = (ROOT_CHUNK_LEVEL + 1);105static const chunklevel_t CHUNK_LEVEL_1M = (ROOT_CHUNK_LEVEL + 2);106static const chunklevel_t CHUNK_LEVEL_512K = (ROOT_CHUNK_LEVEL + 3);107static const chunklevel_t CHUNK_LEVEL_256K = (ROOT_CHUNK_LEVEL + 4);108static const chunklevel_t CHUNK_LEVEL_128K = (ROOT_CHUNK_LEVEL + 5);109static const chunklevel_t CHUNK_LEVEL_64K = (ROOT_CHUNK_LEVEL + 6);110static const chunklevel_t CHUNK_LEVEL_32K = (ROOT_CHUNK_LEVEL + 7);111static const chunklevel_t CHUNK_LEVEL_16K = (ROOT_CHUNK_LEVEL + 8);112static const chunklevel_t CHUNK_LEVEL_8K = (ROOT_CHUNK_LEVEL + 9);113static const chunklevel_t CHUNK_LEVEL_4K = (ROOT_CHUNK_LEVEL + 10);114static const chunklevel_t CHUNK_LEVEL_2K = (ROOT_CHUNK_LEVEL + 11);115static const chunklevel_t CHUNK_LEVEL_1K = (ROOT_CHUNK_LEVEL + 12);116117STATIC_ASSERT(CHUNK_LEVEL_1K == HIGHEST_CHUNK_LEVEL);118STATIC_ASSERT(CHUNK_LEVEL_4M == LOWEST_CHUNK_LEVEL);119STATIC_ASSERT(ROOT_CHUNK_LEVEL == LOWEST_CHUNK_LEVEL);120121/////////////////////////////////////////////////////////122// print helpers123void print_chunk_size(outputStream* st, chunklevel_t lvl);124125} // namespace chunklevel126127} // namespace metaspace128129#endif // SHARE_MEMORY_METASPACE_CHUNKLEVEL_HPP130131132