comparison jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/JVMCIClassLoaderFactory.java @ 22761:f2206f5bb62e

removed @ServiceProvider mechanism (GRAAL-1380)
author Doug Simon <doug.simon@oracle.com>
date Wed, 30 Dec 2015 17:55:07 +0100
parents jvmci/jdk.vm.ci.service/src/jdk/vm/ci/service/JVMCIClassLoaderFactory.java@1bbd4a7c274b
children f84a5ac3be22
comparison
equal deleted inserted replaced
22760:4cf1946f59fc 22761:f2206f5bb62e
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 jdk.vm.ci.services;
24
25 import java.io.File;
26 import java.net.MalformedURLException;
27 import java.net.URL;
28 import java.net.URLClassLoader;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33 * Utility called from the VM to create and register a separate class loader for loading JVMCI
34 * classes (i.e., those in found in lib/jvmci/*.jar).
35 */
36 class JVMCIClassLoaderFactory {
37
38 /**
39 * Copy of the {@code UseJVMCIClassLoader} VM option. Set by the VM before the static
40 * initializer is called.
41 */
42 private static boolean useJVMCIClassLoader;
43
44 /**
45 * Registers the JVMCI class loader in the VM.
46 */
47 private static native void init(ClassLoader loader);
48
49 static {
50 init(useJVMCIClassLoader ? newClassLoader() : null);
51 }
52
53 /**
54 * Creates a new class loader for loading JVMCI classes.
55 */
56 private static ClassLoader newClassLoader() {
57 URL[] urls = getJVMCIJarsUrls();
58 ClassLoader parent = null;
59 return URLClassLoader.newInstance(urls, parent);
60 }
61
62 /**
63 * Gets the URLs for lib/jvmci/*.jar.
64 */
65 private static URL[] getJVMCIJarsUrls() {
66 File javaHome = new File(System.getProperty("java.home"));
67 File lib = new File(javaHome, "lib");
68 File jvmci = new File(lib, "jvmci");
69 if (!jvmci.exists()) {
70 throw new InternalError(jvmci + " does not exist");
71 }
72
73 List<URL> urls = new ArrayList<>();
74 for (String fileName : jvmci.list()) {
75 if (fileName.endsWith(".jar")) {
76 File file = new File(jvmci, fileName);
77 if (file.isDirectory()) {
78 continue;
79 }
80 try {
81 urls.add(file.toURI().toURL());
82 } catch (MalformedURLException e) {
83 throw new InternalError(e);
84 }
85 }
86 }
87
88 return urls.toArray(new URL[urls.size()]);
89 }
90 }