Skip to content

Commit 6bac95d

Browse files
committed
fixes after rebase
1 parent c477751 commit 6bac95d

File tree

5 files changed

+92
-18
lines changed

5 files changed

+92
-18
lines changed

substratevm/mx.substratevm/suite.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,27 @@
391391
],
392392
"checkstyle": "com.oracle.graal.pointsto",
393393
"javaCompliance": "8+",
394-
"checkstyleVersion" : "8.36.1",
394+
"checkstyleVersion": "8.36.1",
395+
"annotationProcessors": [
396+
"compiler:GRAAL_PROCESSOR",
397+
],
398+
"workingSets": "SVM",
399+
},
400+
401+
"com.oracle.graal.reachability": {
402+
"subDir": "src",
403+
"sourceDirs": ["src"],
404+
"dependencies": [
405+
"com.oracle.graal.pointsto",
406+
],
407+
"checkstyle": "com.oracle.graal.pointsto",
408+
"javaCompliance": "8+",
395409
"annotationProcessors": [
396410
"compiler:GRAAL_PROCESSOR",
397411
],
398412
"workingSets": "SVM",
399413
},
414+
400415
"com.oracle.svm.hosted": {
401416
"subDir": "src",
402417
"sourceDirs": ["src"],

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727
import com.oracle.graal.pointsto.api.HostVM;
2828
import com.oracle.graal.pointsto.constraints.UnsupportedFeatures;
2929
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
30-
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
30+
3131
import com.oracle.graal.pointsto.meta.HostedProviders;
3232
import com.oracle.graal.pointsto.util.Timer;
3333
import jdk.vm.ci.meta.ConstantReflectionProvider;
3434
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
3535
import org.graalvm.compiler.debug.DebugContext;
3636
import org.graalvm.compiler.debug.DebugHandlersFactory;
3737
import org.graalvm.compiler.nodes.spi.Replacements;
38-
import org.graalvm.compiler.nodes.spi.Replacements;
38+
3939
import org.graalvm.compiler.options.OptionValues;
4040

4141
import java.io.PrintWriter;
4242
import java.util.List;
4343
import java.util.function.Function;
44-
import java.util.function.Function;
44+
4545

4646
/**
4747
* Central static analysis interface that groups together the functionality of reachability analysis

substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/ReachabilityAnalysis.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
3636
import com.oracle.graal.pointsto.meta.HostedProviders;
3737
import com.oracle.graal.pointsto.typestate.TypeState;
38+
import com.oracle.graal.pointsto.util.AnalysisError;
3839
import com.oracle.graal.pointsto.util.Timer;
3940
import jdk.vm.ci.code.BytecodePosition;
4041
import jdk.vm.ci.meta.JavaConstant;
4142
import jdk.vm.ci.meta.JavaKind;
4243
import jdk.vm.ci.meta.ResolvedJavaMethod;
4344
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
4445
import org.graalvm.compiler.core.common.spi.ForeignCallSignature;
46+
import org.graalvm.compiler.debug.DebugContext;
4547
import org.graalvm.compiler.debug.Indent;
4648
import org.graalvm.compiler.graph.Node;
4749
import org.graalvm.compiler.nodes.FrameState;
@@ -56,6 +58,7 @@
5658
import java.util.Set;
5759
import java.util.concurrent.ConcurrentHashMap;
5860
import java.util.concurrent.ForkJoinPool;
61+
import java.util.function.Function;
5962

6063
import static jdk.vm.ci.common.JVMCIError.shouldNotReachHere;
6164

@@ -288,6 +291,48 @@ public boolean finish() throws InterruptedException {
288291
return true;
289292
}
290293

294+
@Override
295+
public void runAnalysis(DebugContext debugContext, Function<AnalysisUniverse, Boolean> analysisEndCondition) throws InterruptedException {
296+
// todo this is ugly copy paste from points-to
297+
int numIterations = 0;
298+
while (true) {
299+
try (Indent indent2 = debugContext.logAndIndent("new analysis iteration")) {
300+
/*
301+
* Do the analysis (which itself is done in a similar iterative process)
302+
*/
303+
boolean analysisChanged = finish();
304+
305+
numIterations++;
306+
if (numIterations > 1000) {
307+
/*
308+
* Usually there are < 10 iterations. If we have so many iterations, we probably
309+
* have an endless loop (but at least we have a performance problem because we
310+
* re-start the analysis so often).
311+
*/
312+
throw AnalysisError.shouldNotReachHere(String.format("Static analysis did not reach a fix point after %d iterations because a Feature keeps requesting new analysis iterations. " +
313+
"The analysis itself %s find a change in type states in the last iteration.",
314+
numIterations, analysisChanged ? "DID" : "DID NOT"));
315+
}
316+
317+
/*
318+
* Allow features to change the universe.
319+
*/
320+
try (Timer.StopTimer t2 = getProcessFeaturesTimer().start()) {
321+
int numTypes = universe.getTypes().size();
322+
int numMethods = universe.getMethods().size();
323+
int numFields = universe.getFields().size();
324+
if (analysisEndCondition.apply(universe)) {
325+
if (numTypes != universe.getTypes().size() || numMethods != universe.getMethods().size() || numFields != universe.getFields().size()) {
326+
throw AnalysisError.shouldNotReachHere(
327+
"When a feature makes more types, methods, or fields reachable, it must require another analysis iteration via DuringAnalysisAccess.requireAnalysisIteration()");
328+
}
329+
return;
330+
}
331+
}
332+
}
333+
}
334+
}
335+
291336
private void runReachability() throws InterruptedException {
292337
try (Timer.StopTimer t = reachabilityTimer.start()) {
293338
if (!executor.isStarted()) {
@@ -307,7 +352,8 @@ private void checkObjectGraph() throws InterruptedException {
307352
scannedObjects.reset();
308353
// scan constants
309354
boolean isParallel = PointstoOptions.ScanObjectsParallel.getValue(options);
310-
ObjectScanner objectScanner = new ReachabilityObjectScanner(this, isParallel ? executor : null, scannedObjects, metaAccess);
355+
ObjectScanner objectScanner = new ObjectScanner(this, isParallel ? executor : null, scannedObjects, new ReachabilityObjectScanner(this, metaAccess)) {
356+
};
311357
checkObjectGraph(objectScanner);
312358
if (isParallel) {
313359
executor.start();

substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/ReachabilityObjectScanner.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
import com.oracle.graal.pointsto.BigBang;
44
import com.oracle.graal.pointsto.ObjectScanner;
5+
import com.oracle.graal.pointsto.ObjectScanningObserver;
56
import com.oracle.graal.pointsto.meta.AnalysisField;
67
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
78
import com.oracle.graal.pointsto.meta.AnalysisType;
8-
import com.oracle.graal.pointsto.util.CompletionExecutor;
99
import jdk.vm.ci.meta.JavaConstant;
1010
import jdk.vm.ci.meta.JavaKind;
1111

12-
public class ReachabilityObjectScanner extends ObjectScanner {
12+
public class ReachabilityObjectScanner implements ObjectScanningObserver {
1313

14+
private final ReachabilityAnalysis bb;
1415
private final AnalysisMetaAccess access;
1516

16-
public ReachabilityObjectScanner(BigBang bb, CompletionExecutor executor, ReusableSet scannedObjects, AnalysisMetaAccess access) {
17-
super(bb, executor, scannedObjects);
17+
public ReachabilityObjectScanner(BigBang bb, AnalysisMetaAccess access) {
18+
this.bb = ((ReachabilityAnalysis) bb);
1819
this.access = access;
1920
}
2021

@@ -27,24 +28,25 @@ public void forRelocatedPointerFieldValue(JavaConstant receiver, AnalysisField f
2728
field.registerAsAccessed();
2829
if (fieldValue.isNonNull() && fieldValue.getJavaKind() == JavaKind.Object) {
2930
// todo mark as instantiated
30-
// getAnalysis().markTypeInstantiated(constantType(bb, fieldValue));
31+
// getAnalysis().markTypeInstantiated(constantType(bb, fieldValue));
3132
}
3233
}
3334

3435
@Override
3536
public void forNullFieldValue(JavaConstant receiver, AnalysisField field) {
36-
if (receiver != null)
37+
if (receiver != null) {
3738
getAnalysis().markTypeReachable(constantType(bb, receiver));
39+
}
3840
getAnalysis().markTypeReachable(field.getType());
39-
// System.out.println("Scanning field " + field);
41+
// System.out.println("Scanning field " + field);
4042
}
4143

4244
@Override
4345
public void forNonNullFieldValue(JavaConstant receiver, AnalysisField field, JavaConstant fieldValue) {
4446
if (receiver != null)
4547
getAnalysis().markTypeReachable(constantType(bb, receiver));
4648
getAnalysis().markTypeReachable(field.getType());
47-
// System.out.println("Scanning field " + field);
49+
// System.out.println("Scanning field " + field);
4850
}
4951

5052
@Override
@@ -59,10 +61,19 @@ public void forNonNullArrayElement(JavaConstant array, AnalysisType arrayType, J
5961
}
6062

6163
@Override
62-
protected void forScannedConstant(JavaConstant scannedValue, ScanReason reason) {
64+
public void forScannedConstant(JavaConstant scannedValue, ObjectScanner.ScanReason reason) {
6365
AnalysisType type = constantType(bb, scannedValue);
64-
// System.out.println("Scanning constant of type " + type);
66+
// System.out.println("Scanning constant of type " + type);
6567
getAnalysis().markTypeInstantiated(type);
6668
type.registerAsInHeap();
6769
}
70+
71+
private AnalysisType constantType(BigBang bb, JavaConstant constant) {
72+
return access.lookupJavaType(constantAsObject(bb, constant).getClass());
73+
}
74+
75+
public Object constantAsObject(BigBang bb, JavaConstant constant) {
76+
return bb.getSnippetReflectionProvider().asObject(Object.class, constant);
77+
}
78+
6879
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public void checkUserLimitations() {
134134
// todo
135135
}
136136

137+
// todo remove ugly copy paste from this class
138+
137139
public void checkType(AnalysisType type) {
138140
assert type.isReachable();
139141
DynamicHub hub = getHostVM().dynamicHub(type);
@@ -237,7 +239,7 @@ static class GenericInterfacesEncodingKey {
237239

238240
@Override
239241
public boolean equals(Object obj) {
240-
return obj instanceof NativeImagePointsToAnalysis.GenericInterfacesEncodingKey && Arrays.equals(interfaces, ((NativeImagePointsToAnalysis.GenericInterfacesEncodingKey) obj).interfaces);
242+
return obj instanceof GenericInterfacesEncodingKey && Arrays.equals(interfaces, ((GenericInterfacesEncodingKey) obj).interfaces);
241243
}
242244

243245
@Override
@@ -297,8 +299,8 @@ static class AnnotatedInterfacesEncodingKey {
297299

298300
@Override
299301
public boolean equals(Object obj) {
300-
return obj instanceof NativeImagePointsToAnalysis.AnnotatedInterfacesEncodingKey &&
301-
shallowEquals(interfaces, ((NativeImagePointsToAnalysis.AnnotatedInterfacesEncodingKey) obj).interfaces);
302+
return obj instanceof AnnotatedInterfacesEncodingKey &&
303+
shallowEquals(interfaces, ((AnnotatedInterfacesEncodingKey) obj).interfaces);
302304
}
303305

304306
@Override

0 commit comments

Comments
 (0)