Path: blob/master/test/hotspot/gtest/metaspace/test_metaspace_misc.cpp
41144 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 "classfile/classLoaderData.hpp"27#include "memory/classLoaderMetaspace.hpp"28#include "memory/metaspace/chunklevel.hpp"29#include "memory/metaspace/metaspaceSettings.hpp"30#include "utilities/powerOfTwo.hpp"31// #define LOG_PLEASE32#include "metaspaceGtestCommon.hpp"3334using metaspace::chunklevel_t;35using namespace metaspace::chunklevel;36using metaspace::Settings;3738TEST_VM(metaspace, misc_sizes) {3940// Test test common sizes (seems primitive but breaks surprisingly often during development41// because of word vs byte confusion)42// Adjust this test if numbers change.43ASSERT_TRUE(Settings::commit_granule_bytes() == 16 * K ||44Settings::commit_granule_bytes() == 64 * K);45ASSERT_EQ(Settings::commit_granule_bytes(), Metaspace::commit_alignment());46ASSERT_TRUE(is_aligned(Settings::virtual_space_node_default_word_size(),47metaspace::chunklevel::MAX_CHUNK_WORD_SIZE));48ASSERT_EQ(Settings::virtual_space_node_default_word_size(),49metaspace::chunklevel::MAX_CHUNK_WORD_SIZE * 2);50ASSERT_EQ(Settings::virtual_space_node_reserve_alignment_words(),51Metaspace::reserve_alignment_words());5253}5455TEST_VM(metaspace, misc_max_alloc_size) {5657// Make sure we can allocate what we promise to allocate58const size_t sz = Metaspace::max_allocation_word_size();59ClassLoaderData* cld = ClassLoaderData::the_null_class_loader_data();60MetaWord* p = cld->metaspace_non_null()->allocate(sz, Metaspace::NonClassType);61ASSERT_NOT_NULL(p);62cld->metaspace_non_null()->deallocate(p, sz, false);6364}6566TEST_VM(metaspace, chunklevel_utils) {6768// These tests seem to be really basic, but it is amazing what one can69// break accidentally...70LOG(SIZE_FORMAT, MAX_CHUNK_BYTE_SIZE);71LOG(SIZE_FORMAT, MIN_CHUNK_BYTE_SIZE);72LOG(SIZE_FORMAT, MIN_CHUNK_WORD_SIZE);73LOG(SIZE_FORMAT, MAX_CHUNK_WORD_SIZE);74LOG(SIZE_FORMAT, MAX_CHUNK_BYTE_SIZE);75LOG("%u", (unsigned)ROOT_CHUNK_LEVEL);76LOG("%u", (unsigned)HIGHEST_CHUNK_LEVEL);77LOG("%u", (unsigned)LOWEST_CHUNK_LEVEL);7879static const chunklevel_t INVALID_CHUNK_LEVEL = (chunklevel_t) -1;8081EXPECT_TRUE(is_power_of_2(MAX_CHUNK_WORD_SIZE));82EXPECT_TRUE(is_power_of_2(MIN_CHUNK_WORD_SIZE));8384EXPECT_TRUE(is_valid_level(LOWEST_CHUNK_LEVEL));85EXPECT_TRUE(is_valid_level(HIGHEST_CHUNK_LEVEL));86EXPECT_FALSE(is_valid_level(HIGHEST_CHUNK_LEVEL + 1));87EXPECT_FALSE(is_valid_level(LOWEST_CHUNK_LEVEL - 1));8889EXPECT_EQ(word_size_for_level(ROOT_CHUNK_LEVEL), MAX_CHUNK_WORD_SIZE);90EXPECT_EQ(word_size_for_level(HIGHEST_CHUNK_LEVEL), MIN_CHUNK_WORD_SIZE);9192EXPECT_EQ(word_size_for_level(CHUNK_LEVEL_4K), (4 * K) / BytesPerWord);93EXPECT_EQ(word_size_for_level(CHUNK_LEVEL_64K), (64 * K) / BytesPerWord);9495EXPECT_EQ(level_fitting_word_size(0), HIGHEST_CHUNK_LEVEL);96EXPECT_EQ(level_fitting_word_size(1), HIGHEST_CHUNK_LEVEL);97EXPECT_EQ(level_fitting_word_size(MIN_CHUNK_WORD_SIZE), HIGHEST_CHUNK_LEVEL);98EXPECT_EQ(level_fitting_word_size(MIN_CHUNK_WORD_SIZE + 1), HIGHEST_CHUNK_LEVEL - 1);99100EXPECT_EQ(level_fitting_word_size(MAX_CHUNK_WORD_SIZE), ROOT_CHUNK_LEVEL);101EXPECT_EQ(level_fitting_word_size(MAX_CHUNK_WORD_SIZE - 1), ROOT_CHUNK_LEVEL);102EXPECT_EQ(level_fitting_word_size((MAX_CHUNK_WORD_SIZE / 2) + 1), ROOT_CHUNK_LEVEL);103EXPECT_EQ(level_fitting_word_size(MAX_CHUNK_WORD_SIZE / 2), ROOT_CHUNK_LEVEL + 1);104105EXPECT_EQ(level_fitting_word_size(8 * K), LP64_ONLY(CHUNK_LEVEL_64K) NOT_LP64(CHUNK_LEVEL_32K));106EXPECT_EQ(level_fitting_word_size(8 * K + 13), LP64_ONLY(CHUNK_LEVEL_64K) NOT_LP64(CHUNK_LEVEL_32K) - 1);107EXPECT_EQ(level_fitting_word_size(8 * K - 13), LP64_ONLY(CHUNK_LEVEL_64K) NOT_LP64(CHUNK_LEVEL_32K));108109}110111112113