Skip to content

Commit bc61484

Browse files
committedFeb 15, 2022
8280136: Serial: Remove unnecessary use of ExpandHeap_lock
Reviewed-by: iwalulya, kbarrett, sjohanss
1 parent 2112a9d commit bc61484

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed
 

‎src/hotspot/share/gc/parallel/mutableSpace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
217217

218218
// Only used by oldgen allocation.
219219
bool MutableSpace::needs_expand(size_t word_size) const {
220-
assert_lock_strong(ExpandHeap_lock);
220+
assert_lock_strong(PSOldGenExpand_lock);
221221
// Holding the lock means end is stable. So while top may be advancing
222222
// via concurrent allocations, there is no need to order the reads of top
223223
// and end here, unlike in cas_allocate.

‎src/hotspot/share/gc/parallel/mutableSpace.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class MutableSpace: public CHeapObj<mtGC> {
145145
// Return true if this space needs to be expanded in order to satisfy an
146146
// allocation request of the indicated size. Concurrent allocations and
147147
// resizes may change the result of a later call. Used by oldgen allocator.
148-
// precondition: holding ExpandHeap_lock
148+
// precondition: holding PSOldGenExpand_lock
149149
bool needs_expand(size_t word_size) const;
150150

151151
// Iteration.

‎src/hotspot/share/gc/parallel/psOldGen.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool PSOldGen::expand_for_allocate(size_t word_size) {
163163
assert(word_size > 0, "allocating zero words?");
164164
bool result = true;
165165
{
166-
MutexLocker x(ExpandHeap_lock);
166+
MutexLocker x(PSOldGenExpand_lock);
167167
// Avoid "expand storms" by rechecking available space after obtaining
168168
// the lock, because another thread may have already made sufficient
169169
// space available. If insufficient space available, that will remain
@@ -181,7 +181,7 @@ bool PSOldGen::expand_for_allocate(size_t word_size) {
181181
}
182182

183183
bool PSOldGen::expand(size_t bytes) {
184-
assert_lock_strong(ExpandHeap_lock);
184+
assert_lock_strong(PSOldGenExpand_lock);
185185
assert_locked_or_safepoint(Heap_lock);
186186
assert(bytes > 0, "precondition");
187187
const size_t alignment = virtual_space()->alignment();
@@ -219,7 +219,7 @@ bool PSOldGen::expand(size_t bytes) {
219219
}
220220

221221
bool PSOldGen::expand_by(size_t bytes) {
222-
assert_lock_strong(ExpandHeap_lock);
222+
assert_lock_strong(PSOldGenExpand_lock);
223223
assert_locked_or_safepoint(Heap_lock);
224224
assert(bytes > 0, "precondition");
225225
bool result = virtual_space()->expand_by(bytes);
@@ -255,7 +255,7 @@ bool PSOldGen::expand_by(size_t bytes) {
255255
}
256256

257257
bool PSOldGen::expand_to_reserved() {
258-
assert_lock_strong(ExpandHeap_lock);
258+
assert_lock_strong(PSOldGenExpand_lock);
259259
assert_locked_or_safepoint(Heap_lock);
260260

261261
bool result = false;
@@ -268,12 +268,11 @@ bool PSOldGen::expand_to_reserved() {
268268
}
269269

270270
void PSOldGen::shrink(size_t bytes) {
271-
assert_lock_strong(ExpandHeap_lock);
271+
assert_lock_strong(PSOldGenExpand_lock);
272272
assert_locked_or_safepoint(Heap_lock);
273273

274274
size_t size = align_down(bytes, virtual_space()->alignment());
275275
if (size > 0) {
276-
assert_lock_strong(ExpandHeap_lock);
277276
virtual_space()->shrink_by(bytes);
278277
post_resize();
279278

@@ -312,11 +311,11 @@ void PSOldGen::resize(size_t desired_free_space) {
312311
}
313312
if (new_size > current_size) {
314313
size_t change_bytes = new_size - current_size;
315-
MutexLocker x(ExpandHeap_lock);
314+
MutexLocker x(PSOldGenExpand_lock);
316315
expand(change_bytes);
317316
} else {
318317
size_t change_bytes = current_size - new_size;
319-
MutexLocker x(ExpandHeap_lock);
318+
MutexLocker x(PSOldGenExpand_lock);
320319
shrink(change_bytes);
321320
}
322321

‎src/hotspot/share/gc/serial/defNewGeneration.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ void DefNewGeneration::swap_spaces() {
288288
}
289289

290290
bool DefNewGeneration::expand(size_t bytes) {
291-
MutexLocker x(ExpandHeap_lock);
292291
HeapWord* prev_high = (HeapWord*) _virtual_space.high();
293292
bool success = _virtual_space.expand_by(bytes);
294293
if (success && ZapUnusedHeapArea) {

‎src/hotspot/share/gc/serial/tenuredGeneration.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ TenuredGeneration::expand_and_allocate(size_t word_size, bool is_tlab) {
196196
}
197197

198198
bool TenuredGeneration::expand(size_t bytes, size_t expand_bytes) {
199-
GCMutexLocker x(ExpandHeap_lock);
200199
return CardGeneration::expand(bytes, expand_bytes);
201200
}
202201

@@ -209,7 +208,7 @@ size_t TenuredGeneration::contiguous_available() const {
209208
}
210209

211210
void TenuredGeneration::assert_correct_size_change_locking() {
212-
assert_locked_or_safepoint(ExpandHeap_lock);
211+
assert_locked_or_safepoint(Heap_lock);
213212
}
214213

215214
void TenuredGeneration::object_iterate(ObjectClosure* blk) {

‎src/hotspot/share/runtime/mutexLocker.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Monitor* JNICritical_lock = NULL;
5454
Mutex* JvmtiThreadState_lock = NULL;
5555
Monitor* EscapeBarrier_lock = NULL;
5656
Monitor* Heap_lock = NULL;
57-
Mutex* ExpandHeap_lock = NULL;
57+
#ifdef INCLUDE_PARALLELGC
58+
Mutex* PSOldGenExpand_lock = NULL;
59+
#endif
5860
Mutex* AdapterHandlerLibrary_lock = NULL;
5961
Mutex* SignatureHandlerLibrary_lock = NULL;
6062
Mutex* VtableStubs_lock = NULL;
@@ -358,7 +360,11 @@ void mutex_init() {
358360
defl(G1OldGCCount_lock , PaddedMonitor, Threads_lock, true);
359361
}
360362
defl(CompileTaskAlloc_lock , PaddedMutex , MethodCompileQueue_lock);
361-
defl(ExpandHeap_lock , PaddedMutex , Heap_lock, true);
363+
#ifdef INCLUDE_PARALLELGC
364+
if (UseParallelGC) {
365+
defl(PSOldGenExpand_lock , PaddedMutex , Heap_lock, true);
366+
}
367+
#endif
362368
defl(OopMapCacheAlloc_lock , PaddedMutex , Threads_lock, true);
363369
defl(Module_lock , PaddedMutex , ClassLoaderDataGraph_lock);
364370
defl(SystemDictionary_lock , PaddedMonitor, Module_lock);

‎src/hotspot/share/runtime/mutexLocker.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ extern Monitor* JNICritical_lock; // a lock used while entering a
4646
extern Mutex* JvmtiThreadState_lock; // a lock on modification of JVMTI thread data
4747
extern Monitor* EscapeBarrier_lock; // a lock to sync reallocating and relocking objects because of JVMTI access
4848
extern Monitor* Heap_lock; // a lock on the heap
49-
extern Mutex* ExpandHeap_lock; // a lock on expanding the heap
49+
#ifdef INCLUDE_PARALLELGC
50+
extern Mutex* PSOldGenExpand_lock; // a lock on expanding the heap
51+
#endif
5052
extern Mutex* AdapterHandlerLibrary_lock; // a lock on the AdapterHandlerLibrary
5153
extern Mutex* SignatureHandlerLibrary_lock; // a lock on the SignatureHandlerLibrary
5254
extern Mutex* VtableStubs_lock; // a lock on the VtableStubs

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Feb 15, 2022

@openjdk-notifier[bot]
Please sign in to comment.