annotate jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/JVMCIClassLoaderFactory.java @ 24141:d442ede93e4b

[GR-4077] be strict about entries in JVMCI parent class loader class path
author Doug Simon <doug.simon@oracle.com>
date Tue, 13 Jun 2017 22:34:41 +0200
parents d4858e92c9b1
children 15ab3e226b0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
40 * classes (i.e., those in found in {@code <java.home>/lib/jvmci/*.jar)} as well as those available
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
41 * on the class path in the {@code "jvmci.class.path.append"} system property. The JVMCI 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
42 * loader can optionally be given a parent other than the boot class loader as specified by
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
43 * {@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
44 */
21607
71b338926f2e moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21562
diff changeset
45 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
46
ad431bf0de07 added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 /**
21559
be896a1983c0 recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21040
diff changeset
48 * 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
49 * 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
50 */
21559
be896a1983c0 recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21040
diff changeset
51 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
52
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 /**
21559
be896a1983c0 recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21040
diff changeset
54 * 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
55 */
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 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
57
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 static {
21559
be896a1983c0 recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21040
diff changeset
59 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
60 }
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 /**
21559
be896a1983c0 recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21040
diff changeset
63 * 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
64 */
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
65 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
66 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
67 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
68 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
69 }
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 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
71 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
72 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
73 }
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 /**
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
76 * 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
77 * 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
78 * 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
79 * 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
80 *
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 * @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
82 * 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
83 */
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
84 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
85 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
86 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
87 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
88 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
89 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
90 } 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
91 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
92 }
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 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
94 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
95 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
96 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
97 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
98 }
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
99 // 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
100 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
101 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
102 // 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
103 // 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
104 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
105 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
106 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
107 }
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 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
109 }
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 urls[i] = path.toFile().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
111 } 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
112 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
113 }
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 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
116 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
117 }
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
118 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
119 }
16395
ad431bf0de07 added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
120
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
121 /**
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
122 * Gets the URLs for all jar files in the {@code jvmciDir} directory as well as the 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
123 * specified by the {@code "jvmci.class.path.append"} system property.
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
124 */
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
125 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
126 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
127
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
128 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
129 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
130 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
131
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 for (String fileName : dirEntries) {
21559
be896a1983c0 recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21040
diff changeset
133 if (fileName.endsWith(".jar")) {
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
134 Path path = jvmciDir.resolve(fileName);
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 if (Files.isDirectory(path)) {
21040
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
136 continue;
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
137 }
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
138 try {
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
139 urls.add(path.toFile().toURI().toURL());
21040
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
140 } catch (MalformedURLException e) {
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
141 throw new InternalError(e);
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
142 }
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
143 }
16395
ad431bf0de07 added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 }
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
145 for (String path : appendEntries) {
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
146 try {
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
147 urls.add(new File(path).toURI().toURL());
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
148 } 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
149 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
150 }
f84a5ac3be22 make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents: 22761
diff changeset
151 }
f84a5ac3be22 make JVMCI JDK immutable and sharable among different JVMCI clients
Doug Simon <doug.simon@oracle.com>
parents: 22761
diff changeset
152
21040
12e94cba3696 Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 18614
diff changeset
153 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
154 }
ad431bf0de07 added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 }