Skip to content

Commit 9680efd

Browse files
committed
[GR-70318] Add support for deferred init barriers to all barrier sets
PullRequest: graal/22292
2 parents 7adbd98 + 4cec8df commit 9680efd

File tree

16 files changed

+357
-365
lines changed

16 files changed

+357
-365
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/EncodedSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static StructuredGraph decodeSnippetGraph(SymbolicEncodedGraph encodedGraph, Res
349349
nodePlugins = new NodePlugin[]{new SnippetCounterFoldingPlugin()};
350350
}
351351

352-
try (DebugContext debug = replacements.openDebugContext("LibGraal", method, options)) {
352+
try (DebugContext debug = replacements.openSnippetDebugContext("LibGraal", method, options)) {
353353
// @formatter:off
354354
boolean isSubstitution = true;
355355
StructuredGraph result = new StructuredGraph.Builder(options, debug, allowAssumptions)

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotBackendFactory.java

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import jdk.graal.compiler.core.common.LibGraalSupport;
3333
import jdk.graal.compiler.core.common.spi.ConstantFieldProvider;
3434
import jdk.graal.compiler.debug.Assertions;
35-
import jdk.graal.compiler.debug.DebugContext;
36-
import jdk.graal.compiler.graph.Node;
3735
import jdk.graal.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider;
3836
import jdk.graal.compiler.hotspot.meta.HotSpotHostForeignCallsProvider;
3937
import jdk.graal.compiler.hotspot.meta.HotSpotIdentityHashCodeProvider;
@@ -48,19 +46,15 @@
4846
import jdk.graal.compiler.hotspot.nodes.HotSpotCompressionNode;
4947
import jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil;
5048
import jdk.graal.compiler.hotspot.word.HotSpotWordTypes;
51-
import jdk.graal.compiler.nodes.FixedWithNextNode;
5249
import jdk.graal.compiler.nodes.NodeView;
5350
import jdk.graal.compiler.nodes.ValueNode;
54-
import jdk.graal.compiler.nodes.extended.ArrayRangeWrite;
5551
import jdk.graal.compiler.nodes.gc.BarrierSet;
5652
import jdk.graal.compiler.nodes.gc.CardTableBarrierSet;
5753
import jdk.graal.compiler.nodes.gc.G1BarrierSet;
5854
import jdk.graal.compiler.nodes.gc.NoBarrierSet;
5955
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
6056
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
61-
import jdk.graal.compiler.nodes.java.AbstractNewObjectNode;
6257
import jdk.graal.compiler.nodes.loop.LoopsDataProviderImpl;
63-
import jdk.graal.compiler.nodes.memory.FixedAccessNode;
6458
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
6559
import jdk.graal.compiler.nodes.spi.LoopsDataProvider;
6660
import jdk.graal.compiler.nodes.spi.Replacements;
@@ -286,7 +280,7 @@ protected abstract HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProv
286280
protected abstract HotSpotHostForeignCallsProvider createForeignCalls(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalRuntimeProvider graalRuntime, MetaAccessProvider metaAccess,
287281
HotSpotCodeCacheProvider codeCache, HotSpotWordTypes wordTypes, Value[] nativeABICallerSaveRegisters);
288282

289-
private BarrierSet createBarrierSet(GraalHotSpotVMConfig config, MetaAccessProvider metaAccess) {
283+
private static BarrierSet createBarrierSet(GraalHotSpotVMConfig config, MetaAccessProvider metaAccess) {
290284
boolean useDeferredInitBarriers = config.useDeferredInitBarriers;
291285
ResolvedJavaType objectArrayType = metaAccess.lookupJavaType(Object[].class);
292286
ResolvedJavaField referentField = HotSpotReplacementsUtil.referentField(metaAccess);
@@ -297,80 +291,26 @@ private BarrierSet createBarrierSet(GraalHotSpotVMConfig config, MetaAccessProvi
297291
} else if (config.gc == HotSpotGraalRuntime.HotSpotGC.Epsilon) {
298292
return new NoBarrierSet();
299293
} else if (config.useG1GC()) {
300-
return new G1BarrierSet(objectArrayType, referentField) {
301-
@Override
302-
protected boolean writeRequiresPostBarrier(FixedAccessNode node, ValueNode writtenValue) {
303-
if (!super.writeRequiresPostBarrier(node, writtenValue)) {
304-
return false;
305-
}
306-
return !useDeferredInitBarriers || !isWriteToNewObject(node);
307-
}
308-
309-
@Override
310-
protected boolean arrayRangeWriteRequiresPostBarrier(ArrayRangeWrite write) {
311-
if (!super.arrayRangeWriteRequiresPostBarrier(write)) {
312-
return false;
313-
}
314-
return !useDeferredInitBarriers || !isWriteToNewObject(write.asFixedWithNextNode(), write.getAddress().getBase());
315-
}
316-
317-
@Override
318-
protected ValueNode maybeUncompressExpectedValue(ValueNode value) {
319-
if (value != null && (value.stamp(NodeView.DEFAULT) instanceof NarrowOopStamp)) {
320-
return HotSpotCompressionNode.uncompress(value.graph(), value, config.getOopEncoding());
321-
}
322-
return value;
323-
}
324-
};
294+
return new HotSpotG1BarrierSet(objectArrayType, referentField, useDeferredInitBarriers, config);
325295
} else {
326-
return new CardTableBarrierSet(objectArrayType) {
327-
@Override
328-
protected boolean writeRequiresBarrier(FixedAccessNode node, ValueNode writtenValue) {
329-
if (!super.writeRequiresBarrier(node, writtenValue)) {
330-
return false;
331-
}
332-
return !useDeferredInitBarriers || !isWriteToNewObject(node);
333-
}
334-
335-
@Override
336-
protected boolean arrayRangeWriteRequiresBarrier(ArrayRangeWrite write) {
337-
if (!super.arrayRangeWriteRequiresBarrier(write)) {
338-
return false;
339-
}
340-
return !useDeferredInitBarriers || !isWriteToNewObject(write.asFixedWithNextNode(), write.getAddress().getBase());
341-
}
342-
};
296+
return new CardTableBarrierSet(objectArrayType, useDeferredInitBarriers);
343297
}
344298
}
345299

346-
/**
347-
* For initializing writes, the last allocation executed by the JVM is guaranteed to be
348-
* automatically card marked so it's safe to skip the card mark in the emitted code.
349-
*/
350-
protected boolean isWriteToNewObject(FixedAccessNode node) {
351-
if (!node.getLocationIdentity().isInit()) {
352-
return false;
300+
private static class HotSpotG1BarrierSet extends G1BarrierSet {
301+
private final GraalHotSpotVMConfig config;
302+
303+
HotSpotG1BarrierSet(ResolvedJavaType objectArrayType, ResolvedJavaField referentField, boolean useDeferredInitBarriers, GraalHotSpotVMConfig config) {
304+
super(objectArrayType, referentField, useDeferredInitBarriers);
305+
this.config = config;
353306
}
354-
// This is only allowed for the last allocation in sequence
355-
return isWriteToNewObject(node, node.getAddress().getBase());
356-
}
357307

358-
protected boolean isWriteToNewObject(FixedWithNextNode node, ValueNode base) {
359-
if (base instanceof AbstractNewObjectNode) {
360-
Node pred = node.predecessor();
361-
while (pred != null) {
362-
if (pred == base) {
363-
node.getDebug().log(DebugContext.INFO_LEVEL, "Deferred barrier for %s with base %s", node, base);
364-
return true;
365-
}
366-
if (pred instanceof AbstractNewObjectNode) {
367-
node.getDebug().log(DebugContext.INFO_LEVEL, "Disallowed deferred barrier for %s because %s was last allocation instead of %s", node, pred, base);
368-
return false;
369-
}
370-
pred = pred.predecessor();
308+
@Override
309+
protected ValueNode maybeUncompressExpectedValue(ValueNode value) {
310+
if (value != null && (value.stamp(NodeView.DEFAULT) instanceof NarrowOopStamp)) {
311+
return HotSpotCompressionNode.uncompress(value.graph(), value, config.getOopEncoding());
371312
}
313+
return value;
372314
}
373-
node.getDebug().log(DebugContext.INFO_LEVEL, "Unable to find allocation for deferred barrier for %s with base %s", node, base);
374-
return false;
375315
}
376316
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotDecoratedBackendFactory.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@
3636
import jdk.graal.compiler.hotspot.meta.HotSpotStampProvider;
3737
import jdk.graal.compiler.hotspot.meta.HotSpotSuitesProvider;
3838
import jdk.graal.compiler.hotspot.word.HotSpotWordTypes;
39-
import jdk.graal.compiler.nodes.FixedWithNextNode;
40-
import jdk.graal.compiler.nodes.ValueNode;
4139
import jdk.graal.compiler.nodes.gc.BarrierSet;
4240
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
43-
import jdk.graal.compiler.nodes.memory.FixedAccessNode;
4441
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
4542
import jdk.graal.compiler.nodes.spi.LoopsDataProvider;
4643
import jdk.graal.compiler.options.OptionValues;
@@ -126,16 +123,6 @@ protected IdentityHashCodeProvider createIdentityHashCodeProvider() {
126123
return delegate.createIdentityHashCodeProvider();
127124
}
128125

129-
@Override
130-
protected boolean isWriteToNewObject(FixedAccessNode node) {
131-
return delegate.isWriteToNewObject(node);
132-
}
133-
134-
@Override
135-
protected boolean isWriteToNewObject(FixedWithNextNode node, ValueNode base) {
136-
return delegate.isWriteToNewObject(node, base);
137-
}
138-
139126
@Override
140127
protected LoopsDataProvider createLoopsDataProvider() {
141128
return delegate.createLoopsDataProvider();

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/SymbolicSnippetEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private StructuredGraph buildGraph(ResolvedJavaMethod method, ResolvedJavaMethod
281281
// Dumps of the graph preparation step can be captured with -H:Dump=LibGraal:2 and
282282
// MethodFilter can be used to focus on particular snippets.
283283
IntrinsicContext.CompilationContext contextToUse = IntrinsicContext.CompilationContext.INLINE_AFTER_PARSING;
284-
try (DebugContext debug = snippetReplacements.openDebugContext("LibGraalBuildGraph_", method, options)) {
284+
try (DebugContext debug = snippetReplacements.openSnippetDebugContext("LibGraalBuildGraph_", method, options)) {
285285
StructuredGraph graph;
286286
try (DebugContext.Scope s = debug.scope("LibGraal", method)) {
287287
graph = snippetReplacements.makeGraph(debug, snippetReplacements.getDefaultReplacementBytecodeProvider(), method, args, nonNullParameters, original,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.graal.compiler.nodes;
26+
27+
import jdk.graal.compiler.nodes.memory.FixedAccessNode;
28+
29+
/**
30+
* See {@link ValueNodeInterface} for details about these node interfaces.
31+
*/
32+
public interface FixedAccessNodeInterface extends FixedWithNextNodeInterface {
33+
FixedAccessNode asFixedAccessNode();
34+
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/ArrayRangeWrite.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@
2424
*/
2525
package jdk.graal.compiler.nodes.extended;
2626

27+
import jdk.graal.compiler.nodes.FixedAccessNodeInterface;
2728
import jdk.graal.compiler.nodes.FixedNode;
2829
import jdk.graal.compiler.nodes.FixedWithNextNode;
29-
import jdk.graal.compiler.nodes.FixedWithNextNodeInterface;
3030
import jdk.graal.compiler.nodes.ValueNode;
3131
import jdk.graal.compiler.nodes.memory.address.AddressNode;
3232

33-
public interface ArrayRangeWrite extends FixedWithNextNodeInterface {
33+
/**
34+
* Represents a node in the graph that writes to a range of memory in an array. This interface
35+
* provides methods to access the address of the region being written, the length of the range, and
36+
* other relevant information about the write operation.
37+
*/
38+
public interface ArrayRangeWrite extends FixedAccessNodeInterface {
39+
40+
/**
41+
* Returns the address node representing the base address of the array being written to.
42+
*/
3443
AddressNode getAddress();
3544

3645
/**
@@ -50,6 +59,9 @@ public interface ArrayRangeWrite extends FixedWithNextNodeInterface {
5059
*/
5160
boolean isInitialization();
5261

62+
/**
63+
* Returns the stride (in bytes) between consecutive elements in the array.
64+
*/
5365
int getElementStride();
5466

5567
/**

0 commit comments

Comments
 (0)