Skip to content

Commit ff0e899

Browse files
committed
[GR-71469] Clarify the APIs for checking supported JavaKinds in the analysis
PullRequest: graal/22681
2 parents 7cc9133 + cb4cdfb commit ff0e899

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import jdk.graal.compiler.word.WordTypes;
4646
import jdk.vm.ci.code.BytecodePosition;
4747
import jdk.vm.ci.meta.ConstantReflectionProvider;
48+
import jdk.vm.ci.meta.JavaKind;
4849
import jdk.vm.ci.meta.ResolvedJavaType;
4950

5051
/**
@@ -96,6 +97,10 @@ default HostedProviders getProviders(AnalysisMethod method) {
9697

9798
boolean trackPrimitiveValues();
9899

100+
default boolean isSupportedJavaKind(JavaKind javaKind) {
101+
return javaKind == JavaKind.Object;
102+
}
103+
99104
/** You can blacklist certain callees here. */
100105
@SuppressWarnings("unused")
101106
default boolean isCallAllowed(PointsToAnalysis bb, AnalysisMethod caller, AnalysisMethod target, BytecodePosition srcPosition) {

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ public void forceUnsafeUpdate() {
265265

266266
@Override
267267
public void registerAsJNIAccessed(AnalysisField field, boolean writable) {
268-
if (isSupportedJavaKind(field.getStorageKind())) {
269-
field.injectDeclaredType();
270-
}
268+
field.injectDeclaredType();
271269
}
272270

273271
/**
@@ -500,7 +498,7 @@ public AnalysisType addRootClass(AnalysisType type, boolean addFields, boolean a
500498
if (addFields) {
501499
field.registerAsAccessed("field of root class");
502500
}
503-
processRootField(field);
501+
field.injectDeclaredType();
504502
}
505503
if (type.getSuperclass() != null) {
506504
addRootClass(type.getSuperclass(), addFields, addArrayClass);
@@ -521,22 +519,17 @@ public AnalysisType addRootField(Class<?> clazz, String fieldName) {
521519
@Override
522520
public AnalysisType addRootField(AnalysisField field) {
523521
field.registerAsAccessed((field.isStatic() ? "static" : "instance") + " root field");
524-
processRootField(field);
522+
field.injectDeclaredType();
525523
return field.getType();
526524
}
527525

528-
private void processRootField(AnalysisField field) {
529-
if (isSupportedJavaKind(field.getStorageKind())) {
530-
field.injectDeclaredType();
531-
}
532-
}
533-
534526
@Override
535527
public void checkUserLimitations() {
536528
}
537529

530+
@Override
538531
public boolean isSupportedJavaKind(JavaKind javaKind) {
539-
return javaKind == JavaKind.Object || (trackPrimitiveValues && javaKind.isNumericInteger());
532+
return javaKind == JavaKind.Object || (trackPrimitiveValues && javaKind.isPrimitive() && !javaKind.isNumericFloat());
540533
}
541534

542535
@Override

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapScanner.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.lang.reflect.Field;
2828
import java.util.Collection;
29-
import java.util.List;
3029
import java.util.Map;
3130
import java.util.Objects;
3231
import java.util.Optional;
@@ -52,7 +51,6 @@
5251
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
5352
import com.oracle.graal.pointsto.meta.AnalysisType;
5453
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
55-
import com.oracle.graal.pointsto.meta.PointsToAnalysisField;
5654
import com.oracle.graal.pointsto.util.AnalysisError;
5755
import com.oracle.graal.pointsto.util.AnalysisFuture;
5856
import com.oracle.graal.pointsto.util.CompletionExecutor;
@@ -150,11 +148,7 @@ private void onStaticFieldRead(AnalysisField field) {
150148
*
151149
* GR-52421: the field state needs to be serialized from the base layer analysis
152150
*/
153-
if (field.getStorageKind().isObject()) {
154-
bb.injectFieldTypes(field, List.of(field.getType()), true);
155-
} else if (bb.trackPrimitiveValues() && field.getStorageKind().isPrimitive()) {
156-
((PointsToAnalysisField) field).saturatePrimitiveField();
157-
}
151+
field.injectDeclaredType();
158152
} else if (isValueAvailable(field, null)) {
159153
JavaConstant fieldValue = readStaticFieldValue(field);
160154
if (fieldValue instanceof ImageHeapConstant imageHeapConstant && field.isFinal()) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/PointsToAnalysisField.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.List;
2929
import java.util.concurrent.atomic.AtomicReference;
3030

31-
import com.oracle.graal.pointsto.BigBang;
3231
import com.oracle.graal.pointsto.PointsToAnalysis;
3332
import com.oracle.graal.pointsto.flow.ContextInsensitiveFieldTypeFlow;
3433
import com.oracle.graal.pointsto.flow.FieldTypeFlow;
@@ -118,10 +117,17 @@ public FieldTypeFlow getStaticFieldFlow() {
118117

119118
@Override
120119
public void injectDeclaredType() {
121-
BigBang bb = getUniverse().getBigbang();
120+
var bb = getUniverse().getBigbang();
121+
if (!bb.isSupportedJavaKind(getStorageKind())) {
122+
/*
123+
* If this JavaKind is not tracked by the analysis, there is no point in inserting any
124+
* state into the field.
125+
*/
126+
return;
127+
}
122128
if (getStorageKind().isObject()) {
123129
bb.injectFieldTypes(this, List.of(this.getType()), true);
124-
} else if (bb.trackPrimitiveValues() && getStorageKind().isPrimitive()) {
130+
} else {
125131
this.saturatePrimitiveField();
126132
}
127133
}
@@ -151,7 +157,7 @@ public boolean registerAsUnsafeAccessed(Object reason) {
151157
return false;
152158
}
153159

154-
public void saturatePrimitiveField() {
160+
private void saturatePrimitiveField() {
155161
assert fieldType.isPrimitive() || fieldType.isWordType() : this;
156162
var bb = ((PointsToAnalysis) getUniverse().getBigbang());
157163
initialFlow.addState(bb, TypeState.anyPrimitiveState());

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ameta/CustomTypeFieldHandler.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.graal.pointsto.meta.AnalysisField;
3636
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
3737
import com.oracle.graal.pointsto.meta.AnalysisType;
38-
import com.oracle.graal.pointsto.meta.PointsToAnalysisField;
3938
import com.oracle.svm.hosted.analysis.FieldValueComputer;
4039

4140
public final class CustomTypeFieldHandler {
@@ -58,22 +57,20 @@ public void handleField(AnalysisField field) {
5857
* types as allocated when the field is not yet accessed.
5958
*/
6059
assert field.isAccessed();
61-
if (fieldValueInterceptionSupport.hasFieldValueTransformer(field)) {
62-
if (field.getStorageKind().isObject() && !fieldValueInterceptionSupport.isValueAvailable(field, null, !field.isStatic())) {
63-
bb.injectFieldTypes(field, List.of(field.getType()), true);
64-
} else if (bb.trackPrimitiveValues() && field.getStorageKind().isPrimitive() && field instanceof PointsToAnalysisField ptaField) {
65-
ptaField.saturatePrimitiveField();
66-
}
60+
if (fieldValueInterceptionSupport.hasFieldValueTransformer(field) && !fieldValueInterceptionSupport.isValueAvailable(field, null, !field.isStatic())) {
61+
field.injectDeclaredType();
6762
} else if (fieldValueInterceptionSupport.lookupFieldValueInterceptor(field) instanceof FieldValueComputer fieldValueComputer) {
6863
if (field.getStorageKind().isObject()) {
64+
/* Insert the specified set of types. */
6965
List<AnalysisType> types = transformTypes(field, fieldValueComputer.types());
7066
for (AnalysisType type : types) {
7167
assert !type.isPrimitive() : type + " for " + field;
7268
type.registerAsInstantiated("Is declared as the type of an unknown object field.");
7369
}
7470
bb.injectFieldTypes(field, types, fieldValueComputer.canBeNull());
75-
} else if (bb.trackPrimitiveValues() && field.getStorageKind().isPrimitive() && field instanceof PointsToAnalysisField ptaField) {
76-
ptaField.saturatePrimitiveField();
71+
} else {
72+
/* It is a primitive field, let injectDeclaredType handle it. */
73+
field.injectDeclaredType();
7774
}
7875
}
7976
}

0 commit comments

Comments
 (0)