Skip to content

Commit 418b96e

Browse files
test fix for concurrent chunk pool pruning
1 parent 2b0d031 commit 418b96e

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/hotspot/share/memory/arena.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class ChunkPool {
8787
// Our four static pools
8888
static constexpr int _num_pools = 4;
8989
static ChunkPool _pools[_num_pools];
90+
volatile static bool _suspend_cleaning;
9091

9192
Chunk* _first;
9293
const size_t _size; // (inner payload) size of the chunks this pool serves
@@ -135,6 +136,7 @@ class ChunkPool {
135136
ChunkPool(size_t size) : _first(nullptr), _size(size) {}
136137

137138
static void clean() {
139+
if (_suspend_cleaning) return;
138140
NativeHeapTrimmer::SuspendMark sm("chunk pool cleaner");
139141
for (int i = 0; i < _num_pools; i++) {
140142
_pools[i].prune();
@@ -144,6 +146,9 @@ class ChunkPool {
144146
// Returns an initialized and null-terminated Chunk of requested size
145147
static Chunk* allocate_chunk(Arena* arena, size_t length, AllocFailType alloc_failmode);
146148
static void deallocate_chunk(Chunk* p);
149+
static void set_suspend_cleaning(bool suspend) {
150+
_suspend_cleaning = suspend;
151+
}
147152
};
148153

149154
static bool on_compiler_thread() {
@@ -230,6 +235,7 @@ void ChunkPool::deallocate_chunk(Chunk* c) {
230235
}
231236

232237
ChunkPool ChunkPool::_pools[] = { Chunk::size, Chunk::medium_size, Chunk::init_size, Chunk::tiny_size };
238+
volatile bool ChunkPool::_suspend_cleaning = false;
233239

234240
class ChunkPoolCleaner : public PeriodicTask {
235241
static const int cleaning_interval = 5000; // cleaning interval in ms
@@ -241,6 +247,10 @@ class ChunkPoolCleaner : public PeriodicTask {
241247
}
242248
};
243249

250+
void Arena::suspend_chunk_pool_cleaning(bool suspend) {
251+
ChunkPool::set_suspend_cleaning(suspend);
252+
}
253+
244254
void Arena::start_chunk_pool_cleaner_task() {
245255
#ifdef ASSERT
246256
static bool task_created = false;

src/hotspot/share/memory/arena.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class Arena : public CHeapObjBase {
159159

160160
public:
161161
static void initialize_chunk_pool();
162+
static void suspend_chunk_pool_cleaning(bool suspend);
162163

163164
// Start the chunk_pool cleaner task
164165
static void start_chunk_pool_cleaner_task();

test/hotspot/gtest/nmt/test_nmt_chunk_accounting.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ TEST_VM(NMTChunkAccounting, standard_chunks) {
100100
static const size_t GROW_SIZE = Chunk::size;
101101
static const size_t NUM_ALLOCS = 64;
102102
CountersSnapshot after_grow;
103+
Arena::suspend_chunk_pool_cleaning(true);
103104
{
104105
Arena arena(mtTest);
105106
const CountersSnapshot baseline = take_snapshot();

0 commit comments

Comments
 (0)