Skip to content

Commit a17d3fe

Browse files
committed
Respect narrow vs wide writes in store barrier
1 parent 755621d commit a17d3fe

8 files changed

+61
-35
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/shenandoah/AArch64HotSpotShenandoahBarrierSetLIRGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Value emitLoadReferenceBarrier(LIRGeneratorTool tool, Value obj, Value ad
8686
}
8787

8888
@Override
89-
public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean nonNull) {
89+
public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean narrow, boolean nonNull) {
9090
AllocatableValue temp = lirTool.newVariable(LIRKind.value(AArch64Kind.QWORD));
9191
// If the assembly must load the value then it needs a temporary to store it.
9292
AllocatableValue temp2 = expectedObject.equals(Value.ILLEGAL) ? lirTool.newVariable(LIRKind.value(AArch64Kind.QWORD)) : Value.ILLEGAL;
@@ -97,7 +97,7 @@ public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, Allocat
9797

9898
ForeignCallLinkage callTarget = lirTool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_WRITE_BARRIER_PRE);
9999
lirTool.getResult().getFrameMapBuilder().callsMethod(callTarget.getOutgoingCallingConvention());
100-
lirTool.append(new AArch64HotSpotShenandoahSATBBarrierOp(config, providers, addressValue, expectedObject, temp, temp2, callTarget, nonNull));
100+
lirTool.append(new AArch64HotSpotShenandoahSATBBarrierOp(config, providers, addressValue, expectedObject, temp, temp2, callTarget, narrow, nonNull));
101101
}
102102

103103
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/shenandoah/AArch64HotSpotShenandoahSATBBarrierOp.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
*/
2525
package jdk.graal.compiler.hotspot.aarch64.shenandoah;
2626

27+
import static jdk.graal.compiler.asm.Assembler.guaranteeDifferentRegisters;
28+
import static jdk.graal.compiler.asm.aarch64.AArch64Address.AddressingMode.IMMEDIATE_SIGNED_UNSCALED;
29+
import static jdk.graal.compiler.core.common.GraalOptions.AssemblyGCBarriersSlowPathOnly;
30+
import static jdk.graal.compiler.core.common.GraalOptions.VerifyAssemblyGCBarriers;
31+
import static jdk.vm.ci.code.ValueUtil.asRegister;
32+
2733
import jdk.graal.compiler.asm.Label;
2834
import jdk.graal.compiler.asm.aarch64.AArch64Address;
2935
import jdk.graal.compiler.asm.aarch64.AArch64Assembler;
@@ -46,12 +52,6 @@
4652
import jdk.vm.ci.meta.AllocatableValue;
4753
import jdk.vm.ci.meta.Value;
4854

49-
import static jdk.graal.compiler.asm.Assembler.guaranteeDifferentRegisters;
50-
import static jdk.graal.compiler.asm.aarch64.AArch64Address.AddressingMode.IMMEDIATE_SIGNED_UNSCALED;
51-
import static jdk.graal.compiler.core.common.GraalOptions.AssemblyGCBarriersSlowPathOnly;
52-
import static jdk.graal.compiler.core.common.GraalOptions.VerifyAssemblyGCBarriers;
53-
import static jdk.vm.ci.code.ValueUtil.asRegister;
54-
5555
/**
5656
* AArch64 backend for the Shenandoah SATB barrier.
5757
*/
@@ -71,6 +71,11 @@ public class AArch64HotSpotShenandoahSATBBarrierOp extends AArch64LIRInstruction
7171
*/
7272
private final boolean nonNull;
7373

74+
/**
75+
* Whether the reference is compressed.
76+
*/
77+
private final boolean narrow;
78+
7479
/**
7580
* The store address.
7681
*/
@@ -86,7 +91,7 @@ public class AArch64HotSpotShenandoahSATBBarrierOp extends AArch64LIRInstruction
8691
@Temp({OperandFlag.REG, OperandFlag.ILLEGAL}) private Value temp2;
8792

8893
public AArch64HotSpotShenandoahSATBBarrierOp(GraalHotSpotVMConfig config, HotSpotProviders providers,
89-
AllocatableValue address, AllocatableValue expectedObject, AllocatableValue temp, AllocatableValue temp2, ForeignCallLinkage callTarget, boolean nonNull) {
94+
AllocatableValue address, AllocatableValue expectedObject, AllocatableValue temp, AllocatableValue temp2, ForeignCallLinkage callTarget, boolean narrow, boolean nonNull) {
9095
super(TYPE);
9196
this.config = config;
9297
this.providers = providers;
@@ -97,11 +102,12 @@ public AArch64HotSpotShenandoahSATBBarrierOp(GraalHotSpotVMConfig config, HotSpo
97102
this.temp2 = temp2;
98103
this.callTarget = callTarget;
99104
this.nonNull = nonNull;
105+
this.narrow = narrow;
100106
GraalError.guarantee(expectedObject.equals(Value.ILLEGAL) || expectedObject.getPlatformKind().getSizeInBytes() == 8, "expected uncompressed pointer");
101107
}
102108

103109
public void loadObject(AArch64MacroAssembler masm, Register preVal, Register immediateAddress) {
104-
if (config.useCompressedOops) {
110+
if (narrow) {
105111
masm.ldr(32, preVal, AArch64Address.createImmediateAddress(32, IMMEDIATE_SIGNED_UNSCALED, immediateAddress, 0));
106112
CompressEncoding encoding = config.getOopEncoding();
107113
AArch64Move.UncompressPointerOp.emitUncompressCode(masm, preVal, preVal, encoding, false, providers.getRegisters().getHeapBaseRegister(), false);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/shenandoah/AMD64HotSpotShenandoahBarrierSetLIRGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Value emitLoadReferenceBarrier(LIRGeneratorTool tool, Value obj, Value ad
8383
}
8484

8585
@Override
86-
public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean nonNull) {
86+
public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean narrow, boolean nonNull) {
8787
AllocatableValue temp = lirTool.newVariable(LIRKind.value(AMD64Kind.QWORD));
8888
// If the assembly must load the value then it's needs a temporary to store it
8989
AllocatableValue temp2 = expectedObject.equals(Value.ILLEGAL) ? lirTool.newVariable(LIRKind.value(AMD64Kind.QWORD)) : Value.ILLEGAL;
@@ -95,7 +95,7 @@ public void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, Allocat
9595

9696
ForeignCallLinkage callTarget = lirTool.getForeignCalls().lookupForeignCall(HotSpotHostForeignCallsProvider.SHENANDOAH_WRITE_BARRIER_PRE);
9797
lirTool.getResult().getFrameMapBuilder().callsMethod(callTarget.getOutgoingCallingConvention());
98-
lirTool.append(new AMD64HotSpotShenandoahSATBBarrierOp(config, providers, addressValue, expectedObject, temp, temp2, temp3, callTarget, nonNull));
98+
lirTool.append(new AMD64HotSpotShenandoahSATBBarrierOp(config, providers, addressValue, expectedObject, temp, temp2, temp3, callTarget, narrow, nonNull));
9999
}
100100

101101
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/shenandoah/AMD64HotSpotShenandoahSATBBarrierOp.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
*/
2525
package jdk.graal.compiler.hotspot.amd64.shenandoah;
2626

27+
import static jdk.graal.compiler.asm.Assembler.guaranteeDifferentRegisters;
28+
import static jdk.graal.compiler.core.common.GraalOptions.AssemblyGCBarriersSlowPathOnly;
29+
import static jdk.graal.compiler.core.common.GraalOptions.VerifyAssemblyGCBarriers;
30+
import static jdk.vm.ci.code.ValueUtil.asRegister;
31+
2732
import jdk.graal.compiler.asm.Label;
2833
import jdk.graal.compiler.asm.amd64.AMD64Address;
2934
import jdk.graal.compiler.asm.amd64.AMD64Assembler;
@@ -47,11 +52,6 @@
4752
import jdk.vm.ci.meta.AllocatableValue;
4853
import jdk.vm.ci.meta.Value;
4954

50-
import static jdk.graal.compiler.asm.Assembler.guaranteeDifferentRegisters;
51-
import static jdk.graal.compiler.core.common.GraalOptions.AssemblyGCBarriersSlowPathOnly;
52-
import static jdk.graal.compiler.core.common.GraalOptions.VerifyAssemblyGCBarriers;
53-
import static jdk.vm.ci.code.ValueUtil.asRegister;
54-
5555
/**
5656
* X86 backend for the Shenandoah SATB barrier.
5757
*/
@@ -71,6 +71,11 @@ public class AMD64HotSpotShenandoahSATBBarrierOp extends AMD64LIRInstruction {
7171
*/
7272
private final boolean nonNull;
7373

74+
/**
75+
* Whether the reference is compressed.
76+
*/
77+
private final boolean narrow;
78+
7479
/**
7580
* The store address.
7681
*/
@@ -90,7 +95,7 @@ public class AMD64HotSpotShenandoahSATBBarrierOp extends AMD64LIRInstruction {
9095
public AMD64HotSpotShenandoahSATBBarrierOp(GraalHotSpotVMConfig config, HotSpotProviders providers,
9196
AllocatableValue address, AllocatableValue expectedObject,
9297
AllocatableValue temp, AllocatableValue temp2, AllocatableValue temp3,
93-
ForeignCallLinkage callTarget, boolean nonNull) {
98+
ForeignCallLinkage callTarget, boolean narrow, boolean nonNull) {
9499
super(TYPE);
95100
this.config = config;
96101
this.providers = providers;
@@ -102,11 +107,12 @@ public AMD64HotSpotShenandoahSATBBarrierOp(GraalHotSpotVMConfig config, HotSpotP
102107
this.temp3 = temp3;
103108
this.callTarget = callTarget;
104109
this.nonNull = nonNull;
110+
this.narrow = narrow;
105111
GraalError.guarantee(expectedObject.equals(Value.ILLEGAL) || expectedObject.getPlatformKind().getSizeInBytes() == 8, "expected uncompressed pointer");
106112
}
107113

108114
public void loadObject(AMD64MacroAssembler masm, Register preVal, Register immediateAddress) {
109-
if (config.useCompressedOops) {
115+
if (narrow) {
110116
masm.movl(preVal, new AMD64Address(immediateAddress));
111117
CompressEncoding encoding = config.getOopEncoding();
112118
AMD64Move.UncompressPointerOp.emitUncompressCode(masm, preVal, encoding.getShift(), providers.getRegisters().getHeapBaseRegister(), false);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/ShenandoahBarrierSetLIRGeneratorTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public interface ShenandoahBarrierSetLIRGeneratorTool extends BarrierSetLIRGeneratorTool {
3535
Value emitLoadReferenceBarrier(LIRGeneratorTool tool, Value obj, Value address, ShenandoahLoadRefBarrierNode.ReferenceStrength strength, boolean narrow, boolean notNull);
3636

37-
void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean nonNull);
37+
void emitPreWriteBarrier(LIRGeneratorTool lirTool, Value address, AllocatableValue expectedObject, boolean narrow, boolean nonNull);
3838

3939
void emitCardBarrier(LIRGeneratorTool lirTool, Value address);
4040
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/gc/shenandoah/ShenandoahBarrierSet.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void addWriteBarriers(FixedAccessNode node, ValueNode writtenValue, Valu
229229
* be explicitly skipped when this is an initializing store. No keep-alive
230230
* means no need for the pre-barrier.
231231
*/
232-
addShenandoahSATBBarrier(node, node.getAddress(), expectedValue, graph);
232+
addShenandoahSATBBarrier(node, node.getAddress(), writtenValue, expectedValue, graph);
233233
}
234234
if (!init && useCardBarrier && !StampTool.isPointerAlwaysNull(writtenValue)) {
235235
graph.addAfterFixed(node, graph.add(new ShenandoahCardBarrierNode(node.getAddress())));
@@ -270,7 +270,7 @@ private void addReadNodeBarriers(FixedAccessNode node) {
270270
}
271271
if (useSATBBarrier) {
272272
boolean narrow = node.stamp(NodeView.DEFAULT) instanceof NarrowOopStamp;
273-
ShenandoahReferentFieldReadBarrierNode barrier = graph.add(new ShenandoahReferentFieldReadBarrierNode(node.getAddress(), maybeUncompressReference(node, narrow)));
273+
ShenandoahReferentFieldReadBarrierNode barrier = graph.add(new ShenandoahReferentFieldReadBarrierNode(node.getAddress(), maybeUncompressReference(node, narrow), narrow));
274274
graph.addAfterFixed(node, barrier);
275275
}
276276
}
@@ -291,9 +291,11 @@ protected ValueNode maybeCompressReference(ValueNode value, @SuppressWarnings("u
291291
return value;
292292
}
293293

294-
private void addShenandoahSATBBarrier(FixedAccessNode node, AddressNode address, ValueNode value, StructuredGraph graph) {
295-
boolean narrow = value != null && value.stamp(NodeView.DEFAULT) instanceof NarrowOopStamp;
296-
ShenandoahSATBBarrierNode preBarrier = graph.add(new ShenandoahSATBBarrierNode(address, maybeUncompressReference(value, narrow)));
294+
void addShenandoahSATBBarrier(FixedAccessNode node, AddressNode address, ValueNode writtenValue, ValueNode expectedValue, StructuredGraph graph) {
295+
boolean narrow = writtenValue.stamp(NodeView.DEFAULT) instanceof NarrowOopStamp;
296+
assert expectedValue == null || narrow == (expectedValue.stamp(NodeView.DEFAULT) instanceof NarrowOopStamp) : narrow + " " + expectedValue;
297+
298+
ShenandoahSATBBarrierNode preBarrier = graph.add(new ShenandoahSATBBarrierNode(address, maybeUncompressReference(expectedValue, narrow), narrow));
297299
GraalError.guarantee(!node.getUsedAsNullCheck(), "trapping null checks are inserted after write barrier insertion: ", node);
298300
node.setStateBefore(null);
299301
graph.addBeforeFixed(node, preBarrier);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/gc/shenandoah/ShenandoahReferentFieldReadBarrierNode.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
package jdk.graal.compiler.nodes.gc.shenandoah;
2626

27+
import static jdk.graal.compiler.nodeinfo.NodeCycles.CYCLES_64;
28+
import static jdk.graal.compiler.nodeinfo.NodeSize.SIZE_64;
29+
2730
import jdk.graal.compiler.graph.NodeClass;
2831
import jdk.graal.compiler.lir.gen.LIRGeneratorTool;
2932
import jdk.graal.compiler.lir.gen.ShenandoahBarrierSetLIRGeneratorTool;
@@ -34,9 +37,6 @@
3437
import jdk.graal.compiler.nodes.spi.LIRLowerable;
3538
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;
3639

37-
import static jdk.graal.compiler.nodeinfo.NodeCycles.CYCLES_64;
38-
import static jdk.graal.compiler.nodeinfo.NodeSize.SIZE_64;
39-
4040
/**
4141
* A special case of the SATB barrier, needed to support soft and weak references. They are added
4242
* after reads of referents of SoftReference and WeakReference objects, and ensure that such
@@ -46,8 +46,14 @@
4646
public class ShenandoahReferentFieldReadBarrierNode extends ObjectWriteBarrierNode implements LIRLowerable {
4747
public static final NodeClass<ShenandoahReferentFieldReadBarrierNode> TYPE = NodeClass.create(ShenandoahReferentFieldReadBarrierNode.class);
4848

49-
public ShenandoahReferentFieldReadBarrierNode(AddressNode address, ValueNode expectedObject) {
49+
/**
50+
* Whether the reference is compressed.
51+
*/
52+
private final boolean narrow;
53+
54+
public ShenandoahReferentFieldReadBarrierNode(AddressNode address, ValueNode expectedObject, boolean narrow) {
5055
super(TYPE, address, expectedObject, true);
56+
this.narrow = narrow;
5157
}
5258

5359
public ValueNode getExpectedObject() {
@@ -63,6 +69,6 @@ public Kind getKind() {
6369
public void generate(NodeLIRBuilderTool generator) {
6470
LIRGeneratorTool lirGen = generator.getLIRGeneratorTool();
6571
ShenandoahBarrierSetLIRGeneratorTool tool = (ShenandoahBarrierSetLIRGeneratorTool) generator.getLIRGeneratorTool().getBarrierSet();
66-
tool.emitPreWriteBarrier(lirGen, generator.operand(getAddress()), lirGen.asAllocatable(generator.operand(getExpectedObject())), false);
72+
tool.emitPreWriteBarrier(lirGen, generator.operand(getAddress()), lirGen.asAllocatable(generator.operand(getExpectedObject())), narrow, false);
6773
}
6874
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/gc/shenandoah/ShenandoahSATBBarrierNode.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
package jdk.graal.compiler.nodes.gc.shenandoah;
2626

27+
import static jdk.graal.compiler.nodeinfo.NodeCycles.CYCLES_64;
28+
import static jdk.graal.compiler.nodeinfo.NodeSize.SIZE_64;
29+
2730
import jdk.graal.compiler.core.common.type.ObjectStamp;
2831
import jdk.graal.compiler.debug.GraalError;
2932
import jdk.graal.compiler.graph.NodeClass;
@@ -39,9 +42,6 @@
3942
import jdk.vm.ci.meta.AllocatableValue;
4043
import jdk.vm.ci.meta.Value;
4144

42-
import static jdk.graal.compiler.nodeinfo.NodeCycles.CYCLES_64;
43-
import static jdk.graal.compiler.nodeinfo.NodeSize.SIZE_64;
44-
4545
/**
4646
* Shenandoah SATB barrier. Supports concurrent marking, by implementing the so-called
4747
* snapshot-at-the-beginning (SATB). The barrier ensures that we see a consistent and complete
@@ -53,8 +53,14 @@
5353
public final class ShenandoahSATBBarrierNode extends ObjectWriteBarrierNode implements LIRLowerable {
5454
public static final NodeClass<ShenandoahSATBBarrierNode> TYPE = NodeClass.create(ShenandoahSATBBarrierNode.class);
5555

56-
public ShenandoahSATBBarrierNode(AddressNode address, ValueNode expectedObject) {
56+
/**
57+
* Whether the reference is compressed.
58+
*/
59+
private final boolean narrow;
60+
61+
public ShenandoahSATBBarrierNode(AddressNode address, ValueNode expectedObject, boolean narrow) {
5762
super(TYPE, address, expectedObject, true);
63+
this.narrow = narrow;
5864
}
5965

6066
public ValueNode getExpectedObject() {
@@ -79,7 +85,7 @@ public void generate(NodeLIRBuilderTool generator) {
7985
GraalError.guarantee(expectedObject.stamp(NodeView.DEFAULT) instanceof ObjectStamp, "expecting full size object");
8086
}
8187
ShenandoahBarrierSetLIRGeneratorTool tool = (ShenandoahBarrierSetLIRGeneratorTool) generator.getLIRGeneratorTool().getBarrierSet();
82-
tool.emitPreWriteBarrier(lirGen, generator.operand(getAddress()), operand, nonNull);
88+
tool.emitPreWriteBarrier(lirGen, generator.operand(getAddress()), operand, narrow, nonNull);
8389
}
8490
}
8591
}

0 commit comments

Comments
 (0)