Skip to content

Commit

Permalink
analyze runtime compilation snippets.
Browse files Browse the repository at this point in the history
  • Loading branch information
teshull committed Sep 8, 2023
1 parent f2bd761 commit 46e3dea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public AddressNode createFieldAddress(StructuredGraph graph, ValueNode object, R
if (offset >= 0) {
return createOffsetAddress(graph, object, offset);
} else {
return null;
throw GraalError.shouldNotReachHere("Field is missing: " + field.getDeclaringClass().toJavaName(true) + "." + field.getName());
}
}

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

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

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

BarrierType barrierType = barrierSet.fieldWriteBarrierType(field, getStorageKind(field));
WriteNode memoryWrite = graph.add(new WriteNode(address, overrideFieldLocationIdentity(storeField.getLocationIdentity()), value, barrierType, storeField.getMemoryOrder()));
Expand Down Expand Up @@ -976,13 +974,15 @@ protected void lowerCommitAllocationNode(CommitAllocationNode commit, LoweringTo
ValueNode allocValue = allocations[commit.getVirtualObjects().indexOf(value)];
if (!(allocValue.isConstant() && allocValue.asConstant().isDefaultForKind())) {
assert virtual.entryKind(metaAccessExtensionProvider, i) == JavaKind.Object && allocValue.getStackKind() == JavaKind.Object;
AddressNode address;
BarrierType barrierType;
AddressNode address = null;
BarrierType barrierType = null;
if (virtual instanceof VirtualInstanceNode) {
VirtualInstanceNode virtualInstance = (VirtualInstanceNode) virtual;
ResolvedJavaField field = virtualInstance.field(i);
address = createFieldAddress(graph, newObject, field);
barrierType = barrierSet.fieldWriteBarrierType(field, getStorageKind(field));
if (fieldOffset(field) >= 0) {
address = createFieldAddress(graph, newObject, field);
barrierType = barrierSet.fieldWriteBarrierType(field, getStorageKind(field));
}
} else {
assert virtual instanceof VirtualArrayNode;
address = createArrayAddress(graph, newObject, virtual.entryKind(metaAccessExtensionProvider, i), ConstantNode.forInt(i, graph));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.services.Services;

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

protected static List<Class<? extends Feature>> getRequiredFeaturesHelper() {
if (Services.IS_BUILDING_NATIVE_IMAGE) {
if (SubstrateUtil.isBuildingLibgraal()) {
return List.of(FieldsOffsetsFeature.class);
} else {
return List.of(RuntimeCompilationCanaryFeature.class, DeoptimizationFeature.class, FieldsOffsetsFeature.class);
}
return List.of(RuntimeCompilationCanaryFeature.class, DeoptimizationFeature.class, FieldsOffsetsFeature.class);
}

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

/*
* Ensure that all snippet methods have their SubstrateMethod object created by the object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
import com.oracle.graal.pointsto.AnalysisPolicy;
import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.ObjectScanningObserver;
import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
import com.oracle.graal.pointsto.flow.context.bytecode.BytecodeSensitiveAnalysisPolicy;
Expand Down Expand Up @@ -1123,19 +1122,22 @@ public static void initializeBigBang(Inflation bb, OptionValues options, Feature
bb.getAnnotationSubstitutionProcessor(), classInitializationPlugin, ConfigurationValues.getTarget(), supportsStubBasedPlugins);
registerReplacements(debug, featureHandler, null, aProviders, true, initForeignCalls);

Collection<StructuredGraph> snippetGraphs = aReplacements.getSnippetGraphs(GraalOptions.TrackNodeSourcePosition.getValue(options), options);
if (bb instanceof NativeImagePointsToAnalysis) {
for (StructuredGraph graph : snippetGraphs) {
HostedConfiguration.instance().registerUsedElements((PointsToAnalysis) bb, graph, false);
}
} else if (bb instanceof NativeImageReachabilityAnalysisEngine) {
NativeImageReachabilityAnalysisEngine reachabilityAnalysis = (NativeImageReachabilityAnalysisEngine) bb;
for (StructuredGraph graph : snippetGraphs) {
reachabilityAnalysis.processGraph(graph);
}
} else {
throw VMError.shouldNotReachHere("Unknown analysis type - please specify how to handle snippets");
performSnippetGraphAnalysis(bb, aReplacements, options);
}
}

public static void performSnippetGraphAnalysis(BigBang bb, SubstrateReplacements replacements, OptionValues options) {
Collection<StructuredGraph> snippetGraphs = replacements.getSnippetGraphs(GraalOptions.TrackNodeSourcePosition.getValue(options), options);
if (bb instanceof NativeImagePointsToAnalysis pointsToAnalysis) {
for (StructuredGraph graph : snippetGraphs) {
HostedConfiguration.instance().registerUsedElements(pointsToAnalysis, graph, false);
}
} else if (bb instanceof NativeImageReachabilityAnalysisEngine reachabilityAnalysis) {
for (StructuredGraph graph : snippetGraphs) {
reachabilityAnalysis.processGraph(graph);
}
} else {
throw VMError.shouldNotReachHere("Unknown analysis type - please specify how to handle snippets");
}
}

Expand Down

0 comments on commit 46e3dea

Please sign in to comment.