1 /* |
|
2 * Copyright (c) 2016, Oracle and/or its affiliates. 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 it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 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 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 #include "precompiled.hpp" |
|
25 #include "memory/metaspace/spaceManager.hpp" |
|
26 |
|
27 using metaspace::SpaceManager; |
|
28 |
|
29 // The test function is only available in debug builds |
|
30 #ifdef ASSERT |
|
31 |
|
32 #include "unittest.hpp" |
|
33 |
|
34 |
|
35 static void test_adjust_initial_chunk_size(bool is_class) { |
|
36 const size_t smallest = SpaceManager::smallest_chunk_size(is_class); |
|
37 const size_t normal = SpaceManager::small_chunk_size(is_class); |
|
38 const size_t medium = SpaceManager::medium_chunk_size(is_class); |
|
39 |
|
40 #define do_test(value, expected, is_class_value) \ |
|
41 do { \ |
|
42 size_t v = value; \ |
|
43 size_t e = expected; \ |
|
44 assert(SpaceManager::adjust_initial_chunk_size(v, (is_class_value)) == e, \ |
|
45 "Expected: " SIZE_FORMAT " got: " SIZE_FORMAT, e, v); \ |
|
46 } while (0) |
|
47 |
|
48 // Smallest (specialized) |
|
49 do_test(1, smallest, is_class); |
|
50 do_test(smallest - 1, smallest, is_class); |
|
51 do_test(smallest, smallest, is_class); |
|
52 |
|
53 // Small |
|
54 do_test(smallest + 1, normal, is_class); |
|
55 do_test(normal - 1, normal, is_class); |
|
56 do_test(normal, normal, is_class); |
|
57 |
|
58 // Medium |
|
59 do_test(normal + 1, medium, is_class); |
|
60 do_test(medium - 1, medium, is_class); |
|
61 do_test(medium, medium, is_class); |
|
62 |
|
63 // Humongous |
|
64 do_test(medium + 1, medium + 1, is_class); |
|
65 |
|
66 #undef test_adjust_initial_chunk_size |
|
67 } |
|
68 |
|
69 TEST(SpaceManager, adjust_initial_chunk_size) { |
|
70 test_adjust_initial_chunk_size(true); |
|
71 test_adjust_initial_chunk_size(false); |
|
72 } |
|
73 |
|
74 #endif // ASSERT |
|