Skip to content

Commit 183ed23

Browse files
committed
[GR-69986] Fix standalone points-to unittests and add them to gate.
PullRequest: graal/22213
2 parents 1892b1b + a10ff75 commit 183ed23

File tree

9 files changed

+62
-99
lines changed

9 files changed

+62
-99
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
PRIMARY: "substratevm"
123123
- env:
124124
JDK_VERSION: "latest"
125-
GATE_TAGS: "build,helloworld,native_unittests"
125+
GATE_TAGS: "build,helloworld,native_unittests,standalone_pointsto_unittests"
126126
PRIMARY: "substratevm"
127127
PIP_PACKAGES: "jsonschema==4.6.1"
128128
- os: ubuntu-24.04

substratevm/ci/ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"style-fullbuild": mxgate("fullbuild,style,nativeimagehelp,check_libcontainer_annotations,check_libcontainer_namespace") + eclipse + jdt + spotbugs + maven + mx_build_exploded + gdb("14.2") + platform_spec(no_jobs) + platform_spec({
127127
"linux:amd64:jdk-latest": tier1 + t("30:00"),
128128
}),
129-
"basics": mxgate("build,helloworld,native_unittests,truffle_unittests,debuginfotest,hellomodule,java_agent,condconfig") + maven + jsonschema + platform_spec(no_jobs) + platform_spec({
129+
"basics": mxgate("build,helloworld,native_unittests,standalone_pointsto_unittests,truffle_unittests,debuginfotest,hellomodule,java_agent,condconfig") + maven + jsonschema + platform_spec(no_jobs) + platform_spec({
130130
"linux:amd64:jdk-latest": tier2 + partial(2) + gdb("14.2") + t("40:00"),
131131
"windows:amd64:jdk-latest": tier3 + t("1:30:00"),
132132
}) + variants({

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def __getattr__(self, name):
208208
GraalTags = Tags([
209209
'helloworld',
210210
'debuginfotest',
211+
'standalone_pointsto_unittests',
211212
'native_unittests',
212213
'build',
213214
'benchmarktest',
@@ -440,6 +441,16 @@ def svm_gate_body(args, tasks):
440441
with native_image_context(IMAGE_ASSERTION_FLAGS) as native_image:
441442
gdbdebughelperstest(['--output-path', svmbuild_dir()] + args.extra_image_builder_arguments)
442443

444+
with Task('standalone pointsto unittests', tasks, tags=[GraalTags.standalone_pointsto_unittests]) as t:
445+
if t:
446+
if '--static' in args.extra_image_builder_arguments:
447+
mx.warn('Skipping standalone pointsto unittests if --static.')
448+
elif mx.is_windows():
449+
mx.warn('Skipping standalone pointsto unittests on Windows.')
450+
else:
451+
jvm_unittest(['--record-results', '--print-failed', 'failed.txt',
452+
'--use-graalvm'] + args.extra_image_builder_arguments + ['com.oracle.graal.pointsto.standalone.test'])
453+
443454
with Task('native unittests', tasks, tags=[GraalTags.native_unittests]) as t:
444455
if t:
445456
with native_image_context(IMAGE_ASSERTION_FLAGS) as native_image:
@@ -2726,3 +2737,25 @@ def capnp_compile(args):
27262737
shaded = line.replace("org.capnproto", "com.oracle.svm.shaded.org.capnproto")
27272738
f.write(shaded)
27282739
f.write('}\n')
2740+
2741+
class StandalonePointstoUnittestsConfig(mx_unittest.MxUnittestConfig):
2742+
2743+
def __init__(self):
2744+
super(StandalonePointstoUnittestsConfig, self).__init__('standalone-pointsto-unittest')
2745+
2746+
def apply(self, config):
2747+
vmArgs, mainClass, mainClassArgs = config
2748+
2749+
vmArgs.extend(['--add-exports=jdk.graal.compiler/jdk.graal.compiler.options=ALL-UNNAMED'])
2750+
2751+
# JVMCI is dynamically exported to Graal when JVMCI is initialized. This is too late
2752+
# for the junit harness which uses reflection to find @Test methods. In addition, the
2753+
# tests widely use JVMCI classes so JVMCI needs to also export all its packages to
2754+
# ALL-UNNAMED.
2755+
mainClassArgs.extend(['-JUnitOpenPackages', 'jdk.internal.vm.ci/*=jdk.graal.compiler,ALL-UNNAMED'])
2756+
mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.nativeimage/*=ALL-UNNAMED'])
2757+
2758+
return (vmArgs, mainClass, mainClassArgs)
2759+
2760+
2761+
mx_unittest.register_unittest_config(StandalonePointstoUnittestsConfig())

substratevm/mx.substratevm/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,7 @@
24172417
"dependencies" : [
24182418
"com.oracle.graal.pointsto.standalone.test",
24192419
],
2420+
"unittestConfig" : "standalone-pointsto-unittest",
24202421
"distDependencies": [
24212422
"mx:JUNIT_TOOL",
24222423
"sdk:NATIVEIMAGE",

substratevm/src/com.oracle.graal.pointsto.standalone.test/src/com/oracle/graal/pointsto/standalone/test/StandaloneConstantScanDynamicCase.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,5 @@ public static void main(String[] args) {
5050

5151
public void run() {
5252
STATUS.compareAndSet(this, status, 1);
53-
doSomething();
54-
}
55-
56-
private void doSomething() {
5753
}
5854
}

substratevm/src/com.oracle.graal.pointsto.standalone.test/src/com/oracle/graal/pointsto/standalone/test/StandaloneConstantScanDynamicTest.java

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -28,95 +28,14 @@
2828

2929
import org.junit.Test;
3030

31-
/**
32-
* This test shall fail because it makes the analysis code itself reachable if the classes are not
33-
* separated by classloaders.
34-
*
35-
* The exception stack is:
36-
*
37-
* <pre>
38-
* Exception:com.oracle.graal.pointsto.util.ParallelExecutionException
39-
* at com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:261)
40-
* at com.oracle.graal.pointsto.PointsToAnalysis.doTypeflow(PointsToAnalysis.java:528)
41-
* at com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:516)
42-
* at com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:161)
43-
* at com.oracle.graal.pointsto.standalone.PointsToAnalyzer.run(PointsToAnalyzer.java:278)
44-
* at com.oracle.graal.pointsto.standalone.test.PointstoAnalyzerTester.runAnalysisAndAssert(PointstoAnalyzerTester.java:159)
45-
* at com.oracle.graal.pointsto.standalone.test.PointstoAnalyzerTester.runAnalysisAndAssert(PointstoAnalyzerTester.java:145)
46-
* at com.oracle.graal.pointsto.standalone.test.StandaloneConstantScanDynamicTest.test(StandaloneConstantScanDynamicTest.java:43)
47-
* at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
48-
* at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
49-
* at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
50-
* at java.base/java.lang.reflect.Method.invoke(Method.java:568)
51-
* at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
52-
* at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
53-
* at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
54-
* at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
55-
* at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
56-
* at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
57-
* at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
58-
* at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
59-
* at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
60-
* at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
61-
* at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
62-
* at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
63-
* at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
64-
* at org.junit.runners.Suite.runChild(Suite.java:128)
65-
* at org.junit.runners.Suite.runChild(Suite.java:27)
66-
* at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
67-
* at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
68-
* at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
69-
* at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
70-
* at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
71-
* at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
72-
* at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
73-
* at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
74-
* at com.oracle.mxtool.junit.MxJUnitWrapper.runRequest(MxJUnitWrapper.java:375)
75-
* at com.oracle.mxtool.junit.MxJUnitWrapper.main(MxJUnitWrapper.java:230)
76-
* cause 0jdk.graal.compiler.debug.GraalError: jdk.graal.compiler.debug.GraalError: jdk.graal.compiler.debug.GraalError:
77-
* should not reach here: Double wrapping of constant. Most likely, the reachability analysis code itself is seen as reachable. java.lang.Object[]
78-
* at com.oracle.graal.pointsto.util.AnalysisFuture.setException(AnalysisFuture.java:49)
79-
* at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:269)
80-
* at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
81-
* at com.oracle.graal.pointsto.heap.ImageHeapObjectArray.readElementValue(ImageHeapObjectArray.java:84)
82-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.onObjectReachable(ImageHeapScanner.java:463)
83-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$markReachable$5(ImageHeapScanner.java:451)
84-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$postTask$14(ImageHeapScanner.java:690)
85-
* at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:187)
86-
* at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:171)
87-
* at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
88-
* at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
89-
* at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
90-
* at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
91-
* at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
92-
* at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
93-
* Caused by: jdk.graal.compiler.debug.GraalError: jdk.graal.compiler.debug.GraalError: should not reach here: Double wrapping of constant. Most likely, the reachability analysis code itself is seen as reachable. java.lang.Object[]
94-
* at com.oracle.graal.pointsto.util.AnalysisFuture.setException(AnalysisFuture.java:49)
95-
* at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:269)
96-
* at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
97-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.getOrCreateImageHeapConstant(ImageHeapScanner.java:212)
98-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapConstant(ImageHeapScanner.java:186)
99-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$createImageHeapObjectArray$3(ImageHeapScanner.java:270)
100-
* at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
101-
* ... 13 more
102-
* Caused by: jdk.graal.compiler.debug.GraalError: should not reach here: Double wrapping of constant. Most likely, the reachability analysis code itself is seen as reachable. java.lang.Object[]
103-
* at jdk.graal.compiler/jdk.graal.compiler.debug.GraalError.shouldNotReachHere(GraalError.java:57)
104-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.maybeReplace(ImageHeapScanner.java:307)
105-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapObject(ImageHeapScanner.java:225)
106-
* at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$getOrCreateImageHeapConstant$2(ImageHeapScanner.java:205)
107-
* at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
108-
* ... 18 more
109-
* </pre>
110-
*/
11131
public class StandaloneConstantScanDynamicTest {
11232

11333
@Test
11434
public void test() throws NoSuchMethodException {
11535
PointstoAnalyzerTester tester = new PointstoAnalyzerTester(StandaloneConstantScanDynamicCase.class);
11636
tester.setAnalysisArguments(tester.getTestClassName(),
11737
"-H:AnalysisTargetAppCP=" + tester.getTestClassJar());
118-
tester.setExpectedReachableMethods(tester.getTestClass().getDeclaredMethod("run"),
119-
tester.getTestClass().getDeclaredMethod("doSomething"));
38+
tester.setExpectedReachableMethods(tester.getTestClass().getDeclaredMethod("run"));
12039
tester.runAnalysisAndAssert();
12140
}
12241
}

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
package com.oracle.graal.pointsto.standalone;
2828

29-
import static jdk.graal.compiler.replacements.StandardGraphBuilderPlugins.registerInvocationPlugins;
30-
3129
import java.io.File;
3230
import java.lang.reflect.Method;
3331
import java.net.MalformedURLException;
@@ -56,6 +54,7 @@
5654
import com.oracle.graal.pointsto.meta.HostedProviders;
5755
import com.oracle.graal.pointsto.meta.PointsToAnalysisFactory;
5856
import com.oracle.graal.pointsto.phases.NoClassInitializationPlugin;
57+
import com.oracle.graal.pointsto.plugins.PointstoGraphBuilderPlugins;
5958
import com.oracle.graal.pointsto.reports.AnalysisReporter;
6059
import com.oracle.graal.pointsto.standalone.features.StandaloneAnalysisFeatureImpl;
6160
import com.oracle.graal.pointsto.standalone.features.StandaloneAnalysisFeatureManager;
@@ -97,7 +96,6 @@ public final class PointsToAnalyzer {
9796
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base", "sun.text.spi");
9897
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base", "sun.reflect.annotation");
9998
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base", "sun.security.jca");
100-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "jdk.jdeps", "com.sun.tools.classfile");
10199
}
102100

103101
private final OptionValues options;
@@ -212,7 +210,9 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) {
212210
NoClassInitializationPlugin classInitializationPlugin = new NoClassInitializationPlugin();
213211
plugins.setClassInitializationPlugin(classInitializationPlugin);
214212
aProviders.setGraphBuilderPlugins(plugins);
215-
registerInvocationPlugins(originalProviders.getSnippetReflection(), plugins.getInvocationPlugins(), false, true, false);
213+
PointstoGraphBuilderPlugins.registerArrayPlugins(plugins.getInvocationPlugins());
214+
PointstoGraphBuilderPlugins.registerSystemPlugins(plugins.getInvocationPlugins());
215+
PointstoGraphBuilderPlugins.registerObjectPlugins(plugins.getInvocationPlugins());
216216
}
217217
}
218218

@@ -286,6 +286,7 @@ public int run() {
286286
try (Timer t = new Timer("analysis", analysisName)) {
287287
StandaloneAnalysisFeatureImpl.DuringAnalysisAccessImpl config = new StandaloneAnalysisFeatureImpl.DuringAnalysisAccessImpl(standaloneAnalysisFeatureManager, analysisClassLoader, bigbang,
288288
debugContext);
289+
bigbang.getUniverse().setConcurrentAnalysisAccess(config);
289290
bigbang.runAnalysis(debugContext, (analysisUniverse) -> {
290291
bigbang.getHostVM().notifyClassReachabilityListener(analysisUniverse, config);
291292
standaloneAnalysisFeatureManager.forEachFeature(feature -> feature.duringAnalysis(config));

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/StandaloneObjectScanner.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ protected void scanEmbeddedRoot(JavaConstant root, Object position) {
5858
@Override
5959
protected final void scanField(AnalysisField field, JavaConstant receiver, ScanReason prevReason) {
6060
if (shouldScanField.test(field)) {
61-
super.scanField(field, receiver, prevReason);
61+
if (field.isStatic()) {
62+
if (field.getDeclaringClass().isInitialized()) {
63+
super.scanField(field, receiver, prevReason);
64+
}
65+
} else {
66+
super.scanField(field, receiver, prevReason);
67+
}
6268
}
6369
}
6470

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/heap/StandaloneImageHeapScanner.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,26 @@ protected Class<?> getClass(String className) {
6969

7070
@Override
7171
public ValueSupplier<JavaConstant> readHostedFieldValue(AnalysisField field, JavaConstant receiver) {
72+
if (field.isStatic() && !field.getDeclaringClass().isInitialized()) {
73+
return ValueSupplier.eagerValue(getConstantValue(field));
74+
}
7275
ValueSupplier<JavaConstant> ret = super.readHostedFieldValue(field, receiver);
7376
if (ret.get() == null && field.isStatic()) {
74-
ResolvedJavaField wrappedField = field.getWrapped();
75-
JavaConstant constant = wrappedField.getConstantValue();
76-
if (constant == null) {
77-
constant = JavaConstant.defaultForKind(wrappedField.getJavaKind());
78-
}
79-
return ValueSupplier.eagerValue(constant);
77+
return ValueSupplier.eagerValue(getConstantValue(field));
8078
} else {
8179
return ret;
8280
}
8381
}
8482

83+
private static JavaConstant getConstantValue(AnalysisField field) {
84+
ResolvedJavaField wrappedField = field.getWrapped();
85+
JavaConstant constant = wrappedField.getConstantValue();
86+
if (constant == null) {
87+
constant = JavaConstant.defaultForKind(wrappedField.getJavaKind());
88+
}
89+
return constant;
90+
}
91+
8592
@Override
8693
public void scanEmbeddedRoot(JavaConstant root, BytecodePosition position) {
8794
if (shouldScanConstant.test(root)) {

0 commit comments

Comments
 (0)