Skip to content

Commit e17b00a

Browse files
adinnolpaw
authored andcommitted
Rework after 2nd review
1 parent 2176b2b commit e17b00a

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/JDKSourceCache.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.List;
4141

4242
import com.oracle.svm.core.util.VMError;
43+
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
4344

4445
public class JDKSourceCache extends SourceCache {
4546

@@ -72,7 +73,7 @@ protected void initSrcRoots() {
7273
assert javaHome != null;
7374
Path javaHomePath = Paths.get("", javaHome);
7475
Path srcZipPath;
75-
if (isJDK8()) {
76+
if (JavaVersionUtil.JAVA_SPEC < 11) {
7677
Path srcZipDir = javaHomePath.getParent();
7778
if (srcZipDir == null) {
7879
VMError.shouldNotReachHere("Cannot resolve parent directory of " + javaHome);
@@ -88,7 +89,7 @@ protected void initSrcRoots() {
8889
srcRoots.add(root);
8990
}
9091
specialSrcRoots = new HashMap<>();
91-
if (!isJDK8()) {
92+
if (JavaVersionUtil.JAVA_SPEC >= 11) {
9293
for (Path root : srcFileSystem.getRootDirectories()) {
9394
// add dirs named "src" as extra roots for special modules
9495
for (String specialRootModule : specialRootModules) {
@@ -107,7 +108,7 @@ protected void initSrcRoots() {
107108

108109
@Override
109110
public Path checkCacheFile(Path filePath) {
110-
if (!isJDK8()) {
111+
if (JavaVersionUtil.JAVA_SPEC >= 11) {
111112
for (String specialRootModule : specialRootModules) {
112113
if (filePath.startsWith(specialRootModule)) {
113114
// handle this module specially as it has intermediate dirs
@@ -138,7 +139,7 @@ public Path checkCacheFile(Path filePath) {
138139

139140
@Override
140141
public Path tryCacheFile(Path filePath) {
141-
if (!isJDK8()) {
142+
if (JavaVersionUtil.JAVA_SPEC >= 11) {
142143
for (String specialRootModule : specialRootModules) {
143144
if (filePath.startsWith(specialRootModule)) {
144145
// handle this module specially as it has intermediate dirs

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@ public abstract class SourceCache {
7070
*/
7171
protected List<Path> srcRoots;
7272

73-
private static final String JAVA_SPEC_VERSION_PROP = "java.specification.version";
74-
75-
/**
76-
*
77-
* The java spec version for the current JDK.
78-
*/
79-
private static String javaSpecVersion = System.getProperty(JAVA_SPEC_VERSION_PROP);
80-
81-
public static boolean isJDK8() {
82-
return javaSpecVersion.equals("1.8");
83-
}
84-
8573
/**
8674
* Create some flavour of source cache.
8775
*/

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceManager.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
import com.oracle.svm.util.ModuleSupport;
3131
import jdk.vm.ci.meta.ResolvedJavaType;
3232
import org.graalvm.compiler.debug.DebugContext;
33+
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
3334

3435
import java.nio.file.Path;
3536
import java.nio.file.Paths;
3637
import java.util.HashMap;
38+
import java.util.stream.Stream;
3739

3840
/**
3941
* A singleton class responsible for locating source files for classes included in a native image
@@ -178,9 +180,9 @@ private static Path computePrototypeName(String fileName, String packageName, So
178180
}
179181

180182
/**
181-
* An accept list of packages prefixes used to pre-filter JDK11+ runtime class lookups.
183+
* An accept list of packages prefixes used to pre-filter JDK8 runtime class lookups.
182184
*/
183-
public static final String[] JDK_SRC_PACKAGE_PREFIXES = {
185+
public static final String[] JDK8_SRC_PACKAGE_PREFIXES = {
184186
"java.",
185187
"jdk.",
186188
"javax.",
@@ -191,24 +193,15 @@ private static Path computePrototypeName(String fileName, String packageName, So
191193
"org.omg.",
192194
"org.w3c.",
193195
"org.xml",
194-
"org.graalvm.compiler",
195196
};
196197

197198
/**
198-
* A variant accept list of packages prefixes used to pre-filter JDK8 runtime class lookups.
199+
* A variant accept list of packages prefixes used to pre-filter JDK11+ runtime class lookups.
199200
*/
200-
public static final String[] JDK8_SRC_PACKAGE_PREFIXES = {
201-
"java.",
202-
"jdk.",
203-
"javax.",
204-
"sun.",
205-
"com.sun.",
206-
"org.ietf.",
207-
"org.jcp.",
208-
"org.omg.",
209-
"org.w3c.",
210-
"org.xml",
211-
};
201+
public static final String[] JDK_SRC_PACKAGE_PREFIXES = Stream.concat(Stream.of(JDK8_SRC_PACKAGE_PREFIXES),
202+
Stream.of("org.graalvm.compiler"))
203+
.toArray(String[]::new);
204+
212205
/**
213206
* An accept list of packages prefixes used to pre-filter GraalVM class lookups.
214207
*/
@@ -245,7 +238,7 @@ private static boolean acceptList(String packageName, String[] acceptList) {
245238
* @return the corresponding source cache type
246239
*/
247240
private static SourceCacheType sourceCacheType(String packageName) {
248-
if (acceptList(packageName, (SourceCache.isJDK8() ? JDK8_SRC_PACKAGE_PREFIXES : JDK_SRC_PACKAGE_PREFIXES))) {
241+
if (acceptList(packageName, (JavaVersionUtil.JAVA_SPEC >= 11 ? JDK_SRC_PACKAGE_PREFIXES : JDK8_SRC_PACKAGE_PREFIXES))) {
249242
return SourceCacheType.JDK;
250243
}
251244
if (acceptList(packageName, GRAALVM_SRC_PACKAGE_PREFIXES)) {

0 commit comments

Comments
 (0)