author | stuefe |
Fri, 01 Nov 2019 10:28:15 +0100 | |
branch | stuefe-new-metaspace-branch |
changeset 59155 | b537e6386306 |
child 59238 | 6ce12ce00d3e |
permissions | -rw-r--r-- |
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
1 |
/* |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, SAP SE. All rights reserved. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
3 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
5 |
* |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
6 |
* This code is free software; you can redistribute it and/or modify it |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
9 |
* |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
14 |
* accompanied this code). |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
15 |
* |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License version |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
19 |
* |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
22 |
* questions. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
23 |
* |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
24 |
*/ |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
25 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
26 |
#ifndef SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
27 |
#define SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
28 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
29 |
#include "memory/allocation.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
30 |
#include "memory/metaspace/leftOverBins.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
31 |
#include "utilities/debug.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
32 |
#include "utilities/globalDefinitions.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
33 |
#include "utilities/ostream.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
34 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
35 |
namespace metaspace { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
36 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
37 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
38 |
// Starting at (including) pos, find the position of the next 1 bit. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
39 |
// Return -1 if not found. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
40 |
int BinMap::find_next_set_bit(int pos) const { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
41 |
if (get_bit(pos)) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
42 |
return pos; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
43 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
44 |
mask_type m2 = _mask; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
45 |
int pos2 = pos + 1; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
46 |
m2 >>= pos2; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
47 |
if (m2 > 0) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
48 |
while ((m2 & (mask_type)1) == 0) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
49 |
m2 >>= 1; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
50 |
pos2 ++; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
51 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
52 |
return pos2; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
53 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
54 |
return -1; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
55 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
56 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
57 |
/////////////////////////////////////// |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
58 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
59 |
template <size_t min_word_size, size_t spread, int num_bins> |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
60 |
void Bins<min_word_size, spread, num_bins>::put(MetaWord* p, size_t word_size) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
61 |
assert(word_size >= minimal_word_size() && word_size < maximal_word_size(), "Invalid word size"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
62 |
block_t* b = (block_t*)p; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
63 |
int bno = bin_for_size(word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
64 |
assert(bno >= 0 && bno < num_bins, "Sanity"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
65 |
assert(b != _bins[bno], "double add?"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
66 |
b->next = _bins[bno]; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
67 |
b->size = word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
68 |
_bins[bno] = b; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
69 |
_mask.set_bit(bno); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
70 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
71 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
72 |
template <size_t min_word_size, size_t spread, int num_bins> |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
73 |
block_t* Bins<min_word_size, spread, num_bins>::get(size_t word_size) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
74 |
// Adjust size for spread (we need the bin number which guarantees word_size). |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
75 |
word_size += (spread - 1); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
76 |
if (word_size >= maximal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
77 |
return NULL; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
78 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
79 |
int bno = bin_for_size(word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
80 |
bno = _mask.find_next_set_bit(bno); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
81 |
if (bno != -1) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
82 |
assert(bno >= 0 && bno < num_bins, "Sanity"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
83 |
assert(_bins[bno] != NULL, "Sanity"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
84 |
block_t* b = _bins[bno]; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
85 |
_bins[bno] = b->next; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
86 |
if (_bins[bno] == NULL) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
87 |
_mask.clr_bit(bno); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
88 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
89 |
return b; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
90 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
91 |
return NULL; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
92 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
93 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
94 |
#ifdef ASSERT |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
95 |
template <size_t min_word_size, size_t spread, int num_bins> |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
96 |
void Bins<min_word_size, spread, num_bins>::verify() const { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
97 |
for (int i = 0; i < num_bins; i ++) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
98 |
assert(_mask.get_bit(i) == (_bins[i] != NULL), "Sanity"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
99 |
const size_t min_size = minimal_word_size_in_bin(i); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
100 |
const size_t max_size = maximal_word_size_in_bin(i); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
101 |
for(block_t* b = _bins[i]; b != NULL; b = b->next) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
102 |
assert(b->size >= min_size && b->size < max_size, "Sanity"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
103 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
104 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
105 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
106 |
#endif // ASSERT |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
107 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
108 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
109 |
template <size_t min_word_size, size_t spread, int num_bins> |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
110 |
void Bins<min_word_size, spread, num_bins>::statistics(block_stats_t* stats) const { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
111 |
for (int i = 0; i < num_bins; i ++) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
112 |
for(block_t* b = _bins[i]; b != NULL; b = b->next) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
113 |
stats->num_blocks ++; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
114 |
stats->word_size += b->size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
115 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
116 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
117 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
118 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
119 |
template <size_t min_word_size, size_t spread, int num_bins> |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
120 |
void Bins<min_word_size, spread, num_bins>::print(outputStream* st) const { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
121 |
bool first = true; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
122 |
for (int i = 0; i < num_bins; i ++) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
123 |
int n = 0; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
124 |
for(block_t* b = _bins[i]; b != NULL; b = b->next) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
125 |
n ++; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
126 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
127 |
if (n > 0) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
128 |
if (!first) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
129 |
st->print(", "); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
130 |
} else { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
131 |
first = false; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
132 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
133 |
st->print(SIZE_FORMAT "=%d", minimal_word_size_in_bin(i), n); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
134 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
135 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
136 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
137 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
138 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
139 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
140 |
/////////////////////////////////////// |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
141 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
142 |
// Take the topmost block from the large block reserve list |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
143 |
// and make it current. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
144 |
inline void LeftOverManager::prime_current() { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
145 |
if (_large_block_reserve != NULL) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
146 |
_current = (MetaWord*) _large_block_reserve; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
147 |
_current_size = _large_block_reserve->size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
148 |
_large_block_reserve = _large_block_reserve->next; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
149 |
} else { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
150 |
_current = NULL; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
151 |
_current_size = 0; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
152 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
153 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
154 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
155 |
// Allocate from current block. Returns NULL if current block |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
156 |
// is too small. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
157 |
inline MetaWord* LeftOverManager::alloc_from_current(size_t word_size) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
158 |
if (_current_size >= word_size) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
159 |
assert(_current != NULL, "Must be"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
160 |
MetaWord* p = _current; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
161 |
size_t remaining = _current_size - word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
162 |
if (remaining >= _very_small_bins.minimal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
163 |
_current = p + word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
164 |
_current_size = remaining; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
165 |
} else { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
166 |
// completely used up old large block. Proceed to next. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
167 |
prime_current(); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
168 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
169 |
return p; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
170 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
171 |
return NULL; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
172 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
173 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
174 |
inline void LeftOverManager::add_block(MetaWord* p, size_t word_size) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
175 |
if (word_size >= minimal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
176 |
if (word_size < _very_small_bins.maximal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
177 |
_very_small_bins.put(p, word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
178 |
} else { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
179 |
if (_current == NULL) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
180 |
assert(_large_block_reserve == NULL, "Should be primed."); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
181 |
_current = p; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
182 |
_current_size = word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
183 |
} else { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
184 |
assert(sizeof(block_t) <= word_size * BytesPerWord, "must be"); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
185 |
block_t* b = (block_t*)p; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
186 |
b->size = word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
187 |
b->next = _large_block_reserve; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
188 |
_large_block_reserve = b; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
189 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
190 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
191 |
_total_word_size.increment_by(word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
192 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
193 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
194 |
DEBUG_ONLY(verify();) |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
195 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
196 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
197 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
198 |
inline MetaWord* LeftOverManager::get_block(size_t requested_word_size) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
199 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
200 |
requested_word_size = MAX2(requested_word_size, minimal_word_size()); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
201 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
202 |
// First attempt to take from current large block because that is cheap (pointer bump) |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
203 |
// and efficient (no spread) |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
204 |
MetaWord* p = alloc_from_current(requested_word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
205 |
if (p == NULL && _current_size > 0) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
206 |
// current large block is too small. If it is moth-eaten enough to be put |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
207 |
// into the small remains bin, do so. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
208 |
if (_current_size < _very_small_bins.maximal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
209 |
_very_small_bins.put(_current, _current_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
210 |
prime_current(); // proceed to next large block. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
211 |
// --- and re-attempt - but only once more. If that fails too, we give up. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
212 |
p = alloc_from_current(requested_word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
213 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
214 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
215 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
216 |
if (p == NULL) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
217 |
// Did not work. Check the small bins. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
218 |
if (requested_word_size < _very_small_bins.maximal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
219 |
block_t* b = _very_small_bins.get(requested_word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
220 |
if (b != NULL) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
221 |
p = (MetaWord*)b; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
222 |
size_t remaining = b->size - requested_word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
223 |
if (remaining >= _very_small_bins.minimal_word_size()) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
224 |
MetaWord* q = p + requested_word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
225 |
_very_small_bins.put(q, remaining); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
226 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
227 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
228 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
229 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
230 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
231 |
if (p != NULL) { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
232 |
_total_word_size.decrement_by(requested_word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
233 |
DEBUG_ONLY(verify();) |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
234 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
235 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
236 |
return p; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
237 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
238 |
} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
239 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
240 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
241 |
} // namespace metaspace |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
242 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
243 |
#endif // SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP |