Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.options/src/jdk/vm/ci/options/JVMCIJarsOptionDescriptorsProvider.java @ 22672:1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Thu, 08 Oct 2015 17:28:41 -0700 |
parents | jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/JVMCIJarsOptionDescriptorsProvider.java@5cd42bb63fad |
children |
rev | line source |
---|---|
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22649
diff
changeset
|
23 package jdk.vm.ci.options; |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
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:
22398
diff
changeset
|
25 import java.io.BufferedReader; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
26 import java.io.File; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
27 import java.io.IOException; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
28 import java.io.InputStreamReader; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
29 import java.util.ArrayList; |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
30 import java.util.Collections; |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
31 import java.util.Iterator; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
32 import java.util.List; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
33 import java.util.jar.JarFile; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
34 import java.util.zip.ZipEntry; |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22649
diff
changeset
|
36 import jdk.vm.ci.options.OptionsParser.OptionDescriptorsProvider; |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 /** |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 * Access to the {@link OptionDescriptors} declared by |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22649
diff
changeset
|
40 * {@code META-INF/services/jdk.vm.ci.options.OptionDescriptors} files in |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 * {@code <jre>/lib/jvmci/*.jar}. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 */ |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
43 final class JVMCIJarsOptionDescriptorsProvider implements OptionDescriptorsProvider { |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 static final String OptionDescriptorsServiceFile = "META-INF/services/" + OptionDescriptors.class.getName(); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 private final Iterator<File> jars; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 private final List<OptionDescriptors> optionsDescriptorsList; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
50 /** |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
51 * Creates a {@link JVMCIJarsOptionDescriptorsProvider} if at least one JVMCI jar is available |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
52 * otherwise returns null. |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
53 */ |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
54 static JVMCIJarsOptionDescriptorsProvider create() { |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 List<File> jarsList = findJVMCIJars(); |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
56 if (jarsList.isEmpty()) { |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
57 return null; |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
58 } |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
59 return new JVMCIJarsOptionDescriptorsProvider(jarsList); |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
60 } |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
61 |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
62 private JVMCIJarsOptionDescriptorsProvider(List<File> jarsList) { |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 this.jars = jarsList.iterator(); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 this.optionsDescriptorsList = new ArrayList<>(jarsList.size() * 3); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 /** |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 * Finds the list of JVMCI jars. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 */ |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 private static List<File> findJVMCIJars() { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 File javaHome = new File(System.getProperty("java.home")); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 File lib = new File(javaHome, "lib"); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 File jvmci = new File(lib, "jvmci"); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 if (!jvmci.exists()) { |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
75 return Collections.emptyList(); |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 List<File> jarFiles = new ArrayList<>(); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 for (String fileName : jvmci.list()) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 if (fileName.endsWith(".jar")) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 File file = new File(jvmci, fileName); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 if (file.isDirectory()) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 continue; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 jarFiles.add(file); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 return jarFiles; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 public OptionDescriptor get(String name) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 // Look up loaded option descriptors first |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 for (OptionDescriptors optionDescriptors : optionsDescriptorsList) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 OptionDescriptor desc = optionDescriptors.get(name); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 if (desc != null) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 return desc; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 while (jars.hasNext()) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 File path = jars.next(); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 try (JarFile jar = new JarFile(path)) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 ZipEntry entry = jar.getEntry(OptionDescriptorsServiceFile); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 if (entry != null) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 BufferedReader br = new BufferedReader(new InputStreamReader(jar.getInputStream(entry))); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 String line = null; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 OptionDescriptor desc = null; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 while ((line = br.readLine()) != null) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 OptionDescriptors options; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 try { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 options = (OptionDescriptors) Class.forName(line).newInstance(); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 optionsDescriptorsList.add(options); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
112 if (desc == null) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
113 desc = options.get(name); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
115 } catch (Exception e) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 throw new InternalError("Error instantiating class " + line + " read from " + path, e); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
119 if (desc != null) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 return desc; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 } catch (IOException e) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 throw new InternalError("Error reading " + path, e); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
125 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
126 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
127 return null; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
128 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
129 } |