author | stuefe |
Mon, 25 Nov 2019 16:35:14 +0100 | |
branch | stuefe-new-metaspace-branch |
changeset 59257 | 990b1fed3b47 |
parent 59155 | b537e6386306 |
permissions | -rw-r--r-- |
50193 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50193
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
3 |
* Copyright (c) 2018, 2019 SAP SE. 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_SPACEMANAGER_HPP |
|
27 |
#define SHARE_MEMORY_METASPACE_SPACEMANAGER_HPP |
|
28 |
||
29 |
#include "memory/allocation.hpp" |
|
30 |
#include "memory/metaspace.hpp" |
|
31 |
#include "memory/metaspace/blockFreelist.hpp" |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
32 |
#include "memory/metaspace/chunkAllocSequence.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
33 |
#include "memory/metaspace/chunkManager.hpp" |
50193 | 34 |
#include "memory/metaspace/metachunk.hpp" |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
35 |
#include "memory/metaspace/metaspaceCommon.hpp" |
50193 | 36 |
|
58683 | 37 |
|
50193 | 38 |
class outputStream; |
39 |
class Mutex; |
|
40 |
||
41 |
namespace metaspace { |
|
42 |
||
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
43 |
class BlockFreeList; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
44 |
class LeftOverManager; |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
45 |
|
58099 | 46 |
struct sm_stats_t; |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
47 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
48 |
// The SpaceManager: |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
49 |
// - keeps a list of chunks-in-use by the class loader, as well as a current chunk used |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
50 |
// to allocate from |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
51 |
// - keeps a dictionary of free MetaBlocks. Those can be remnants of a retired chunk or |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
52 |
// allocations which were not needed anymore for some reason (e.g. releasing half-allocated |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
53 |
// structures when class loading fails) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
54 |
|
50193 | 55 |
class SpaceManager : public CHeapObj<mtClass> { |
56 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
57 |
// Lock handed down from the associated ClassLoaderData. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
58 |
// Protects allocations from this space. |
50193 | 59 |
Mutex* const _lock; |
60 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
61 |
// The chunk manager to allocate chunks from. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
62 |
ChunkManager* const _chunk_manager; |
50193 | 63 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
64 |
// The chunk allocation strategy to use. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
65 |
const ChunkAllocSequence* const _chunk_alloc_sequence; |
50193 | 66 |
|
67 |
// List of chunks in use by this SpaceManager. Allocations |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
68 |
// are done from the current chunk. The list is used for deallocating |
50193 | 69 |
// chunks when the SpaceManager is freed. |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
70 |
MetachunkList _chunks; |
50193 | 71 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
72 |
Metachunk* current_chunk() { return _chunks.first(); } |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
73 |
const Metachunk* current_chunk() const { return _chunks.first(); } |
50193 | 74 |
|
59257 | 75 |
// These structures take care of 1) prematurely deallocated Metaspace blocks |
76 |
// and 2) leftover space from retired chunks. |
|
77 |
// Only one of these is active; one will eventually go. We are still testing |
|
78 |
// which implementation is better suited to the task. _lom is default. Change |
|
79 |
// with -XX:+-MetaspaceUseLOM. |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
80 |
BlockFreelist* _block_freelist; |
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
81 |
LeftOverManager* _lom; |
50193 | 82 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
83 |
// Points to outside size counter which we are to increase/decrease when we allocate memory |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
84 |
// on behalf of a user or when we are destroyed. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
85 |
SizeAtomicCounter* const _total_used_words_counter; |
50193 | 86 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
87 |
const char* const _name; |
50193 | 88 |
|
58883
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58683
diff
changeset
|
89 |
// Whether or not this is a "micro loader" which is not expected to load more than one class. |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58683
diff
changeset
|
90 |
const bool _is_micro_loader; |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58683
diff
changeset
|
91 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
92 |
Mutex* lock() const { return _lock; } |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
93 |
ChunkManager* chunk_manager() const { return _chunk_manager; } |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
94 |
const ChunkAllocSequence* chunk_alloc_sequence() const { return _chunk_alloc_sequence; } |
50193 | 95 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
96 |
BlockFreelist* block_freelist() const { return _block_freelist; } |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
97 |
void create_block_freelist(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
98 |
void add_allocation_to_block_freelist(MetaWord* p, size_t word_size); |
50193 | 99 |
|
59155
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
100 |
LeftOverManager* lom() const { return _lom; } |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
101 |
void create_lom(); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
102 |
void add_allocation_to_lom(MetaWord* p, size_t word_size); |
b537e6386306
LeftOverBins as an optional replacement of free block dictionary which is rather ineffective
stuefe
parents:
58883
diff
changeset
|
103 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
104 |
// The remaining committed free space in the current chunk is chopped up and stored in the block |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
105 |
// free list for later use. As a result, the current chunk will remain current but completely |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
106 |
// used up. This is a preparation for calling allocate_new_current_chunk(). |
50193 | 107 |
void retire_current_chunk(); |
108 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
109 |
// Given a requested word size, will allocate a chunk large enough to at least fit that |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
110 |
// size, but may be larger according to internal heuristics. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
111 |
// |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
112 |
// On success, it will replace the current chunk with the newly allocated one, which will |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
113 |
// become the current chunk. The old current chunk should be retired beforehand. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
114 |
// |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
115 |
// May fail if we could not allocate a new chunk. In that case the current chunk remains |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
116 |
// unchanged and false is returned. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
117 |
bool allocate_new_current_chunk(size_t requested_word_size); |
50193 | 118 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
119 |
// Prematurely returns a metaspace allocation to the _block_freelists |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
120 |
// because it is not needed anymore (requires CLD lock to be active). |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
121 |
void deallocate_locked(MetaWord* p, size_t word_size); |
50193 | 122 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
123 |
// Returns true if the area indicated by pointer and size have actually been allocated |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
124 |
// from this space manager. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
125 |
DEBUG_ONLY(bool is_valid_area(MetaWord* p, size_t word_size) const;) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
126 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
127 |
public: |
50193 | 128 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
129 |
SpaceManager(ChunkManager* chunk_manager, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
130 |
const ChunkAllocSequence* alloc_sequence, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
131 |
Mutex* lock, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
132 |
SizeAtomicCounter* total_used_words_counter, |
58883
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58683
diff
changeset
|
133 |
const char* name, |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58683
diff
changeset
|
134 |
bool is_micro_loader); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
135 |
|
50193 | 136 |
~SpaceManager(); |
137 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
138 |
// Allocate memory from Metaspace. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
139 |
// 1) Attempt to allocate from the dictionary of deallocated blocks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
140 |
// 2) Attempt to allocate from the current chunk. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
141 |
// 3) Attempt to enlarge the current chunk in place if it is too small. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
142 |
// 4) Attempt to get a new chunk and allocate from that chunk. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
143 |
// At any point, if we hit a commit limit, we return NULL. |
50193 | 144 |
MetaWord* allocate(size_t word_size); |
145 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
146 |
// Prematurely returns a metaspace allocation to the _block_freelists because it is not |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
147 |
// needed anymore. |
50193 | 148 |
void deallocate(MetaWord* p, size_t word_size); |
149 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
150 |
// Update statistics. This walks all in-use chunks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
53244
diff
changeset
|
151 |
void add_to_statistics(sm_stats_t* out) const; |
50193 | 152 |
|
58227 | 153 |
DEBUG_ONLY(void verify() const;) |
154 |
DEBUG_ONLY(void verify_locked() const;) |
|
50193 | 155 |
|
156 |
}; |
|
157 |
||
158 |
} // namespace metaspace |
|
159 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50193
diff
changeset
|
160 |
#endif // SHARE_MEMORY_METASPACE_SPACEMANAGER_HPP |