Skip to content

Commit 521bb73

Browse files
committed
Simplify SubstrateType checking.
1 parent a19101a commit 521bb73

File tree

6 files changed

+28
-35
lines changed

6 files changed

+28
-35
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import java.util.Optional;
3535
import java.util.concurrent.CopyOnWriteArrayList;
3636
import java.util.function.BiConsumer;
37-
import java.util.function.Function;
37+
import java.util.function.Predicate;
3838

3939
import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess;
4040

@@ -550,8 +550,8 @@ public boolean ignoreInstanceOfTypeDisallowed() {
550550
/**
551551
* Returns the function Strengthen Graphs should use to improve types based on analysis results.
552552
*/
553-
public Function<AnalysisType, ResolvedJavaType> getStrengthenGraphsToTargetFunction(@SuppressWarnings("unused") MultiMethod.MultiMethodKey key) {
554-
return (t) -> t;
553+
public Predicate<AnalysisType> getStrengthenGraphsTypePredicate(@SuppressWarnings("unused") MultiMethod.MultiMethodKey key) {
554+
return (t) -> true;
555555
}
556556

557557
public boolean allowConstantFolding(AnalysisMethod method) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/ReachabilitySimplifier.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
*/
2525
package com.oracle.graal.pointsto.results;
2626

27-
import java.util.function.Function;
27+
import java.util.function.Predicate;
2828
import java.util.function.Supplier;
2929

3030
import com.oracle.graal.pointsto.heap.ImageHeapConstant;
3131
import com.oracle.graal.pointsto.meta.AnalysisField;
3232
import com.oracle.graal.pointsto.meta.AnalysisMethod;
3333
import com.oracle.graal.pointsto.meta.AnalysisType;
34+
import com.oracle.graal.pointsto.results.StrengthenGraphs.AnalysisStrengthenGraphsPhase;
3435
import com.oracle.graal.pointsto.util.AnalysisError;
3536

3637
import jdk.graal.compiler.core.common.type.AbstractObjectStamp;
@@ -65,7 +66,6 @@
6566
import jdk.graal.compiler.phases.common.inlining.InliningUtil;
6667
import jdk.graal.compiler.replacements.nodes.MacroInvokable;
6768
import jdk.vm.ci.meta.JavaKind;
68-
import jdk.vm.ci.meta.ResolvedJavaType;
6969

7070
/**
7171
* Simplify graphs based on reachability information tracked by the static analysis.
@@ -76,16 +76,16 @@ class ReachabilitySimplifier implements CustomSimplification {
7676
protected final StructuredGraph graph;
7777

7878
/**
79-
* For runtime compiled methods, we must be careful to ensure new SubstrateTypes are not created
80-
* due to the optimizations performed during the
81-
* {@link StrengthenGraphs.AnalysisStrengthenGraphsPhase}.
79+
* Tests if a SubstrateTypes was already created for the corresponding {@link AnalysisType}. For
80+
* runtime compiled methods, we must be careful to ensure new SubstrateTypes are not created due
81+
* to the optimizations performed during the {@link AnalysisStrengthenGraphsPhase}.
8282
*/
83-
protected final Function<AnalysisType, ResolvedJavaType> toTargetFunction;
83+
protected final Predicate<AnalysisType> typePredicate;
8484

8585
ReachabilitySimplifier(StrengthenGraphs strengthenGraphs, AnalysisMethod method, StructuredGraph graph) {
8686
this.strengthenGraphs = strengthenGraphs;
8787
this.graph = graph;
88-
this.toTargetFunction = strengthenGraphs.bb.getHostVM().getStrengthenGraphsToTargetFunction(method.getMultiMethodKey());
88+
this.typePredicate = strengthenGraphs.bb.getHostVM().getStrengthenGraphsTypePredicate(method.getMultiMethodKey());
8989
}
9090

9191
@Override
@@ -313,9 +313,8 @@ private Stamp strengthenStamp(Stamp s) {
313313

314314
AnalysisType singleImplementorType = strengthenGraphs.getSingleImplementorType(originalType);
315315
if (singleImplementorType != null && (!stamp.isExactType() || !singleImplementorType.equals(originalType))) {
316-
ResolvedJavaType targetType = toTargetFunction.apply(singleImplementorType);
317-
if (targetType != null) {
318-
TypeReference typeRef = TypeReference.createExactTrusted(targetType);
316+
if (typePredicate.test(singleImplementorType)) {
317+
TypeReference typeRef = TypeReference.createExactTrusted(singleImplementorType);
319318
return StampFactory.object(typeRef, stamp.nonNull());
320319
}
321320
}
@@ -339,12 +338,11 @@ private Stamp strengthenStamp(Stamp s) {
339338
/* We must be in dead code. */
340339
return StampFactory.empty(JavaKind.Object);
341340
} else {
342-
ResolvedJavaType targetType = toTargetFunction.apply(strengthenType);
343-
if (targetType == null) {
344-
return null;
341+
if (typePredicate.test(strengthenType)) {
342+
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(strengthenType);
343+
return StampFactory.object(typeRef, stamp.nonNull());
345344
}
346-
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(targetType);
347-
return StampFactory.object(typeRef, stamp.nonNull());
345+
return null;
348346
}
349347
}
350348
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/TypeFlowSimplifier.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import jdk.vm.ci.meta.JavaMethodProfile;
9191
import jdk.vm.ci.meta.JavaTypeProfile;
9292
import jdk.vm.ci.meta.PrimitiveConstant;
93-
import jdk.vm.ci.meta.ResolvedJavaType;
9493

9594
/**
9695
* Simplify graphs based on reachability information tracked by the static analysis. Additionally,
@@ -640,9 +639,8 @@ private Object strengthenStampFromTypeFlow(ValueNode node, TypeFlow<?> nodeFlow,
640639
assert exactType.equals(strengthenGraphs.getStrengthenStampType(exactType)) : exactType;
641640

642641
if (!oldStamp.isExactType() || !exactType.equals(oldType)) {
643-
ResolvedJavaType targetType = toTargetFunction.apply(exactType);
644-
if (targetType != null) {
645-
TypeReference typeRef = TypeReference.createExactTrusted(targetType);
642+
if (typePredicate.test(exactType)) {
643+
TypeReference typeRef = TypeReference.createExactTrusted(exactType);
646644
return StampFactory.object(typeRef, nonNull);
647645
}
648646
}
@@ -678,9 +676,8 @@ private Object strengthenStampFromTypeFlow(ValueNode node, TypeFlow<?> nodeFlow,
678676
assert typeStateTypes.stream().map(newType::isAssignableFrom).reduce(Boolean::logicalAnd).get() : typeStateTypes;
679677

680678
if (!newType.equals(oldType) && (oldType != null || !newType.isJavaLangObject())) {
681-
ResolvedJavaType targetType = toTargetFunction.apply(newType);
682-
if (targetType != null) {
683-
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(targetType);
679+
if (typePredicate.test(newType)) {
680+
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(newType);
684681
return StampFactory.object(typeRef, nonNull);
685682
}
686683
}

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/RuntimeCompilationFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,15 +825,15 @@ public InlineBeforeAnalysisPolicy inlineBeforeAnalysisPolicy(MultiMethod.MultiMe
825825
}
826826

827827
@Override
828-
public Function<AnalysisType, ResolvedJavaType> getStrengthenGraphsToTargetFunction(MultiMethod.MultiMethodKey key) {
828+
public Predicate<AnalysisType> getStrengthenGraphsTypePredicate(MultiMethod.MultiMethodKey key) {
829829
if (key == RUNTIME_COMPILED_METHOD) {
830830
/*
831831
* For runtime compiled methods, we must be careful to ensure new SubstrateTypes are
832832
* not created during the AnalysisStrengthenGraphsPhase. If the type does not
833833
* already exist at this point (which is after the analysis phase), then we must
834-
* return null.
834+
* return false.
835835
*/
836-
return (t) -> objectReplacer.typeCreated(t) ? t : null;
836+
return (t) -> objectReplacer.typeCreated(t);
837837
}
838838
return null;
839839
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.concurrent.CopyOnWriteArrayList;
4444
import java.util.function.BiPredicate;
4545
import java.util.function.BooleanSupplier;
46-
import java.util.function.Function;
4746
import java.util.function.Predicate;
4847

4948
import org.graalvm.nativeimage.AnnotationAccess;
@@ -1434,14 +1433,14 @@ public boolean ignoreInstanceOfTypeDisallowed() {
14341433
}
14351434

14361435
@Override
1437-
public Function<AnalysisType, ResolvedJavaType> getStrengthenGraphsToTargetFunction(MultiMethod.MultiMethodKey key) {
1436+
public Predicate<AnalysisType> getStrengthenGraphsTypePredicate(MultiMethod.MultiMethodKey key) {
14381437
if (parsingSupport != null) {
1439-
var result = parsingSupport.getStrengthenGraphsToTargetFunction(key);
1438+
var result = parsingSupport.getStrengthenGraphsTypePredicate(key);
14401439
if (result != null) {
14411440
return result;
14421441
}
14431442
}
1444-
return super.getStrengthenGraphsToTargetFunction(key);
1443+
return super.getStrengthenGraphsTypePredicate(key);
14451444
}
14461445

14471446
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/SVMParsingSupport.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
package com.oracle.svm.hosted.analysis;
2626

27-
import java.util.function.Function;
27+
import java.util.function.Predicate;
2828

2929
import com.oracle.graal.pointsto.BigBang;
3030
import com.oracle.graal.pointsto.PointsToAnalysis;
@@ -39,7 +39,6 @@
3939
import jdk.graal.compiler.debug.DebugContext;
4040
import jdk.graal.compiler.nodes.StructuredGraph;
4141
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
42-
import jdk.vm.ci.meta.ResolvedJavaType;
4342

4443
/**
4544
* {@link com.oracle.graal.pointsto.api.HostVM} methods which may be overwritten by substratevm
@@ -65,5 +64,5 @@ public interface SVMParsingSupport {
6564

6665
InlineBeforeAnalysisPolicy inlineBeforeAnalysisPolicy(MultiMethod.MultiMethodKey multiMethodKey, InlineBeforeAnalysisPolicy defaultPolicy);
6766

68-
Function<AnalysisType, ResolvedJavaType> getStrengthenGraphsToTargetFunction(MultiMethod.MultiMethodKey key);
67+
Predicate<AnalysisType> getStrengthenGraphsTypePredicate(MultiMethod.MultiMethodKey key);
6968
}

0 commit comments

Comments
 (0)