1 /*
2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3  * Copyright (c) 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 #include "memory/metaspace.hpp"
28 #include "memory/metaspace/chunklevel.hpp"
29 #include "memory/metaspace/metaspaceArenaGrowthPolicy.hpp"
30 //#define LOG_PLEASE
31 #include "metaspaceGtestCommon.hpp"
32 
33 using metaspace::ArenaGrowthPolicy;
34 using metaspace::chunklevel_t;
35 using namespace metaspace::chunklevel;
36 
test_arena_growth_policy(Metaspace::MetaspaceType spacetype,bool is_class)37 static void test_arena_growth_policy(Metaspace::MetaspaceType spacetype, bool is_class) {
38 
39   const ArenaGrowthPolicy* a =
40       ArenaGrowthPolicy::policy_for_space_type((Metaspace::MetaspaceType)spacetype, is_class);
41 
42   // initial level
43   chunklevel_t lvl = a->get_level_at_step(0);
44   ASSERT_TRUE(is_valid_level(lvl));
45   if (spacetype != Metaspace::BootMetaspaceType) {
46     // All types save boot loader should start with small or very small chunks
47     ASSERT_GE(lvl, CHUNK_LEVEL_4K);
48   }
49 
50   for (int step = 1; step < 100; step++) {
51     chunklevel_t lvl2 = a->get_level_at_step(step);
52     ASSERT_TRUE(is_valid_level(lvl2));
53     // limit steepness: no growth allowed beyond last chunksize * 2
54     ASSERT_LE(word_size_for_level(lvl2), word_size_for_level(lvl) * 2);
55     lvl = lvl2;
56   }
57 }
58 
59 #define DEFINE_GROWTH_POLICY_TEST(spacetype, is_class) \
60 TEST_VM(metaspace, arena_growth_policy_##spacetype##_##is_class) { \
61   test_arena_growth_policy(Metaspace::spacetype, is_class); \
62 }
63 
64 DEFINE_GROWTH_POLICY_TEST(ReflectionMetaspaceType, true)
65 DEFINE_GROWTH_POLICY_TEST(ReflectionMetaspaceType, false)
66 DEFINE_GROWTH_POLICY_TEST(ClassMirrorHolderMetaspaceType, true)
67 DEFINE_GROWTH_POLICY_TEST(ClassMirrorHolderMetaspaceType, false)
68 DEFINE_GROWTH_POLICY_TEST(StandardMetaspaceType, true)
69 DEFINE_GROWTH_POLICY_TEST(StandardMetaspaceType, false)
70 DEFINE_GROWTH_POLICY_TEST(BootMetaspaceType, true)
71 DEFINE_GROWTH_POLICY_TEST(BootMetaspaceType, false)
72 
73