Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/JVMCIClassLoaderFactory.java @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | 15ab3e226b0d |
children |
rev | line source |
---|---|
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
22761
f2206f5bb62e
removed @ServiceProvider mechanism (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
23 package jdk.vm.ci.services; |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
25 import java.io.File; |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
26 import java.io.IOException; |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
27 import java.net.MalformedURLException; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
28 import java.net.URL; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
29 import java.net.URLClassLoader; |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
30 import java.nio.file.Files; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
31 import java.nio.file.Path; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
32 import java.nio.file.Paths; |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
33 import java.util.ArrayList; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
34 import java.util.List; |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
23408
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
22761
diff
changeset
|
36 import sun.misc.VM; |
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
22761
diff
changeset
|
37 |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 /** |
21607
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21562
diff
changeset
|
39 * Utility called from the VM to create and register a separate class loader for loading JVMCI |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
40 * classes. The core JVMCI classes are in {@code lib/jvmci/jvmci-api.jar} and |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
41 * {@code lib/jvmci/jvmci-hotspot.jar}. The JVMCI compiler classes are in {@code lib/jvmci/*.jar)} |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
42 * and the class path specified by the {@code "jvmci.class.path.append"} system property. The JVMCI |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
43 * class loader can optionally be given a parent other than the boot class loader as specified by |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
44 * {@link #getJVMCIParentClassLoader(Path)}. |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 */ |
21607
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21562
diff
changeset
|
46 class JVMCIClassLoaderFactory { |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 /** |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
49 * Copy of the {@code UseJVMCIClassLoader} VM option. Set by the VM before the static |
18614
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
50 * initializer is called. |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
51 */ |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
52 private static boolean useJVMCIClassLoader; |
18614
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
53 |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
54 /** |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
55 * Registers the JVMCI class loader in the VM. |
18614
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
56 */ |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
57 private static native void init(ClassLoader loader); |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
58 |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
59 static { |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
60 init(useJVMCIClassLoader ? newClassLoader() : null); |
18614
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
61 } |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
62 |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
63 /** |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
64 * Creates a new class loader for loading JVMCI classes. |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 */ |
18614
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
66 private static ClassLoader newClassLoader() { |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
67 Path jvmciDir = Paths.get(VM.getSavedProperty("java.home"), "lib", "jvmci"); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
68 if (!Files.isDirectory(jvmciDir)) { |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
69 throw new InternalError(jvmciDir + " does not exist or is not a directory"); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
70 } |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
71 URL[] urls = getJVMCIJarsUrls(jvmciDir); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
72 ClassLoader parent = getJVMCIParentClassLoader(jvmciDir); |
16681
74123ce7599b
Graal class loader must delegate directly to the boot class loader
Doug Simon <doug.simon@oracle.com>
parents:
16623
diff
changeset
|
73 return URLClassLoader.newInstance(urls, parent); |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 } |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 /** |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
77 * Creates a parent class loader for the JVMCI class loader. The class path for the loader is |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
78 * specified in the optional file {@code <java.home>/lib/jvmci/parentClassLoader.classpath}. If |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
79 * the file exists, its contents must be a well formed class path. Relative entries in the class |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
80 * path are resolved against {@code <java.home>/lib/jvmci}. |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
81 * |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
82 * @return {@code null} if {@code <java.home>/lib/jvmci/parentClassLoader.classpath} does not |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
83 * exist otherwise a {@link URLClassLoader} constructed from the class path in the file |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 */ |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
85 private static ClassLoader getJVMCIParentClassLoader(Path jvmciDir) { |
24141
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
86 Path parentClassPathFile = jvmciDir.resolve("parentClassLoader.classpath"); |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
87 if (Files.exists(parentClassPathFile)) { |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
88 String[] entries; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
89 try { |
24141
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
90 entries = new String(Files.readAllBytes(parentClassPathFile)).trim().split(File.pathSeparator); |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
91 } catch (IOException e) { |
24141
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
92 throw new InternalError("Error reading " + parentClassPathFile.toAbsolutePath(), e); |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
93 } |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
94 URL[] urls = new URL[entries.length]; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
95 for (int i = 0; i < entries.length; i++) { |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
96 try { |
24141
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
97 if (entries[i].isEmpty()) { |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
98 throw new InternalError("Class path entry " + i + " in " + parentClassPathFile + " is empty"); |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
99 } |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
100 // If entries[i] is already absolute, it will remain unchanged |
24141
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
101 Path path = jvmciDir.resolve(entries[i]); |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
102 if (!Files.exists(path)) { |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
103 // Unlike the user class path, be strict about this class |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
104 // path only referring to existing locations. |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
105 String errorMsg = "Class path entry " + i + " in " + parentClassPathFile + " refers to a file or directory that does not exist: \"" + entries[i] + "\""; |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
106 if (!path.toString().equals(entries[i])) { |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
107 errorMsg += " (resolved: \"" + path + "\")"; |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
108 } |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
109 throw new InternalError(errorMsg); |
d442ede93e4b
[GR-4077] be strict about entries in JVMCI parent class loader class path
Doug Simon <doug.simon@oracle.com>
parents:
24140
diff
changeset
|
110 } |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
111 urls[i] = path.toUri().toURL(); |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
112 } catch (MalformedURLException e) { |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
113 throw new InternalError(e); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
114 } |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
115 } |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
116 ClassLoader parent = null; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
117 return URLClassLoader.newInstance(urls, parent); |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 } |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
119 return null; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
120 } |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
122 private static Path ensureExists(Path path) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
123 if (!Files.exists(path)) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
124 throw new InternalError("Required JVMCI jar is missing: " + path); |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
125 } |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
126 return path; |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
127 } |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
128 |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
129 /** |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
130 * Gets the URLs for the required JVMCI jars, all the other jar files in the {@code jvmciDir} |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
131 * directory and the entries specified by the {@code "jvmci.class.path.append"} system property. |
24140
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
132 */ |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
133 private static URL[] getJVMCIJarsUrls(Path jvmciDir) { |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
134 String[] dirEntries = jvmciDir.toFile().list(); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
135 String append = VM.getSavedProperty("jvmci.class.path.append"); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
136 String[] appendEntries = append != null ? append.split(File.pathSeparator) : new String[0]; |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
137 List<URL> urls = new ArrayList<>(dirEntries.length + appendEntries.length); |
d4858e92c9b1
[GR-4077] support Graal.SDK on the boot class path and Truffle on a class path invisible to apps but visible to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
23776
diff
changeset
|
138 |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
139 try { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
140 urls.add(ensureExists(jvmciDir.resolve("jvmci-api.jar")).toUri().toURL()); |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
141 urls.add(ensureExists(jvmciDir.resolve("jvmci-hotspot.jar")).toUri().toURL()); |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
142 |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
143 for (String e : dirEntries) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
144 if (e.endsWith(".jar")) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
145 if (!e.equals("jvmci-api.jar") && !e.equals("jvmci-hotspot.jar")) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
146 urls.add(jvmciDir.resolve(e).toUri().toURL()); |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
147 } |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
148 } |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
149 } |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
150 for (int i = 0; i < appendEntries.length; ++i) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
151 Path path = Paths.get(appendEntries[i]); |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
152 if (!Files.exists(path)) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
153 // Unlike the user class path, be strict about this class |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
154 // path only referring to existing locations. |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
155 String errorMsg = "Entry " + i + " of class path specified by jvmci.class.path.append " + |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
156 "system property refers to a file or directory that does not exist: \"" + |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
157 appendEntries[i] + "\""; |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
158 throw new InternalError(errorMsg); |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
159 } |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
160 urls.add(path.toUri().toURL()); |
23408
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
22761
diff
changeset
|
161 } |
24143
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
162 } catch (MalformedURLException e) { |
15ab3e226b0d
set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
Doug Simon <doug.simon@oracle.com>
parents:
24141
diff
changeset
|
163 throw new InternalError(e); |
23408
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
22761
diff
changeset
|
164 } |
f84a5ac3be22
make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents:
22761
diff
changeset
|
165 |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
166 return urls.toArray(new URL[urls.size()]); |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 } |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
168 } |