Skip to content

Commit 7acd5ce

Browse files
committed
[GR-59855] Make StaticFinalFieldFoldingFeature layer aware
PullRequest: graal/19639
2 parents 883ee06 + d61c649 commit 7acd5ce

9 files changed

+440
-141
lines changed

substratevm/src/com.oracle.svm.hosted/resources/SharedLayerSnapshotCapnProtoSchema.capnp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ struct PersistedAnalysisField {
133133
isSynthetic @13 :Bool;
134134
annotationList @14 :List(Annotation);
135135
name @15 :Text;
136-
fieldCheckIndex @16 :Int32;
137136
}
138137

139138
struct CEntryPointLiteralReference {
@@ -258,6 +257,15 @@ struct SharedLayerSnapshot {
258257
singletonObjects @12 :List(ImageSingletonObject);
259258
fields @13 :List(PersistedAnalysisField);
260259
nextLayerNumber @14 :Int32;
260+
staticFinalFieldFoldingSingleton @15 :StaticFinalFieldFoldingSingleton;
261+
}
262+
263+
struct StaticFinalFieldFoldingSingleton {
264+
fields @0 :List(FieldId);
265+
fieldCheckIndexes @1 :List(Int32);
266+
fieldInitializationStatusList @2 :List(Bool);
267+
bytecodeParsedFoldedFieldValues @3 :List(ConstantReference);
268+
afterParsingHooksDoneFoldedFieldValues @4 :List(ConstantReference);
261269
}
262270

263271
struct PrimitiveValue {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/fieldfolding/IsStaticFinalFieldInitializedNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
/**
4646
* Node that checks if a static final field is initialized. This is basically just a load of the
47-
* value in the {@link StaticFinalFieldFoldingFeature#fieldInitializationStatus} array. But we
47+
* value in the {@link StaticFinalFieldFoldingSingleton#fieldInitializationStatus} array. But we
4848
* cannot immediately emit a {@link LoadIndexedNode} in the bytecode parser because we do not know
4949
* at the time of parsing if the declaring class of the field is initialized at image build time.
5050
*/
@@ -87,10 +87,10 @@ public void simplify(SimplifierTool tool) {
8787
replacementNode = ConstantNode.forBoolean(true, graph());
8888

8989
} else {
90-
StaticFinalFieldFoldingFeature feature = StaticFinalFieldFoldingFeature.singleton();
91-
Integer fieldCheckIndex = feature.getFieldCheckIndex(field);
90+
StaticFinalFieldFoldingSingleton singleton = StaticFinalFieldFoldingSingleton.singleton();
91+
Integer fieldCheckIndex = singleton.getFieldCheckIndex(field);
9292
assert fieldCheckIndex != null : "Field must be optimizable: " + field;
93-
ConstantNode fieldInitializationStatusNode = ConstantNode.forConstant(tool.getSnippetReflection().forObject(feature.fieldInitializationStatus), tool.getMetaAccess(), graph());
93+
ConstantNode fieldInitializationStatusNode = ConstantNode.forConstant(tool.getSnippetReflection().forObject(singleton.fieldInitializationStatus), tool.getMetaAccess(), graph());
9494
ConstantNode fieldCheckIndexNode = ConstantNode.forInt(fieldCheckIndex, graph());
9595

9696
replacementNode = graph().addOrUniqueWithInputs(LoadIndexedNode.create(graph().getAssumptions(), fieldInitializationStatusNode, fieldCheckIndexNode,

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/fieldfolding/MarkStaticFinalFieldInitializedNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343

4444
/**
4545
* Node that marks a static final field as initialized. This is basically just a store of the value
46-
* true in the {@link StaticFinalFieldFoldingFeature#fieldInitializationStatus} array. But we cannot
47-
* immediately emit a {@link StoreIndexedNode} in the bytecode parser because we do not know at the
48-
* time of parsing if the field can actually be optimized or not. So this node is emitted for every
49-
* static final field store, and then just removed if the field cannot be optimized.
46+
* true in the {@link StaticFinalFieldFoldingSingleton#fieldInitializationStatus} array. But we
47+
* cannot immediately emit a {@link StoreIndexedNode} in the bytecode parser because we do not know
48+
* at the time of parsing if the field can actually be optimized or not. So this node is emitted for
49+
* every static final field store, and then just removed if the field cannot be optimized.
5050
*/
5151
@NodeInfo(size = NodeSize.SIZE_1, cycles = NodeCycles.CYCLES_1)
5252
public final class MarkStaticFinalFieldInitializedNode extends AbstractStateSplit implements Simplifiable {
@@ -75,10 +75,10 @@ public void simplify(SimplifierTool tool) {
7575
}
7676
assert field instanceof HostedField;
7777

78-
StaticFinalFieldFoldingFeature feature = StaticFinalFieldFoldingFeature.singleton();
79-
Integer fieldCheckIndex = feature.getFieldCheckIndex(field);
78+
StaticFinalFieldFoldingSingleton singleton = StaticFinalFieldFoldingSingleton.singleton();
79+
Integer fieldCheckIndex = singleton.getFieldCheckIndex(field);
8080
if (fieldCheckIndex != null) {
81-
ConstantNode fieldInitializationStatusNode = ConstantNode.forConstant(tool.getSnippetReflection().forObject(feature.fieldInitializationStatus), tool.getMetaAccess(), graph());
81+
ConstantNode fieldInitializationStatusNode = ConstantNode.forConstant(tool.getSnippetReflection().forObject(singleton.fieldInitializationStatus), tool.getMetaAccess(), graph());
8282
ConstantNode fieldCheckIndexNode = ConstantNode.forInt(fieldCheckIndex, graph());
8383
ConstantNode trueNode = ConstantNode.forBoolean(true, graph());
8484
StoreIndexedNode replacementNode = graph().add(new StoreIndexedNode(fieldInitializationStatusNode, fieldCheckIndexNode, null, null, JavaKind.Boolean, trueNode));

0 commit comments

Comments
 (0)