|
1 /* |
|
2 * Copyright (c) 2019, SAP SE. All rights reserved. |
|
3 * Copyright (c) 2019, Oracle and/or its affiliates. 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 #ifndef SHARE_MEMORY_METASPACE_CHUNKLEVEL_HPP |
|
27 #define SHARE_MEMORY_METASPACE_CHUNKLEVEL_HPP |
|
28 |
|
29 #include "utilities/globalDefinitions.hpp" |
|
30 |
|
31 // Constants for the chunk levels and some utility functions. |
|
32 |
|
33 class outputStream; |
|
34 |
|
35 namespace metaspace { |
|
36 |
|
37 // Metachunk level (must be signed) |
|
38 typedef signed char chklvl_t; |
|
39 |
|
40 #define CHKLVL_FORMAT "lv%.2d" |
|
41 |
|
42 // Chunks are managed by a binary buddy allocator. |
|
43 |
|
44 // Chunk sizes range from 1K to 4MB (64bit). |
|
45 // |
|
46 // Reasoning: .... TODO explain |
|
47 |
|
48 // Each chunk has a level; the level corresponds to its position in the tree |
|
49 // and describes its size. |
|
50 // |
|
51 // The largest chunks are called root chunks, of 4MB in size, and have level 0. |
|
52 // From there on it goes: |
|
53 // |
|
54 // size level |
|
55 // 4MB 0 |
|
56 // 2MB 1 |
|
57 // 1MB 2 |
|
58 // 512K 3 |
|
59 // 256K 4 |
|
60 // 128K 5 |
|
61 // 64K 6 |
|
62 // 32K 7 |
|
63 // 16K 8 |
|
64 // 8K 9 |
|
65 // 4K 10 |
|
66 // 2K 11 |
|
67 // 1K 12 |
|
68 |
|
69 namespace chklvl { |
|
70 |
|
71 static const size_t MAX_CHUNK_BYTE_SIZE = 4 * M; |
|
72 static const int NUM_CHUNK_LEVELS = 13; |
|
73 static const size_t MIN_CHUNK_BYTE_SIZE = (MAX_CHUNK_BYTE_SIZE >> (size_t)NUM_CHUNK_LEVELS); |
|
74 |
|
75 static const size_t MIN_CHUNK_WORD_SIZE = MIN_CHUNK_BYTE_SIZE / sizeof(MetaWord); |
|
76 static const size_t MAX_CHUNK_WORD_SIZE = MAX_CHUNK_BYTE_SIZE / sizeof(MetaWord); |
|
77 |
|
78 static const chklvl_t ROOT_CHUNK_LEVEL = 0; |
|
79 |
|
80 static const chklvl_t HIGHEST_CHUNK_LEVEL = NUM_CHUNK_LEVELS - 1; |
|
81 static const chklvl_t LOWEST_CHUNK_LEVEL = 0; |
|
82 |
|
83 static const chklvl_t INVALID_CHUNK_LEVEL = (chklvl_t) -1; |
|
84 |
|
85 inline bool is_valid_level(chklvl_t level) { |
|
86 return level >= LOWEST_CHUNK_LEVEL && |
|
87 level <= HIGHEST_CHUNK_LEVEL; |
|
88 } |
|
89 |
|
90 inline void check_valid_level(chklvl_t lvl) { |
|
91 assert(is_valid_level(lvl), "invalid level (%d)", (int)lvl); |
|
92 } |
|
93 |
|
94 // Given a level return the chunk size, in words. |
|
95 inline size_t word_size_for_level(chklvl_t level) { |
|
96 check_valid_level(level); |
|
97 return (MAX_CHUNK_BYTE_SIZE >> level) / BytesPerWord; |
|
98 } |
|
99 |
|
100 // Given an arbitrary word size smaller than the highest chunk size, |
|
101 // return the highest chunk level able to hold this size. |
|
102 // Returns INVALID_CHUNK_LEVEL if no fitting level can be found. |
|
103 chklvl_t level_fitting_word_size(size_t word_size); |
|
104 |
|
105 // Shorthands to refer to exact sizes |
|
106 static const chklvl_t CHUNK_LEVEL_4M = ROOT_CHUNK_LEVEL; |
|
107 static const chklvl_t CHUNK_LEVEL_2M = (ROOT_CHUNK_LEVEL + 1); |
|
108 static const chklvl_t CHUNK_LEVEL_1M = (ROOT_CHUNK_LEVEL + 2); |
|
109 static const chklvl_t CHUNK_LEVEL_512K = (ROOT_CHUNK_LEVEL + 3); |
|
110 static const chklvl_t CHUNK_LEVEL_256K = (ROOT_CHUNK_LEVEL + 4); |
|
111 static const chklvl_t CHUNK_LEVEL_128K = (ROOT_CHUNK_LEVEL + 5); |
|
112 static const chklvl_t CHUNK_LEVEL_64K = (ROOT_CHUNK_LEVEL + 6); |
|
113 static const chklvl_t CHUNK_LEVEL_32K = (ROOT_CHUNK_LEVEL + 7); |
|
114 static const chklvl_t CHUNK_LEVEL_16K = (ROOT_CHUNK_LEVEL + 8); |
|
115 static const chklvl_t CHUNK_LEVEL_8K = (ROOT_CHUNK_LEVEL + 9); |
|
116 static const chklvl_t CHUNK_LEVEL_4K = (ROOT_CHUNK_LEVEL + 10); |
|
117 static const chklvl_t CHUNK_LEVEL_2K = (ROOT_CHUNK_LEVEL + 11); |
|
118 static const chklvl_t CHUNK_LEVEL_1K = (ROOT_CHUNK_LEVEL + 12); |
|
119 |
|
120 STATIC_ASSERT(CHUNK_LEVEL_1K == HIGHEST_CHUNK_LEVEL); |
|
121 |
|
122 ///////////////////////////////////////////////////////// |
|
123 // print helpers |
|
124 void print_chunk_size(outputStream* st, chklvl_t lvl); |
|
125 |
|
126 |
|
127 } // namespace chklvl |
|
128 |
|
129 } // namespace metaspace |
|
130 |
|
131 #endif // SHARE_MEMORY_METASPACE_BLOCKFREELIST_HPP |