1 /* 2 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018, 2020 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 28 // #define LOG_PLEASE 29 30 #include "classfile/classLoaderData.hpp" 31 #include "metaspaceTestsCommon.hpp" 32 #include "utilities/powerOfTwo.hpp" 33 34 35 TEST_VM(metaspace, misc_sizes) { 36 37 // Test test common sizes (seems primitive but breaks surprisingly often during development 38 // because of word vs byte confusion) 39 // Adjust this test if numbers change. 40 ASSERT_TRUE(Settings::commit_granule_bytes() == 16 * K || 41 Settings::commit_granule_bytes() == 64 * K); 42 ASSERT_EQ(Settings::commit_granule_bytes(), Metaspace::commit_alignment()); 43 ASSERT_TRUE(is_aligned(Settings::virtual_space_node_default_word_size(), 44 metaspace::chunklevel::MAX_CHUNK_WORD_SIZE)); 45 ASSERT_EQ(Settings::virtual_space_node_default_word_size(), 46 metaspace::chunklevel::MAX_CHUNK_WORD_SIZE * 2); 47 ASSERT_EQ(Settings::virtual_space_node_reserve_alignment_words(), 48 Metaspace::reserve_alignment_words()); 49 50 } 51 52 53 TEST_VM(metaspace, misc_max_alloc_size) { 54 55 // Make sure we can allocate what we promise to allocate 56 const size_t sz = Metaspace::max_allocation_word_size(); 57 ClassLoaderData* cld = ClassLoaderData::the_null_class_loader_data(); 58 MetaWord* p = cld->metaspace_non_null()->allocate(sz, Metaspace::NonClassType); 59 ASSERT_NOT_NULL(p); 60 cld->metaspace_non_null()->deallocate(p, sz, false); 61 62 } 63 64 TEST_VM(metaspace, chunklevel_utils) { 65 66 LOG(SIZE_FORMAT, MAX_CHUNK_BYTE_SIZE); 67 LOG(SIZE_FORMAT, MIN_CHUNK_BYTE_SIZE); 68 LOG(SIZE_FORMAT, MIN_CHUNK_WORD_SIZE); 69 LOG(SIZE_FORMAT, MAX_CHUNK_WORD_SIZE); 70 LOG(SIZE_FORMAT, MAX_CHUNK_BYTE_SIZE); 71 LOG("%u", (unsigned)ROOT_CHUNK_LEVEL); 72 LOG("%u", (unsigned)HIGHEST_CHUNK_LEVEL); 73 LOG("%u", (unsigned)LOWEST_CHUNK_LEVEL); 74 75 static const chunklevel_t INVALID_CHUNK_LEVEL = (chunklevel_t) -1; 76 77 EXPECT_TRUE(is_power_of_2(MAX_CHUNK_WORD_SIZE)); 78 EXPECT_TRUE(is_power_of_2(MIN_CHUNK_WORD_SIZE)); 79 80 EXPECT_TRUE(is_valid_level(LOWEST_CHUNK_LEVEL)); 81 EXPECT_TRUE(is_valid_level(HIGHEST_CHUNK_LEVEL)); 82 EXPECT_FALSE(is_valid_level(HIGHEST_CHUNK_LEVEL + 1)); 83 EXPECT_FALSE(is_valid_level(LOWEST_CHUNK_LEVEL - 1)); 84 85 EXPECT_EQ(word_size_for_level(ROOT_CHUNK_LEVEL), MAX_CHUNK_WORD_SIZE); 86 EXPECT_EQ(word_size_for_level(HIGHEST_CHUNK_LEVEL), MIN_CHUNK_WORD_SIZE); 87 88 EXPECT_EQ(word_size_for_level(CHUNK_LEVEL_4K), (4 * K) / BytesPerWord); 89 EXPECT_EQ(word_size_for_level(CHUNK_LEVEL_64K), (64 * K) / BytesPerWord); 90 91 EXPECT_EQ(level_fitting_word_size(0), HIGHEST_CHUNK_LEVEL); 92 EXPECT_EQ(level_fitting_word_size(1), HIGHEST_CHUNK_LEVEL); 93 EXPECT_EQ(level_fitting_word_size(MIN_CHUNK_WORD_SIZE), HIGHEST_CHUNK_LEVEL); 94 EXPECT_EQ(level_fitting_word_size(MIN_CHUNK_WORD_SIZE + 1), HIGHEST_CHUNK_LEVEL - 1); 95 96 EXPECT_EQ(level_fitting_word_size(MAX_CHUNK_WORD_SIZE), ROOT_CHUNK_LEVEL); 97 EXPECT_EQ(level_fitting_word_size(MAX_CHUNK_WORD_SIZE - 1), ROOT_CHUNK_LEVEL); 98 EXPECT_EQ(level_fitting_word_size((MAX_CHUNK_WORD_SIZE / 2) + 1), ROOT_CHUNK_LEVEL); 99 EXPECT_EQ(level_fitting_word_size(MAX_CHUNK_WORD_SIZE / 2), ROOT_CHUNK_LEVEL + 1); 100 101 EXPECT_EQ(level_fitting_word_size(8 * K), CHUNK_LEVEL_64K); 102 EXPECT_EQ(level_fitting_word_size(8 * K + 13), CHUNK_LEVEL_64K - 1); 103 EXPECT_EQ(level_fitting_word_size(8 * K - 13), CHUNK_LEVEL_64K); 104 105 106 } 107