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
25 #ifndef SHARE_MEMORY_METASPACE_SMALLBLOCKS_HPP_
26 #define SHARE_MEMORY_METASPACE_SMALLBLOCKS_HPP_
27
28 #include "memory/allocation.hpp"
29 #include "memory/binaryTreeDictionary.hpp"
30 #include "memory/metaspace/metablock.hpp"
31 #include "utilities/globalDefinitions.hpp"
32
33 class outputStream;
34
35 namespace metaspace {
36 namespace internals {
37
38 class SmallBlocks : public CHeapObj<mtClass> {
39
40 const static uint _small_block_max_size = sizeof(TreeChunk<Metablock, FreeList<Metablock> >)/HeapWordSize;
41 // Note: this corresponds to the imposed miminum allocation size, see SpaceManager::get_allocation_word_size()
42 const static uint _small_block_min_size = sizeof(Metablock)/HeapWordSize;
43
44 private:
45 FreeList<Metablock> _small_lists[_small_block_max_size - _small_block_min_size];
46
47 FreeList<Metablock>& list_at(size_t word_size) {
48 assert(word_size >= _small_block_min_size, "There are no metaspace objects less than %u words", _small_block_min_size);
49 return _small_lists[word_size - _small_block_min_size];
50 }
51
52 public:
53 SmallBlocks() {
54 for (uint i = _small_block_min_size; i < _small_block_max_size; i++) {
55 uint k = i - _small_block_min_size;
56 _small_lists[k].set_size(i);
67 static uint small_block_min_size() { return _small_block_min_size; }
68
69 MetaWord* get_block(size_t word_size) {
70 if (list_at(word_size).count() > 0) {
71 MetaWord* new_block = (MetaWord*) list_at(word_size).get_chunk_at_head();
72 return new_block;
73 } else {
74 return NULL;
75 }
76 }
77 void return_block(Metablock* free_chunk, size_t word_size) {
78 list_at(word_size).return_chunk_at_head(free_chunk, false);
79 assert(list_at(word_size).count() > 0, "Should have a chunk");
80 }
81
82 void print_on(outputStream* st) const;
83
84 };
85
86 } // namespace metaspace
87 } // namespace internals
88
89
90 #endif /* SHARE_MEMORY_METASPACE_SMALLBLOCKS_HPP_ */
|
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
25 #ifndef SHARE_MEMORY_METASPACE_SMALLBLOCKS_HPP_
26 #define SHARE_MEMORY_METASPACE_SMALLBLOCKS_HPP_
27
28 #include "memory/allocation.hpp"
29 #include "memory/binaryTreeDictionary.hpp"
30 #include "memory/metaspace/metablock.hpp"
31 #include "utilities/globalDefinitions.hpp"
32
33 class outputStream;
34
35 namespace metaspace {
36
37 class SmallBlocks : public CHeapObj<mtClass> {
38
39 const static uint _small_block_max_size = sizeof(TreeChunk<Metablock, FreeList<Metablock> >)/HeapWordSize;
40 // Note: this corresponds to the imposed miminum allocation size, see SpaceManager::get_allocation_word_size()
41 const static uint _small_block_min_size = sizeof(Metablock)/HeapWordSize;
42
43 private:
44 FreeList<Metablock> _small_lists[_small_block_max_size - _small_block_min_size];
45
46 FreeList<Metablock>& list_at(size_t word_size) {
47 assert(word_size >= _small_block_min_size, "There are no metaspace objects less than %u words", _small_block_min_size);
48 return _small_lists[word_size - _small_block_min_size];
49 }
50
51 public:
52 SmallBlocks() {
53 for (uint i = _small_block_min_size; i < _small_block_max_size; i++) {
54 uint k = i - _small_block_min_size;
55 _small_lists[k].set_size(i);
66 static uint small_block_min_size() { return _small_block_min_size; }
67
68 MetaWord* get_block(size_t word_size) {
69 if (list_at(word_size).count() > 0) {
70 MetaWord* new_block = (MetaWord*) list_at(word_size).get_chunk_at_head();
71 return new_block;
72 } else {
73 return NULL;
74 }
75 }
76 void return_block(Metablock* free_chunk, size_t word_size) {
77 list_at(word_size).return_chunk_at_head(free_chunk, false);
78 assert(list_at(word_size).count() > 0, "Should have a chunk");
79 }
80
81 void print_on(outputStream* st) const;
82
83 };
84
85 } // namespace metaspace
86
87
88 #endif /* SHARE_MEMORY_METASPACE_SMALLBLOCKS_HPP_ */
89
|