author | stuefe |
Fri, 15 Nov 2019 10:11:04 +0100 | |
branch | stuefe-new-metaspace-branch |
changeset 59107 | 245a39d9e24d |
parent 58883 | 08102295011d |
child 59155 | b537e6386306 |
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(). |
58883
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
106 |
assert(current_chunk() == NULL || |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
107 |
(_is_micro_loader || current_chunk()->free_below_committed_words() <= 10), "Must retire chunk beforehand"); |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
108 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
112 |
if (pref_level > min_level) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
113 |
pref_level = min_level; |
50193 | 114 |
} |
115 |
||
58882 | 116 |
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
|
117 |
CHKLVL_FORMAT ", min level: " CHKLVL_FORMAT ".", |
58882 | 118 |
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
|
119 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
120 |
Metachunk* c = _chunk_manager->get_chunk(min_level, pref_level); |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
121 |
if (c == NULL) { |
58882 | 122 |
log_debug(metaspace)(LOGFMT_SPCMGR ": failed to allocate new chunk for requested word size " SIZE_FORMAT ".", |
123 |
LOGFMT_SPCMGR_ARGS, requested_word_size); |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
124 |
return false; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
125 |
} |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
126 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
127 |
assert(c->is_in_use(), "Wrong chunk state."); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
128 |
assert(c->level() <= min_level && c->level() >= pref_level, "Sanity"); |
50193 | 129 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
130 |
_chunks.add(c); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
131 |
|
58882 | 132 |
log_debug(metaspace)(LOGFMT_SPCMGR ": allocated new chunk " METACHUNK_FORMAT " for requested word size " SIZE_FORMAT ".", |
133 |
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
|
134 |
|
58840 | 135 |
// Workaround for JDK-8233019: never return space allocated at a 32bit aligned address |
136 |
if (Settings::do_not_return_32bit_aligned_addresses() && |
|
137 |
(((intptr_t)c->base()) & 0xFFFFFFFF) == 0) |
|
138 |
{ |
|
139 |
bool ignored; |
|
140 |
c->allocate(1, &ignored); |
|
59107
245a39d9e24d
Fix counter mismatch after workaround for JDK-8233019
stuefe
parents:
58883
diff
changeset
|
141 |
_total_used_words_counter->increment(); |
58840 | 142 |
} |
143 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
144 |
return c; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
145 |
|
50193 | 146 |
} |
147 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
148 |
void SpaceManager::create_block_freelist() { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
149 |
assert(_block_freelist == NULL, "Only call once"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
150 |
_block_freelist = new BlockFreelist(); |
50193 | 151 |
} |
152 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
153 |
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
|
154 |
if (_block_freelist == NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
155 |
_block_freelist = new BlockFreelist(); // Create only on demand |
50193 | 156 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
157 |
_block_freelist->return_block(p, word_size); |
50193 | 158 |
} |
159 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
160 |
SpaceManager::SpaceManager(ChunkManager* chunk_manager, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
161 |
const ChunkAllocSequence* alloc_sequence, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
162 |
Mutex* lock, |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
163 |
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:
58882
diff
changeset
|
164 |
const char* name, |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
165 |
bool is_micro_loader) |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
166 |
: _lock(lock), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
167 |
_chunk_manager(chunk_manager), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
168 |
_chunk_alloc_sequence(alloc_sequence), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
169 |
_chunks(), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
170 |
_block_freelist(NULL), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
171 |
_total_used_words_counter(total_used_words_counter), |
58883
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
172 |
_name(name), |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
173 |
_is_micro_loader(is_micro_loader) |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
174 |
{ |
50193 | 175 |
} |
176 |
||
177 |
SpaceManager::~SpaceManager() { |
|
178 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
179 |
MutexLocker fcl(lock(), Mutex::_no_safepoint_check_flag); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
180 |
Metachunk* c = _chunks.first(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
181 |
Metachunk* c2 = NULL; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
182 |
while(c) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
183 |
// c may become invalid. Take care while iterating. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
184 |
c2 = c->next(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
185 |
_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
|
186 |
_chunks.remove(c); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
187 |
_chunk_manager->return_chunk(c); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
188 |
c = c2; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
189 |
} |
50193 | 190 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
191 |
DEBUG_ONLY(chunk_manager()->verify(true);) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
192 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
193 |
delete _block_freelist; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
194 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
195 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
196 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
197 |
// 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
|
198 |
// 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
|
199 |
// 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
|
200 |
void SpaceManager::retire_current_chunk() { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
201 |
assert_lock_strong(lock()); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
202 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
203 |
Metachunk* c = current_chunk(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
204 |
assert(c != NULL, "Sanity"); |
50193 | 205 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
206 |
// Side note: |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
207 |
// 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
|
208 |
// 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
|
209 |
// 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
|
210 |
// the code simple. |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
211 |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
212 |
size_t raw_remaining_words = c->free_below_committed_words(); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
213 |
size_t net_remaining_words = get_net_allocation_word_size(raw_remaining_words); |
58883
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
214 |
|
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
215 |
// Note: Micro class loaders (lambdas, reflection) are typically the vast majority of loaders. They |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
216 |
// will typically only once - if at all - ever retire a chunk, and the remaining size is typically |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
217 |
// very small. |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
218 |
// That means that the structure needed to manage this left over space will not see much action. However, |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
219 |
// that structure is expensive as well (pointer lists) and therefore we only should generate it if the |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
220 |
// benefit of managing free space out-weights the costs for that structure. |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
221 |
// Non-micro loaders may continue loading, deallocating and retiring more chunks, so the cost of that |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
222 |
// structure may amortize over time. But micro loaders probably never will. |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
223 |
const size_t dont_bother_below_word_size = _is_micro_loader ? 64 : 0; |
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
224 |
|
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
225 |
if (net_remaining_words > dont_bother_below_word_size) { |
58882 | 226 |
|
227 |
log_debug(metaspace)(LOGFMT_SPCMGR " @" PTR_FORMAT " : retiring chunk " METACHUNK_FULL_FORMAT ".", |
|
228 |
LOGFMT_SPCMGR_ARGS, p2i(this), METACHUNK_FULL_FORMAT_ARGS(c)); |
|
229 |
||
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
230 |
bool did_hit_limit = false; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
231 |
MetaWord* ptr = c->allocate(net_remaining_words, &did_hit_limit); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
232 |
assert(ptr != NULL && did_hit_limit == false, "Should have worked"); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
233 |
add_allocation_to_block_freelist(ptr, net_remaining_words); |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
234 |
_total_used_words_counter->increment_by(net_remaining_words); |
50193 | 235 |
|
58882 | 236 |
// After this operation: the current chunk should have (almost) no free committed space left. |
237 |
assert(current_chunk()->free_below_committed_words() <= highest_possible_delta_between_raw_and_net_size, |
|
238 |
"Chunk retiring did not work (current chunk " METACHUNK_FULL_FORMAT ").", |
|
239 |
METACHUNK_FULL_FORMAT_ARGS(current_chunk())); |
|
50193 | 240 |
|
58882 | 241 |
DEBUG_ONLY(verify_locked();) |
242 |
||
58883
08102295011d
Micro loaders shall not retire chunks if the costs for retiring chunks outqweights the saved space
stuefe
parents:
58882
diff
changeset
|
243 |
DEBUG_ONLY(InternalStats::inc_num_chunks_retired();) |
58882 | 244 |
} |
58227 | 245 |
|
50193 | 246 |
} |
247 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
248 |
// Allocate memory from Metaspace. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
249 |
// 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
|
250 |
// 2) Attempt to allocate from the current chunk. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
251 |
// 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
|
252 |
// 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
|
253 |
// 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
|
254 |
MetaWord* SpaceManager::allocate(size_t requested_word_size) { |
50193 | 255 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
256 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
50193 | 257 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
258 |
const size_t raw_word_size = get_raw_allocation_word_size(requested_word_size); |
50193 | 259 |
|
58882 | 260 |
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
|
261 |
"raw word size: " SIZE_FORMAT ".", |
58882 | 262 |
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
|
263 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
264 |
MetaWord* p = NULL; |
50193 | 265 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
266 |
bool did_hit_limit = false; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
267 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
268 |
// Allocate first chunk if needed. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
269 |
if (current_chunk() == NULL) { |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
270 |
if (allocate_new_current_chunk(raw_word_size) == false) { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
271 |
did_hit_limit = true; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
272 |
} else { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
273 |
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
|
274 |
} |
50193 | 275 |
} |
276 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
277 |
// 1) Attempt to allocate from the dictionary of deallocated blocks. |
50193 | 278 |
|
279 |
// Allocation from the dictionary is expensive in the sense that |
|
280 |
// the dictionary has to be searched for a size. Don't allocate |
|
281 |
// from the dictionary until it starts to get fat. Is this |
|
282 |
// a reasonable policy? Maybe an skinny dictionary is fast enough |
|
283 |
// for allocations. Do some profiling. JJJ |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
284 |
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
|
285 |
p = _block_freelist->get_block(raw_word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
286 |
|
50193 | 287 |
if (p != NULL) { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
288 |
DEBUG_ONLY(InternalStats::inc_num_allocs_from_deallocated_blocks();) |
58882 | 289 |
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
|
290 |
// 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
|
291 |
// 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
|
292 |
// Therefore we return here. |
e3aa9f95b85e
Fix issue with statistics which caused Metaspace::used_words() to be too high
stuefe
parents:
58382
diff
changeset
|
293 |
return p; |
50193 | 294 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
295 |
|
50193 | 296 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
297 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
298 |
// 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
|
299 |
if (p == NULL && !did_hit_limit) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
300 |
p = current_chunk()->allocate(raw_word_size, &did_hit_limit); |
58882 | 301 |
log_trace(metaspace)(LOGFMT_SPCMGR ": .. taken from current chunk.", LOGFMT_SPCMGR_ARGS); |
50193 | 302 |
} |
303 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
304 |
// 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
|
305 |
// (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
|
306 |
if (p == NULL && !did_hit_limit) { |
53970 | 307 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
308 |
// 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
|
309 |
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
|
310 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
311 |
DEBUG_ONLY(InternalStats::inc_num_allocs_failed_chunk_too_small();) |
50193 | 312 |
|
58382
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
313 |
// 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
|
314 |
// 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
|
315 |
// 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
|
316 |
// 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
|
317 |
// 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
|
318 |
// 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
|
319 |
// 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
|
320 |
// 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
|
321 |
if (Settings::enlarge_chunks_in_place() && // 0 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
322 |
current_chunk()->is_root_chunk() == false && // 1 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
323 |
current_chunk()->is_leader() && // 2 |
2e16658b7776
do not enlarge chunks faster than chunk alloc strategy would allow
stuefe
parents:
58228
diff
changeset
|
324 |
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
|
325 |
_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
|
326 |
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
|
327 |
{ |
50193 | 328 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
329 |
if (_chunk_manager->attempt_enlarge_chunk(current_chunk())) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
330 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
331 |
// Re-attempt allocation. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
332 |
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
|
333 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
334 |
if (p != NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
335 |
DEBUG_ONLY(InternalStats::inc_num_chunk_enlarged();) |
58882 | 336 |
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
|
337 |
} |
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 |
} |
50193 | 340 |
} |
341 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
342 |
// 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
|
343 |
// limit, in which case we return NULL. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
344 |
if (p == NULL && !did_hit_limit) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
345 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
346 |
// 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
|
347 |
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
|
348 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
349 |
// 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
|
350 |
// but may still have free committed words. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
351 |
retire_current_chunk(); |
50193 | 352 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
353 |
// Allocate a new chunk. |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
354 |
if (allocate_new_current_chunk(raw_word_size) == false) { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
355 |
did_hit_limit = true; |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
356 |
} else { |
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
357 |
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
|
358 |
p = current_chunk()->allocate(raw_word_size, &did_hit_limit); |
58882 | 359 |
log_trace(metaspace)(LOGFMT_SPCMGR ": .. allocated new chunk " CHKLVL_FORMAT " and taken from that.", |
360 |
LOGFMT_SPCMGR_ARGS, current_chunk()->level()); |
|
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
361 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
362 |
|
50193 | 363 |
} |
364 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
365 |
assert(p != NULL || (p == NULL && did_hit_limit), "Sanity"); |
50193 | 366 |
|
58227 | 367 |
SOMETIMES(verify_locked();) |
368 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
369 |
if (p == NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
370 |
DEBUG_ONLY(InternalStats::inc_num_allocs_failed_limit();) |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
371 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
372 |
DEBUG_ONLY(InternalStats::inc_num_allocs();) |
58085
a5f523f2ff91
Fix jtreg/vmTestbase/metaspace/shrink_grow/CompressedClassSpaceSize
stuefe
parents:
58063
diff
changeset
|
373 |
_total_used_words_counter->increment_by(raw_word_size); |
50193 | 374 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
375 |
|
58882 | 376 |
log_trace(metaspace)(LOGFMT_SPCMGR ": returned " PTR_FORMAT ".", |
377 |
LOGFMT_SPCMGR_ARGS, p2i(p)); |
|
50193 | 378 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
379 |
return p; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
380 |
|
50193 | 381 |
} |
382 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
383 |
// 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
|
384 |
// 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
|
385 |
void SpaceManager::deallocate_locked(MetaWord* p, size_t word_size) { |
50193 | 386 |
assert_lock_strong(lock()); |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
387 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
388 |
// Allocations and deallocations are in raw_word_size |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
389 |
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
|
390 |
|
58882 | 391 |
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
|
392 |
", word size: " SIZE_FORMAT ", raw size: " SIZE_FORMAT ".", |
58882 | 393 |
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
|
394 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
395 |
assert(current_chunk() != NULL, "SpaceManager is empty."); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
396 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
397 |
assert(is_valid_area(p, word_size), |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
398 |
"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
|
399 |
p2i(p), p2i(p + word_size)); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
400 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
401 |
// 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
|
402 |
// 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
|
403 |
if (current_chunk()->attempt_rollback_allocation(p, raw_word_size)) { |
58882 | 404 |
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
|
405 |
return; |
50193 | 406 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
407 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
408 |
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
|
409 |
|
58227 | 410 |
DEBUG_ONLY(verify_locked();) |
411 |
||
50193 | 412 |
} |
413 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
414 |
// 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
|
415 |
// needed anymore. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
416 |
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
|
417 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
418 |
deallocate_locked(p, word_size); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
419 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
420 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
421 |
// Update statistics. This walks all in-use chunks. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
422 |
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
|
423 |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53970
diff
changeset
|
424 |
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
|
425 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
426 |
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
|
427 |
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
|
428 |
ucs.num ++; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
429 |
ucs.word_size += c->word_size(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
430 |
ucs.committed_words += c->committed_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
431 |
ucs.used_words += c->used_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
432 |
// 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
|
433 |
if (c == current_chunk()) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
434 |
ucs.free_words += c->free_below_committed_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
435 |
} else { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
436 |
ucs.waste_words += c->free_below_committed_words(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
437 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
438 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
439 |
|
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
440 |
if (block_freelist() != NULL) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
441 |
out->free_blocks_num += block_freelist()->num_blocks(); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
442 |
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
|
443 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
444 |
|
58227 | 445 |
SOMETIMES(out->verify();) |
58683 | 446 |
|
50193 | 447 |
} |
448 |
||
449 |
#ifdef ASSERT |
|
450 |
||
58227 | 451 |
void SpaceManager::verify_locked() const { |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
452 |
|
58227 | 453 |
assert_lock_strong(lock()); |
50193 | 454 |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
455 |
assert(_chunk_alloc_sequence != NULL && _chunk_manager != NULL, "Sanity"); |
50193 | 456 |
|
58227 | 457 |
_chunks.verify(); |
458 |
||
459 |
} |
|
460 |
||
461 |
void SpaceManager::verify() const { |
|
462 |
||
463 |
MutexLocker cl(lock(), Mutex::_no_safepoint_check_flag); |
|
464 |
verify_locked(); |
|
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
465 |
|
50193 | 466 |
} |
467 |
||
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
468 |
// 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
|
469 |
// from this space manager. |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
470 |
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
|
471 |
assert(p != NULL && word_size > 0, "Sanity"); |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
472 |
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
|
473 |
if (c->is_valid_pointer(p)) { |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
474 |
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
|
475 |
return true; |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
476 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
477 |
} |
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
478 |
return false; |
50193 | 479 |
} |
58063
bdf136b8ae0e
Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
54623
diff
changeset
|
480 |
|
50193 | 481 |
#endif // ASSERT |
482 |
||
483 |
||
484 |
} // namespace metaspace |
|
485 |