Skip to content

Commit 46e3dea

Browse files
committed
analyze runtime compilation snippets.
1 parent f2bd761 commit 46e3dea

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/replacements/DefaultJavaLoweringProvider.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public AddressNode createFieldAddress(StructuredGraph graph, ValueNode object, R
442442
if (offset >= 0) {
443443
return createOffsetAddress(graph, object, offset);
444444
} else {
445-
return null;
445+
throw GraalError.shouldNotReachHere("Field is missing: " + field.getDeclaringClass().toJavaName(true) + "." + field.getName());
446446
}
447447
}
448448

@@ -463,7 +463,6 @@ protected void lowerLoadFieldNode(LoadFieldNode loadField, LoweringTool tool) {
463463
Stamp loadStamp = loadStamp(loadField.stamp(NodeView.DEFAULT), getStorageKind(field));
464464

465465
AddressNode address = createFieldAddress(graph, object, field);
466-
assert address != null : "Field that is loaded must not be eliminated: " + field.getDeclaringClass().toJavaName(true) + "." + field.getName();
467466

468467
BarrierType barrierType = barrierSet.fieldReadBarrierType(field, getStorageKind(field));
469468
ReadNode memoryRead = graph.add(new ReadNode(address, overrideFieldLocationIdentity(loadField.getLocationIdentity()), loadStamp, barrierType, loadField.getMemoryOrder()));
@@ -479,7 +478,6 @@ protected void lowerStoreFieldNode(StoreFieldNode storeField, LoweringTool tool)
479478
object = createNullCheckedValue(object, storeField, tool);
480479
ValueNode value = implicitStoreConvert(graph, getStorageKind(storeField.field()), storeField.value());
481480
AddressNode address = createFieldAddress(graph, object, field);
482-
assert address != null;
483481

484482
BarrierType barrierType = barrierSet.fieldWriteBarrierType(field, getStorageKind(field));
485483
WriteNode memoryWrite = graph.add(new WriteNode(address, overrideFieldLocationIdentity(storeField.getLocationIdentity()), value, barrierType, storeField.getMemoryOrder()));
@@ -976,13 +974,15 @@ protected void lowerCommitAllocationNode(CommitAllocationNode commit, LoweringTo
976974
ValueNode allocValue = allocations[commit.getVirtualObjects().indexOf(value)];
977975
if (!(allocValue.isConstant() && allocValue.asConstant().isDefaultForKind())) {
978976
assert virtual.entryKind(metaAccessExtensionProvider, i) == JavaKind.Object && allocValue.getStackKind() == JavaKind.Object;
979-
AddressNode address;
980-
BarrierType barrierType;
977+
AddressNode address = null;
978+
BarrierType barrierType = null;
981979
if (virtual instanceof VirtualInstanceNode) {
982980
VirtualInstanceNode virtualInstance = (VirtualInstanceNode) virtual;
983981
ResolvedJavaField field = virtualInstance.field(i);
984-
address = createFieldAddress(graph, newObject, field);
985-
barrierType = barrierSet.fieldWriteBarrierType(field, getStorageKind(field));
982+
if (fieldOffset(field) >= 0) {
983+
address = createFieldAddress(graph, newObject, field);
984+
barrierType = barrierSet.fieldWriteBarrierType(field, getStorageKind(field));
985+
}
986986
} else {
987987
assert virtual instanceof VirtualArrayNode;
988988
address = createArrayAddress(graph, newObject, virtual.entryKind(metaAccessExtensionProvider, i), ConstantNode.forInt(i, graph));

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/RuntimeCompilationFeature.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
import jdk.vm.ci.meta.ResolvedJavaField;
123123
import jdk.vm.ci.meta.ResolvedJavaMethod;
124124
import jdk.vm.ci.meta.ResolvedJavaType;
125-
import jdk.vm.ci.services.Services;
126125

127126
/**
128127
* The main handler for running the Graal compiler in the Substrate VM at run time. This feature
@@ -367,10 +366,11 @@ public GraalGraphObjectReplacer getObjectReplacer() {
367366
}
368367

369368
protected static List<Class<? extends Feature>> getRequiredFeaturesHelper() {
370-
if (Services.IS_BUILDING_NATIVE_IMAGE) {
369+
if (SubstrateUtil.isBuildingLibgraal()) {
371370
return List.of(FieldsOffsetsFeature.class);
371+
} else {
372+
return List.of(RuntimeCompilationCanaryFeature.class, DeoptimizationFeature.class, FieldsOffsetsFeature.class);
372373
}
373-
return List.of(RuntimeCompilationCanaryFeature.class, DeoptimizationFeature.class, FieldsOffsetsFeature.class);
374374
}
375375

376376
public void setUniverseFactory(SubstrateUniverseFactory universeFactory) {
@@ -475,6 +475,12 @@ protected final void beforeAnalysisHelper(BeforeAnalysisAccess c) {
475475
for (NodeClass<?> nodeClass : replacements.getSnippetNodeClasses()) {
476476
config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated("All " + NodeClass.class.getName() + " classes are marked as instantiated eagerly.");
477477
}
478+
/*
479+
* Ensure runtime snippet graphs are analyzed.
480+
*/
481+
if (!SubstrateUtil.isBuildingLibgraal()) {
482+
NativeImageGenerator.performSnippetGraphAnalysis(config.getBigBang(), replacements, config.getBigBang().getOptions());
483+
}
478484

479485
/*
480486
* Ensure that all snippet methods have their SubstrateMethod object created by the object

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
import com.oracle.graal.pointsto.AnalysisPolicy;
140140
import com.oracle.graal.pointsto.BigBang;
141141
import com.oracle.graal.pointsto.ObjectScanningObserver;
142-
import com.oracle.graal.pointsto.PointsToAnalysis;
143142
import com.oracle.graal.pointsto.api.PointstoOptions;
144143
import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
145144
import com.oracle.graal.pointsto.flow.context.bytecode.BytecodeSensitiveAnalysisPolicy;
@@ -1123,19 +1122,22 @@ public static void initializeBigBang(Inflation bb, OptionValues options, Feature
11231122
bb.getAnnotationSubstitutionProcessor(), classInitializationPlugin, ConfigurationValues.getTarget(), supportsStubBasedPlugins);
11241123
registerReplacements(debug, featureHandler, null, aProviders, true, initForeignCalls);
11251124

1126-
Collection<StructuredGraph> snippetGraphs = aReplacements.getSnippetGraphs(GraalOptions.TrackNodeSourcePosition.getValue(options), options);
1127-
if (bb instanceof NativeImagePointsToAnalysis) {
1128-
for (StructuredGraph graph : snippetGraphs) {
1129-
HostedConfiguration.instance().registerUsedElements((PointsToAnalysis) bb, graph, false);
1130-
}
1131-
} else if (bb instanceof NativeImageReachabilityAnalysisEngine) {
1132-
NativeImageReachabilityAnalysisEngine reachabilityAnalysis = (NativeImageReachabilityAnalysisEngine) bb;
1133-
for (StructuredGraph graph : snippetGraphs) {
1134-
reachabilityAnalysis.processGraph(graph);
1135-
}
1136-
} else {
1137-
throw VMError.shouldNotReachHere("Unknown analysis type - please specify how to handle snippets");
1125+
performSnippetGraphAnalysis(bb, aReplacements, options);
1126+
}
1127+
}
1128+
1129+
public static void performSnippetGraphAnalysis(BigBang bb, SubstrateReplacements replacements, OptionValues options) {
1130+
Collection<StructuredGraph> snippetGraphs = replacements.getSnippetGraphs(GraalOptions.TrackNodeSourcePosition.getValue(options), options);
1131+
if (bb instanceof NativeImagePointsToAnalysis pointsToAnalysis) {
1132+
for (StructuredGraph graph : snippetGraphs) {
1133+
HostedConfiguration.instance().registerUsedElements(pointsToAnalysis, graph, false);
11381134
}
1135+
} else if (bb instanceof NativeImageReachabilityAnalysisEngine reachabilityAnalysis) {
1136+
for (StructuredGraph graph : snippetGraphs) {
1137+
reachabilityAnalysis.processGraph(graph);
1138+
}
1139+
} else {
1140+
throw VMError.shouldNotReachHere("Unknown analysis type - please specify how to handle snippets");
11391141
}
11401142
}
11411143

0 commit comments

Comments
 (0)