author | stuefe |
Fri, 01 Nov 2019 13:02:09 +0100 | |
branch | stuefe-new-metaspace-branch |
changeset 58882 | 58b20be7bc04 |
parent 58840 | 7678903a348f |
child 58883 | 08102295011d |
permissions | -rw-r--r-- |
50193 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53970
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:
54623
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 |
#include "precompiled.hpp" |
|
26 |
||
27 |
#include "logging/log.hpp" |
|
28 |
#include "logging/logStream.hpp" |
|
29 |
#include "memory/metaspace/chunkManager.hpp" |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
30 |
#include "memory/metaspace/internStat.hpp" |
50193 | 31 |
#include "memory/metaspace/metachunk.hpp" |
32 |
#include "memory/metaspace/metaDebug.hpp" |
|
33 |
#include "memory/metaspace/metaspaceCommon.hpp" |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
34 |
#include "memory/metaspace/metaspaceStatistics.hpp" |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
35 |
#include "memory/metaspace/smallBlocks.hpp" |
50193 | 36 |
#include "memory/metaspace/spaceManager.hpp" |
37 |
#include "memory/metaspace/virtualSpaceList.hpp" |
|
38 |
#include "runtime/atomic.hpp" |
|
39 |
#include "runtime/init.hpp" |
|
40 |
#include "services/memoryService.hpp" |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
41 |
#include "utilities/align.hpp" |
50193 | 42 |
#include "utilities/debug.hpp" |
43 |
#include "utilities/globalDefinitions.hpp" |
|
44 |
||
45 |
namespace metaspace { |
|
46 |
||
58882 | 47 |
#define LOGFMT_SPCMGR "SpcMgr @" PTR_FORMAT " (%s)" |
48 |
#define LOGFMT_SPCMGR_ARGS p2i(this), this->_name |
|
49 |
||
50 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
51 |
// Given a net allocation word size, return the raw word size |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
52 |
// we need to actually allocate in order to: |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
53 |
// 1) be able to deallocate the allocation - deallocated blocks are stored either in SmallBlocks |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
54 |
// (an array of short lists) or, beyond a certain size, in a dictionary tree. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
55 |
// For that to work the allocated block must be at least three words. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
56 |
// 2) be aligned to sizeof(void*) |
50193 | 57 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
58 |
// Note: externally visible for gtests. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
59 |
//static |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
60 |
size_t get_raw_allocation_word_size(size_t net_word_size) { |
50193 | 61 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
62 |
size_t byte_size = net_word_size * BytesPerWord; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
63 |
byte_size = MAX2(byte_size, (size_t)SmallBlocks::small_block_min_byte_size()); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
64 |
byte_size = align_up(byte_size, Metachunk::allocation_alignment_bytes); |
50193 | 65 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
66 |
size_t word_size = byte_size / BytesPerWord; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
67 |
assert(word_size * BytesPerWord == byte_size, "Sanity"); |
50193 | 68 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
69 |
return word_size; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
70 |
|
50193 | 71 |
} |
72 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
73 |
static const size_t highest_possible_delta_between_raw_and_net_size = get_raw_allocation_word_size(1) - 1; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
74 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
75 |
// The inverse function to get_raw_allocation_word_size: Given a raw size, return the max net word size |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
76 |
// fitting into it. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
77 |
static size_t get_net_allocation_word_size(size_t raw_word_size) { |
50193 | 78 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
79 |
size_t byte_size = raw_word_size * BytesPerWord; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
80 |
byte_size = align_down(byte_size, Metachunk::allocation_alignment_bytes); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
81 |
if (byte_size < SmallBlocks::small_block_min_byte_size()) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
82 |
return 0; |
50193 | 83 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
84 |
return byte_size / BytesPerWord; |
50193 | 85 |
|
86 |
} |
|
87 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
88 |
// 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
|
89 |
// size, but may be larger according to internal heuristics. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
90 |
// |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
91 |
// 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
|
92 |
// 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
|
93 |
// |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
94 |
// 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
|
95 |
// unchanged and false is returned. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
96 |
bool SpaceManager::allocate_new_current_chunk(size_t requested_word_size) { |
50193 | 97 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
98 |
assert_lock_strong(lock()); |
50193 | 99 |
|
58228 | 100 |
guarantee(requested_word_size <= chklvl::MAX_CHUNK_WORD_SIZE, |
101 |
"Requested size too large (" SIZE_FORMAT ") - max allowed size per allocation is " SIZE_FORMAT ".", |
|
102 |
requested_word_size, chklvl::MAX_CHUNK_WORD_SIZE); |
|
50193 | 103 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
104 |
// If we have a current chunk, it should have been retired (almost empty) beforehand. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
105 |
// See: retire_current_chunk(). |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
106 |
assert(current_chunk() == NULL || current_chunk()->free_below_committed_words() <= 10, "Must retire chunk beforehand"); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
107 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
108 |
const chklvl_t min_level = chklvl::level_fitting_word_size(requested_word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
109 |
chklvl_t pref_level = _chunk_alloc_sequence->get_next_chunk_level(_chunks.size()); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
110 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
111 |
if (pref_level > min_level) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
112 |
pref_level = min_level; |
50193 | 113 |
} |
114 |
||
58882 | 115 |
log_trace(metaspace)(LOGFMT_SPCMGR ": requested word size_ " SIZE_FORMAT ", num chunks so far: %d, preferred level: " |
58716
960e372a6065
Fix error in chunk allocation strategy which caused small chunks to dominate
stuefe
parents:
58683
diff
changeset
|
116 |
CHKLVL_FORMAT ", min level: " CHKLVL_FORMAT ".", |
58882 | 117 |
LOGFMT_SPCMGR_ARGS, requested_word_size, _chunks.size(), pref_level, min_level); |
58716
960e372a6065
Fix error in chunk allocation strategy which caused small chunks to dominate
stuefe
parents:
58683
diff
changeset
|
118 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
119 |
Metachunk* c = _chunk_manager->get_chunk(min_level, pref_level); |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
120 |
if (c == NULL) { |
58882 | 121 |
log_debug(metaspace)(LOGFMT_SPCMGR ": failed to allocate new chunk for requested word size " SIZE_FORMAT ".", |
122 |
LOGFMT_SPCMGR_ARGS, requested_word_size); |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
123 |
return false; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
124 |
} |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
125 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
126 |
assert(c->is_in_use(), "Wrong chunk state."); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
127 |
assert(c->level() <= min_level && c->level() >= pref_level, "Sanity"); |
50193 | 128 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
129 |
_chunks.add(c); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
130 |
|
58882 | 131 |
log_debug(metaspace)(LOGFMT_SPCMGR ": allocated new chunk " METACHUNK_FORMAT " for requested word size " SIZE_FORMAT ".", |
132 |
LOGFMT_SPCMGR_ARGS, METACHUNK_FORMAT_ARGS(c), requested_word_size); |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
133 |
|
58840 | 134 |
// Workaround for JDK-8233019: never return space allocated at a 32bit aligned address |
135 |
if (Settings::do_not_return_32bit_aligned_addresses() && |
|
136 |
(((intptr_t)c->base()) & 0xFFFFFFFF) == 0) |
|
137 |
{ |
|
138 |
bool ignored; |
|
139 |
c->allocate(1, &ignored); |
|
140 |
} |
|
141 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
142 |
return c; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
143 |
|
50193 | 144 |
} |
145 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
146 |
void SpaceManager::create_block_freelist() { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
147 |
assert(_block_freelist == NULL, "Only call once"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
148 |
_block_freelist = new BlockFreelist(); |
50193 | 149 |
} |
150 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
151 |
void SpaceManager::add_allocation_to_block_freelist(MetaWord* p, size_t word_size) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
152 |
if (_block_freelist == NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
153 |
_block_freelist = new BlockFreelist(); // Create only on demand |
50193 | 154 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
155 |
_block_freelist->return_block(p, word_size); |
50193 | 156 |
} |
157 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
158 |
SpaceManager::SpaceManager(ChunkManager* chunk_manager, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
159 |
const ChunkAllocSequence* alloc_sequence, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
160 |
Mutex* lock, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
161 |
SizeAtomicCounter* total_used_words_counter, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
162 |
const char* name) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
163 |
: _lock(lock), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
164 |
_chunk_manager(chunk_manager), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
165 |
_chunk_alloc_sequence(alloc_sequence), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
166 |
_chunks(), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
167 |
_block_freelist(NULL), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
168 |
_total_used_words_counter(total_used_words_counter), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
169 |
_name(name) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
170 |
{ |
50193 | 171 |
} |
172 |
||
173 |
SpaceManager::~SpaceManager() { |
|
174 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
175 |
MutexLocker fcl(lock(), Mutex::_no_safepoint_check_flag); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
176 |
Metachunk* c = _chunks.first(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
177 |
Metachunk* c2 = NULL; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
178 |
while(c) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
179 |
// c may become invalid. Take care while iterating. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
180 |
c2 = c->next(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
181 |
_total_used_words_counter->decrement_by(c->used_words()); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
182 |
_chunks.remove(c); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
183 |
_chunk_manager->return_chunk(c); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
184 |
c = c2; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
185 |
} |
50193 | 186 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
187 |
DEBUG_ONLY(chunk_manager()->verify(true);) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
188 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
189 |
delete _block_freelist; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
190 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
191 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
192 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
193 |
// 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
|
194 |
// 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
|
195 |
// used up. This is a preparation for calling allocate_new_current_chunk(). |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
196 |
void SpaceManager::retire_current_chunk() { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
197 |
assert_lock_strong(lock()); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
198 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
199 |
Metachunk* c = current_chunk(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
200 |
assert(c != NULL, "Sanity"); |
50193 | 201 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
202 |
// Side note: |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
203 |
// In theory it could happen that we are asked to retire a completely empty chunk. This may be the |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
204 |
// result of rolled back allocations (see deallocate in place) and a lot of luck. |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
205 |
// But since these cases should be exceedingly rare, we do not handle them special in order to keep |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
206 |
// the code simple. |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
207 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
208 |
size_t raw_remaining_words = c->free_below_committed_words(); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
209 |
size_t net_remaining_words = get_net_allocation_word_size(raw_remaining_words); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
210 |
if (net_remaining_words > 0) { |
58882 | 211 |
|
212 |
log_debug(metaspace)(LOGFMT_SPCMGR " @" PTR_FORMAT " : retiring chunk " METACHUNK_FULL_FORMAT ".", |
|
213 |
LOGFMT_SPCMGR_ARGS, p2i(this), METACHUNK_FULL_FORMAT_ARGS(c)); |
|
214 |
||
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
215 |
bool did_hit_limit = false; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
216 |
MetaWord* ptr = c->allocate(net_remaining_words, &did_hit_limit); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
217 |
assert(ptr != NULL && did_hit_limit == false, "Should have worked"); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
218 |
add_allocation_to_block_freelist(ptr, net_remaining_words); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
219 |
_total_used_words_counter->increment_by(net_remaining_words); |
50193 | 220 |
|
58882 | 221 |
// After this operation: the current chunk should have (almost) no free committed space left. |
222 |
assert(current_chunk()->free_below_committed_words() <= highest_possible_delta_between_raw_and_net_size, |
|
223 |
"Chunk retiring did not work (current chunk " METACHUNK_FULL_FORMAT ").", |
|
224 |
METACHUNK_FULL_FORMAT_ARGS(current_chunk())); |
|
50193 | 225 |
|
58882 | 226 |
DEBUG_ONLY(verify_locked();) |
227 |
||
228 |
} |
|
58227 | 229 |
|
50193 | 230 |
} |
231 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
232 |
// Allocate memory from Metaspace. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
233 |
// 1) Attempt to allocate from the dictionary of deallocated blocks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
234 |
// 2) Attempt to allocate from the current chunk. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
235 |
// 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:
54623
diff
changeset
|
236 |
// 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:
54623
diff
changeset
|
237 |
// At any point, if we hit a commit limit, we return NULL. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
238 |
MetaWord* SpaceManager::allocate(size_t requested_word_size) { |
50193 | 239 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
240 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
50193 | 241 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
242 |
const size_t raw_word_size = get_raw_allocation_word_size(requested_word_size); |
50193 | 243 |
|
58882 | 244 |
log_debug(metaspace)(LOGFMT_SPCMGR ": requested " SIZE_FORMAT " words, " |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
245 |
"raw word size: " SIZE_FORMAT ".", |
58882 | 246 |
LOGFMT_SPCMGR_ARGS, requested_word_size, raw_word_size); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
247 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
248 |
MetaWord* p = NULL; |
50193 | 249 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
250 |
bool did_hit_limit = false; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
251 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
252 |
// Allocate first chunk if needed. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
253 |
if (current_chunk() == NULL) { |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
254 |
if (allocate_new_current_chunk(raw_word_size) == false) { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
255 |
did_hit_limit = true; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
256 |
} else { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
257 |
assert(current_chunk() != NULL && current_chunk()->free_words() >= raw_word_size, "Sanity"); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
258 |
} |
50193 | 259 |
} |
260 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
261 |
// 1) Attempt to allocate from the dictionary of deallocated blocks. |
50193 | 262 |
|
263 |
// Allocation from the dictionary is expensive in the sense that |
|
264 |
// the dictionary has to be searched for a size. Don't allocate |
|
265 |
// from the dictionary until it starts to get fat. Is this |
|
266 |
// a reasonable policy? Maybe an skinny dictionary is fast enough |
|
267 |
// for allocations. Do some profiling. JJJ |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
268 |
if (_block_freelist != NULL && _block_freelist->total_size() > Settings::allocation_from_dictionary_limit()) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
269 |
p = _block_freelist->get_block(raw_word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
270 |
|
50193 | 271 |
if (p != NULL) { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
272 |
DEBUG_ONLY(InternalStats::inc_num_allocs_from_deallocated_blocks();) |
58882 | 273 |
log_trace(metaspace)(LOGFMT_SPCMGR ": .. taken from freelist.", LOGFMT_SPCMGR_ARGS); |
58475
e3aa9f95b85e
Fix issue with statistics which caused Metaspace::used_words() to be too high
stuefe
parents:
58382
diff
changeset
|
274 |
// Note: space in the freeblock dictionary counts as used (see retire_current_chunk()) - |
e3aa9f95b85e
Fix issue with statistics which caused Metaspace::used_words() to be too high
stuefe
parents:
58382
diff
changeset
|
275 |
// that means that we must not increase the used counter again when allocating from the dictionary. |
e3aa9f95b85e
Fix issue with statistics which caused Metaspace::used_words() to be too high
stuefe
parents:
58382
diff
changeset
|
276 |
// Therefore we return here. |
e3aa9f95b85e
Fix issue with statistics which caused Metaspace::used_words() to be too high
stuefe
parents:
58382
diff
changeset
|
277 |
return p; |
50193 | 278 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
279 |
|
50193 | 280 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
281 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
282 |
// 2) Failing that, attempt to allocate from the current chunk. If we hit commit limit, return NULL. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
283 |
if (p == NULL && !did_hit_limit) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
284 |
p = current_chunk()->allocate(raw_word_size, &did_hit_limit); |
58882 | 285 |
log_trace(metaspace)(LOGFMT_SPCMGR ": .. taken from current chunk.", LOGFMT_SPCMGR_ARGS); |
50193 | 286 |
} |
287 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
288 |
// 3) Failing that because the remaining chunk space is too small for the requested size |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
289 |
// (and not because commit limit), attempt to enlarge the chunk in place. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
290 |
if (p == NULL && !did_hit_limit) { |
53970 | 291 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
292 |
// Since we did not hit the commit limit, the current chunk must have been too small. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
293 |
assert(current_chunk()->free_words() < raw_word_size, "Sanity"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
294 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
295 |
DEBUG_ONLY(InternalStats::inc_num_allocs_failed_chunk_too_small();) |
50193 | 296 |
|
58382
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
297 |
// Under certain conditions we can just attempt to enlarge the chunk - fusing it with its follower |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
298 |
// chunk to produce a chunk double the size (level decreased by 1). |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
299 |
// 0) only if it is not switched off |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
300 |
// 1) obviously, this only works for non-root chunks |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
301 |
// 2) ... which are leader of their buddy pair. |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
302 |
// 3) only if the requested allocation would fit into a thus enlarged chunk |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
303 |
// 4) do not grow memory faster than what the chunk allocation strategy would allow |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
304 |
// 5) as a safety feature, only below a certain limit |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
305 |
if (Settings::enlarge_chunks_in_place() && // 0 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
306 |
current_chunk()->is_root_chunk() == false && // 1 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
307 |
current_chunk()->is_leader() && // 2 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
308 |
current_chunk()->word_size() + current_chunk()->free_words() >= requested_word_size && // 3 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
309 |
_chunk_alloc_sequence->get_next_chunk_level(_chunks.size()) <= current_chunk()->level() && // 4 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
310 |
current_chunk()->word_size() <= Settings::enlarge_chunks_in_place_max_word_size()) // 5 |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
311 |
{ |
50193 | 312 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
313 |
if (_chunk_manager->attempt_enlarge_chunk(current_chunk())) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
314 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
315 |
// Re-attempt allocation. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
316 |
p = current_chunk()->allocate(raw_word_size, &did_hit_limit); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
317 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
318 |
if (p != NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
319 |
DEBUG_ONLY(InternalStats::inc_num_chunk_enlarged();) |
58882 | 320 |
log_trace(metaspace)(LOGFMT_SPCMGR ": .. taken from current chunk (enlarged chunk).", LOGFMT_SPCMGR_ARGS); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
321 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
322 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
323 |
} |
50193 | 324 |
} |
325 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
326 |
// 4) Failing that, attempt to get a new chunk and allocate from that chunk. Again, we may hit a commit |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
327 |
// limit, in which case we return NULL. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
328 |
if (p == NULL && !did_hit_limit) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
329 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
330 |
// Since we did not hit the commit limit, the current chunk must have been too small. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
331 |
assert(current_chunk()->free_words() < raw_word_size, "Sanity"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
332 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
333 |
// Before we allocate a new chunk we need to retire the old chunk, which is too small to serve our request |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
334 |
// but may still have free committed words. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
335 |
retire_current_chunk(); |
50193 | 336 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
337 |
DEBUG_ONLY(InternalStats::inc_num_chunks_retired();) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
338 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
339 |
// Allocate a new chunk. |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
340 |
if (allocate_new_current_chunk(raw_word_size) == false) { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
341 |
did_hit_limit = true; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
342 |
} else { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
343 |
assert(current_chunk() != NULL && current_chunk()->free_words() >= raw_word_size, "Sanity"); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
344 |
p = current_chunk()->allocate(raw_word_size, &did_hit_limit); |
58882 | 345 |
log_trace(metaspace)(LOGFMT_SPCMGR ": .. allocated new chunk " CHKLVL_FORMAT " and taken from that.", |
346 |
LOGFMT_SPCMGR_ARGS, current_chunk()->level()); |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
347 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
348 |
|
50193 | 349 |
} |
350 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
351 |
assert(p != NULL || (p == NULL && did_hit_limit), "Sanity"); |
50193 | 352 |
|
58227 | 353 |
SOMETIMES(verify_locked();) |
354 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
355 |
if (p == NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
356 |
DEBUG_ONLY(InternalStats::inc_num_allocs_failed_limit();) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
357 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
358 |
DEBUG_ONLY(InternalStats::inc_num_allocs();) |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
359 |
_total_used_words_counter->increment_by(raw_word_size); |
50193 | 360 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
361 |
|
58882 | 362 |
log_trace(metaspace)(LOGFMT_SPCMGR ": returned " PTR_FORMAT ".", |
363 |
LOGFMT_SPCMGR_ARGS, p2i(p)); |
|
50193 | 364 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
365 |
return p; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
366 |
|
50193 | 367 |
} |
368 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
369 |
// Prematurely returns a metaspace allocation to the _block_freelists |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
370 |
// 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:
54623
diff
changeset
|
371 |
void SpaceManager::deallocate_locked(MetaWord* p, size_t word_size) { |
50193 | 372 |
assert_lock_strong(lock()); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
373 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
374 |
// Allocations and deallocations are in raw_word_size |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
375 |
size_t raw_word_size = get_raw_allocation_word_size(word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
376 |
|
58882 | 377 |
log_debug(metaspace)(LOGFMT_SPCMGR ": deallocating " PTR_FORMAT |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
378 |
", word size: " SIZE_FORMAT ", raw size: " SIZE_FORMAT ".", |
58882 | 379 |
LOGFMT_SPCMGR_ARGS, p2i(p), word_size, raw_word_size); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
380 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
381 |
assert(current_chunk() != NULL, "SpaceManager is empty."); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
382 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
383 |
assert(is_valid_area(p, word_size), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
384 |
"Pointer range not part of this SpaceManager and cannot be deallocated: (" PTR_FORMAT ".." PTR_FORMAT ").", |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
385 |
p2i(p), p2i(p + word_size)); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
386 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
387 |
// If this allocation has just been allocated from the current chunk, it may still be on the top of the |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
388 |
// current chunk. In that case, just roll back the allocation. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
389 |
if (current_chunk()->attempt_rollback_allocation(p, raw_word_size)) { |
58882 | 390 |
log_trace(metaspace)(LOGFMT_SPCMGR ": ... rollback succeeded.", LOGFMT_SPCMGR_ARGS); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
391 |
return; |
50193 | 392 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
393 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
394 |
add_allocation_to_block_freelist(p, raw_word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
395 |
|
58227 | 396 |
DEBUG_ONLY(verify_locked();) |
397 |
||
50193 | 398 |
} |
399 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
400 |
// 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:
54623
diff
changeset
|
401 |
// needed anymore. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
402 |
void SpaceManager::deallocate(MetaWord* p, size_t word_size) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
403 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
404 |
deallocate_locked(p, word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
405 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
406 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
407 |
// Update statistics. This walks all in-use chunks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
408 |
void SpaceManager::add_to_statistics(sm_stats_t* out) const { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
409 |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53970
diff
changeset
|
410 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
411 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
412 |
for (const Metachunk* c = _chunks.first(); c != NULL; c = c->next()) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
413 |
in_use_chunk_stats_t& ucs = out->stats[c->level()]; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
414 |
ucs.num ++; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
415 |
ucs.word_size += c->word_size(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
416 |
ucs.committed_words += c->committed_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
417 |
ucs.used_words += c->used_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
418 |
// Note: for free and waste, we only count what's committed. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
419 |
if (c == current_chunk()) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
420 |
ucs.free_words += c->free_below_committed_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
421 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
422 |
ucs.waste_words += c->free_below_committed_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
423 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
424 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
425 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
426 |
if (block_freelist() != NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
427 |
out->free_blocks_num += block_freelist()->num_blocks(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
428 |
out->free_blocks_word_size += block_freelist()->total_size(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
429 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
430 |
|
58227 | 431 |
SOMETIMES(out->verify();) |
58683 | 432 |
|
50193 | 433 |
} |
434 |
||
435 |
#ifdef ASSERT |
|
436 |
||
58227 | 437 |
void SpaceManager::verify_locked() const { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
438 |
|
58227 | 439 |
assert_lock_strong(lock()); |
50193 | 440 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
441 |
assert(_chunk_alloc_sequence != NULL && _chunk_manager != NULL, "Sanity"); |
50193 | 442 |
|
58227 | 443 |
_chunks.verify(); |
444 |
||
445 |
} |
|
446 |
||
447 |
void SpaceManager::verify() const { |
|
448 |
||
449 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
|
450 |
verify_locked(); |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
451 |
|
50193 | 452 |
} |
453 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
454 |
// 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:
54623
diff
changeset
|
455 |
// from this space manager. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
456 |
bool SpaceManager::is_valid_area(MetaWord* p, size_t word_size) const { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
457 |
assert(p != NULL && word_size > 0, "Sanity"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
458 |
for (const Metachunk* c = _chunks.first(); c != NULL; c = c->next()) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
459 |
if (c->is_valid_pointer(p)) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
460 |
assert(c->is_valid_pointer(p + word_size - 1), "Range partly oob"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
461 |
return true; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
462 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
463 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
464 |
return false; |
50193 | 465 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
466 |
|
50193 | 467 |
#endif // ASSERT |
468 |
||
469 |
||
470 |
} // namespace metaspace |
|
471 |