Skip to content

Commit fe1b459

Browse files
committed
[GR-38184] Simplify type state.
PullRequest: graal/11690
2 parents cf2980b + 27299f8 commit fe1b459

26 files changed

+2450
-1952
lines changed

substratevm/mx.substratevm/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@
15041504
"com.oracle.graal.pointsto.typestate",
15051505
"com.oracle.graal.pointsto.infrastructure",
15061506
"com.oracle.graal.pointsto.flow.context.object",
1507+
"com.oracle.graal.pointsto.flow.context.bytecode",
15071508
],
15081509
"requires": [
15091510
"java.management",

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/AnalysisObjectScanningObserver.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ public boolean forNonNullFieldValue(JavaConstant receiver, AnalysisField field,
6868
/* Add the constant value object to the field's type flow. */
6969
FieldTypeFlow fieldTypeFlow = getFieldTypeFlow(field, receiver);
7070
AnalysisObject constantObject = bb.analysisPolicy().createConstantObject(analysis, fieldValue, fieldType);
71-
if (!fieldTypeFlow.getState().containsObject(constantObject)) {
72-
/* Add the new constant to the field's flow state. */
73-
TypeState constantTypeState = TypeState.forNonNullObject(analysis, constantObject);
74-
return fieldTypeFlow.addState(analysis, constantTypeState);
75-
}
76-
return false;
71+
/* Add the new constant to the field's flow state. */
72+
TypeState constantTypeState = TypeState.forNonNullObject(analysis, constantObject);
73+
return fieldTypeFlow.addState(analysis, constantTypeState);
7774
}
7875

7976
/**
@@ -111,12 +108,9 @@ public boolean forNonNullArrayElement(JavaConstant array, AnalysisType arrayType
111108
ArrayElementsTypeFlow arrayObjElementsFlow = getArrayElementsFlow(array, arrayType);
112109
PointsToAnalysis analysis = getAnalysis();
113110
AnalysisObject constantObject = bb.analysisPolicy().createConstantObject(analysis, elementConstant, elementType);
114-
if (!arrayObjElementsFlow.getState().containsObject(constantObject)) {
115-
/* Add the constant element to the constant's array type flow. */
116-
TypeState elementTypeState = TypeState.forNonNullObject(analysis, constantObject);
117-
return arrayObjElementsFlow.addState(analysis, elementTypeState);
118-
}
119-
return false;
111+
/* Add the constant element to the constant's array type flow. */
112+
TypeState elementTypeState = TypeState.forNonNullObject(analysis, constantObject);
113+
return arrayObjElementsFlow.addState(analysis, elementTypeState);
120114
}
121115

122116
/**

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/AnalysisPolicy.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package com.oracle.graal.pointsto;
2626

27+
import java.util.BitSet;
28+
2729
import org.graalvm.compiler.options.OptionValues;
2830

2931
import com.oracle.graal.pointsto.api.PointstoOptions;
@@ -41,7 +43,10 @@
4143
import com.oracle.graal.pointsto.meta.AnalysisType;
4244
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
4345
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
46+
import com.oracle.graal.pointsto.typestate.MultiTypeState;
47+
import com.oracle.graal.pointsto.typestate.SingleTypeState;
4448
import com.oracle.graal.pointsto.typestate.TypeState;
49+
import com.oracle.graal.pointsto.typestate.TypeStateUtils;
4550
import com.oracle.graal.pointsto.typestore.ArrayElementsTypeStore;
4651
import com.oracle.graal.pointsto.typestore.FieldTypeStore;
4752

@@ -169,4 +174,75 @@ public int makePropertiesForUnion(TypeState s1, TypeState s2) {
169174
/* The default analysis policy doesn't use properties. */
170175
return 0;
171176
}
177+
178+
/**
179+
* Simplifies a type state by replacing all context sensitive objects with context insensitive
180+
* objects.
181+
*/
182+
public abstract TypeState forContextInsensitiveTypeState(PointsToAnalysis bb, TypeState state);
183+
184+
public abstract SingleTypeState singleTypeState(PointsToAnalysis bb, boolean canBeNull, int properties, AnalysisType type, AnalysisObject... objects);
185+
186+
public abstract MultiTypeState multiTypeState(PointsToAnalysis bb, boolean canBeNull, int properties, BitSet typesBitSet, AnalysisObject... objects);
187+
188+
public abstract TypeState doUnion(PointsToAnalysis bb, SingleTypeState s1, SingleTypeState s2);
189+
190+
public abstract TypeState doUnion(PointsToAnalysis bb, MultiTypeState s1, SingleTypeState s2);
191+
192+
public abstract TypeState doUnion(PointsToAnalysis bb, MultiTypeState s1, MultiTypeState s2);
193+
194+
@SuppressWarnings("static-method")
195+
public final TypeState doIntersection(PointsToAnalysis bb, SingleTypeState s1, SingleTypeState s2) {
196+
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
197+
boolean resultCanBeNull = s1.canBeNull() && s2.canBeNull();
198+
if (s1.exactType().equals(s2.exactType())) {
199+
/* The inputs have the same type, the result will be s1. */
200+
return s1.forCanBeNull(bb, resultCanBeNull);
201+
} else {
202+
/* The inputs have different types then the result is empty or null. */
203+
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
204+
}
205+
}
206+
207+
@SuppressWarnings("static-method")
208+
public final TypeState doIntersection(PointsToAnalysis bb, SingleTypeState s1, MultiTypeState s2) {
209+
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
210+
boolean resultCanBeNull = s1.canBeNull() && s2.canBeNull();
211+
if (s2.containsType(s1.exactType())) {
212+
return s1.forCanBeNull(bb, resultCanBeNull);
213+
} else {
214+
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
215+
}
216+
}
217+
218+
public abstract TypeState doIntersection(PointsToAnalysis bb, MultiTypeState s1, SingleTypeState s2);
219+
220+
public abstract TypeState doIntersection(PointsToAnalysis bb, MultiTypeState s1, MultiTypeState s2);
221+
222+
@SuppressWarnings("static-method")
223+
public final TypeState doSubtraction(PointsToAnalysis bb, SingleTypeState s1, SingleTypeState s2) {
224+
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
225+
boolean resultCanBeNull = s1.canBeNull() && !s2.canBeNull();
226+
if (s1.exactType().equals(s2.exactType())) {
227+
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
228+
} else {
229+
return s1.forCanBeNull(bb, resultCanBeNull);
230+
}
231+
}
232+
233+
@SuppressWarnings("static-method")
234+
public final TypeState doSubtraction(PointsToAnalysis bb, SingleTypeState s1, MultiTypeState s2) {
235+
assert !bb.extendedAsserts() || TypeStateUtils.isContextInsensitiveTypeState(bb, s2) : "Current implementation limitation.";
236+
boolean resultCanBeNull = s1.canBeNull() && !s2.canBeNull();
237+
if (s2.containsType(s1.exactType())) {
238+
return TypeState.forEmpty().forCanBeNull(bb, resultCanBeNull);
239+
} else {
240+
return s1.forCanBeNull(bb, resultCanBeNull);
241+
}
242+
}
243+
244+
public abstract TypeState doSubtraction(PointsToAnalysis bb, MultiTypeState s1, SingleTypeState s2);
245+
246+
public abstract TypeState doSubtraction(PointsToAnalysis bb, MultiTypeState s1, MultiTypeState s2);
247+
172248
}

0 commit comments

Comments
 (0)