Skip to content

Commit

Permalink
[GR-53705] Remove the concept of "Unsafe partitions".
Browse files Browse the repository at this point in the history
PullRequest: graal/17621
  • Loading branch information
christianwimmer committed May 9, 2024
2 parents e3d8479 + 2c795c5 commit 126bcc8
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 593 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.graal.pointsto.standalone.StandaloneHost;
import com.oracle.svm.util.UnsafePartitionKind;

import jdk.graal.compiler.debug.DebugContext;

Expand Down Expand Up @@ -226,14 +225,8 @@ public void registerAsFrozenUnsafeAccessed(AnalysisField aField) {
registerAsUnsafeAccessed(aField, "registered from standalone feature");
}

public void registerAsUnsafeAccessed(Field field, UnsafePartitionKind partitionKind, Object reason) {
registerAsUnsafeAccessed(getMetaAccess().lookupJavaField(field), partitionKind, reason);
}

public void registerAsUnsafeAccessed(AnalysisField aField, UnsafePartitionKind partitionKind, Object reason) {
if (!aField.isUnsafeAccessed()) {
aField.registerAsUnsafeAccessed(partitionKind, reason);
}
public void registerAsUnsafeAccessed(Field field, Object reason) {
registerAsUnsafeAccessed(getMetaAccess().lookupJavaField(field), reason);
}

public void registerAsInvoked(Executable method, boolean invokeSpecial, Object reason) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.debug.Indent;
import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.graph.NodeList;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.word.WordTypes;
import jdk.vm.ci.meta.ConstantReflectionProvider;
Expand Down Expand Up @@ -280,14 +278,6 @@ public AnalysisType getObjectArrayType() {
return metaAccess.lookupJavaType(Object[].class);
}

public AnalysisType getGraalNodeType() {
return metaAccess.lookupJavaType(Node.class);
}

public AnalysisType getGraalNodeListType() {
return metaAccess.lookupJavaType(NodeList.class);
}

public TypeFlow<?> getAllInstantiatedTypeFlow() {
return objectType.getTypeFlow(this, true);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
import com.oracle.graal.pointsto.flow.MethodFlowsGraph.GraphKind;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.LoadIndexedTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafeLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.UnsafePartitionLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.StoreIndexedTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafePartitionStoreTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.UnsafeStoreTypeFlow;
import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreInstanceFieldTypeFlow;
import com.oracle.graal.pointsto.flow.StoreFieldTypeFlow.StoreStaticFieldTypeFlow;
Expand All @@ -57,8 +55,6 @@
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.HostedProviders;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.nodes.UnsafePartitionLoadNode;
import com.oracle.graal.pointsto.nodes.UnsafePartitionStoreNode;
import com.oracle.graal.pointsto.phases.InlineBeforeAnalysis;
import com.oracle.graal.pointsto.results.StrengthenGraphs;
import com.oracle.graal.pointsto.typestate.TypeState;
Expand Down Expand Up @@ -1060,65 +1056,6 @@ protected void node(FixedNode n) {
processStoreIndexed(node, node.array(), node.value(), node.value().getStackKind(), state);
processImplicitNonNull(node.array(), state);

} else if (n instanceof UnsafePartitionLoadNode) {
UnsafePartitionLoadNode node = (UnsafePartitionLoadNode) n;
assert node.object().getStackKind() == JavaKind.Object : node.object();

checkUnsafeOffset(node.object(), node.offset());

AnalysisType partitionType = (AnalysisType) node.partitionType();

AnalysisType objectType = (AnalysisType) StampTool.typeOrNull(node.object(), bb.getMetaAccess());
assert bb.getGraalNodeType().isAssignableFrom(objectType) : objectType;

/* Use the Object type as a conservative type for the values loaded. */
AnalysisType componentType = bb.getObjectType();

TypeFlowBuilder<?> objectBuilder = state.lookup(node.object());
TypeFlowBuilder<?> unsafeLoadBuilder = TypeFlowBuilder.create(bb, node, UnsafePartitionLoadTypeFlow.class, () -> {
UnsafePartitionLoadTypeFlow loadTypeFlow = new UnsafePartitionLoadTypeFlow(AbstractAnalysisEngine.sourcePosition(node), objectType, componentType, objectBuilder.get(),
node.unsafePartitionKind(), partitionType);
flowsGraph.addMiscEntryFlow(loadTypeFlow);
return loadTypeFlow;
});
unsafeLoadBuilder.addObserverDependency(objectBuilder);
state.add(node, unsafeLoadBuilder);

} else if (n instanceof UnsafePartitionStoreNode) {
UnsafePartitionStoreNode node = (UnsafePartitionStoreNode) n;

assert node.object().getStackKind() == JavaKind.Object : node.object();
assert node.value().getStackKind() == JavaKind.Object : node.value();

checkUnsafeOffset(node.object(), node.offset());

AnalysisType partitionType = (AnalysisType) node.partitionType();

AnalysisType objectType = (AnalysisType) StampTool.typeOrNull(node.object(), bb.getMetaAccess());
assert bb.getGraalNodeType().isAssignableFrom(objectType) : objectType;

/* Use the Object type as a conservative type for the values stored. */
AnalysisType componentType = bb.getObjectType();

AnalysisType valueType = (AnalysisType) StampTool.typeOrNull(node.value(), bb.getMetaAccess());
assert valueType.isJavaLangObject() || bb.getGraalNodeType().isAssignableFrom(valueType) || bb.getGraalNodeListType().isAssignableFrom(valueType) : valueType;

TypeFlowBuilder<?> objectBuilder = state.lookup(node.object());
TypeFlowBuilder<?> valueBuilder = state.lookup(node.value());

TypeFlowBuilder<?> unsafeStoreBuilder = TypeFlowBuilder.create(bb, node, UnsafePartitionStoreTypeFlow.class, () -> {
UnsafePartitionStoreTypeFlow storeTypeFlow = new UnsafePartitionStoreTypeFlow(AbstractAnalysisEngine.sourcePosition(node), objectType, componentType, objectBuilder.get(),
valueBuilder.get(),
node.partitionKind(), partitionType);
flowsGraph.addMiscEntryFlow(storeTypeFlow);
return storeTypeFlow;
});
unsafeStoreBuilder.addUseDependency(valueBuilder);
unsafeStoreBuilder.addObserverDependency(objectBuilder);

/* Unsafe stores must not be removed. */
typeFlowGraphBuilder.registerSinkBuilder(unsafeStoreBuilder);

} else if (n instanceof RawLoadNode node) {
modelUnsafeReadOnlyFlow(node, node.object(), node.offset());
} else if (n instanceof RawStoreNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.svm.util.UnsafePartitionKind;

import jdk.vm.ci.code.BytecodePosition;

Expand Down Expand Up @@ -250,58 +249,4 @@ public String toString() {
return "UnsafeLoadTypeFlow<" + getState() + ">";
}
}

public static class UnsafePartitionLoadTypeFlow extends AbstractUnsafeLoadTypeFlow {

protected final UnsafePartitionKind partitionKind;
protected final AnalysisType partitionType;

public UnsafePartitionLoadTypeFlow(BytecodePosition loadLocation, AnalysisType objectType, AnalysisType componentType, TypeFlow<?> arrayFlow,
UnsafePartitionKind partitionKind, AnalysisType partitionType) {
super(loadLocation, objectType, componentType, arrayFlow);
this.partitionKind = partitionKind;
this.partitionType = partitionType;
}

private UnsafePartitionLoadTypeFlow(PointsToAnalysis bb, MethodFlowsGraph methodFlows, UnsafePartitionLoadTypeFlow original) {
super(bb, methodFlows, original);
this.partitionKind = original.partitionKind;
this.partitionType = original.partitionType;
}

@Override
public AbstractUnsafeLoadTypeFlow copy(PointsToAnalysis bb, MethodFlowsGraph methodFlows) {
return new UnsafePartitionLoadTypeFlow(bb, methodFlows, this);
}

@Override
public TypeState filter(PointsToAnalysis bb, TypeState update) {
if (partitionType.equals(bb.getObjectType())) {
/* No need to filter. */
return update;
} else {
/* Filter the incoming state with the partition type. */
return TypeState.forIntersection(bb, update, partitionType.getAssignableTypes(true));
}
}

@Override
public void onObservedUpdate(PointsToAnalysis bb) {
TypeState objectState = getObjectState();

for (AnalysisObject object : objectState.objects(bb)) {
AnalysisType objectType = object.type();
assert !objectType.isArray() : objectType;

for (AnalysisField field : objectType.unsafeAccessedFields(partitionKind)) {
processField(bb, object, field);
}
}
}

@Override
public String toString() {
return "UnsafePartitionLoadTypeFlow<" + getState() + "> : " + partitionKind;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
*/
package com.oracle.graal.pointsto.flow;

import java.util.List;
import java.util.Collection;

import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.api.DefaultUnsafePartition;
import com.oracle.graal.pointsto.flow.context.object.AnalysisObject;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.PointsToAnalysisType;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.svm.util.UnsafePartitionKind;

import jdk.vm.ci.code.BytecodePosition;

Expand Down Expand Up @@ -219,7 +217,7 @@ public void forceUpdate(PointsToAnalysis bb) {
}
}

void handleUnsafeAccessedFields(PointsToAnalysis bb, List<AnalysisField> unsafeAccessedFields, AnalysisObject object) {
void handleUnsafeAccessedFields(PointsToAnalysis bb, Collection<AnalysisField> unsafeAccessedFields, AnalysisObject object) {
for (AnalysisField field : unsafeAccessedFields) {
/* Write through the field filter flow. */
if (field.hasUnsafeFrozenTypeState()) {
Expand Down Expand Up @@ -271,7 +269,7 @@ public void onObservedUpdate(PointsToAnalysis bb) {
TypeFlow<?> elementsFlow = object.getArrayElementsFlow(bb, true);
this.addUse(bb, elementsFlow);
} else {
handleUnsafeAccessedFields(bb, type.unsafeAccessedFields(DefaultUnsafePartition.get()), object);
handleUnsafeAccessedFields(bb, type.unsafeAccessedFields(), object);
}
}
}
Expand Down Expand Up @@ -305,63 +303,4 @@ public String toString() {
return "UnsafeStoreTypeFlow<" + getState() + ">";
}
}

public static class UnsafePartitionStoreTypeFlow extends AbstractUnsafeStoreTypeFlow {

protected final UnsafePartitionKind partitionKind;
protected final AnalysisType partitionType;

public UnsafePartitionStoreTypeFlow(BytecodePosition storeLocation, AnalysisType objectType, AnalysisType componentType, TypeFlow<?> objectFlow, TypeFlow<?> valueFlow,
UnsafePartitionKind partitionKind, AnalysisType partitionType) {
super(storeLocation, objectType, componentType, objectFlow, valueFlow);
this.partitionKind = partitionKind;
this.partitionType = partitionType;
}

public UnsafePartitionStoreTypeFlow(PointsToAnalysis bb, MethodFlowsGraph methodFlows, UnsafePartitionStoreTypeFlow original) {
super(bb, methodFlows, original);
this.partitionKind = original.partitionKind;
this.partitionType = original.partitionType;
}

@Override
public UnsafePartitionStoreTypeFlow makeCopy(PointsToAnalysis bb, MethodFlowsGraph methodFlows) {
return new UnsafePartitionStoreTypeFlow(bb, methodFlows, this);
}

@Override
public TypeState filter(PointsToAnalysis bb, TypeState update) {
if (partitionType.equals(bb.getObjectType())) {
/* No need to filter. */
return update;
} else {
/* Filter the incoming state with the partition type. */
return TypeState.forIntersection(bb, update, partitionType.getAssignableTypes(true));
}
}

@Override
public void onObservedUpdate(PointsToAnalysis bb) {
TypeState objectState = objectFlow.getState();

/* Iterate over the receiver objects. */
for (AnalysisObject object : objectState.objects(bb)) {
AnalysisType type = object.type();
assert !type.isArray() : type;

handleUnsafeAccessedFields(bb, type.unsafeAccessedFields(partitionKind), object);
}
}

@Override
public void onObservedSaturated(PointsToAnalysis bb, TypeFlow<?> observed) {
/* When receiver object flow saturates start observing the flow of the object type. */
replaceObservedWith(bb, objectType);
}

@Override
public String toString() {
return "UnsafePartitionStoreTypeFlow<" + getState() + "> : " + partitionKind;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import com.oracle.graal.pointsto.api.DefaultUnsafePartition;
import com.oracle.graal.pointsto.api.HostVM;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.flow.ContextInsensitiveFieldTypeFlow;
Expand All @@ -44,7 +43,6 @@
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.graal.pointsto.util.AnalysisFuture;
import com.oracle.graal.pointsto.util.AtomicUtils;
import com.oracle.svm.util.UnsafePartitionKind;

import jdk.graal.compiler.debug.GraalError;
import jdk.vm.ci.code.BytecodePosition;
Expand Down Expand Up @@ -323,11 +321,7 @@ public void registerAsFolded(Object reason) {
}
}

public void registerAsUnsafeAccessed(Object reason) {
registerAsUnsafeAccessed(DefaultUnsafePartition.get(), reason);
}

public boolean registerAsUnsafeAccessed(UnsafePartitionKind partitionKind, Object reason) {
public boolean registerAsUnsafeAccessed(Object reason) {
assert isValidReason(reason) : "Registering a field as unsafe accessed needs to provide a valid reason.";
registerAsAccessed(reason);
/*
Expand Down Expand Up @@ -356,7 +350,7 @@ public boolean registerAsUnsafeAccessed(UnsafePartitionKind partitionKind, Objec
} else {
/* Register the instance field as unsafe accessed on the declaring type. */
AnalysisType declaringType = getDeclaringClass();
declaringType.registerUnsafeAccessedField(this, partitionKind);
declaringType.registerUnsafeAccessedField(this);
}
return true;
}
Expand Down

0 comments on commit 126bcc8

Please sign in to comment.