author | stuefe |
Mon, 08 Jul 2019 22:30:19 +0200 | |
branch | stuefe-improved-metaspace |
changeset 57464 | 32e61f51ee09 |
parent 53970 | 1ad7c590a6e7 |
permissions | -rw-r--r-- |
50193 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52363
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
50193 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
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_CHUNKMANAGER_HPP |
|
26 |
#define SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
57464 | 29 |
#include "memory/metaspace/chunkLevel.hpp" |
50193 | 30 |
|
31 |
namespace metaspace { |
|
32 |
||
57464 | 33 |
class VirtualSpaceList; |
34 |
class Metachunk; |
|
50193 | 35 |
|
36 |
||
57464 | 37 |
// class ChunkManager |
38 |
// |
|
39 |
// The ChunkManager has a central role. Callers request chunks from it. |
|
40 |
// It keeps the freelists for chunks. If the freelist is exhausted it |
|
41 |
// allocates new chunks from a connected VirtualSpaceList. |
|
42 |
// |
|
43 |
class ChunkManager : public CHeapObj<mtInternal> { |
|
50193 | 44 |
|
57464 | 45 |
// A chunk manager is connected to a virtual space list which is used |
46 |
// to allocate new root chunks when no free chunks are found. |
|
47 |
VirtualSpaceList* const _vs_list; |
|
50193 | 48 |
|
57464 | 49 |
// Name |
50 |
const char* const _name; |
|
50193 | 51 |
|
57464 | 52 |
// Freelist |
53 |
Metachunk* _chunks [NUM_CHUNK_LEVELS]; |
|
50193 | 54 |
|
57464 | 55 |
// Statistics. |
56 |
// Number of counters per level. |
|
57 |
int _num_chunks [NUM_CHUNK_LEVELS]; |
|
50193 | 58 |
|
57464 | 59 |
// Total size in all chunks, and total number of chunks. |
60 |
size_t _total_word_size; |
|
61 |
int _total_num_chunks; |
|
50193 | 62 |
|
57464 | 63 |
// Remove a chunk of the given level from its freelist, and adjust accounting. |
64 |
// If no chunk of this given level is free, return NULL. |
|
65 |
Metachunk* get_chunk_simple(chklvl_t level); |
|
50193 | 66 |
|
57464 | 67 |
// Update counters after a chunk has been added or removed. |
50193 | 68 |
void account_for_added_chunk(const Metachunk* c); |
69 |
void account_for_removed_chunk(const Metachunk* c); |
|
70 |
||
57464 | 71 |
// Returns true if this manager contains the given chunk. Slow (walks free list) and |
72 |
// only needed for verifications. |
|
73 |
DEBUG_ONLY(bool contains_chunk(Metachunk* metachunk) const;) |
|
50193 | 74 |
|
57464 | 75 |
public: |
50193 | 76 |
|
57464 | 77 |
// Creates a chunk manager with a given name (which is for debug purposes only) |
78 |
// and an associated space list which will be used to request new chunks from |
|
79 |
// (see get_chunk()) |
|
80 |
ChunkManager(const char* name, VirtualSpaceList* space_list); |
|
50193 | 81 |
|
57464 | 82 |
// Get a chunk and be smart about it. |
83 |
// - Attempt to find a free chunk of exactly the pref_level level |
|
84 |
// - Failing that, attempt to find a chunk smaller or equal the minimal level. |
|
85 |
// - Failing that, attempt to find a free chunk of larger size and split it. |
|
86 |
// - Failing that, attempt to allocate a new chunk from the connected virtual space. |
|
87 |
// This may fail if we hit GC threshold or metaspace limit. |
|
88 |
// - Failing that, give up and return NULL. |
|
89 |
Metachunk* get_chunk(chklvl_t min_level, chklvl_t pref_level); |
|
50193 | 90 |
|
57464 | 91 |
// Remove the given chunk from its free list and adjust accounting. |
92 |
// (Called during VirtualSpaceNode purging which happens during a Metaspace GC.) |
|
50193 | 93 |
void remove_chunk(Metachunk* chunk); |
94 |
||
57464 | 95 |
// Return a chunk to the ChunkManager and adjust accounting. May merge chunk |
96 |
// with neighbors. |
|
97 |
// Happens after a Classloader was unloaded and releases its metaspace chunks. |
|
98 |
// !! Note: this may invalidate the chunk. Do not access the chunk after |
|
99 |
// this function returns !! |
|
100 |
void return_chunk(Metachunk* chunk); |
|
50193 | 101 |
|
57464 | 102 |
// Uncommit payload area of free chunks. Will be called during Metaspace GC. |
103 |
void uncommit_free_chunks(); |
|
50193 | 104 |
|
57464 | 105 |
// Run verifications. slow=true: verify chunk-internal integrity too. |
106 |
DEBUG_ONLY(void verify(bool slow) const;) |
|
107 |
DEBUG_ONLY(void locked_verify(bool slow) const;) |
|
50193 | 108 |
|
57464 | 109 |
// Returns the name of this chunk manager. |
110 |
const char* name() const { return _name; } |
|
50193 | 111 |
|
112 |
}; |
|
113 |
||
114 |
} // namespace metaspace |
|
115 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
52363
diff
changeset
|
116 |
#endif // SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP |