Skip to content

Commit bcc4c25

Browse files
committed
Parse pointsto options for standalone pointsto
The standalone pointsto need to take the input options. The options and parsing should follow the same way as native image's hosted options. So we extract the commom part of SubstrateOptionsParser to a new project where both pointsto and svm can share.
1 parent b8dc933 commit bcc4c25

File tree

23 files changed

+1090
-545
lines changed

23 files changed

+1090
-545
lines changed

compiler/mx.compiler/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@
21682168
"jdk.unsupported" # sun.misc.Unsafe
21692169
],
21702170
"exports" : [
2171-
"* to com.oracle.graal.graal_enterprise,org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,com.oracle.svm.svm_enterprise",
2171+
"* to com.oracle.graal.graal_enterprise,org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,com.oracle.svm.svm_enterprise,org.graalvm.nativeimage.base",
21722172
"org.graalvm.compiler.core.common to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.agent.tracing",
21732173
"org.graalvm.compiler.debug to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.objectfile",
21742174
"org.graalvm.compiler.hotspot to jdk.internal.vm.compiler.management",

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ def native_image_context_run(func, func_args=None, config=None, build_if_missing
761761
'substratevm:SVM',
762762
'substratevm:OBJECTFILE',
763763
'substratevm:POINTSTO',
764+
'substratevm:NATIVE_IMAGE_BASE',
764765
],
765766
support_distributions=['substratevm:SVM_GRAALVM_SUPPORT'],
766767
stability="earlyadopter",

substratevm/mx.substratevm/suite.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@
137137
"checkstyle": "com.oracle.svm.core",
138138
"workingSets": "SVM",
139139
},
140+
"org.graalvm.nativeimage.base": {
141+
"subDir": "src",
142+
"sourceDirs": ["src"],
143+
"dependencies": [
144+
"com.oracle.svm.util"
145+
],
146+
"javaCompliance": "8+",
147+
"annotationProcessors": [
148+
"compiler:GRAAL_PROCESSOR",
149+
],
150+
"checkstyle": "com.oracle.svm.core",
151+
"workingSets": "SVM",
152+
},
140153
"com.oracle.svm.util.jdk11": {
141154
"subDir": "src",
142155
"sourceDirs": ["src"],
@@ -164,7 +177,7 @@
164177
"headers",
165178
],
166179
"dependencies": [
167-
"com.oracle.svm.util",
180+
"org.graalvm.nativeimage.base",
168181
],
169182
"javaCompliance": "8+",
170183
"checkstyleVersion" : "8.36.1",
@@ -380,7 +393,7 @@
380393
"subDir": "src",
381394
"sourceDirs": ["src"],
382395
"dependencies": [
383-
"com.oracle.svm.util",
396+
"org.graalvm.nativeimage.base",
384397
],
385398
"checkstyle": "com.oracle.graal.pointsto",
386399
"javaCompliance": "8+",
@@ -1088,6 +1101,7 @@
10881101
"OBJECTFILE",
10891102
"POINTSTO",
10901103
"compiler:GRAAL",
1104+
"NATIVE_IMAGE_BASE",
10911105
],
10921106
"moduleInfo" : {
10931107
"name" : "org.graalvm.nativeimage.builder",
@@ -1100,7 +1114,7 @@
11001114
"com.oracle.svm.hosted to java.base",
11011115
"com.oracle.svm.hosted.agent to java.instrument",
11021116
"com.oracle.svm.truffle.api to org.graalvm.truffle",
1103-
"* to jdk.internal.vm.compiler,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.configure,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,com.oracle.svm.svm_enterprise",
1117+
"* to org.graalvm.nativeimage.base,jdk.internal.vm.compiler,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.configure,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,com.oracle.svm.svm_enterprise",
11041118
],
11051119
"opens" : [
11061120
"com.oracle.svm.core.nodes to jdk.internal.vm.compiler",
@@ -1219,7 +1233,7 @@
12191233
"static hamcrest",
12201234
],
12211235
"exports" : [
1222-
"* to org.graalvm.nativeimage.builder",
1236+
"* to org.graalvm.nativeimage.base,org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder",
12231237
],
12241238
},
12251239
},
@@ -1405,6 +1419,26 @@
14051419
},
14061420
},
14071421

1422+
"NATIVE_IMAGE_BASE": {
1423+
"subDir": "src",
1424+
"description" : "Native Image base that can be shared by native image building and pointsto.",
1425+
"dependencies": [
1426+
"org.graalvm.nativeimage.base",
1427+
"com.oracle.svm.util",
1428+
],
1429+
"distDependencies": [
1430+
"compiler:GRAAL",
1431+
],
1432+
"exclude": [
1433+
],
1434+
"moduleInfo" : {
1435+
"name" : "org.graalvm.nativeimage.base",
1436+
"exports" : [
1437+
"com.oracle.svm.util",
1438+
"org.graalvm.nativeimage.base.option",
1439+
],
1440+
}
1441+
},
14081442

14091443
"POINTSTO": {
14101444
"subDir": "src",
@@ -1415,13 +1449,13 @@
14151449
],
14161450
"distDependencies": [
14171451
"compiler:GRAAL",
1452+
"NATIVE_IMAGE_BASE",
14181453
],
14191454
"exclude": [
14201455
],
14211456
"moduleInfo" : {
14221457
"name" : "org.graalvm.nativeimage.pointsto",
14231458
"exports" : [
1424-
"com.oracle.svm.util",
14251459
"com.oracle.graal.pointsto",
14261460
"com.oracle.graal.pointsto.api",
14271461
"com.oracle.graal.pointsto.reports",
@@ -1590,7 +1624,7 @@
15901624
"moduleInfo" : {
15911625
"name" : "org.graalvm.nativeimage.llvm",
15921626
"exports" : [
1593-
"* to org.graalvm.nativeimage.builder",
1627+
"* to org.graalvm.nativeimage.builder,org.graalvm.nativeimage.base",
15941628
],
15951629
},
15961630
"maven" : False,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,10 @@ public String value() {
219219
return value;
220220
}
221221
}
222+
223+
@Option(help = "Specify the analysis entry point class. It should be a main Class.")//
224+
public static final OptionKey<String> AnalysisEntryClass = new OptionKey<>(null);
225+
226+
@Option(help = "Configurations used in native image building time can also be used in analysis. Specify the configurations' directory.")//
227+
public static final OptionKey<String> AnalysisConfigDir = new OptionKey<>(null);
222228
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/util/AnalysisError.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ private static String message(PointsToAnalysis bb, TypeFlow<?> objectFlow, Bytec
125125
}
126126
}
127127

128+
public static class InterruptAnalysis extends AnalysisError {
129+
private static final long serialVersionUID = 7126612141948542452L;
130+
131+
InterruptAnalysis(String msg) {
132+
super(msg);
133+
}
134+
}
135+
128136
public static TypeNotFoundError typeNotFound(ResolvedJavaType type) {
129137
throw new TypeNotFoundError(type);
130138
}
@@ -166,4 +174,8 @@ public static void guarantee(boolean condition, String format, Object... args) {
166174
// Checkstyle: resume
167175
}
168176
}
177+
178+
public static RuntimeException interruptAnalysis(String msg) {
179+
throw new InterruptAnalysis(msg);
180+
}
169181
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2021, 2021, Alibaba Group Holding Limited. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
27+
package com.oracle.graal.pointsto.util;
28+
29+
import java.io.File;
30+
import java.io.IOException;
31+
import java.nio.file.FileVisitResult;
32+
import java.nio.file.Files;
33+
import java.nio.file.Path;
34+
import java.nio.file.SimpleFileVisitor;
35+
import java.nio.file.attribute.BasicFileAttributes;
36+
import java.util.Enumeration;
37+
import java.util.function.Consumer;
38+
import java.util.jar.JarEntry;
39+
import java.util.jar.JarFile;
40+
41+
public class ClassPathSearcher {
42+
43+
public static void search(Consumer<String> matchClass) {
44+
String classpath = System.getProperty("java.class.path");
45+
String[] classPathEntries = classpath.split(File.pathSeparator);
46+
for (String entry : classPathEntries) {
47+
File file = new File(entry);
48+
if (file.isFile() && file.getName().endsWith(".jar")) {
49+
scanJar(file, matchClass);
50+
} else if (file.isDirectory()) {
51+
scanDir(file, matchClass);
52+
} else if (file.isFile()) {
53+
matchClass.accept(file.toString());
54+
}
55+
}
56+
}
57+
58+
private static void scanDir(File p, Consumer<String> matchClass) {
59+
try {
60+
Files.walkFileTree(p.toPath(), new SimpleFileVisitor<Path>() {
61+
@Override
62+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
63+
Path relativePath = p.toPath().relativize(file);
64+
matchClass.accept(relativePath.toString());
65+
return FileVisitResult.CONTINUE;
66+
}
67+
68+
});
69+
} catch (IOException e) {
70+
e.printStackTrace();
71+
}
72+
}
73+
74+
private static void scanJar(File file, Consumer<String> matchClass) {
75+
try {
76+
JarFile jf = new JarFile(file);
77+
Enumeration<JarEntry> entries = jf.entries();
78+
while (entries.hasMoreElements()) {
79+
matchClass.accept(entries.nextElement().getName());
80+
}
81+
} catch (IOException e) {
82+
e.printStackTrace();
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)