Mercurial > hg > truffle
annotate graal/com.oracle.jvmci.service/src/com/oracle/jvmci/service/JVMCIClassLoaderFactory.java @ 21654:cd6b1b2189a0
Remove GuardingPiNode and replace with FixedGuardNode + PiNode.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 02 Jun 2015 11:45:43 +0200 |
parents | 71b338926f2e |
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 */ |
21607
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21562
diff
changeset
|
23 package com.oracle.jvmci.service; |
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 |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import java.net.*; |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
27 import java.util.*; |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 /** |
21607
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21562
diff
changeset
|
30 * Utility called from the VM to create and register a separate class loader for loading JVMCI |
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21562
diff
changeset
|
31 * classes (i.e., those in found in lib/jvmci/*.jar). |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 */ |
21607
71b338926f2e
moved JVMCI classes into their own distributions (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21562
diff
changeset
|
33 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
|
34 |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 /** |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
36 * 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
|
37 * 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
|
38 */ |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
39 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
|
40 |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
41 /** |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
42 * 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
|
43 */ |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
44 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
|
45 |
c307546c7b0a
made initialization of the Graal class loader and well known Graal classes lazy
Doug Simon <doug.simon@oracle.com>
parents:
16681
diff
changeset
|
46 static { |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
47 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
|
48 } |
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 |
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 * 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
|
52 */ |
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 private static ClassLoader newClassLoader() { |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
54 URL[] urls = getJVMCIJarsUrls(); |
16681
74123ce7599b
Graal class loader must delegate directly to the boot class loader
Doug Simon <doug.simon@oracle.com>
parents:
16623
diff
changeset
|
55 ClassLoader parent = null; |
74123ce7599b
Graal class loader must delegate directly to the boot class loader
Doug Simon <doug.simon@oracle.com>
parents:
16623
diff
changeset
|
56 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
|
57 } |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 /** |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
60 * Gets the URLs for lib/jvmci/*.jar. |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 */ |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
62 private static URL[] getJVMCIJarsUrls() { |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
63 File javaHome = new File(System.getProperty("java.home")); |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
64 File lib = new File(javaHome, "lib"); |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
65 File jvmci = new File(lib, "jvmci"); |
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
66 if (!jvmci.exists()) { |
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
67 throw new InternalError(jvmci + " does not exist"); |
16395
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 } |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
70 List<URL> urls = new ArrayList<>(); |
21559
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
71 for (String fileName : jvmci.list()) { |
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
72 if (fileName.endsWith(".jar")) { |
be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21040
diff
changeset
|
73 File file = new File(jvmci, fileName); |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
74 if (file.isDirectory()) { |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
75 continue; |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
76 } |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
77 try { |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
78 urls.add(file.toURI().toURL()); |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
79 } 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
|
80 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
|
81 } |
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
82 } |
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 } |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 |
21040
12e94cba3696
Graal Loader: load all jars matching lib/graal/graal*.jar
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
18614
diff
changeset
|
85 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
|
86 } |
ad431bf0de07
added support to load classes from graal.jar with a separate class loader
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 } |