Skip to content

Commit

Permalink
[GR-38184] Simplify type state.
Browse files Browse the repository at this point in the history
PullRequest: graal/11690
  • Loading branch information
cstancu committed May 20, 2022
2 parents cf2980b + 27299f8 commit fe1b459
Show file tree
Hide file tree
Showing 26 changed files with 2,450 additions and 1,952 deletions.
1 change: 1 addition & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@
"com.oracle.graal.pointsto.typestate",
"com.oracle.graal.pointsto.infrastructure",
"com.oracle.graal.pointsto.flow.context.object",
"com.oracle.graal.pointsto.flow.context.bytecode",
],
"requires": [
"java.management",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ public boolean forNonNullFieldValue(JavaConstant receiver, AnalysisField field,
/* Add the constant value object to the field's type flow. */
FieldTypeFlow fieldTypeFlow = getFieldTypeFlow(field, receiver);
AnalysisObject constantObject = bb.analysisPolicy().createConstantObject(analysis, fieldValue, fieldType);
if (!fieldTypeFlow.getState().containsObject(constantObject)) {
/* Add the new constant to the field's flow state. */
TypeState constantTypeState = TypeState.forNonNullObject(analysis, constantObject);
return fieldTypeFlow.addState(analysis, constantTypeState);
}
return false;
/* Add the new constant to the field's flow state. */
TypeState constantTypeState = TypeState.forNonNullObject(analysis, constantObject);
return fieldTypeFlow.addState(analysis, constantTypeState);
}

/**
Expand Down Expand Up @@ -111,12 +108,9 @@ public boolean forNonNullArrayElement(JavaConstant array, AnalysisType arrayType
ArrayElementsTypeFlow arrayObjElementsFlow = getArrayElementsFlow(array, arrayType);
PointsToAnalysis analysis = getAnalysis();
AnalysisObject constantObject = bb.analysisPolicy().createConstantObject(analysis, elementConstant, elementType);
if (!arrayObjElementsFlow.getState().containsObject(constantObject)) {
/* Add the constant element to the constant's array type flow. */
TypeState elementTypeState = TypeState.forNonNullObject(analysis, constantObject);
return arrayObjElementsFlow.addState(analysis, elementTypeState);
}
return false;
/* Add the constant element to the constant's array type flow. */
TypeState elementTypeState = TypeState.forNonNullObject(analysis, constantObject);
return arrayObjElementsFlow.addState(analysis, elementTypeState);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package com.oracle.graal.pointsto;

import java.util.BitSet;

import org.graalvm.compiler.options.OptionValues;

import com.oracle.graal.pointsto.api.PointstoOptions;
Expand All @@ -41,7 +43,10 @@
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.typestate.MultiTypeState;
import com.oracle.graal.pointsto.typestate.SingleTypeState;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.graal.pointsto.typestate.TypeStateUtils;
import com.oracle.graal.pointsto.typestore.ArrayElementsTypeStore;
import com.oracle.graal.pointsto.typestore.FieldTypeStore;

Expand Down Expand Up @@ -169,4 +174,75 @@ public int makePropertiesForUnion(TypeState s1, TypeState s2) {
/* The default analysis policy doesn't use properties. */
return 0;
}

/**
* Simplifies a type state by replacing all context sensitive objects with context insensitive
* objects.
*/
public abstract TypeState forContextInsensitiveTypeState(PointsToAnalysis bb, TypeState state);

public abstract SingleTypeState singleTypeState(PointsToAnalysis bb, boolean canBeNull, int properties, AnalysisType type, AnalysisObject... objects);

public abstract MultiTypeState multiTypeState(PointsToAnalysis bb, boolean canBeNull, int properties, BitSet typesBitSet, AnalysisObject... objects);

public abstract TypeState doUnion(PointsToAnalysis bb, SingleTypeState s1, SingleTypeState s2);

public abstract TypeState doUnion(PointsToAnalysis bb, MultiTypeState s1, SingleTypeState s2);

public abstract TypeState doUnion(PointsToAnalysis bb, MultiTypeState s1, MultiTypeState s2);

@SuppressWarnings("static-method")
public final TypeState doIntersection(PointsToAnalysis bb, SingleTypeState s1, SingleTypeState s2) {
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
boolean resultCanBeNull = s1.canBeNull() && s2.canBeNull();
if (s1.exactType().equals(s2.exactType())) {
/* The inputs have the same type, the result will be s1. */
return s1.forCanBeNull(bb, resultCanBeNull);
} else {
/* The inputs have different types then the result is empty or null. */
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
}
}

@SuppressWarnings("static-method")
public final TypeState doIntersection(PointsToAnalysis bb, SingleTypeState s1, MultiTypeState s2) {
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
boolean resultCanBeNull = s1.canBeNull() && s2.canBeNull();
if (s2.containsType(s1.exactType())) {
return s1.forCanBeNull(bb, resultCanBeNull);
} else {
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
}
}

public abstract TypeState doIntersection(PointsToAnalysis bb, MultiTypeState s1, SingleTypeState s2);

public abstract TypeState doIntersection(PointsToAnalysis bb, MultiTypeState s1, MultiTypeState s2);

@SuppressWarnings("static-method")
public final TypeState doSubtraction(PointsToAnalysis bb, SingleTypeState s1, SingleTypeState s2) {
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
boolean resultCanBeNull = s1.canBeNull() && !s2.canBeNull();
if (s1.exactType().equals(s2.exactType())) {
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
} else {
return s1.forCanBeNull(bb, resultCanBeNull);
}
}

@SuppressWarnings("static-method")
public final TypeState doSubtraction(PointsToAnalysis bb, SingleTypeState s1, MultiTypeState s2) {
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
boolean resultCanBeNull = s1.canBeNull() && !s2.canBeNull();
if (s2.containsType(s1.exactType())) {
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
} else {
return s1.forCanBeNull(bb, resultCanBeNull);
}
}

public abstract TypeState doSubtraction(PointsToAnalysis bb, MultiTypeState s1, SingleTypeState s2);

public abstract TypeState doSubtraction(PointsToAnalysis bb, MultiTypeState s1, MultiTypeState s2);

}
Loading

0 comments on commit fe1b459

Please sign in to comment.