author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58299 | 6df94ce3ab2f |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
2 |
* Copyright (c) 2016, 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 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.serviceprovider; |
26 |
||
49873 | 27 |
import static java.lang.Thread.currentThread; |
46459 | 28 |
|
49873 | 29 |
import java.io.IOException; |
30 |
import java.io.InputStream; |
|
54084 | 31 |
import java.util.Arrays; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
32 |
import java.util.ArrayList; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
33 |
import java.util.HashMap; |
43972 | 34 |
import java.util.Iterator; |
49873 | 35 |
import java.util.List; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
36 |
import java.util.Map; |
43972 | 37 |
import java.util.ServiceConfigurationError; |
38 |
import java.util.ServiceLoader; |
|
49873 | 39 |
import java.util.concurrent.atomic.AtomicLong; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
40 |
import java.util.function.Supplier; |
43972 | 41 |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
42 |
import org.graalvm.compiler.serviceprovider.SpeculationReasonGroup.SpeculationContextObject; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
43 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
44 |
import jdk.vm.ci.code.BytecodePosition; |
55159
a38132298eda
8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents:
54914
diff
changeset
|
45 |
import jdk.vm.ci.code.VirtualObject; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
46 |
import jdk.vm.ci.meta.ResolvedJavaField; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
47 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
48 |
import jdk.vm.ci.meta.ResolvedJavaType; |
54084 | 49 |
import jdk.vm.ci.meta.SpeculationLog.SpeculationReason; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
50 |
import jdk.vm.ci.meta.SpeculationLog.SpeculationReasonEncoding; |
52578 | 51 |
import jdk.vm.ci.runtime.JVMCI; |
43972 | 52 |
import jdk.vm.ci.services.JVMCIPermission; |
53 |
import jdk.vm.ci.services.Services; |
|
54 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
55 |
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
56 |
import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
57 |
|
43972 | 58 |
/** |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
59 |
* JDK 13+ version of {@link GraalServices}. |
43972 | 60 |
*/ |
61 |
public final class GraalServices { |
|
62 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
63 |
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:
54601
diff
changeset
|
64 |
|
49873 | 65 |
private GraalServices() { |
46459 | 66 |
} |
43972 | 67 |
|
68 |
/** |
|
69 |
* Gets an {@link Iterable} of the providers available for a given service. |
|
70 |
* |
|
71 |
* @throws SecurityException if on JDK8 and a security manager is present and it denies |
|
72 |
* {@link JVMCIPermission} |
|
73 |
*/ |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
74 |
@SuppressWarnings("unchecked") |
43972 | 75 |
public static <S> Iterable<S> load(Class<S> service) { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
76 |
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:
54601
diff
changeset
|
77 |
List<?> list = servicesCache.get(service); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
78 |
if (list != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
79 |
return (Iterable<S>) list; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
80 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
81 |
if (IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
82 |
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:
54601
diff
changeset
|
83 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
84 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
85 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
86 |
Iterable<S> providers = load0(service); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
87 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
88 |
if (IS_BUILDING_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
89 |
synchronized (servicesCache) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
90 |
ArrayList<S> providersList = new ArrayList<>(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
91 |
for (S provider : providers) { |
55509 | 92 |
Module module = provider.getClass().getModule(); |
58299 | 93 |
if (isHotSpotGraalModule(module.getName())) { |
55509 | 94 |
providersList.add(provider); |
95 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
96 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
97 |
providers = providersList; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
98 |
servicesCache.put(service, providersList); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
99 |
return providers; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
100 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
101 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
102 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
103 |
return providers; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
104 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
105 |
|
58299 | 106 |
/** |
107 |
* Determines if the module named by {@code name} is part of Graal when it is configured as a |
|
108 |
* HotSpot JIT compiler. |
|
109 |
*/ |
|
110 |
private static boolean isHotSpotGraalModule(String name) { |
|
111 |
if (name != null) { |
|
112 |
return name.equals("jdk.internal.vm.compiler") || |
|
113 |
name.equals("jdk.internal.vm.compiler.management") || |
|
114 |
name.equals("com.oracle.graal.graal_enterprise"); |
|
115 |
} |
|
116 |
return false; |
|
117 |
} |
|
118 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
119 |
protected static <S> Iterable<S> load0(Class<S> service) { |
58299 | 120 |
Module module = GraalServices.class.getModule(); |
121 |
// Graal cannot know all the services used by another module |
|
122 |
// (e.g. enterprise) so dynamically register the service use now. |
|
123 |
if (!module.canUse(service)) { |
|
124 |
module.addUses(service); |
|
125 |
} |
|
126 |
||
127 |
ModuleLayer layer = module.getLayer(); |
|
128 |
Iterable<S> iterable = ServiceLoader.load(layer, service); |
|
49873 | 129 |
return new Iterable<>() { |
43972 | 130 |
@Override |
131 |
public Iterator<S> iterator() { |
|
132 |
Iterator<S> iterator = iterable.iterator(); |
|
49873 | 133 |
return new Iterator<>() { |
43972 | 134 |
@Override |
135 |
public boolean hasNext() { |
|
136 |
return iterator.hasNext(); |
|
137 |
} |
|
138 |
||
139 |
@Override |
|
140 |
public S next() { |
|
141 |
S provider = iterator.next(); |
|
46459 | 142 |
// Allow Graal extensions to access JVMCI |
143 |
openJVMCITo(provider.getClass()); |
|
43972 | 144 |
return provider; |
145 |
} |
|
146 |
||
147 |
@Override |
|
148 |
public void remove() { |
|
149 |
iterator.remove(); |
|
150 |
} |
|
151 |
}; |
|
152 |
} |
|
153 |
}; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
49873 | 157 |
* Opens all JVMCI packages to the module of a given class. This relies on JVMCI already having |
158 |
* opened all its packages to the module defining {@link GraalServices}. |
|
159 |
* |
|
160 |
* @param other all JVMCI packages will be opened to the module defining this class |
|
46459 | 161 |
*/ |
49873 | 162 |
static void openJVMCITo(Class<?> other) { |
55509 | 163 |
if (IS_IN_NATIVE_IMAGE) { |
164 |
return; |
|
165 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
166 |
|
49873 | 167 |
Module jvmciModule = JVMCI_MODULE; |
168 |
Module otherModule = other.getModule(); |
|
169 |
if (jvmciModule != otherModule) { |
|
170 |
for (String pkg : jvmciModule.getPackages()) { |
|
171 |
if (!jvmciModule.isOpen(pkg, otherModule)) { |
|
52578 | 172 |
// JVMCI initialization opens all JVMCI packages |
173 |
// to Graal which is a prerequisite for Graal to |
|
174 |
// open JVMCI packages to other modules. |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
175 |
JVMCI.getRuntime(); |
52578 | 176 |
|
49873 | 177 |
jvmciModule.addOpens(pkg, otherModule); |
178 |
} |
|
46459 | 179 |
} |
180 |
} |
|
181 |
} |
|
182 |
||
183 |
/** |
|
43972 | 184 |
* Gets the provider for a given service for which at most one provider must be available. |
185 |
* |
|
186 |
* @param service the service whose provider is being requested |
|
187 |
* @param required specifies if an {@link InternalError} should be thrown if no provider of |
|
188 |
* {@code service} is available |
|
189 |
* @return the requested provider if available else {@code null} |
|
190 |
* @throws SecurityException if on JDK8 and a security manager is present and it denies |
|
191 |
* {@link JVMCIPermission} |
|
192 |
*/ |
|
193 |
public static <S> S loadSingle(Class<S> service, boolean required) { |
|
194 |
assert !service.getName().startsWith("jdk.vm.ci") : "JVMCI services must be loaded via " + Services.class.getName(); |
|
46459 | 195 |
Iterable<S> providers = load(service); |
43972 | 196 |
S singleProvider = null; |
197 |
try { |
|
198 |
for (Iterator<S> it = providers.iterator(); it.hasNext();) { |
|
199 |
singleProvider = it.next(); |
|
200 |
if (it.hasNext()) { |
|
46459 | 201 |
S other = it.next(); |
202 |
throw new InternalError(String.format("Multiple %s providers found: %s, %s", service.getName(), singleProvider.getClass().getName(), other.getClass().getName())); |
|
43972 | 203 |
} |
204 |
} |
|
205 |
} catch (ServiceConfigurationError e) { |
|
206 |
// If the service is required we will bail out below. |
|
207 |
} |
|
208 |
if (singleProvider == null) { |
|
209 |
if (required) { |
|
210 |
throw new InternalError(String.format("No provider for %s found", service.getName())); |
|
211 |
} |
|
212 |
} |
|
213 |
return singleProvider; |
|
214 |
} |
|
49873 | 215 |
|
216 |
/** |
|
217 |
* Gets the class file bytes for {@code c}. |
|
218 |
*/ |
|
219 |
public static InputStream getClassfileAsStream(Class<?> c) throws IOException { |
|
220 |
String classfilePath = c.getName().replace('.', '/') + ".class"; |
|
221 |
return c.getModule().getResourceAsStream(classfilePath); |
|
222 |
} |
|
223 |
||
224 |
private static final Module JVMCI_MODULE = Services.class.getModule(); |
|
225 |
||
226 |
/** |
|
227 |
* A JVMCI package dynamically exported to trusted modules. |
|
228 |
*/ |
|
229 |
private static final String JVMCI_RUNTIME_PACKAGE = "jdk.vm.ci.runtime"; |
|
230 |
static { |
|
231 |
assert JVMCI_MODULE.getPackages().contains(JVMCI_RUNTIME_PACKAGE); |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Determines if invoking {@link Object#toString()} on an instance of {@code c} will only run |
|
236 |
* trusted code. |
|
237 |
*/ |
|
238 |
public static boolean isToStringTrusted(Class<?> c) { |
|
58299 | 239 |
if (IS_IN_NATIVE_IMAGE) { |
240 |
return true; |
|
241 |
} |
|
242 |
||
49873 | 243 |
Module module = c.getModule(); |
244 |
Module jvmciModule = JVMCI_MODULE; |
|
245 |
assert jvmciModule.getPackages().contains("jdk.vm.ci.runtime"); |
|
246 |
if (module == jvmciModule || jvmciModule.isOpen(JVMCI_RUNTIME_PACKAGE, module)) { |
|
247 |
// Can access non-statically-exported package in JVMCI |
|
248 |
return true; |
|
249 |
} |
|
250 |
return false; |
|
251 |
} |
|
252 |
||
253 |
/** |
|
54084 | 254 |
* An implementation of {@link SpeculationReason} based on direct, unencoded values. |
255 |
*/ |
|
256 |
static final class DirectSpeculationReason implements SpeculationReason { |
|
257 |
final int groupId; |
|
258 |
final String groupName; |
|
259 |
final Object[] context; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
260 |
private SpeculationReasonEncoding encoding; |
54084 | 261 |
|
262 |
DirectSpeculationReason(int groupId, String groupName, Object[] context) { |
|
263 |
this.groupId = groupId; |
|
264 |
this.groupName = groupName; |
|
265 |
this.context = context; |
|
266 |
} |
|
267 |
||
268 |
@Override |
|
269 |
public boolean equals(Object obj) { |
|
270 |
if (obj instanceof DirectSpeculationReason) { |
|
271 |
DirectSpeculationReason that = (DirectSpeculationReason) obj; |
|
272 |
return this.groupId == that.groupId && Arrays.equals(this.context, that.context); |
|
273 |
} |
|
274 |
return false; |
|
275 |
} |
|
276 |
||
277 |
@Override |
|
278 |
public int hashCode() { |
|
279 |
return groupId + Arrays.hashCode(this.context); |
|
280 |
} |
|
281 |
||
282 |
@Override |
|
283 |
public String toString() { |
|
284 |
return String.format("%s@%d%s", groupName, groupId, Arrays.toString(context)); |
|
285 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
286 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
287 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
288 |
public SpeculationReasonEncoding encode(Supplier<SpeculationReasonEncoding> encodingSupplier) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
289 |
if (encoding == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
290 |
encoding = encodingSupplier.get(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
291 |
encoding.addInt(groupId); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
292 |
for (Object o : context) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
293 |
if (o == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
294 |
encoding.addInt(0); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
295 |
} else { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
296 |
addNonNullObject(encoding, o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
297 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
298 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
299 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
300 |
return encoding; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
301 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
302 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
303 |
static void addNonNullObject(SpeculationReasonEncoding encoding, Object o) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
304 |
Class<? extends Object> c = o.getClass(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
305 |
if (c == String.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
306 |
encoding.addString((String) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
307 |
} else if (c == Byte.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
308 |
encoding.addByte((Byte) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
309 |
} else if (c == Short.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
310 |
encoding.addShort((Short) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
311 |
} else if (c == Character.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
312 |
encoding.addShort((Character) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
313 |
} else if (c == Integer.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
314 |
encoding.addInt((Integer) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
315 |
} else if (c == Long.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
316 |
encoding.addLong((Long) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
317 |
} else if (c == Float.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
318 |
encoding.addInt(Float.floatToRawIntBits((Float) o)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
319 |
} else if (c == Double.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
320 |
encoding.addLong(Double.doubleToRawLongBits((Double) o)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
321 |
} else if (o instanceof Enum) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
322 |
encoding.addInt(((Enum<?>) o).ordinal()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
323 |
} else if (o instanceof ResolvedJavaMethod) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
324 |
encoding.addMethod((ResolvedJavaMethod) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
325 |
} else if (o instanceof ResolvedJavaType) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
326 |
encoding.addType((ResolvedJavaType) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
327 |
} else if (o instanceof ResolvedJavaField) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
328 |
encoding.addField((ResolvedJavaField) o); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
329 |
} else if (o instanceof SpeculationContextObject) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
330 |
SpeculationContextObject sco = (SpeculationContextObject) o; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
331 |
// These are compiler objects which all have the same class |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
332 |
// loader so the class name uniquely identifies the class. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
333 |
encoding.addString(o.getClass().getName()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
334 |
sco.accept(new EncodingAdapter(encoding)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
335 |
} else if (o.getClass() == BytecodePosition.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
336 |
BytecodePosition p = (BytecodePosition) o; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
337 |
while (p != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
338 |
encoding.addInt(p.getBCI()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
339 |
encoding.addMethod(p.getMethod()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
340 |
p = p.getCaller(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
341 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
342 |
} else { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
343 |
throw new IllegalArgumentException("Unsupported type for encoding: " + c.getName()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
344 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
345 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
346 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
347 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
348 |
static class EncodingAdapter implements SpeculationContextObject.Visitor { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
349 |
private final SpeculationReasonEncoding encoding; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
350 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
351 |
EncodingAdapter(SpeculationReasonEncoding encoding) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
352 |
this.encoding = encoding; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
353 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
354 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
355 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
356 |
public void visitBoolean(boolean v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
357 |
encoding.addByte(v ? 1 : 0); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
358 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
359 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
360 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
361 |
public void visitByte(byte v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
362 |
encoding.addByte(v); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
363 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
364 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
365 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
366 |
public void visitChar(char v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
367 |
encoding.addShort(v); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
368 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
369 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
370 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
371 |
public void visitShort(short v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
372 |
encoding.addInt(v); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
373 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
374 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
375 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
376 |
public void visitInt(int v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
377 |
encoding.addInt(v); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
378 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
379 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
380 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
381 |
public void visitLong(long v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
382 |
encoding.addLong(v); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
383 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
384 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
385 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
386 |
public void visitFloat(float v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
387 |
encoding.addInt(Float.floatToRawIntBits(v)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
388 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
389 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
390 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
391 |
public void visitDouble(double v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
392 |
encoding.addLong(Double.doubleToRawLongBits(v)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
393 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
394 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
395 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
396 |
public void visitObject(Object v) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
397 |
if (v == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
398 |
encoding.addInt(0); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
399 |
} else { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
400 |
DirectSpeculationReason.addNonNullObject(encoding, v); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
401 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54601
diff
changeset
|
402 |
} |
54084 | 403 |
} |
404 |
||
405 |
static SpeculationReason createSpeculationReason(int groupId, String groupName, Object... context) { |
|
406 |
return new DirectSpeculationReason(groupId, groupName, context); |
|
407 |
} |
|
408 |
||
409 |
/** |
|
49873 | 410 |
* Gets a unique identifier for this execution such as a process ID or a |
411 |
* {@linkplain #getGlobalTimeStamp() fixed timestamp}. |
|
412 |
*/ |
|
413 |
public static String getExecutionID() { |
|
414 |
return Long.toString(ProcessHandle.current().pid()); |
|
415 |
} |
|
416 |
||
417 |
private static final AtomicLong globalTimeStamp = new AtomicLong(); |
|
418 |
||
419 |
/** |
|
420 |
* Gets a time stamp for the current process. This method will always return the same value for |
|
421 |
* the current VM execution. |
|
422 |
*/ |
|
423 |
public static long getGlobalTimeStamp() { |
|
424 |
if (globalTimeStamp.get() == 0) { |
|
425 |
globalTimeStamp.compareAndSet(0, System.currentTimeMillis()); |
|
426 |
} |
|
427 |
return globalTimeStamp.get(); |
|
428 |
} |
|
429 |
||
430 |
/** |
|
431 |
* Returns an approximation of the total amount of memory, in bytes, allocated in heap memory |
|
432 |
* for the thread of the specified ID. The returned value is an approximation because some Java |
|
433 |
* virtual machine implementations may use object allocation mechanisms that result in a delay |
|
434 |
* between the time an object is allocated and the time its size is recorded. |
|
435 |
* <p> |
|
436 |
* If the thread of the specified ID is not alive or does not exist, this method returns |
|
437 |
* {@code -1}. If thread memory allocation measurement is disabled, this method returns |
|
438 |
* {@code -1}. A thread is alive if it has been started and has not yet died. |
|
439 |
* <p> |
|
440 |
* If thread memory allocation measurement is enabled after the thread has started, the Java |
|
441 |
* virtual machine implementation may choose any time up to and including the time that the |
|
442 |
* capability is enabled as the point where thread memory allocation measurement starts. |
|
443 |
* |
|
444 |
* @param id the thread ID of a thread |
|
445 |
* @return an approximation of the total memory allocated, in bytes, in heap memory for a thread |
|
446 |
* of the specified ID if the thread of the specified ID exists, the thread is alive, |
|
447 |
* and thread memory allocation measurement is enabled; {@code -1} otherwise. |
|
448 |
* |
|
449 |
* @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}. |
|
450 |
* @throws UnsupportedOperationException if the Java virtual machine implementation does not |
|
451 |
* {@linkplain #isThreadAllocatedMemorySupported() support} thread memory allocation |
|
452 |
* measurement. |
|
453 |
*/ |
|
454 |
public static long getThreadAllocatedBytes(long id) { |
|
455 |
JMXService jmx = JMXService.instance; |
|
456 |
if (jmx == null) { |
|
457 |
throw new UnsupportedOperationException(); |
|
458 |
} |
|
459 |
return jmx.getThreadAllocatedBytes(id); |
|
460 |
} |
|
461 |
||
462 |
/** |
|
463 |
* Convenience method for calling {@link #getThreadAllocatedBytes(long)} with the id of the |
|
464 |
* current thread. |
|
465 |
*/ |
|
466 |
public static long getCurrentThreadAllocatedBytes() { |
|
467 |
return getThreadAllocatedBytes(currentThread().getId()); |
|
468 |
} |
|
469 |
||
470 |
/** |
|
471 |
* Returns the total CPU time for the current thread in nanoseconds. The returned value is of |
|
472 |
* nanoseconds precision but not necessarily nanoseconds accuracy. If the implementation |
|
473 |
* distinguishes between user mode time and system mode time, the returned CPU time is the |
|
474 |
* amount of time that the current thread has executed in user mode or system mode. |
|
475 |
* |
|
476 |
* @return the total CPU time for the current thread if CPU time measurement is enabled; |
|
477 |
* {@code -1} otherwise. |
|
478 |
* |
|
479 |
* @throws UnsupportedOperationException if the Java virtual machine does not |
|
480 |
* {@linkplain #isCurrentThreadCpuTimeSupported() support} CPU time measurement for |
|
481 |
* the current thread |
|
482 |
*/ |
|
483 |
public static long getCurrentThreadCpuTime() { |
|
484 |
JMXService jmx = JMXService.instance; |
|
485 |
if (jmx == null) { |
|
486 |
throw new UnsupportedOperationException(); |
|
487 |
} |
|
488 |
return jmx.getCurrentThreadCpuTime(); |
|
489 |
} |
|
490 |
||
491 |
/** |
|
492 |
* Determines if the Java virtual machine implementation supports thread memory allocation |
|
493 |
* measurement. |
|
494 |
*/ |
|
495 |
public static boolean isThreadAllocatedMemorySupported() { |
|
496 |
JMXService jmx = JMXService.instance; |
|
497 |
if (jmx == null) { |
|
498 |
return false; |
|
499 |
} |
|
500 |
return jmx.isThreadAllocatedMemorySupported(); |
|
501 |
} |
|
502 |
||
503 |
/** |
|
504 |
* Determines if the Java virtual machine supports CPU time measurement for the current thread. |
|
505 |
*/ |
|
506 |
public static boolean isCurrentThreadCpuTimeSupported() { |
|
507 |
JMXService jmx = JMXService.instance; |
|
508 |
if (jmx == null) { |
|
509 |
return false; |
|
510 |
} |
|
511 |
return jmx.isCurrentThreadCpuTimeSupported(); |
|
512 |
} |
|
513 |
||
514 |
/** |
|
515 |
* Gets the input arguments passed to the Java virtual machine which does not include the |
|
516 |
* arguments to the {@code main} method. This method returns an empty list if there is no input |
|
517 |
* argument to the Java virtual machine. |
|
518 |
* <p> |
|
519 |
* Some Java virtual machine implementations may take input arguments from multiple different |
|
520 |
* sources: for examples, arguments passed from the application that launches the Java virtual |
|
521 |
* machine such as the 'java' command, environment variables, configuration files, etc. |
|
522 |
* <p> |
|
523 |
* Typically, not all command-line options to the 'java' command are passed to the Java virtual |
|
524 |
* machine. Thus, the returned input arguments may not include all command-line options. |
|
525 |
* |
|
526 |
* @return the input arguments to the JVM or {@code null} if they are unavailable |
|
527 |
*/ |
|
528 |
public static List<String> getInputArguments() { |
|
529 |
JMXService jmx = JMXService.instance; |
|
530 |
if (jmx == null) { |
|
531 |
return null; |
|
532 |
} |
|
533 |
return jmx.getInputArguments(); |
|
534 |
} |
|
54914 | 535 |
|
536 |
/** |
|
537 |
* Returns the fused multiply add of the three arguments; that is, returns the exact product of |
|
538 |
* the first two arguments summed with the third argument and then rounded once to the nearest |
|
539 |
* {@code float}. |
|
540 |
*/ |
|
541 |
public static float fma(float a, float b, float c) { |
|
542 |
return Math.fma(a, b, c); |
|
543 |
} |
|
544 |
||
545 |
/** |
|
546 |
* Returns the fused multiply add of the three arguments; that is, returns the exact product of |
|
547 |
* the first two arguments summed with the third argument and then rounded once to the nearest |
|
548 |
* {@code double}. |
|
549 |
*/ |
|
550 |
public static double fma(double a, double b, double c) { |
|
551 |
return Math.fma(a, b, c); |
|
552 |
} |
|
55159
a38132298eda
8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents:
54914
diff
changeset
|
553 |
|
57537 | 554 |
public static VirtualObject createVirtualObject(ResolvedJavaType type, int id, boolean isAutoBox) { |
555 |
return VirtualObject.get(type, id, isAutoBox); |
|
55159
a38132298eda
8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents:
54914
diff
changeset
|
556 |
} |
43972 | 557 |
} |