comparison graal/com.oracle.jvmci.hotspot.loader/src/com/oracle/jvmci/hotspot/loader/Factory.java @ 21559:be896a1983c0

recast all Graal native code as JVMCI code (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 May 2015 15:36:48 +0200
parents graal/com.oracle.graal.hotspot.loader/src/com/oracle/graal/hotspot/loader/Factory.java@12e94cba3696
children 47bebae7454f
comparison
equal deleted inserted replaced
21558:d563baeca9df 21559:be896a1983c0
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.jvmci.hotspot.loader;
24
25 import java.io.*;
26 import java.net.*;
27 import java.util.*;
28
29 /**
30 * Utility to create and register a separate class loader for loading JVMCI classes (i.e., those in
31 * found in lib/jvmci/*.jar).
32 */
33 public class Factory {
34
35 /**
36 * Copy of the {@code UseJVMCIClassLoader} VM option. Set by the VM before the static
37 * initializer is called.
38 */
39 private static boolean useJVMCIClassLoader;
40
41 /**
42 * Registers the JVMCI class loader in the VM.
43 */
44 private static native void init(ClassLoader loader);
45
46 static {
47 init(useJVMCIClassLoader ? newClassLoader() : null);
48 }
49
50 /**
51 * Creates a new class loader for loading JVMCI classes.
52 */
53 private static ClassLoader newClassLoader() {
54 URL[] urls = getJVMCIJarsUrls();
55 ClassLoader parent = null;
56 return URLClassLoader.newInstance(urls, parent);
57 }
58
59 /**
60 * Gets the URLs for lib/jvmci/*.jar.
61 */
62 private static URL[] getJVMCIJarsUrls() {
63 File javaHome = new File(System.getProperty("java.home"));
64 File lib = new File(javaHome, "lib");
65 File jvmci = new File(lib, "jvmci");
66 if (!jvmci.exists()) {
67 throw new InternalError(jvmci + " does not exist");
68 }
69
70 List<URL> urls = new ArrayList<>();
71 for (String fileName : jvmci.list()) {
72 if (fileName.endsWith(".jar")) {
73 File file = new File(jvmci, fileName);
74 if (file.isDirectory()) {
75 continue;
76 }
77 try {
78 urls.add(file.toURI().toURL());
79 } catch (MalformedURLException e) {
80 throw new InternalError(e);
81 }
82 }
83 }
84
85 return urls.toArray(new URL[urls.size()]);
86 }
87 }