Skip to content

Commit 00d80fd

Browse files
author
Kim Barrett
committed
8258255: Move PtrQueue active flag to SATBMarkQueue
Reviewed-by: tschatzl, sjohanss
1 parent 853c047 commit 00d80fd

8 files changed

+40
-56
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ void G1BarrierSet::on_thread_destroy(Thread* thread) {
144144
void G1BarrierSet::on_thread_attach(Thread* thread) {
145145
assert(!G1ThreadLocalData::satb_mark_queue(thread).is_active(), "SATB queue should not be active");
146146
assert(G1ThreadLocalData::satb_mark_queue(thread).is_empty(), "SATB queue should be empty");
147-
assert(G1ThreadLocalData::dirty_card_queue(thread).is_active(), "Dirty card queue should be active");
148147
// Can't assert that the DCQ is empty. There is early execution on
149148
// the main thread, before it gets added to the threads list, which
150149
// is where this is called. That execution may enqueue dirty cards.

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
#include "utilities/ticks.hpp"
5151

5252
G1DirtyCardQueue::G1DirtyCardQueue(G1DirtyCardQueueSet* qset) :
53-
// Dirty card queues are always active, so we create them with their
54-
// active field set to true.
55-
PtrQueue(qset, true /* active */),
53+
PtrQueue(qset),
5654
_refinement_stats(new G1ConcurrentRefineStats())
5755
{ }
5856

@@ -86,9 +84,7 @@ G1DirtyCardQueueSet::G1DirtyCardQueueSet(BufferNode::Allocator* allocator) :
8684
_max_cards(MaxCardsUnlimited),
8785
_padded_max_cards(MaxCardsUnlimited),
8886
_detached_refinement_stats()
89-
{
90-
_all_active = true;
91-
}
87+
{}
9288

9389
G1DirtyCardQueueSet::~G1DirtyCardQueueSet() {
9490
abandon_completed_buffers();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void G1RedirtyCardsLocalQueueSet::flush() {
7171
// G1RedirtyCardsQueue
7272

7373
G1RedirtyCardsQueue::G1RedirtyCardsQueue(G1RedirtyCardsLocalQueueSet* qset) :
74-
PtrQueue(qset, true /* always active */)
74+
PtrQueue(qset)
7575
{}
7676

7777
#ifdef ASSERT

src/hotspot/share/gc/g1/vmStructs_g1.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, 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
@@ -70,7 +70,7 @@
7070
\
7171
nonstatic_field(HeapRegionSetBase, _length, uint) \
7272
\
73-
nonstatic_field(PtrQueue, _active, bool) \
73+
nonstatic_field(SATBMarkQueue, _active, bool) \
7474
nonstatic_field(PtrQueue, _buf, void**) \
7575
nonstatic_field(PtrQueue, _index, size_t)
7676

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535

3636
#include <new>
3737

38-
PtrQueue::PtrQueue(PtrQueueSet* qset, bool active) :
38+
PtrQueue::PtrQueue(PtrQueueSet* qset) :
3939
_qset(qset),
40-
_active(active),
4140
_index(0),
4241
_capacity_in_bytes(index_to_byte_index(qset->buffer_size())),
4342
_buf(NULL)
@@ -221,8 +220,7 @@ size_t BufferNode::Allocator::reduce_free_list(size_t remove_goal) {
221220
}
222221

223222
PtrQueueSet::PtrQueueSet(BufferNode::Allocator* allocator) :
224-
_allocator(allocator),
225-
_all_active(false)
223+
_allocator(allocator)
226224
{}
227225

228226
PtrQueueSet::~PtrQueueSet() {}

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

+1-31
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class PtrQueue {
4747
// The ptr queue set to which this queue belongs.
4848
PtrQueueSet* const _qset;
4949

50-
// Whether updates should be logged.
51-
bool _active;
52-
5350
// The (byte) index at which an object was last enqueued. Starts at
5451
// capacity_in_bytes (indicating an empty buffer) and goes towards zero.
5552
// Value is always pointer-size aligned.
@@ -92,7 +89,7 @@ class PtrQueue {
9289

9390
// Initialize this queue to contain a null buffer, and be part of the
9491
// given PtrQueueSet.
95-
PtrQueue(PtrQueueSet* qset, bool active = false);
92+
PtrQueue(PtrQueueSet* qset);
9693

9794
// Requires queue flushed.
9895
~PtrQueue();
@@ -145,21 +142,6 @@ class PtrQueue {
145142
return _buf == NULL || capacity_in_bytes() == _index;
146143
}
147144

148-
// Set the "active" property of the queue to "b". An enqueue to an
149-
// inactive thread is a no-op. Setting a queue to inactive resets its
150-
// log to the empty state.
151-
void set_active(bool b) {
152-
_active = b;
153-
if (!b && _buf != NULL) {
154-
reset();
155-
} else if (b && _buf != NULL) {
156-
assert(index() == capacity(),
157-
"invariant: queues are empty when activated.");
158-
}
159-
}
160-
161-
bool is_active() const { return _active; }
162-
163145
// To support compiler.
164146

165147
protected:
@@ -176,14 +158,6 @@ class PtrQueue {
176158
}
177159

178160
static ByteSize byte_width_of_buf() { return in_ByteSize(_element_size); }
179-
180-
template<typename Derived>
181-
static ByteSize byte_offset_of_active() {
182-
return byte_offset_of(Derived, _active);
183-
}
184-
185-
static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); }
186-
187161
};
188162

189163
class BufferNode {
@@ -290,8 +264,6 @@ class PtrQueueSet {
290264
NONCOPYABLE(PtrQueueSet);
291265

292266
protected:
293-
bool _all_active;
294-
295267
// Create an empty ptr queue set.
296268
PtrQueueSet(BufferNode::Allocator* allocator);
297269
~PtrQueueSet();
@@ -329,8 +301,6 @@ class PtrQueueSet {
329301
// Adds node to the completed buffer list.
330302
virtual void enqueue_completed_buffer(BufferNode* node) = 0;
331303

332-
bool is_active() { return _all_active; }
333-
334304
size_t buffer_size() const {
335305
return _allocator->buffer_size();
336306
}

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

+15-8
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
#include "utilities/globalCounter.inline.hpp"
3939

4040
SATBMarkQueue::SATBMarkQueue(SATBMarkQueueSet* qset) :
41-
// SATB queues are only active during marking cycles. We create
42-
// them with their active field set to false. If a thread is
43-
// created during a cycle and its SATB queue needs to be activated
44-
// before the thread starts running, we'll need to set its active
45-
// field to true. This must be done in the collector-specific
41+
PtrQueue(qset),
42+
// SATB queues are only active during marking cycles. We create them
43+
// with their active field set to false. If a thread is created
44+
// during a cycle, it's SATB queue needs to be activated before the
45+
// thread starts running. This is handled by the collector-specific
4646
// BarrierSet thread attachment protocol.
47-
PtrQueue(qset, false /* active */)
47+
_active(false)
4848
{ }
4949

5050
void SATBMarkQueue::flush() {
@@ -86,7 +86,8 @@ SATBMarkQueueSet::SATBMarkQueueSet(BufferNode::Allocator* allocator) :
8686
_list(),
8787
_count_and_process_flag(0),
8888
_process_completed_buffers_threshold(SIZE_MAX),
89-
_buffer_enqueue_threshold(0)
89+
_buffer_enqueue_threshold(0),
90+
_all_active(false)
9091
{}
9192

9293
SATBMarkQueueSet::~SATBMarkQueueSet() {
@@ -207,7 +208,13 @@ void SATBMarkQueueSet::set_active_all_threads(bool active, bool expected_active)
207208
SetThreadActiveClosure(SATBMarkQueueSet* qset, bool active) :
208209
_qset(qset), _active(active) {}
209210
virtual void do_thread(Thread* t) {
210-
_qset->satb_queue_for_thread(t).set_active(_active);
211+
SATBMarkQueue& queue = _qset->satb_queue_for_thread(t);
212+
if (queue.buffer() != nullptr) {
213+
assert(!_active || queue.index() == _qset->buffer_size(),
214+
"queues should be empty when activated");
215+
queue.set_index(_qset->buffer_size());
216+
}
217+
queue.set_active(_active);
211218
}
212219
} closure(this, active);
213220
Threads::threads_do(&closure);

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,23 @@ class SATBBufferClosure : public StackObj {
4646

4747
// A PtrQueue whose elements are (possibly stale) pointers to object heads.
4848
class SATBMarkQueue: public PtrQueue {
49+
friend class VMStructs;
4950
friend class SATBMarkQueueSet;
5051

5152
private:
53+
// Per-queue (so thread-local) cache of the SATBMarkQueueSet's
54+
// active state, to support inline barriers in compiled code.
55+
bool _active;
56+
5257
// Filter out unwanted entries from the buffer.
5358
inline void filter();
5459

5560
public:
5661
SATBMarkQueue(SATBMarkQueueSet* qset);
5762

63+
bool is_active() const { return _active; }
64+
void set_active(bool value) { _active = value; }
65+
5866
// Process queue entries and free resources.
5967
void flush();
6068

@@ -81,10 +89,10 @@ class SATBMarkQueue: public PtrQueue {
8189
using PtrQueue::byte_width_of_buf;
8290

8391
static ByteSize byte_offset_of_active() {
84-
return PtrQueue::byte_offset_of_active<SATBMarkQueue>();
92+
return byte_offset_of(SATBMarkQueue, _active);
8593
}
86-
using PtrQueue::byte_width_of_active;
8794

95+
static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); }
8896
};
8997

9098
class SATBMarkQueueSet: public PtrQueueSet {
@@ -95,7 +103,9 @@ class SATBMarkQueueSet: public PtrQueueSet {
95103
// These are rarely (if ever) changed, so same cache line as count.
96104
size_t _process_completed_buffers_threshold;
97105
size_t _buffer_enqueue_threshold;
98-
DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, 3 * sizeof(size_t));
106+
// SATB is only active during marking. Enqueuing is only done when active.
107+
bool _all_active;
108+
DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, 4 * sizeof(size_t));
99109

100110
BufferNode* get_completed_buffer();
101111
void abandon_completed_buffers();
@@ -121,6 +131,8 @@ class SATBMarkQueueSet: public PtrQueueSet {
121131
public:
122132
virtual SATBMarkQueue& satb_queue_for_thread(Thread* const t) const = 0;
123133

134+
bool is_active() const { return _all_active; }
135+
124136
// Apply "set_active(active)" to all SATB queues in the set. It should be
125137
// called only with the world stopped. The method will assert that the
126138
// SATB queues of all threads it visits, as well as the SATB queue
@@ -138,9 +150,11 @@ class SATBMarkQueueSet: public PtrQueueSet {
138150
// buffer; the leading entries may be excluded due to filtering.
139151
bool apply_closure_to_completed_buffer(SATBBufferClosure* cl);
140152

153+
// When active, add obj to queue by calling enqueue_known_active.
141154
void enqueue(SATBMarkQueue& queue, oop obj) {
142155
if (queue.is_active()) enqueue_known_active(queue, obj);
143156
}
157+
// Add obj to queue. This qset and the queue must be active.
144158
void enqueue_known_active(SATBMarkQueue& queue, oop obj);
145159
virtual void filter(SATBMarkQueue& queue) = 0;
146160
virtual void enqueue_completed_buffer(BufferNode* node);

0 commit comments

Comments
 (0)