Skip to content

Commit f91185a

Browse files
[GR-34229] Fix G1 write barrier location identities.
PullRequest: graal/10006
2 parents 32796df + 0287f8c commit f91185a

File tree

4 files changed

+40
-45
lines changed

4 files changed

+40
-45
lines changed

compiler/src/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ private static String markWordField(String simpleName) {
630630
// G1 Collector Related Values.
631631
public final byte dirtyCardValue;
632632
public final byte g1YoungCardValue;
633-
public final int g1SATBQueueMarkingOffset;
633+
public final int g1SATBQueueMarkingActiveOffset;
634634
public final int g1SATBQueueIndexOffset;
635635
public final int g1SATBQueueBufferOffset;
636636
public final int g1CardQueueIndexOffset;
@@ -649,13 +649,13 @@ private static String markWordField(String simpleName) {
649649
g1YoungCardValue = getFieldValue("CompilerToVM::Data::g1_young_card", Byte.class, "int");
650650
g1CardQueueIndexOffset = javaThreadDirtyCardQueueOffset + dirtyCardQueueIndexOffset;
651651
g1CardQueueBufferOffset = javaThreadDirtyCardQueueOffset + dirtyCardQueueBufferOffset;
652-
g1SATBQueueMarkingOffset = javaThreadSatbMarkQueueOffset + satbMarkQueueActiveOffset;
652+
g1SATBQueueMarkingActiveOffset = javaThreadSatbMarkQueueOffset + satbMarkQueueActiveOffset;
653653
g1SATBQueueIndexOffset = javaThreadSatbMarkQueueOffset + satbMarkQueueIndexOffset;
654654
g1SATBQueueBufferOffset = javaThreadSatbMarkQueueOffset + satbMarkQueueBufferOffset;
655655
} else {
656656
dirtyCardValue = getConstant("CardTable::dirty_card", Byte.class);
657657
g1YoungCardValue = getConstant("G1CardTable::g1_young_gen", Byte.class);
658-
g1SATBQueueMarkingOffset = getConstant("G1ThreadLocalData::satb_mark_queue_active_offset", Integer.class);
658+
g1SATBQueueMarkingActiveOffset = getConstant("G1ThreadLocalData::satb_mark_queue_active_offset", Integer.class);
659659
g1SATBQueueIndexOffset = getConstant("G1ThreadLocalData::satb_mark_queue_index_offset", Integer.class);
660660
g1SATBQueueBufferOffset = getConstant("G1ThreadLocalData::satb_mark_queue_buffer_offset", Integer.class);
661661
g1CardQueueIndexOffset = getConstant("G1ThreadLocalData::dirty_card_queue_index_offset", Integer.class);

compiler/src/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotG1WriteBarrierSnippets.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ protected int objectArrayIndexScale() {
9292
}
9393

9494
@Override
95-
protected int satbQueueMarkingOffset() {
96-
return HotSpotReplacementsUtil.g1SATBQueueMarkingOffset(INJECTED_VMCONFIG);
95+
protected int satbQueueMarkingActiveOffset() {
96+
return HotSpotReplacementsUtil.g1SATBQueueMarkingActiveOffset(INJECTED_VMCONFIG);
9797
}
9898

9999
@Override
@@ -202,15 +202,15 @@ public Templates(OptionValues options, Iterable<DebugHandlersFactory> factories,
202202
this.lowerer = new HotspotG1WriteBarrierLowerer(config, factory);
203203

204204
HotSpotG1WriteBarrierSnippets receiver = new HotSpotG1WriteBarrierSnippets(providers.getRegisters());
205-
g1PreWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1PreWriteBarrier", null, receiver, GC_INDEX_LOCATION, GC_LOG_LOCATION, SATB_QUEUE_MARKING_LOCATION, SATB_QUEUE_INDEX_LOCATION,
205+
g1PreWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1PreWriteBarrier", null, receiver, SATB_QUEUE_LOG_LOCATION, SATB_QUEUE_MARKING_ACTIVE_LOCATION, SATB_QUEUE_INDEX_LOCATION,
206206
SATB_QUEUE_BUFFER_LOCATION);
207-
g1ReferentReadBarrier = snippet(G1WriteBarrierSnippets.class, "g1ReferentReadBarrier", null, receiver, GC_INDEX_LOCATION, GC_LOG_LOCATION, SATB_QUEUE_MARKING_LOCATION,
207+
g1ReferentReadBarrier = snippet(G1WriteBarrierSnippets.class, "g1ReferentReadBarrier", null, receiver, SATB_QUEUE_LOG_LOCATION, SATB_QUEUE_MARKING_ACTIVE_LOCATION,
208208
SATB_QUEUE_INDEX_LOCATION, SATB_QUEUE_BUFFER_LOCATION);
209-
g1PostWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1PostWriteBarrier", null, receiver, GC_CARD_LOCATION, GC_INDEX_LOCATION, GC_LOG_LOCATION, CARD_QUEUE_INDEX_LOCATION,
209+
g1PostWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1PostWriteBarrier", null, receiver, GC_CARD_LOCATION, CARD_QUEUE_LOG_LOCATION, CARD_QUEUE_INDEX_LOCATION,
210210
CARD_QUEUE_BUFFER_LOCATION);
211-
g1ArrayRangePreWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1ArrayRangePreWriteBarrier", null, receiver, GC_INDEX_LOCATION, GC_LOG_LOCATION, SATB_QUEUE_MARKING_LOCATION,
211+
g1ArrayRangePreWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1ArrayRangePreWriteBarrier", null, receiver, SATB_QUEUE_LOG_LOCATION, SATB_QUEUE_MARKING_ACTIVE_LOCATION,
212212
SATB_QUEUE_INDEX_LOCATION, SATB_QUEUE_BUFFER_LOCATION);
213-
g1ArrayRangePostWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1ArrayRangePostWriteBarrier", null, receiver, GC_CARD_LOCATION, GC_INDEX_LOCATION, GC_LOG_LOCATION,
213+
g1ArrayRangePostWriteBarrier = snippet(G1WriteBarrierSnippets.class, "g1ArrayRangePostWriteBarrier", null, receiver, GC_CARD_LOCATION, CARD_QUEUE_LOG_LOCATION,
214214
CARD_QUEUE_INDEX_LOCATION, CARD_QUEUE_BUFFER_LOCATION);
215215
}
216216

compiler/src/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotReplacementsUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ public static int logOfHeapRegionGrainBytes(@InjectedParameter GraalHotSpotVMCon
660660
}
661661

662662
@Fold
663-
public static int g1SATBQueueMarkingOffset(@InjectedParameter GraalHotSpotVMConfig config) {
664-
return config.g1SATBQueueMarkingOffset;
663+
public static int g1SATBQueueMarkingActiveOffset(@InjectedParameter GraalHotSpotVMConfig config) {
664+
return config.g1SATBQueueMarkingActiveOffset;
665665
}
666666

667667
@Fold

compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/gc/G1WriteBarrierSnippets.java

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@
7676
*/
7777
public abstract class G1WriteBarrierSnippets extends WriteBarrierSnippets implements Snippets {
7878

79-
public static final LocationIdentity GC_LOG_LOCATION = NamedLocationIdentity.mutable("GC-Log");
80-
public static final LocationIdentity GC_INDEX_LOCATION = NamedLocationIdentity.mutable("GC-Index");
81-
public static final LocationIdentity SATB_QUEUE_MARKING_LOCATION = NamedLocationIdentity.mutable("GC-Queue-Marking");
82-
public static final LocationIdentity SATB_QUEUE_INDEX_LOCATION = NamedLocationIdentity.mutable("GC-Queue-Index");
83-
public static final LocationIdentity SATB_QUEUE_BUFFER_LOCATION = NamedLocationIdentity.mutable("GC-Queue-Buffer");
84-
public static final LocationIdentity CARD_QUEUE_INDEX_LOCATION = NamedLocationIdentity.mutable("GC-Card-Queue-Index");
79+
public static final LocationIdentity SATB_QUEUE_MARKING_ACTIVE_LOCATION = NamedLocationIdentity.mutable("GC-SATB-Marking-Active");
80+
public static final LocationIdentity SATB_QUEUE_BUFFER_LOCATION = NamedLocationIdentity.mutable("GC-SATB-Queue-Buffer");
81+
public static final LocationIdentity SATB_QUEUE_LOG_LOCATION = NamedLocationIdentity.mutable("GC-SATB-Queue-Log");
82+
public static final LocationIdentity SATB_QUEUE_INDEX_LOCATION = NamedLocationIdentity.mutable("GC-SATB-Queue-Index");
83+
8584
public static final LocationIdentity CARD_QUEUE_BUFFER_LOCATION = NamedLocationIdentity.mutable("GC-Card-Queue-Buffer");
85+
public static final LocationIdentity CARD_QUEUE_LOG_LOCATION = NamedLocationIdentity.mutable("GC-Card-Queue-Log");
86+
public static final LocationIdentity CARD_QUEUE_INDEX_LOCATION = NamedLocationIdentity.mutable("GC-Card-Queue-Index");
8687

87-
protected static final LocationIdentity[] KILLED_PRE_WRITE_BARRIER_STUB_LOCATIONS = new LocationIdentity[]{SATB_QUEUE_INDEX_LOCATION, SATB_QUEUE_BUFFER_LOCATION, GC_LOG_LOCATION,
88-
GC_INDEX_LOCATION};
89-
protected static final LocationIdentity[] KILLED_POST_WRITE_BARRIER_STUB_LOCATIONS = new LocationIdentity[]{CARD_QUEUE_INDEX_LOCATION, CARD_QUEUE_BUFFER_LOCATION, GC_LOG_LOCATION,
90-
GC_INDEX_LOCATION, GC_CARD_LOCATION};
88+
protected static final LocationIdentity[] KILLED_PRE_WRITE_BARRIER_STUB_LOCATIONS = new LocationIdentity[]{SATB_QUEUE_INDEX_LOCATION, SATB_QUEUE_BUFFER_LOCATION, SATB_QUEUE_LOG_LOCATION};
89+
protected static final LocationIdentity[] KILLED_POST_WRITE_BARRIER_STUB_LOCATIONS = new LocationIdentity[]{CARD_QUEUE_INDEX_LOCATION, CARD_QUEUE_BUFFER_LOCATION, CARD_QUEUE_LOG_LOCATION,
90+
GC_CARD_LOCATION};
9191

9292
public static class Counters {
9393
Counters(SnippetCounter.Group.Factory factory) {
@@ -131,7 +131,7 @@ private void satbBarrier(Address address, Object object, Object expectedObject,
131131
Word thread = getThread();
132132
verifyOop(object);
133133
Word field = Word.fromAddress(address);
134-
byte markingValue = thread.readByte(satbQueueMarkingOffset(), SATB_QUEUE_MARKING_LOCATION);
134+
byte markingValue = thread.readByte(satbQueueMarkingActiveOffset(), SATB_QUEUE_MARKING_ACTIVE_LOCATION);
135135

136136
boolean trace = isTracingActive(traceStartCycle);
137137
int gcCycle = 0;
@@ -167,17 +167,14 @@ private void satbBarrier(Address address, Object object, Object expectedObject,
167167
counters.g1ExecutedPreWriteBarrierCounter.inc();
168168
// If the thread-local SATB buffer is full issue a native call which will
169169
// initialize a new one and add the entry.
170-
Word indexAddress = thread.add(satbQueueIndexOffset());
171-
Word indexValue = indexAddress.readWord(0, SATB_QUEUE_INDEX_LOCATION);
170+
Word indexValue = thread.readWord(satbQueueIndexOffset(), SATB_QUEUE_INDEX_LOCATION);
172171
if (probability(FREQUENT_PROBABILITY, indexValue.notEqual(0))) {
173172
Word bufferAddress = thread.readWord(satbQueueBufferOffset(), SATB_QUEUE_BUFFER_LOCATION);
174173
Word nextIndex = indexValue.subtract(wordSize());
175-
Word logAddress = bufferAddress.add(nextIndex);
176-
// Log the object to be marked as well as update the SATB's buffer next
177-
// index.
178-
Word previousOop = Word.objectToTrackedPointer(previousObject);
179-
logAddress.writeWord(0, previousOop, GC_LOG_LOCATION);
180-
indexAddress.writeWord(0, nextIndex, GC_INDEX_LOCATION);
174+
175+
// Log the object to be marked as well as update the SATB's buffer next index.
176+
bufferAddress.writeWord(nextIndex, Word.objectToTrackedPointer(previousObject), SATB_QUEUE_LOG_LOCATION);
177+
thread.writeWord(satbQueueIndexOffset(), nextIndex, SATB_QUEUE_INDEX_LOCATION);
181178
} else {
182179
g1PreBarrierStub(previousObject);
183180
}
@@ -245,12 +242,11 @@ public void g1PostWriteBarrier(Address address, Object object, Object value, @Co
245242
if (probability(FREQUENT_PROBABILITY, indexValue.notEqual(0))) {
246243
Word bufferAddress = thread.readWord(cardQueueBufferOffset(), CARD_QUEUE_BUFFER_LOCATION);
247244
Word nextIndex = indexValue.subtract(wordSize());
248-
Word logAddress = bufferAddress.add(nextIndex);
249-
Word indexAddress = thread.add(cardQueueIndexOffset());
250-
// Log the object to be scanned as well as update
251-
// the card queue's next index.
252-
logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION);
253-
indexAddress.writeWord(0, nextIndex, GC_INDEX_LOCATION);
245+
246+
// Log the object to be scanned as well as update the card queue's next
247+
// index.
248+
bufferAddress.writeWord(nextIndex, cardAddress, CARD_QUEUE_LOG_LOCATION);
249+
thread.writeWord(cardQueueIndexOffset(), nextIndex, CARD_QUEUE_INDEX_LOCATION);
254250
} else {
255251
g1PostBarrierStub(cardAddress);
256252
}
@@ -263,7 +259,7 @@ public void g1PostWriteBarrier(Address address, Object object, Object value, @Co
263259
@Snippet
264260
public void g1ArrayRangePreWriteBarrier(Address address, long length, @ConstantParameter int elementStride) {
265261
Word thread = getThread();
266-
byte markingValue = thread.readByte(satbQueueMarkingOffset(), SATB_QUEUE_MARKING_LOCATION);
262+
byte markingValue = thread.readByte(satbQueueMarkingActiveOffset(), SATB_QUEUE_MARKING_ACTIVE_LOCATION);
267263
// If the concurrent marker is not enabled or the vector length is zero, return.
268264
if (probability(FREQUENT_PROBABILITY, markingValue == (byte) 0 || length == 0)) {
269265
return;
@@ -283,10 +279,9 @@ public void g1ArrayRangePreWriteBarrier(Address address, long length, @ConstantP
283279
if (probability(FREQUENT_PROBABILITY, indexValue != 0)) {
284280
indexValue = indexValue - wordSize();
285281
Word logAddress = bufferAddress.add(WordFactory.unsigned(indexValue));
286-
// Log the object to be marked as well as update the SATB's buffer next index.
287-
Word previousOop = Word.objectToTrackedPointer(previousObject);
288-
logAddress.writeWord(0, previousOop, GC_LOG_LOCATION);
289-
indexAddress.writeWord(0, WordFactory.unsigned(indexValue), GC_INDEX_LOCATION);
282+
// Log the object to be marked and update the SATB's buffer next index.
283+
logAddress.writeWord(0, Word.objectToTrackedPointer(previousObject), SATB_QUEUE_LOG_LOCATION);
284+
indexAddress.writeWord(0, WordFactory.unsigned(indexValue), SATB_QUEUE_INDEX_LOCATION);
290285
} else {
291286
g1PreBarrierStub(previousObject);
292287
}
@@ -324,8 +319,8 @@ public void g1ArrayRangePostWriteBarrier(Address address, long length, @Constant
324319
Word logAddress = bufferAddress.add(WordFactory.unsigned(indexValue));
325320
// Log the object to be scanned as well as update
326321
// the card queue's next index.
327-
logAddress.writeWord(0, cur, GC_LOG_LOCATION);
328-
indexAddress.writeWord(0, WordFactory.unsigned(indexValue), GC_INDEX_LOCATION);
322+
logAddress.writeWord(0, cur, CARD_QUEUE_LOG_LOCATION);
323+
indexAddress.writeWord(0, WordFactory.unsigned(indexValue), CARD_QUEUE_INDEX_LOCATION);
329324
} else {
330325
g1PostBarrierStub(cur);
331326
}
@@ -341,7 +336,7 @@ public void g1ArrayRangePostWriteBarrier(Address address, long length, @Constant
341336

342337
protected abstract int objectArrayIndexScale();
343338

344-
protected abstract int satbQueueMarkingOffset();
339+
protected abstract int satbQueueMarkingActiveOffset();
345340

346341
protected abstract int satbQueueBufferOffset();
347342

0 commit comments

Comments
 (0)