author | kvn |
Tue, 29 Oct 2019 15:35:06 -0700 | |
changeset 58851 | f1e6442241ca |
parent 54732 | 2d012a75d35c |
child 59262 | 06970ab040d4 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 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 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
25 |
import java.io.ByteArrayInputStream; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
26 |
import java.io.ByteArrayOutputStream; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
27 |
import java.io.DataInputStream; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
28 |
import java.io.DataOutputStream; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
29 |
import java.io.IOException; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
30 |
import java.util.ArrayList; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
31 |
import java.util.Collections; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
32 |
import java.util.Formatter; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
33 |
import java.util.HashMap; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
34 |
import java.util.List; |
44836 | 35 |
import java.util.Map; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
36 |
import java.util.ServiceLoader; |
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
37 |
import java.util.Set; |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
38 |
|
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
39 |
import jdk.internal.misc.VM; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
40 |
import jdk.internal.reflect.Reflection; |
43972 | 41 |
|
42 |
/** |
|
44836 | 43 |
* Provides utilities needed by JVMCI clients. |
43972 | 44 |
*/ |
45 |
public final class Services { |
|
46 |
||
50858 | 47 |
/** |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
48 |
* Guards code that should be run when building an JVMCI shared library but should be excluded |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
49 |
* from (being compiled into) the library. Such code must be directly guarded by an {@code if} |
50858 | 50 |
* statement on this field - the guard cannot be behind a method call. |
51 |
*/ |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
52 |
public static final boolean IS_BUILDING_NATIVE_IMAGE = Boolean.parseBoolean(VM.getSavedProperty("jdk.vm.ci.services.aot")); |
50858 | 53 |
|
54 |
/** |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
55 |
* Guards code that should only be run in a JVMCI shared library. Such code must be directly |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
56 |
* guarded by an {@code if} statement on this field - the guard cannot be behind a method call. |
50858 | 57 |
* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
58 |
* The value of this field in a JVMCI shared library runtime must be {@code true}. |
50858 | 59 |
*/ |
60 |
public static final boolean IS_IN_NATIVE_IMAGE; |
|
61 |
static { |
|
62 |
/* |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
63 |
* Prevents javac from constant folding use of this field. It is set to true by the process |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
64 |
* that builds the shared library. |
50858 | 65 |
*/ |
66 |
IS_IN_NATIVE_IMAGE = false; |
|
67 |
} |
|
68 |
||
43972 | 69 |
private Services() { |
70 |
} |
|
71 |
||
58851 | 72 |
/** |
73 |
* In a native image, this field is initialized by {@link #initializeSavedProperties(byte[])}. |
|
74 |
*/ |
|
75 |
private static volatile Map<String, String> savedProperties; |
|
76 |
||
77 |
static final boolean JVMCI_ENABLED = Boolean.parseBoolean(VM.getSavedProperties().get("jdk.internal.vm.ci.enabled")); |
|
44836 | 78 |
|
79 |
/** |
|
80 |
* Checks that JVMCI is enabled in the VM and throws an error if it isn't. |
|
81 |
*/ |
|
82 |
static void checkJVMCIEnabled() { |
|
83 |
if (!JVMCI_ENABLED) { |
|
84 |
throw new Error("The EnableJVMCI VM option must be true (i.e., -XX:+EnableJVMCI) to use JVMCI"); |
|
43972 | 85 |
} |
86 |
} |
|
87 |
||
88 |
/** |
|
44836 | 89 |
* Gets an unmodifiable copy of the system properties saved when {@link System} is initialized. |
43972 | 90 |
*/ |
44836 | 91 |
public static Map<String, String> getSavedProperties() { |
92 |
checkJVMCIEnabled(); |
|
58851 | 93 |
if (IS_IN_NATIVE_IMAGE) { |
94 |
if (savedProperties == null) { |
|
95 |
throw new InternalError("Saved properties not initialized"); |
|
96 |
} |
|
97 |
} else { |
|
98 |
if (savedProperties == null) { |
|
99 |
synchronized (Services.class) { |
|
100 |
if (savedProperties == null) { |
|
101 |
SecurityManager sm = System.getSecurityManager(); |
|
102 |
if (sm != null) { |
|
103 |
sm.checkPermission(new JVMCIPermission()); |
|
104 |
} |
|
105 |
savedProperties = VM.getSavedProperties(); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
43972 | 109 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
110 |
return savedProperties; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
111 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
112 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
113 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
114 |
* Helper method equivalent to {@link #getSavedProperties()}{@code .getOrDefault(name, def)}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
115 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
116 |
public static String getSavedProperty(String name, String def) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
117 |
return Services.getSavedProperties().getOrDefault(name, def); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
118 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
119 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
120 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
121 |
* Helper method equivalent to {@link #getSavedProperties()}{@code .get(name)}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
122 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
123 |
public static String getSavedProperty(String name) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
124 |
return Services.getSavedProperties().get(name); |
43972 | 125 |
} |
126 |
||
127 |
/** |
|
44836 | 128 |
* Causes the JVMCI subsystem to be initialized if it isn't already initialized. |
43972 | 129 |
*/ |
44836 | 130 |
public static void initializeJVMCI() { |
131 |
checkJVMCIEnabled(); |
|
132 |
try { |
|
133 |
Class.forName("jdk.vm.ci.runtime.JVMCI"); |
|
134 |
} catch (ClassNotFoundException e) { |
|
135 |
throw new InternalError(e); |
|
43972 | 136 |
} |
137 |
} |
|
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
138 |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
139 |
private static boolean jvmciEnabled = true; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
140 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
141 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
142 |
* When {@code -XX:-UseJVMCIClassLoader} is in use, JVMCI classes are loaded via the boot class |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
143 |
* loader. When {@code null} is the second argument to |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
144 |
* {@link ServiceLoader#load(Class, ClassLoader)}, service lookup will use the system class |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
145 |
* loader and thus find application classes which violates the API of {@link #load} and |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
146 |
* {@link #loadSingle}. To avoid this, a class loader that simply delegates to the boot class |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
147 |
* loader is used. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
148 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
149 |
static class LazyBootClassPath { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
150 |
static final ClassLoader bootClassPath = new ClassLoader(null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
151 |
}; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
152 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
153 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
154 |
private static ClassLoader findBootClassLoaderChild(ClassLoader start) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
155 |
ClassLoader cl = start; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
156 |
while (cl.getParent() != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
157 |
cl = cl.getParent(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
158 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
159 |
return cl; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
160 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
161 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
162 |
private static final Map<Class<?>, List<?>> servicesCache = IS_BUILDING_NATIVE_IMAGE ? new HashMap<>() : null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
163 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
164 |
@SuppressWarnings("unchecked") |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
165 |
private static <S> Iterable<S> load0(Class<S> service) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
166 |
if (IS_IN_NATIVE_IMAGE || IS_BUILDING_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
167 |
List<?> list = servicesCache.get(service); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
168 |
if (list != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
169 |
return (Iterable<S>) list; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
170 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
171 |
if (IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
172 |
throw new InternalError(String.format("No %s providers found when building native image", service.getName())); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
173 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
174 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
175 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
176 |
Iterable<S> providers = Collections.emptyList(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
177 |
if (jvmciEnabled) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
178 |
ClassLoader cl = null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
179 |
try { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
180 |
cl = getJVMCIClassLoader(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
181 |
if (cl == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
182 |
cl = LazyBootClassPath.bootClassPath; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
183 |
// JVMCI classes are loaded via the boot class loader. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
184 |
// If we use null as the second argument to ServiceLoader.load, |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
185 |
// service loading will use the system class loader |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
186 |
// and find classes on the application class path. Since we |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
187 |
// don't want this, we use a loader that is as close to the |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
188 |
// boot class loader as possible (since it is impossible |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
189 |
// to force service loading to use only the boot class loader). |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
190 |
cl = findBootClassLoaderChild(ClassLoader.getSystemClassLoader()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
191 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
192 |
providers = ServiceLoader.load(service, cl); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
193 |
} catch (UnsatisfiedLinkError e) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
194 |
jvmciEnabled = false; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
195 |
} catch (InternalError e) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
196 |
if (e.getMessage().equals("JVMCI is not enabled")) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
197 |
jvmciEnabled = false; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
198 |
} else { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
199 |
throw e; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
200 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
201 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
202 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
203 |
if (IS_BUILDING_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
204 |
synchronized (servicesCache) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
205 |
ArrayList<S> providersList = new ArrayList<>(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
206 |
for (S provider : providers) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
207 |
providersList.add(provider); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
208 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
209 |
servicesCache.put(service, providersList); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
210 |
providers = providersList; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
211 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
212 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
213 |
return providers; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
214 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
215 |
|
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
216 |
/** |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
217 |
* Opens all JVMCI packages to {@code otherModule}. |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
218 |
*/ |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
219 |
static void openJVMCITo(Module otherModule) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
220 |
Module jvmci = Services.class.getModule(); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
221 |
if (jvmci != otherModule) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
222 |
Set<String> packages = jvmci.getPackages(); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
223 |
for (String pkg : packages) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
224 |
boolean opened = jvmci.isOpen(pkg, otherModule); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
225 |
if (!opened) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
226 |
jvmci.addOpens(pkg, otherModule); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
227 |
} |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
228 |
} |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
229 |
} |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
230 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
231 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
232 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
233 |
* Gets an {@link Iterable} of the JVMCI providers available for a given service. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
234 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
235 |
* @throws SecurityException if a security manager is present and it denies <tt> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
236 |
* {@link RuntimePermission}("jvmci")</tt> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
237 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
238 |
public static <S> Iterable<S> load(Class<S> service) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
239 |
SecurityManager sm = System.getSecurityManager(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
240 |
if (sm != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
241 |
sm.checkPermission(new JVMCIPermission()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
242 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
243 |
return load0(service); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
244 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
245 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
246 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
247 |
* Gets the JVMCI provider for a given service for which at most one provider must be available. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
248 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
249 |
* @param service the service whose provider is being requested |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
250 |
* @param required specifies if an {@link InternalError} should be thrown if no provider of |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
251 |
* {@code service} is available |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
252 |
* @throws SecurityException if a security manager is present and it denies <tt> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
253 |
* {@link RuntimePermission}("jvmci")</tt> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
254 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
255 |
public static <S> S loadSingle(Class<S> service, boolean required) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
256 |
SecurityManager sm = System.getSecurityManager(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
257 |
if (sm != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
258 |
sm.checkPermission(new JVMCIPermission()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
259 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
260 |
Iterable<S> providers = load0(service); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
261 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
262 |
S singleProvider = null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
263 |
for (S provider : providers) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
264 |
if (singleProvider != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
265 |
throw new InternalError(String.format("Multiple %s providers found: %s, %s", service.getName(), singleProvider.getClass().getName(), provider.getClass().getName())); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
266 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
267 |
singleProvider = provider; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
268 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
269 |
if (singleProvider == null && required) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
270 |
String javaHome = Services.getSavedProperty("java.home"); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
271 |
String vmName = Services.getSavedProperty("java.vm.name"); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
272 |
Formatter errorMessage = new Formatter(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
273 |
errorMessage.format("The VM does not expose required service %s.%n", service.getName()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
274 |
errorMessage.format("Currently used Java home directory is %s.%n", javaHome); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
275 |
errorMessage.format("Currently used VM configuration is: %s", vmName); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
276 |
throw new UnsupportedOperationException(errorMessage.toString()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
277 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
278 |
return singleProvider; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
279 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
280 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
281 |
static { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
282 |
Reflection.registerMethodsToFilter(Services.class, Set.of("getJVMCIClassLoader")); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
283 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
284 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
285 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
286 |
* Gets the JVMCI class loader. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
287 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
288 |
* @throws InternalError with the {@linkplain Throwable#getMessage() message} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
289 |
* {@code "JVMCI is not enabled"} iff JVMCI is not enabled |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
290 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
291 |
private static ClassLoader getJVMCIClassLoader() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
292 |
if (IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
293 |
return null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
294 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
295 |
return ClassLoader.getSystemClassLoader(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
296 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
297 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
298 |
/** |
54732 | 299 |
* A Java {@code char} has a maximal UTF8 length of 3. |
300 |
*/ |
|
301 |
private static final int MAX_UNICODE_IN_UTF8_LENGTH = 3; |
|
302 |
||
303 |
/** |
|
304 |
* {@link DataOutputStream#writeUTF(String)} only supports values whose UTF8 encoding length is |
|
305 |
* less than 65535. |
|
306 |
*/ |
|
307 |
private static final int MAX_UTF8_PROPERTY_STRING_LENGTH = 65535 / MAX_UNICODE_IN_UTF8_LENGTH; |
|
308 |
||
309 |
/** |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
310 |
* Serializes the {@linkplain #getSavedProperties() saved system properties} to a byte array for |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
311 |
* the purpose of {@linkplain #initializeSavedProperties(byte[]) initializing} the initial |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
312 |
* properties in the JVMCI shared library. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
313 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
314 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
315 |
private static byte[] serializeSavedProperties() throws IOException { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
316 |
if (IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
317 |
throw new InternalError("Can only serialize saved properties in HotSpot runtime"); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
318 |
} |
54732 | 319 |
return serializeProperties(Services.getSavedProperties()); |
320 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
321 |
|
54732 | 322 |
private static byte[] serializeProperties(Map<String, String> props) throws IOException { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
323 |
// Compute size of output on the assumption that |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
324 |
// all system properties have ASCII names and values |
54732 | 325 |
int estimate = 4 + 4; |
326 |
int nonUtf8Props = 0; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
327 |
for (Map.Entry<String, String> e : props.entrySet()) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
328 |
String name = e.getKey(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
329 |
String value = e.getValue(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
330 |
estimate += (2 + (name.length())) + (2 + (value.length())); |
54732 | 331 |
if (name.length() > MAX_UTF8_PROPERTY_STRING_LENGTH || value.length() > MAX_UTF8_PROPERTY_STRING_LENGTH) { |
332 |
nonUtf8Props++; |
|
333 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
334 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
335 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
336 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(estimate); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
337 |
DataOutputStream out = new DataOutputStream(baos); |
54732 | 338 |
out.writeInt(props.size() - nonUtf8Props); |
339 |
out.writeInt(nonUtf8Props); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
340 |
for (Map.Entry<String, String> e : props.entrySet()) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
341 |
String name = e.getKey(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
342 |
String value = e.getValue(); |
54732 | 343 |
if (name.length() <= MAX_UTF8_PROPERTY_STRING_LENGTH && value.length() <= MAX_UTF8_PROPERTY_STRING_LENGTH) { |
344 |
out.writeUTF(name); |
|
345 |
out.writeUTF(value); |
|
346 |
} |
|
347 |
} |
|
348 |
if (nonUtf8Props != 0) { |
|
349 |
for (Map.Entry<String, String> e : props.entrySet()) { |
|
350 |
String name = e.getKey(); |
|
351 |
String value = e.getValue(); |
|
352 |
if (name.length() > MAX_UTF8_PROPERTY_STRING_LENGTH || value.length() > MAX_UTF8_PROPERTY_STRING_LENGTH) { |
|
353 |
byte[] utf8Name = name.getBytes("UTF-8"); |
|
354 |
byte[] utf8Value = value.getBytes("UTF-8"); |
|
355 |
out.writeInt(utf8Name.length); |
|
356 |
out.write(utf8Name); |
|
357 |
out.writeInt(utf8Value.length); |
|
358 |
out.write(utf8Value); |
|
359 |
} |
|
360 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
361 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
362 |
return baos.toByteArray(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
363 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
364 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
365 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
366 |
* Initialized the {@linkplain #getSavedProperties() saved system properties} in the JVMCI |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
367 |
* shared library from the {@linkplain #serializeSavedProperties() serialized saved properties} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
368 |
* in the HotSpot runtime. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
369 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
370 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
371 |
private static void initializeSavedProperties(byte[] serializedProperties) throws IOException { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
372 |
if (!IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
373 |
throw new InternalError("Can only initialize saved properties in JVMCI shared library runtime"); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
374 |
} |
54732 | 375 |
savedProperties = Collections.unmodifiableMap(deserializeProperties(serializedProperties)); |
376 |
} |
|
377 |
||
378 |
private static Map<String, String> deserializeProperties(byte[] serializedProperties) throws IOException { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
379 |
DataInputStream in = new DataInputStream(new ByteArrayInputStream(serializedProperties)); |
54732 | 380 |
int utf8Props = in.readInt(); |
381 |
int nonUtf8Props = in.readInt(); |
|
382 |
Map<String, String> props = new HashMap<>(utf8Props + nonUtf8Props); |
|
383 |
int index = 0; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
384 |
while (in.available() != 0) { |
54732 | 385 |
if (index < utf8Props) { |
386 |
String name = in.readUTF(); |
|
387 |
String value = in.readUTF(); |
|
388 |
props.put(name, value); |
|
389 |
} else { |
|
390 |
int nameLen = in.readInt(); |
|
391 |
byte[] nameBytes = new byte[nameLen]; |
|
392 |
in.read(nameBytes); |
|
393 |
int valueLen = in.readInt(); |
|
394 |
byte[] valueBytes = new byte[valueLen]; |
|
395 |
in.read(valueBytes); |
|
396 |
String name = new String(nameBytes, "UTF-8"); |
|
397 |
String value = new String(valueBytes, "UTF-8"); |
|
398 |
props.put(name, value); |
|
399 |
} |
|
400 |
index++; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
401 |
} |
54732 | 402 |
return props; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52433
diff
changeset
|
403 |
} |
43972 | 404 |
} |