author | stuefe |
Wed, 16 Oct 2019 16:10:24 +0200 | |
branch | stuefe-new-metaspace-branch |
changeset 58646 | bcdba1c9f1fe |
parent 58333 | 78b2e8f46dd4 |
permissions | -rw-r--r-- |
50193 | 1 |
/* |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
2 |
* Copyright (c) 2019, SAP SE. All rights reserved. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
3 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
50193 | 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_CHUNKMANAGER_HPP |
|
27 |
#define SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP |
|
28 |
||
29 |
#include "memory/allocation.hpp" |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
30 |
#include "memory/metaspace/chunkLevel.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
31 |
#include "memory/metaspace/counter.hpp" |
50193 | 32 |
#include "memory/metaspace/metachunk.hpp" |
33 |
||
34 |
namespace metaspace { |
|
35 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
36 |
class VirtualSpaceList; |
58099 | 37 |
struct cm_stats_t; |
50193 | 38 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
39 |
// class ChunkManager |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
40 |
// |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
41 |
// The ChunkManager has a central role. Callers request chunks from it. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
42 |
// It keeps the freelists for chunks. If the freelist is exhausted it |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
43 |
// allocates new chunks from a connected VirtualSpaceList. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
44 |
// |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
45 |
class ChunkManager : public CHeapObj<mtInternal> { |
50193 | 46 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
47 |
// A chunk manager is connected to a virtual space list which is used |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
48 |
// to allocate new root chunks when no free chunks are found. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
49 |
VirtualSpaceList* const _vslist; |
50193 | 50 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
51 |
// Name |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
52 |
const char* const _name; |
50193 | 53 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
54 |
// Freelist |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
55 |
MetachunkListCluster _chunks; |
50193 | 56 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
57 |
// Returns true if this manager contains the given chunk. Slow (walks free list) and |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
58 |
// only needed for verifications. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
59 |
DEBUG_ONLY(bool contains_chunk(Metachunk* c) const;) |
50193 | 60 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
61 |
// Given a chunk we are about to handout to the caller, make sure it is committed |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
62 |
// according to constants::committed_words_on_fresh_chunks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
63 |
// May fail if we hit the commit limit. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
64 |
static bool commit_chunk_before_handout(Metachunk* c); |
50193 | 65 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
66 |
// Take a single chunk from the given freelist and adjust counters. Returns NULL |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
67 |
// if there is no fitting chunk for this level. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
68 |
Metachunk* remove_first_chunk_at_level(chklvl_t l); |
50193 | 69 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
70 |
// Given a chunk which must be outside of a freelist and must be free, split it to |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
71 |
// meet a target level and return it. Splinters are added to the freelist. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
72 |
Metachunk* split_chunk_and_add_splinters(Metachunk* c, chklvl_t target_level); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
73 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
74 |
// Uncommit all chunks equal or below the given level. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
75 |
void uncommit_free_chunks(chklvl_t max_level); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
76 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
77 |
public: |
50193 | 78 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
79 |
// Creates a chunk manager with a given name (which is for debug purposes only) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
80 |
// and an associated space list which will be used to request new chunks from |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
81 |
// (see get_chunk()) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
82 |
ChunkManager(const char* name, VirtualSpaceList* space_list); |
50193 | 83 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
84 |
// Get a chunk and be smart about it. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
85 |
// - 1) Attempt to find a free chunk of exactly the pref_level level |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
86 |
// - 2) Failing that, attempt to find a chunk smaller or equal the maximal level. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
87 |
// - 3) Failing that, attempt to find a free chunk of larger size and split it. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
88 |
// - 4) Failing that, attempt to allocate a new chunk from the connected virtual space. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
89 |
// - Failing that, give up and return NULL. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
90 |
// Note: this is not guaranteed to return a *committed* chunk. The chunk manager will |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
91 |
// attempt to commit the returned chunk according to constants::committed_words_on_fresh_chunks; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
92 |
// but this may fail if we hit a commit limit. In that case, a partly uncommitted chunk |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
93 |
// will be returned, and the commit is attempted again when we allocate from the chunk's |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
94 |
// uncommitted area. See also Metachunk::allocate. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
95 |
Metachunk* get_chunk(chklvl_t max_level, chklvl_t pref_level); |
50193 | 96 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
97 |
// Return a single chunk to the ChunkManager and adjust accounting. May merge chunk |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
98 |
// with neighbors. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
99 |
// Happens after a Classloader was unloaded and releases its metaspace chunks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
100 |
// !! Notes: |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
101 |
// 1) After this method returns, c may not be valid anymore. Do not access the chunk after this function returns. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
102 |
// 2) This function will not remove c from its current chunk list. This has to be done by the caller prior to |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
103 |
// calling this method. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
104 |
void return_chunk(Metachunk* c); |
50193 | 105 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
106 |
// Return a single chunk to the freelist and adjust accounting. No merge is attempted. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
107 |
void return_chunk_simple(Metachunk* c); |
50193 | 108 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
109 |
// Given a chunk c, which must be "in use" and must not be a root chunk, attempt to |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
110 |
// enlarge it in place by claiming its trailing buddy. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
111 |
// |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
112 |
// This will only work if c is the leader of the buddy pair and the trailing buddy is free. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
113 |
// |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
114 |
// If successful, the follower chunk will be removed from the freelists, the leader chunk c will |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
115 |
// double in size (level decreased by one). |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
116 |
// |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
117 |
// On success, true is returned, false otherwise. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
118 |
bool attempt_enlarge_chunk(Metachunk* c); |
50193 | 119 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
120 |
// Attempt to reclaim free areas in metaspace wholesale: |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
121 |
// - first, attempt to purge nodes of the backing virtual space. This can only be successful |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
122 |
// if whole nodes are only containing free chunks, so it highly depends on fragmentation. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
123 |
// - then, it will uncommit areas of free chunks according to the rules laid down in |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
124 |
// settings (see settings.hpp). |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
125 |
void wholesale_reclaim(); |
50193 | 126 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
127 |
// Run verifications. slow=true: verify chunk-internal integrity too. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
128 |
DEBUG_ONLY(void verify(bool slow) const;) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
129 |
DEBUG_ONLY(void verify_locked(bool slow) const;) |
50193 | 130 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
131 |
// Returns the name of this chunk manager. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
132 |
const char* name() const { return _name; } |
50193 | 133 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
134 |
// Returns total number of chunks |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
135 |
int total_num_chunks() const { return _chunks.total_num_chunks(); } |
50193 | 136 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
137 |
// Returns number of words in all free chunks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
138 |
size_t total_word_size() const { return _chunks.total_word_size(); } |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
139 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
140 |
// Update statistics. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
141 |
void add_to_statistics(cm_stats_t* out) const; |
50193 | 142 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
143 |
void print_on(outputStream* st) const; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
144 |
void print_on_locked(outputStream* st) const; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
145 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
146 |
private: |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
147 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
148 |
static ChunkManager* _chunkmanager_class; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
149 |
static ChunkManager* _chunkmanager_nonclass; |
50193 | 150 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
151 |
public: |
50193 | 152 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
153 |
static ChunkManager* chunkmanager_class() { return _chunkmanager_class; } |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
154 |
static ChunkManager* chunkmanager_nonclass() { return _chunkmanager_nonclass; } |
50193 | 155 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
156 |
static void set_chunkmanager_class(ChunkManager* cm); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53970
diff
changeset
|
157 |
static void set_chunkmanager_nonclass(ChunkManager* cm); |
50193 | 158 |
|
58333 | 159 |
|
50193 | 160 |
}; |
161 |
||
162 |
} // namespace metaspace |
|
163 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52363
diff
changeset
|
164 |
#endif // SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP |