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