Skip to content

Commit 77f6290

Browse files
author
Kim Barrett
committedJan 12, 2021
8258254: Move PtrQueue flush to PtrQueueSet subclasses
Reviewed-by: tschatzl, shade
1 parent 2255ab7 commit 77f6290

12 files changed

+78
-92
lines changed
 

‎src/hotspot/share/gc/g1/g1BarrierSet.cpp

+11-3
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
@@ -158,6 +158,14 @@ void G1BarrierSet::on_thread_attach(Thread* thread) {
158158
void G1BarrierSet::on_thread_detach(Thread* thread) {
159159
// Flush any deferred card marks.
160160
CardTableBarrierSet::on_thread_detach(thread);
161-
G1ThreadLocalData::satb_mark_queue(thread).flush();
162-
G1ThreadLocalData::dirty_card_queue(thread).on_thread_detach();
161+
{
162+
SATBMarkQueue& queue = G1ThreadLocalData::satb_mark_queue(thread);
163+
G1BarrierSet::satb_mark_queue_set().flush_queue(queue);
164+
}
165+
{
166+
G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue(thread);
167+
G1DirtyCardQueueSet& qset = G1BarrierSet::dirty_card_queue_set();
168+
qset.flush_queue(queue);
169+
qset.record_detached_refinement_stats(queue.refinement_stats());
170+
}
163171
}

‎src/hotspot/share/gc/g1/g1DirtyCardQueue.cpp

+17-17
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
@@ -55,21 +55,10 @@ G1DirtyCardQueue::G1DirtyCardQueue(G1DirtyCardQueueSet* qset) :
5555
{ }
5656

5757
G1DirtyCardQueue::~G1DirtyCardQueue() {
58-
flush();
58+
G1BarrierSet::dirty_card_queue_set().flush_queue(*this);
5959
delete _refinement_stats;
6060
}
6161

62-
void G1DirtyCardQueue::flush() {
63-
_refinement_stats->inc_dirtied_cards(size());
64-
flush_impl();
65-
}
66-
67-
void G1DirtyCardQueue::on_thread_detach() {
68-
assert(this == &G1ThreadLocalData::dirty_card_queue(Thread::current()), "precondition");
69-
flush();
70-
dirty_card_qset()->record_detached_refinement_stats(_refinement_stats);
71-
}
72-
7362
// Assumed to be zero by concurrent threads.
7463
static uint par_ids_start() { return 0; }
7564

@@ -95,6 +84,14 @@ uint G1DirtyCardQueueSet::num_par_ids() {
9584
return (uint)os::initial_active_processor_count();
9685
}
9786

87+
void G1DirtyCardQueueSet::flush_queue(G1DirtyCardQueue& queue) {
88+
if (queue.buffer() != nullptr) {
89+
G1ConcurrentRefineStats* stats = queue.refinement_stats();
90+
stats->inc_dirtied_cards(buffer_size() - queue.index());
91+
}
92+
PtrQueueSet::flush_queue(queue);
93+
}
94+
9895
void G1DirtyCardQueueSet::enqueue(G1DirtyCardQueue& queue,
9996
volatile CardValue* card_ptr) {
10097
CardValue* value = const_cast<CardValue*>(card_ptr);
@@ -645,13 +642,16 @@ void G1DirtyCardQueueSet::concatenate_logs() {
645642
set_max_cards(MaxCardsUnlimited);
646643

647644
struct ConcatenateThreadLogClosure : public ThreadClosure {
645+
G1DirtyCardQueueSet& _qset;
646+
ConcatenateThreadLogClosure(G1DirtyCardQueueSet& qset) : _qset(qset) {}
648647
virtual void do_thread(Thread* t) {
649-
G1DirtyCardQueue& dcq = G1ThreadLocalData::dirty_card_queue(t);
650-
if (!dcq.is_empty()) {
651-
dcq.flush();
648+
G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue(t);
649+
if ((queue.buffer() != nullptr) &&
650+
(queue.index() != _qset.buffer_size())) {
651+
_qset.flush_queue(queue);
652652
}
653653
}
654-
} closure;
654+
} closure(*this);
655655
Threads::threads_do(&closure);
656656

657657
G1BarrierSet::shared_dirty_card_queue().flush();

‎src/hotspot/share/gc/g1/g1DirtyCardQueue.hpp

+3-8
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
@@ -49,19 +49,12 @@ class G1DirtyCardQueue: public PtrQueue {
4949
// doing something else, with auto-flush on completion.
5050
~G1DirtyCardQueue();
5151

52-
// Process queue entries and release resources.
53-
void flush();
54-
5552
inline G1DirtyCardQueueSet* dirty_card_qset() const;
5653

5754
G1ConcurrentRefineStats* refinement_stats() const {
5855
return _refinement_stats;
5956
}
6057

61-
// To be called by the barrier set's on_thread_detach, to notify this
62-
// object of the corresponding state change of its owning thread.
63-
void on_thread_detach();
64-
6558
// Compiler support.
6659
static ByteSize byte_offset_of_index() {
6760
return PtrQueue::byte_offset_of_index<G1DirtyCardQueue>();
@@ -313,6 +306,8 @@ class G1DirtyCardQueueSet: public PtrQueueSet {
313306

314307
G1BufferNodeList take_all_completed_buffers();
315308

309+
void flush_queue(G1DirtyCardQueue& queue);
310+
316311
using CardValue = G1CardTable::CardValue;
317312
void enqueue(G1DirtyCardQueue& queue, volatile CardValue* card_ptr);
318313

‎src/hotspot/share/gc/g1/g1EvacFailure.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -219,7 +219,7 @@ class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
219219
}
220220

221221
~RemoveSelfForwardPtrHRClosure() {
222-
_rdcq.flush();
222+
_rdc_local_qset.flush_queue(_rdcq);
223223
_rdc_local_qset.flush();
224224
}
225225

‎src/hotspot/share/gc/g1/g1ParScanThreadState.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 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
@@ -114,7 +114,7 @@ G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h,
114114
}
115115

116116
size_t G1ParScanThreadState::flush(size_t* surviving_young_words) {
117-
_rdcq.flush();
117+
_rdc_local_qset.flush_queue(_rdcq);
118118
_rdc_local_qset.flush();
119119
flush_numa_stats();
120120
// Update allocation statistics.

‎src/hotspot/share/gc/g1/g1RedirtyCardsQueue.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 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
@@ -68,6 +68,10 @@ void G1RedirtyCardsLocalQueueSet::flush() {
6868
_buffers = G1BufferNodeList();
6969
}
7070

71+
void G1RedirtyCardsLocalQueueSet::flush_queue(G1RedirtyCardsQueue& queue) {
72+
PtrQueueSet::flush_queue(queue);
73+
}
74+
7175
// G1RedirtyCardsQueue
7276

7377
G1RedirtyCardsQueue::G1RedirtyCardsQueue(G1RedirtyCardsLocalQueueSet* qset) :
@@ -76,14 +80,10 @@ G1RedirtyCardsQueue::G1RedirtyCardsQueue(G1RedirtyCardsLocalQueueSet* qset) :
7680

7781
#ifdef ASSERT
7882
G1RedirtyCardsQueue::~G1RedirtyCardsQueue() {
79-
assert(is_empty(), "unflushed queue");
83+
assert(buffer() == nullptr, "unflushed queue");
8084
}
8185
#endif // ASSERT
8286

83-
void G1RedirtyCardsQueue::flush() {
84-
flush_impl();
85-
}
86-
8787
// G1RedirtyCardsQueueSet
8888

8989
G1RedirtyCardsQueueSet::G1RedirtyCardsQueueSet(BufferNode::Allocator* allocator) :

‎src/hotspot/share/gc/g1/g1RedirtyCardsQueue.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 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
@@ -50,16 +50,15 @@ class G1RedirtyCardsLocalQueueSet : public PtrQueueSet {
5050

5151
// Transfer all completed buffers to the shared qset.
5252
void flush();
53+
54+
void flush_queue(G1RedirtyCardsQueue& queue);
5355
};
5456

5557
// Worker-local queues of card table entries.
5658
class G1RedirtyCardsQueue : public PtrQueue {
5759
public:
5860
G1RedirtyCardsQueue(G1RedirtyCardsLocalQueueSet* qset);
5961
~G1RedirtyCardsQueue() NOT_DEBUG(= default);
60-
61-
// Flushes all enqueued cards to qset.
62-
void flush();
6362
};
6463

6564
// Card table entries to be redirtied and the cards reprocessed later.

‎src/hotspot/share/gc/shared/ptrQueue.cpp

+16-27
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
@@ -46,32 +46,6 @@ PtrQueue::~PtrQueue() {
4646
assert(_buf == NULL, "queue must be flushed before delete");
4747
}
4848

49-
void PtrQueue::flush_impl() {
50-
if (_buf != NULL) {
51-
BufferNode* node = BufferNode::make_node_from_buffer(_buf, index());
52-
if (is_empty()) {
53-
// No work to do.
54-
qset()->deallocate_buffer(node);
55-
} else {
56-
qset()->enqueue_completed_buffer(node);
57-
}
58-
_buf = NULL;
59-
set_index(0);
60-
}
61-
}
62-
63-
void PtrQueue::allocate_buffer() {
64-
_buf = qset()->allocate_buffer();
65-
reset();
66-
}
67-
68-
void PtrQueue::enqueue_completed_buffer() {
69-
assert(_buf != NULL, "precondition");
70-
BufferNode* node = BufferNode::make_node_from_buffer(_buf, index());
71-
qset()->enqueue_completed_buffer(node);
72-
allocate_buffer();
73-
}
74-
7549
BufferNode* BufferNode::allocate(size_t size) {
7650
size_t byte_size = size * sizeof(void*);
7751
void* data = NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC);
@@ -225,6 +199,21 @@ PtrQueueSet::PtrQueueSet(BufferNode::Allocator* allocator) :
225199

226200
PtrQueueSet::~PtrQueueSet() {}
227201

202+
void PtrQueueSet::flush_queue(PtrQueue& queue) {
203+
void** buffer = queue.buffer();
204+
if (buffer != nullptr) {
205+
size_t index = queue.index();
206+
queue.set_buffer(nullptr);
207+
queue.set_index(0);
208+
BufferNode* node = BufferNode::make_node_from_buffer(buffer, index);
209+
if (index == buffer_size()) {
210+
deallocate_buffer(node);
211+
} else {
212+
enqueue_completed_buffer(node);
213+
}
214+
}
215+
}
216+
228217
bool PtrQueueSet::try_enqueue(PtrQueue& queue, void* value) {
229218
size_t index = queue.index();
230219
if (index == 0) return false;

‎src/hotspot/share/gc/shared/ptrQueue.hpp

+5-9
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
@@ -79,14 +79,6 @@ class PtrQueue {
7979

8080
PtrQueueSet* qset() const { return _qset; }
8181

82-
// Process queue entries and release resources.
83-
void flush_impl();
84-
85-
void allocate_buffer();
86-
87-
// Enqueue the current buffer in the qset and allocate a new buffer.
88-
void enqueue_completed_buffer();
89-
9082
// Initialize this queue to contain a null buffer, and be part of the
9183
// given PtrQueueSet.
9284
PtrQueue(PtrQueueSet* qset);
@@ -268,6 +260,10 @@ class PtrQueueSet {
268260
PtrQueueSet(BufferNode::Allocator* allocator);
269261
~PtrQueueSet();
270262

263+
// If queue has any buffered enqueued data, transfer it to this qset.
264+
// Otherwise, deallocate queue's buffer.
265+
void flush_queue(PtrQueue& queue);
266+
271267
// Add value to queue's buffer, returning true. If buffer is full
272268
// or if queue doesn't have a buffer, does nothing and returns false.
273269
bool try_enqueue(PtrQueue& queue, void* value);

‎src/hotspot/share/gc/shared/satbMarkQueue.cpp

+8-8
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
@@ -47,13 +47,6 @@ SATBMarkQueue::SATBMarkQueue(SATBMarkQueueSet* qset) :
4747
_active(false)
4848
{ }
4949

50-
void SATBMarkQueue::flush() {
51-
// Filter now to possibly save work later. If filtering empties the
52-
// buffer then flush_impl can deallocate the buffer.
53-
filter();
54-
flush_impl();
55-
}
56-
5750
void SATBMarkQueue::apply_closure_and_empty(SATBBufferClosure* cl) {
5851
assert(SafepointSynchronize::is_at_safepoint(),
5952
"SATB queues must only be processed at safepoints");
@@ -235,6 +228,13 @@ bool SATBMarkQueueSet::apply_closure_to_completed_buffer(SATBBufferClosure* cl)
235228
}
236229
}
237230

231+
void SATBMarkQueueSet::flush_queue(SATBMarkQueue& queue) {
232+
// Filter now to possibly save work later. If filtering empties the
233+
// buffer then flush_queue can deallocate the buffer.
234+
filter(queue);
235+
PtrQueueSet::flush_queue(queue);
236+
}
237+
238238
void SATBMarkQueueSet::enqueue_known_active(SATBMarkQueue& queue, oop obj) {
239239
assert(queue.is_active(), "precondition");
240240
void* value = cast_from_oop<void*>(obj);

‎src/hotspot/share/gc/shared/satbMarkQueue.hpp

+3-4
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
@@ -63,9 +63,6 @@ class SATBMarkQueue: public PtrQueue {
6363
bool is_active() const { return _active; }
6464
void set_active(bool value) { _active = value; }
6565

66-
// Process queue entries and free resources.
67-
void flush();
68-
6966
inline SATBMarkQueueSet* satb_qset() const;
7067

7168
// Apply cl to the active part of the buffer.
@@ -150,6 +147,8 @@ class SATBMarkQueueSet: public PtrQueueSet {
150147
// buffer; the leading entries may be excluded due to filtering.
151148
bool apply_closure_to_completed_buffer(SATBBufferClosure* cl);
152149

150+
void flush_queue(SATBMarkQueue& queue);
151+
153152
// When active, add obj to queue by calling enqueue_known_active.
154153
void enqueue(SATBMarkQueue& queue, oop obj) {
155154
if (queue.is_active()) enqueue_known_active(queue, obj);

‎src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2013, 2021, Red Hat, Inc. 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
@@ -116,7 +116,7 @@ void ShenandoahBarrierSet::on_thread_attach(Thread *thread) {
116116

117117
void ShenandoahBarrierSet::on_thread_detach(Thread *thread) {
118118
SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
119-
queue.flush();
119+
_satb_mark_queue_set.flush_queue(queue);
120120
if (thread->is_Java_thread()) {
121121
PLAB* gclab = ShenandoahThreadLocalData::gclab(thread);
122122
if (gclab != NULL) {

0 commit comments

Comments
 (0)
Please sign in to comment.