Skip to content

Commit a6c106b

Browse files
committed
small size optimization for typestate
1 parent 1892b1b commit a6c106b

File tree

12 files changed

+953
-201
lines changed

12 files changed

+953
-201
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.oracle.graal.pointsto.typestate.TypeState;
5050
import com.oracle.graal.pointsto.typestore.ArrayElementsTypeStore;
5151
import com.oracle.graal.pointsto.typestore.FieldTypeStore;
52+
import com.oracle.graal.pointsto.util.AnalysisError;
5253
import com.oracle.svm.common.meta.MultiMethod;
5354

5455
import jdk.graal.compiler.options.OptionValues;
@@ -72,6 +73,8 @@ public abstract class AnalysisPolicy {
7273
protected final boolean useConservativeUnsafeAccess;
7374
private final int parsingContextMaxDepth;
7475
private final boolean trackAccessChain;
76+
protected final int multiTypeStateArrayBitSetThreshold;
77+
protected final int multiTypeStateArrayBitSetIntersectionSpeculationThreshold;
7578

7679
public AnalysisPolicy(OptionValues options) {
7780
this.options = options;
@@ -88,6 +91,11 @@ public AnalysisPolicy(OptionValues options) {
8891
useConservativeUnsafeAccess = PointstoOptions.UseConservativeUnsafeAccess.getValue(options);
8992
trackAccessChain = PointstoOptions.TrackAccessChain.getValue(options);
9093
parsingContextMaxDepth = PointstoOptions.ParsingContextMaxDepth.getValue(options);
94+
multiTypeStateArrayBitSetThreshold = PointstoOptions.MultiTypeStateArrayBitSetThreshold.getValue(options);
95+
multiTypeStateArrayBitSetIntersectionSpeculationThreshold = PointstoOptions.MultiTypeStateArrayBitSetIntersectionSpeculationThreshold.getValue(options);
96+
AnalysisError.guarantee(multiTypeStateArrayBitSetIntersectionSpeculationThreshold >= multiTypeStateArrayBitSetThreshold,
97+
"The MultiTypeStateArrayBitSetIntersectionSpeculationThreshold (%d) should always be larger than MultiTypeStateArrayBitSetThreshold (%d)",
98+
multiTypeStateArrayBitSetIntersectionSpeculationThreshold, multiTypeStateArrayBitSetThreshold);
9199
}
92100

93101
public abstract boolean isContextSensitiveAnalysis();
@@ -306,4 +314,20 @@ public TypeState doSubtraction(PointsToAnalysis bb, SingleTypeState s1, MultiTyp
306314
protected static boolean areTypesCompatibleForSystemArraycopy(AnalysisType srcType, AnalysisType dstType) {
307315
return dstType.isAssignableFrom(srcType) || srcType.isAssignableFrom(dstType);
308316
}
317+
318+
/**
319+
* @return The maximum number of types represented in {@link MultiTypeState} as an array before
320+
* converting to bitset-based implementation.
321+
*/
322+
public int multiTypeStateArrayBitSetThreshold() {
323+
return multiTypeStateArrayBitSetThreshold;
324+
}
325+
326+
/**
327+
* @return The maximum number of types on which the analysis should speculate that the result
328+
* will be small enough to be array-based.
329+
*/
330+
public int multiTypeStateArrayBitSetIntersectionSpeculationThreshold() {
331+
return multiTypeStateArrayBitSetIntersectionSpeculationThreshold;
332+
}
309333
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/PointstoOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ public class PointstoOptions {
111111
@Option(help = "The maximum number of types recorded in a type flow. -1 indicates no limitation.")//
112112
public static final OptionKey<Integer> TypeFlowSaturationCutoff = new OptionKey<>(20);
113113

114+
@Option(help = "The maximum number of types that will be represented as an array before switching to bitsets. By default 20 to align with TypeFlowSaturationCutoff. " +
115+
"Note that we can also disable the array-based handling completely by setting the threshold to zero.")//
116+
public static final OptionKey<Integer> MultiTypeStateArrayBitSetThreshold = new OptionKey<>(20);
117+
118+
@Option(help = "The maximum number of types on which the analysis should speculate that the result will be small enough to be array-based.")//
119+
public static final OptionKey<Integer> MultiTypeStateArrayBitSetIntersectionSpeculationThreshold = new OptionKey<>(32);
120+
114121
@Option(help = "Enable the type flow saturation analysis performance optimization.")//
115122
public static final OptionKey<Boolean> RemoveSaturatedTypeFlows = new OptionKey<>(true) {
116123
@Override

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/context/bytecode/ContextSensitiveMultiTypeState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
import com.oracle.graal.pointsto.PointsToAnalysis;
3333
import com.oracle.graal.pointsto.flow.context.object.AnalysisObject;
3434
import com.oracle.graal.pointsto.meta.AnalysisType;
35-
import com.oracle.graal.pointsto.typestate.MultiTypeState;
35+
import com.oracle.graal.pointsto.typestate.MultiTypeStateWithBitSet;
3636
import com.oracle.graal.pointsto.typestate.PointsToStats;
3737
import com.oracle.graal.pointsto.typestate.TypeState;
3838

39-
public class ContextSensitiveMultiTypeState extends MultiTypeState {
39+
public class ContextSensitiveMultiTypeState extends MultiTypeStateWithBitSet {
4040

4141
/** The objects of this type state. */
4242
protected final AnalysisObject[] objects;

0 commit comments

Comments
 (0)