Skip to content

Commit 06348df

Browse files
author
Kim Barrett
committedJan 23, 2021
8259776: Remove ParallelGC non-CAS oldgen allocation
Reviewed-by: tschatzl, sjohanss
1 parent 6c4c96f commit 06348df

10 files changed

+31
-137
lines changed
 

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

-45
Original file line numberDiff line numberDiff line change
@@ -792,51 +792,6 @@ void MutableNUMASpace::clear(bool mangle_space) {
792792
objects.
793793
*/
794794

795-
HeapWord* MutableNUMASpace::allocate(size_t size) {
796-
Thread* thr = Thread::current();
797-
int lgrp_id = thr->lgrp_id();
798-
if (lgrp_id == -1 || !os::numa_has_group_homing()) {
799-
lgrp_id = os::numa_get_group_id();
800-
thr->set_lgrp_id(lgrp_id);
801-
}
802-
803-
int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
804-
805-
// It is possible that a new CPU has been hotplugged and
806-
// we haven't reshaped the space accordingly.
807-
if (i == -1) {
808-
i = os::random() % lgrp_spaces()->length();
809-
}
810-
811-
LGRPSpace* ls = lgrp_spaces()->at(i);
812-
MutableSpace *s = ls->space();
813-
HeapWord *p = s->allocate(size);
814-
815-
if (p != NULL) {
816-
size_t remainder = s->free_in_words();
817-
if (remainder < CollectedHeap::min_fill_size() && remainder > 0) {
818-
s->set_top(s->top() - size);
819-
p = NULL;
820-
}
821-
}
822-
if (p != NULL) {
823-
if (top() < s->top()) { // Keep _top updated.
824-
MutableSpace::set_top(s->top());
825-
}
826-
}
827-
// Make the page allocation happen here if there is no static binding..
828-
if (p != NULL && !os::numa_has_static_binding()) {
829-
for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
830-
*(int*)i = 0;
831-
}
832-
}
833-
if (p == NULL) {
834-
ls->set_allocation_failed();
835-
}
836-
return p;
837-
}
838-
839-
// This version is lock-free.
840795
HeapWord* MutableNUMASpace::cas_allocate(size_t size) {
841796
Thread* thr = Thread::current();
842797
int lgrp_id = thr->lgrp_id();

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -227,7 +227,6 @@ class MutableNUMASpace : public MutableSpace {
227227
virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
228228

229229
// Allocation (return NULL if full)
230-
virtual HeapWord* allocate(size_t word_size);
231230
virtual HeapWord* cas_allocate(size_t word_size);
232231

233232
// Debugging

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

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -173,25 +173,6 @@ void MutableSpace::set_top_for_allocations() {
173173
}
174174
#endif
175175

176-
// This version requires locking. */
177-
HeapWord* MutableSpace::allocate(size_t size) {
178-
assert(Heap_lock->owned_by_self() ||
179-
(SafepointSynchronize::is_at_safepoint() &&
180-
Thread::current()->is_VM_thread()),
181-
"not locked");
182-
HeapWord* obj = top();
183-
if (pointer_delta(end(), obj) >= size) {
184-
HeapWord* new_top = obj + size;
185-
set_top(new_top);
186-
assert(is_object_aligned(obj) && is_object_aligned(new_top),
187-
"checking alignment");
188-
return obj;
189-
} else {
190-
return NULL;
191-
}
192-
}
193-
194-
// This version is lock-free.
195176
HeapWord* MutableSpace::cas_allocate(size_t size) {
196177
do {
197178
// Read top before end, else the range check may pass when it shouldn't.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -130,7 +130,6 @@ class MutableSpace: public ImmutableSpace {
130130
virtual size_t unsafe_max_tlab_alloc(Thread* thr) const { return free_in_bytes(); }
131131

132132
// Allocation (return NULL if full)
133-
virtual HeapWord* allocate(size_t word_size);
134133
virtual HeapWord* cas_allocate(size_t word_size);
135134
// Optional deallocation. Used in NUMA-allocator.
136135
bool cas_deallocate(HeapWord *obj, size_t size);

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -398,18 +398,27 @@ ParallelScavengeHeap::death_march_check(HeapWord* const addr, size_t size) {
398398
}
399399
}
400400

401+
HeapWord* ParallelScavengeHeap::allocate_old_gen_and_record(size_t size) {
402+
assert_locked_or_safepoint(Heap_lock);
403+
HeapWord* res = old_gen()->allocate(size);
404+
if (res != NULL) {
405+
_size_policy->tenured_allocation(size * HeapWordSize);
406+
}
407+
return res;
408+
}
409+
401410
HeapWord* ParallelScavengeHeap::mem_allocate_old_gen(size_t size) {
402411
if (!should_alloc_in_eden(size) || GCLocker::is_active_and_needs_gc()) {
403412
// Size is too big for eden, or gc is locked out.
404-
return old_gen()->allocate(size);
413+
return allocate_old_gen_and_record(size);
405414
}
406415

407416
// If a "death march" is in progress, allocate from the old gen a limited
408417
// number of times before doing a GC.
409418
if (_death_march_count > 0) {
410419
if (_death_march_count < 64) {
411420
++_death_march_count;
412-
return old_gen()->allocate(size);
421+
return allocate_old_gen_and_record(size);
413422
} else {
414423
_death_march_count = 0;
415424
}
@@ -457,7 +466,7 @@ HeapWord* ParallelScavengeHeap::failed_mem_allocate(size_t size) {
457466
// After mark sweep and young generation allocation failure,
458467
// allocate in old generation.
459468
if (result == NULL) {
460-
result = old_gen()->allocate(size);
469+
result = allocate_old_gen_and_record(size);
461470
}
462471

463472
// Fourth level allocation failure. We're running out of memory.
@@ -470,7 +479,7 @@ HeapWord* ParallelScavengeHeap::failed_mem_allocate(size_t size) {
470479
// Fifth level allocation failure.
471480
// After more complete mark sweep, allocate in old generation.
472481
if (result == NULL) {
473-
result = old_gen()->allocate(size);
482+
result = allocate_old_gen_and_record(size);
474483
}
475484

476485
return result;

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,6 @@
4343
#include "utilities/growableArray.hpp"
4444
#include "utilities/ostream.hpp"
4545

46-
class AdjoiningGenerations;
4746
class GCHeapSummary;
4847
class HeapBlockClaimer;
4948
class MemoryManager;
@@ -80,6 +79,9 @@ class ParallelScavengeHeap : public CollectedHeap {
8079
void trace_actual_reserved_page_size(const size_t reserved_heap_size, const ReservedSpace rs);
8180
void trace_heap(GCWhen::Type when, const GCTracer* tracer);
8281

82+
// Allocate in oldgen and record the allocation with the size_policy.
83+
HeapWord* allocate_old_gen_and_record(size_t word_size);
84+
8385
protected:
8486
static inline size_t total_invocations();
8587
HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);

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

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -147,25 +147,6 @@ bool PSOldGen::is_allocated() {
147147
return virtual_space()->reserved_size() != 0;
148148
}
149149

150-
// Allocation. We report all successful allocations to the size policy
151-
// Note that the perm gen does not use this method, and should not!
152-
HeapWord* PSOldGen::allocate(size_t word_size) {
153-
assert_locked_or_safepoint(Heap_lock);
154-
HeapWord* res = allocate_noexpand(word_size);
155-
156-
if (res == NULL) {
157-
res = expand_and_allocate(word_size);
158-
}
159-
160-
// Allocations in the old generation need to be reported
161-
if (res != NULL) {
162-
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
163-
heap->size_policy()->tenured_allocation(word_size * HeapWordSize);
164-
}
165-
166-
return res;
167-
}
168-
169150
size_t PSOldGen::num_iterable_blocks() const {
170151
return (object_space()->used_in_bytes() + IterateBlockSize - 1) / IterateBlockSize;
171152
}
@@ -198,14 +179,6 @@ void PSOldGen::object_iterate_block(ObjectClosure* cl, size_t block_index) {
198179
}
199180
}
200181

201-
HeapWord* PSOldGen::expand_and_allocate(size_t word_size) {
202-
expand(word_size*HeapWordSize);
203-
if (GCExpandToAllocateDelayMillis > 0) {
204-
os::naked_sleep(GCExpandToAllocateDelayMillis);
205-
}
206-
return allocate_noexpand(word_size);
207-
}
208-
209182
HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) {
210183
expand(word_size*HeapWordSize);
211184
if (GCExpandToAllocateDelayMillis > 0) {

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

+6-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,9 +34,6 @@
3434

3535
class PSOldGen : public CHeapObj<mtGC> {
3636
friend class VMStructs;
37-
friend class PSPromotionManager; // Uses the cas_allocate methods
38-
friend class ParallelScavengeHeap;
39-
friend class AdjoiningGenerations;
4037

4138
private:
4239
MemRegion _reserved; // Used for simple containment tests
@@ -72,22 +69,8 @@ class PSOldGen : public CHeapObj<mtGC> {
7269
}
7370
#endif
7471

75-
HeapWord* allocate_noexpand(size_t word_size) {
76-
// We assume the heap lock is held here.
77-
assert_locked_or_safepoint(Heap_lock);
78-
HeapWord* res = object_space()->allocate(word_size);
79-
if (res != NULL) {
80-
DEBUG_ONLY(assert_block_in_covered_region(MemRegion(res, word_size)));
81-
_start_array.allocate_block(res);
82-
}
83-
return res;
84-
}
85-
86-
// Support for MT garbage collection. CAS allocation is lower overhead than grabbing
87-
// and releasing the heap lock, which is held during gc's anyway. This method is not
88-
// safe for use at the same time as allocate_noexpand()!
8972
HeapWord* cas_allocate_noexpand(size_t word_size) {
90-
assert(SafepointSynchronize::is_at_safepoint(), "Must only be called at safepoint");
73+
assert_locked_or_safepoint(Heap_lock);
9174
HeapWord* res = object_space()->cas_allocate(word_size);
9275
if (res != NULL) {
9376
DEBUG_ONLY(assert_block_in_covered_region(MemRegion(res, word_size)));
@@ -96,13 +79,6 @@ class PSOldGen : public CHeapObj<mtGC> {
9679
return res;
9780
}
9881

99-
// Support for MT garbage collection. See above comment.
100-
HeapWord* cas_allocate(size_t word_size) {
101-
HeapWord* res = cas_allocate_noexpand(word_size);
102-
return (res == NULL) ? expand_and_cas_allocate(word_size) : res;
103-
}
104-
105-
HeapWord* expand_and_allocate(size_t word_size);
10682
HeapWord* expand_and_cas_allocate(size_t word_size);
10783
void expand(size_t bytes);
10884
bool expand_by(size_t bytes);
@@ -158,9 +134,10 @@ class PSOldGen : public CHeapObj<mtGC> {
158134
// Calculating new sizes
159135
void resize(size_t desired_free_space);
160136

161-
// Allocation. We report all successful allocations to the size policy
162-
// Note that the perm gen does not use this method, and should not!
163-
HeapWord* allocate(size_t word_size);
137+
HeapWord* allocate(size_t word_size) {
138+
HeapWord* res = cas_allocate_noexpand(word_size);
139+
return (res == NULL) ? expand_and_cas_allocate(word_size) : res;
140+
}
164141

165142
// Iteration.
166143
void oop_iterate(OopIterateClosure* cl) { object_space()->oop_iterate(cl); }

‎src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ inline oop PSPromotionManager::copy_to_survivor_space(oop o) {
194194
// Do we allocate directly, or flush and refill?
195195
if (new_obj_size > (OldPLABSize / 2)) {
196196
// Allocate this object directly
197-
new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
197+
new_obj = (oop)old_gen()->allocate(new_obj_size);
198198
promotion_trace_event(new_obj, o, new_obj_size, age, true, NULL);
199199
} else {
200200
// Flush and fill
201201
_old_lab.flush();
202202

203-
HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
203+
HeapWord* lab_base = old_gen()->allocate(OldPLABSize);
204204
if(lab_base != NULL) {
205205
#ifdef ASSERT
206206
// Delay the initialization of the promotion lab (plab).

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,6 @@
3434
class PSYoungGen : public CHeapObj<mtGC> {
3535
friend class VMStructs;
3636
friend class ParallelScavengeHeap;
37-
friend class AdjoiningGenerations;
3837

3938
private:
4039
MemRegion _reserved;

0 commit comments

Comments
 (0)
Please sign in to comment.