author | stuefe |
Tue, 26 Nov 2019 11:29:20 +0100 | |
branch | stuefe-new-metaspace-branch |
changeset 59271 | 1558266946de |
parent 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_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_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" |
59238
6ce12ce00d3e
Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
59155
diff
changeset
|
30 |
#include "memory/metaspace/blockListArray.hpp" |
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
31 |
#include "memory/metaspace/counter.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
32 |
#include "utilities/bitMap.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
33 |
#include "utilities/debug.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
34 |
#include "utilities/globalDefinitions.hpp" |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
35 |
|
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 |
class outputStream; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
38 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
39 |
namespace metaspace { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
40 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
41 |
// The LeftOverManager is responsible for managing small leftover- |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
42 |
// and deallocated blocks. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
43 |
// They come from two sources: |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
44 |
// a) the leftover space left in a chunk when a chunk gets retired |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
45 |
// because it cannot serve a requested allocation. These blocks |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
46 |
// can be largeish (100s - 1000s of words). |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
47 |
// b) when a metaspace allocation is deallocated prematurely - e.g. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
48 |
// due to interrupted class loading. These blocks are small or |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
49 |
// very small. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
50 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
51 |
class LeftOverManager : public CHeapObj<mtInternal> { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
52 |
|
59238
6ce12ce00d3e
Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
59155
diff
changeset
|
53 |
typedef BlockListArray<2, 2, 16> VerySmallBinsType; |
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
54 |
VerySmallBinsType _very_small_bins; |
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 |
block_t* _large_block_reserve; |
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 |
// The current large block we gnaw on |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
59 |
MetaWord* _current; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
60 |
size_t _current_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
61 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
62 |
SizeCounter _total_word_size; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
63 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
64 |
// 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
|
65 |
// and make it current. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
66 |
inline void prime_current(); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
67 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
68 |
// 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
|
69 |
// is too small. |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
70 |
inline MetaWord* 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
|
71 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
72 |
void large_block_statistics(block_stats_t* stats) const; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
73 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
74 |
public: |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
75 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
76 |
static size_t minimal_word_size() { |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
77 |
return VerySmallBinsType::minimal_word_size(); |
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 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
80 |
LeftOverManager() : |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
81 |
_very_small_bins(), |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
82 |
_large_block_reserve(NULL), |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
83 |
_current(NULL), |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
84 |
_current_size(0) |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
85 |
{} |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
86 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
87 |
inline void 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
|
88 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
89 |
inline MetaWord* 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
|
90 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
91 |
#ifdef ASSERT |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
92 |
void verify() const; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
93 |
#endif |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
94 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
95 |
void statistics(block_stats_t* stats) const; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
96 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
97 |
void print(outputStream* st, bool detailed = false) const; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
98 |
|
59271 | 99 |
bool is_empty() const { |
100 |
return _very_small_bins.is_empty() && _current == NULL; |
|
101 |
} |
|
102 |
||
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
103 |
size_t total_word_size() const { return _total_word_size.get(); } |
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 |
|
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 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
110 |
} // namespace metaspace |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
111 |
|
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
diff
changeset
|
112 |
#endif // SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP |