Skip to content

Commit 8d8153e

Browse files
committed
8307958: Metaspace verification is slow causing extreme class unloading times
Reviewed-by: stuefe, coleenp
1 parent d877134 commit 8d8153e

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

src/hotspot/share/memory/metaspace/chunkManager.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace metaspace {
4949
// Return a single chunk to the freelist and adjust accounting. No merge is attempted.
5050
void ChunkManager::return_chunk_simple_locked(Metachunk* c) {
5151
assert_lock_strong(Metaspace_lock);
52-
DEBUG_ONLY(c->verify());
52+
SOMETIMES(c->verify();)
5353
_chunks.add(c);
5454
c->reset_used_words();
5555
// Tracing
@@ -82,7 +82,7 @@ void ChunkManager::split_chunk_and_add_splinters(Metachunk* c, chunklevel_t targ
8282
assert(c->prev() == nullptr && c->next() == nullptr, "Chunk must be outside of any list.");
8383

8484
DEBUG_ONLY(chunklevel::check_valid_level(target_level);)
85-
DEBUG_ONLY(c->verify();)
85+
SOMETIMES(c->verify();)
8686

8787
UL2(debug, "splitting chunk " METACHUNK_FORMAT " to " CHKLVL_FORMAT ".",
8888
METACHUNK_FORMAT_ARGS(c), target_level);
@@ -101,8 +101,8 @@ void ChunkManager::split_chunk_and_add_splinters(Metachunk* c, chunklevel_t targ
101101
} else {
102102
assert(c->committed_words() == committed_words_before, "Sanity");
103103
}
104-
c->verify();
105-
verify_locked();
104+
SOMETIMES(c->verify();)
105+
SOMETIMES(verify_locked();)
106106
SOMETIMES(c->vsnode()->verify_locked();)
107107
#endif
108108
InternalStats::inc_num_chunk_splits();
@@ -136,7 +136,7 @@ Metachunk* ChunkManager::get_chunk(chunklevel_t preferred_level, chunklevel_t ma
136136
// This may be either the GC threshold or MaxMetaspaceSize.
137137
Metachunk* ChunkManager::get_chunk_locked(chunklevel_t preferred_level, chunklevel_t max_level, size_t min_committed_words) {
138138
assert_lock_strong(Metaspace_lock);
139-
DEBUG_ONLY(verify_locked();)
139+
SOMETIMES(verify_locked();)
140140
DEBUG_ONLY(chunklevel::check_valid_level(max_level);)
141141
DEBUG_ONLY(chunklevel::check_valid_level(preferred_level);)
142142

@@ -255,8 +255,8 @@ void ChunkManager::return_chunk(Metachunk* c) {
255255
void ChunkManager::return_chunk_locked(Metachunk* c) {
256256
assert_lock_strong(Metaspace_lock);
257257
UL2(debug, ": returning chunk " METACHUNK_FORMAT ".", METACHUNK_FORMAT_ARGS(c));
258-
DEBUG_ONLY(c->verify();)
259-
assert(contains_chunk(c) == false, "A chunk to be added to the freelist must not be in the freelist already.");
258+
SOMETIMES(c->verify();)
259+
ASSERT_SOMETIMES(contains_chunk(c) == false, "A chunk to be added to the freelist must not be in the freelist already.");
260260
assert(c->is_in_use() || c->is_free(), "Unexpected chunk state");
261261
assert(!c->in_list(), "Remove from list first");
262262

@@ -272,15 +272,15 @@ void ChunkManager::return_chunk_locked(Metachunk* c) {
272272

273273
if (merged != nullptr) {
274274
InternalStats::inc_num_chunk_merges();
275-
DEBUG_ONLY(merged->verify());
275+
SOMETIMES(merged->verify();)
276276
// We did merge chunks and now have a bigger chunk.
277277
assert(merged->level() < orig_lvl, "Sanity");
278278
UL2(debug, "merged into chunk " METACHUNK_FORMAT ".", METACHUNK_FORMAT_ARGS(merged));
279279
c = merged;
280280
}
281281

282282
return_chunk_simple_locked(c);
283-
DEBUG_ONLY(verify_locked();)
283+
SOMETIMES(verify_locked();)
284284
SOMETIMES(c->vsnode()->verify_locked();)
285285
InternalStats::inc_num_chunks_returned_to_freelist();
286286
}
@@ -373,8 +373,8 @@ void ChunkManager::purge() {
373373
ls.cr();
374374
}
375375
}
376-
DEBUG_ONLY(_vslist->verify_locked());
377-
DEBUG_ONLY(verify_locked());
376+
SOMETIMES(_vslist->verify_locked();)
377+
SOMETIMES(verify_locked();)
378378
}
379379

380380
// Convenience methods to return the global class-space chunkmanager

src/hotspot/share/memory/metaspace/freeChunkList.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "memory/metaspace/counters.hpp"
3232
#include "memory/metaspace/metachunk.hpp"
3333
#include "memory/metaspace/metachunkList.hpp"
34+
#include "memory/metaspace/metaspaceCommon.hpp"
3435

3536
class outputStream;
3637

@@ -102,7 +103,7 @@ class FreeChunkList {
102103

103104
// Remove given chunk from anywhere in the list.
104105
Metachunk* remove(Metachunk* c) {
105-
assert(contains(c), "Must be contained here");
106+
ASSERT_SOMETIMES(contains(c), "Must be contained here");
106107
Metachunk* pred = c->prev();
107108
Metachunk* succ = c->next();
108109
if (pred) {
@@ -124,7 +125,7 @@ class FreeChunkList {
124125
}
125126

126127
void add(Metachunk* c) {
127-
assert(contains(c) == false, "Chunk already in freelist");
128+
ASSERT_SOMETIMES(contains(c) == false, "Chunk already in freelist");
128129
assert(_first == nullptr || _first->level() == c->level(),
129130
"List should only contains chunks of the same level.");
130131
// Uncommitted chunks go to the back, fully or partially committed to the front.

src/hotspot/share/memory/metaspace/metaspaceArena.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ MetaspaceArena::MetaspaceArena(ChunkManager* chunk_manager, const ArenaGrowthPol
129129

130130
MetaspaceArena::~MetaspaceArena() {
131131
#ifdef ASSERT
132-
verify();
132+
SOMETIMES(verify();)
133133
if (Settings::use_allocation_guard()) {
134-
verify_allocation_guards();
134+
SOMETIMES(verify_allocation_guards();)
135135
}
136136
#endif
137137

@@ -156,7 +156,7 @@ MetaspaceArena::~MetaspaceArena() {
156156
return_counter.count(), return_counter.total_size());
157157

158158
_total_used_words_counter->decrement_by(return_counter.total_size());
159-
DEBUG_ONLY(chunk_manager()->verify();)
159+
SOMETIMES(chunk_manager()->verify();)
160160
delete _fbl;
161161
UL(debug, ": dies.");
162162

@@ -368,7 +368,7 @@ void MetaspaceArena::deallocate_locked(MetaWord* p, size_t word_size) {
368368
size_t raw_word_size = get_raw_word_size_for_requested_word_size(word_size);
369369
add_allocation_to_fbl(p, raw_word_size);
370370

371-
DEBUG_ONLY(verify_locked();)
371+
SOMETIMES(verify_locked();)
372372
}
373373

374374
// Prematurely returns a metaspace allocation to the _block_freelists because it is not

src/hotspot/share/memory/metaspace/rootChunkArea.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void RootChunkArea::split(chunklevel_t target_level, Metachunk* c, FreeChunkList
9898
//
9999

100100
DEBUG_ONLY(check_pointer(c->base());)
101-
DEBUG_ONLY(c->verify();)
101+
SOMETIMES(c->verify();)
102102
assert(c->is_free(), "Can only split free chunks.");
103103

104104
DEBUG_ONLY(chunklevel::check_valid_level(target_level));
@@ -139,8 +139,8 @@ void RootChunkArea::split(chunklevel_t target_level, Metachunk* c, FreeChunkList
139139

140140
assert(c->level() == target_level, "Sanity");
141141

142-
DEBUG_ONLY(verify();)
143-
DEBUG_ONLY(c->verify();)
142+
SOMETIMES(verify();)
143+
SOMETIMES(c->verify();)
144144
}
145145

146146
// Given a chunk, attempt to merge it recursively with its neighboring chunks.
@@ -194,7 +194,7 @@ Metachunk* RootChunkArea::merge(Metachunk* c, FreeChunkListVector* freelists) {
194194
assert(!c->is_root_chunk(), "Cannot be merged further.");
195195
assert(c->is_free(), "Can only merge free chunks.");
196196

197-
DEBUG_ONLY(c->verify();)
197+
SOMETIMES(c->verify();)
198198

199199
log_trace(metaspace)("Attempting to merge chunk " METACHUNK_FORMAT ".", METACHUNK_FORMAT_ARGS(c));
200200

@@ -208,7 +208,7 @@ Metachunk* RootChunkArea::merge(Metachunk* c, FreeChunkListVector* freelists) {
208208

209209
// Note: this is either our buddy or a splinter of the buddy.
210210
Metachunk* const buddy = c->is_leader() ? c->next_in_vs() : c->prev_in_vs();
211-
DEBUG_ONLY(buddy->verify();)
211+
SOMETIMES(buddy->verify();)
212212

213213
// A buddy chunk must be of the same or higher level (so, same size or smaller)
214214
// never be larger.
@@ -270,14 +270,14 @@ Metachunk* RootChunkArea::merge(Metachunk* c, FreeChunkListVector* freelists) {
270270
}
271271

272272
result = c = leader;
273-
DEBUG_ONLY(leader->verify();)
273+
SOMETIMES(leader->verify();)
274274
}
275275
} while (!stop);
276276

277277
#ifdef ASSERT
278-
verify();
278+
SOMETIMES(verify();)
279279
if (result != nullptr) {
280-
result->verify();
280+
SOMETIMES(result->verify();)
281281
}
282282
#endif // ASSERT
283283
return result;
@@ -299,15 +299,15 @@ bool RootChunkArea::attempt_enlarge_chunk(Metachunk* c, FreeChunkListVector* fre
299299
// There is no real reason for this limitation other than it is not
300300
// needed on free chunks since they should be merged already:
301301
assert(c->is_in_use(), "Can only enlarge in use chunks.");
302-
DEBUG_ONLY(c->verify();)
302+
SOMETIMES(c->verify();)
303303

304304
if (!c->is_leader()) {
305305
return false;
306306
}
307307

308308
// We are the leader, so the buddy must follow us.
309309
Metachunk* const buddy = c->next_in_vs();
310-
DEBUG_ONLY(buddy->verify();)
310+
SOMETIMES(buddy->verify();)
311311

312312
// Of course buddy cannot be larger than us.
313313
assert(buddy->level() >= c->level(), "Sanity");
@@ -352,7 +352,7 @@ bool RootChunkArea::attempt_enlarge_chunk(Metachunk* c, FreeChunkListVector* fre
352352

353353
log_debug(metaspace)("Enlarged chunk " METACHUNK_FULL_FORMAT ".", METACHUNK_FULL_FORMAT_ARGS(c));
354354

355-
DEBUG_ONLY(verify());
355+
SOMETIMES(verify();)
356356
return true;
357357
}
358358

src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Metachunk* VirtualSpaceNode::allocate_root_chunk() {
322322
Metachunk* c = rca->alloc_root_chunk_header(this);
323323
assert(c->base() == loc && c->vsnode() == this &&
324324
c->is_free(), "Sanity");
325-
DEBUG_ONLY(c->verify();)
325+
SOMETIMES(c->verify();)
326326

327327
UL2(debug, "new root chunk " METACHUNK_FORMAT ".", METACHUNK_FORMAT_ARGS(c));
328328
return c;
@@ -338,7 +338,7 @@ void VirtualSpaceNode::split(chunklevel_t target_level, Metachunk* c, FreeChunkL
338338
assert_lock_strong(Metaspace_lock);
339339
// Get the area associated with this chunk and let it handle the splitting
340340
RootChunkArea* rca = _root_chunk_area_lut.get_area_by_address(c->base());
341-
DEBUG_ONLY(rca->verify_area_is_ideally_merged();)
341+
SOMETIMES(rca->verify_area_is_ideally_merged();)
342342
rca->split(target_level, c, freelists);
343343
}
344344

@@ -358,7 +358,7 @@ Metachunk* VirtualSpaceNode::merge(Metachunk* c, FreeChunkListVector* freelists)
358358
// Get the rca associated with this chunk and let it handle the merging
359359
RootChunkArea* rca = _root_chunk_area_lut.get_area_by_address(c->base());
360360
Metachunk* c2 = rca->merge(c, freelists);
361-
DEBUG_ONLY(rca->verify_area_is_ideally_merged();)
361+
SOMETIMES(rca->verify_area_is_ideally_merged();)
362362
return c2;
363363
}
364364

@@ -379,7 +379,7 @@ bool VirtualSpaceNode::attempt_enlarge_chunk(Metachunk* c, FreeChunkListVector*
379379
RootChunkArea* rca = _root_chunk_area_lut.get_area_by_address(c->base());
380380

381381
bool rc = rca->attempt_enlarge_chunk(c, freelists);
382-
DEBUG_ONLY(rca->verify_area_is_ideally_merged();)
382+
SOMETIMES(rca->verify_area_is_ideally_merged();)
383383
if (rc) {
384384
InternalStats::inc_num_chunks_enlarged();
385385
}

test/hotspot/jtreg/gtest/MetaspaceGtests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* java.xml
3838
* @requires vm.debug
3939
* @requires vm.flagless
40-
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:+UnlockDiagnosticVMOptions -XX:VerifyMetaspaceInterval=3
40+
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:+UnlockDiagnosticVMOptions -XX:VerifyMetaspaceInterval=1
4141
*/
4242

4343
/* @test id=balanced-with-guards
@@ -47,7 +47,7 @@
4747
* java.xml
4848
* @requires vm.debug
4949
* @requires vm.flagless
50-
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:VerifyMetaspaceInterval=3 -XX:+MetaspaceGuardAllocations
50+
* @run main/native GTestWrapper --gtest_filter=metaspace* -XX:VerifyMetaspaceInterval=1 -XX:+MetaspaceGuardAllocations
5151
*/
5252

5353
/* @test id=balanced-no-ccs

0 commit comments

Comments
 (0)