author | dlong |
Thu, 25 Jul 2019 17:35:58 -0400 | |
changeset 57537 | ecc6e394475f |
parent 55509 | d58442b8abc1 |
child 57804 | 9b7b9f16dfd9 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54084 | 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 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.hotspot.test; |
26 |
||
57537 | 27 |
import static org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins.aesDecryptName; |
28 |
import static org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins.aesEncryptName; |
|
29 |
||
43972 | 30 |
import java.lang.reflect.Method; |
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Arrays; |
|
33 |
import java.util.Collection; |
|
34 |
import java.util.Collections; |
|
50609 | 35 |
import java.util.Formatter; |
43972 | 36 |
import java.util.List; |
50609 | 37 |
import java.util.ServiceLoader; |
43972 | 38 |
import java.util.Set; |
39 |
import java.util.TreeSet; |
|
40 |
import java.util.stream.Collectors; |
|
41 |
||
49873 | 42 |
import jdk.internal.vm.compiler.collections.EconomicMap; |
43 |
import jdk.internal.vm.compiler.collections.MapCursor; |
|
43972 | 44 |
import org.graalvm.compiler.api.test.Graal; |
45 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
|
46 |
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; |
|
57537 | 47 |
import org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins; |
43972 | 48 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
49 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; |
|
50 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; |
|
51 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; |
|
46459 | 52 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Binding; |
43972 | 53 |
import org.graalvm.compiler.runtime.RuntimeProvider; |
54084 | 54 |
import org.graalvm.compiler.serviceprovider.JavaVersionUtil; |
43972 | 55 |
import org.graalvm.compiler.test.GraalTest; |
46459 | 56 |
import org.junit.Test; |
43972 | 57 |
|
50858 | 58 |
import jdk.vm.ci.aarch64.AArch64; |
50609 | 59 |
import jdk.vm.ci.amd64.AMD64; |
60 |
import jdk.vm.ci.code.Architecture; |
|
43972 | 61 |
import jdk.vm.ci.hotspot.HotSpotVMConfigStore; |
62 |
import jdk.vm.ci.hotspot.VMIntrinsicMethod; |
|
63 |
import jdk.vm.ci.meta.MetaAccessProvider; |
|
46459 | 64 |
import jdk.vm.ci.meta.MetaUtil; |
43972 | 65 |
import jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod; |
66 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
67 |
||
68 |
/** |
|
46459 | 69 |
* Checks the intrinsics implemented by Graal against the set of intrinsics declared by HotSpot. The |
70 |
* purpose of this test is to detect when new intrinsics are added to HotSpot and process them |
|
50609 | 71 |
* appropriately in Graal. This will be achieved by working through {@link #toBeInvestigated} and |
72 |
* either implementing the intrinsic or moving it to {@link #ignore} . |
|
43972 | 73 |
*/ |
74 |
public class CheckGraalIntrinsics extends GraalTest { |
|
75 |
||
46459 | 76 |
public static boolean match(String type, Binding binding, VMIntrinsicMethod intrinsic) { |
77 |
if (intrinsic.name.equals(binding.name)) { |
|
78 |
if (intrinsic.descriptor.startsWith(binding.argumentsDescriptor)) { |
|
79 |
if (type.equals(intrinsic.declaringClass)) { |
|
43972 | 80 |
return true; |
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
return false; |
|
85 |
} |
|
86 |
||
46459 | 87 |
public static InvocationPlugin findPlugin(EconomicMap<String, List<Binding>> bindings, VMIntrinsicMethod intrinsic) { |
88 |
MapCursor<String, List<Binding>> cursor = bindings.getEntries(); |
|
89 |
while (cursor.advance()) { |
|
90 |
// Match format of VMIntrinsicMethod.declaringClass |
|
91 |
String type = MetaUtil.internalNameToJava(cursor.getKey(), true, false).replace('.', '/'); |
|
92 |
for (Binding binding : cursor.getValue()) { |
|
93 |
if (match(type, binding, intrinsic)) { |
|
94 |
return binding.plugin; |
|
95 |
} |
|
43972 | 96 |
} |
97 |
} |
|
98 |
return null; |
|
99 |
} |
|
100 |
||
46459 | 101 |
public static ResolvedJavaMethod resolveIntrinsic(MetaAccessProvider metaAccess, VMIntrinsicMethod intrinsic) throws ClassNotFoundException { |
46807 | 102 |
Class<?> c; |
103 |
try { |
|
104 |
c = Class.forName(intrinsic.declaringClass.replace('/', '.'), false, CheckGraalIntrinsics.class.getClassLoader()); |
|
105 |
} catch (ClassNotFoundException ex) { |
|
106 |
try { |
|
107 |
Class.forName("javax.naming.Reference"); |
|
108 |
} catch (ClassNotFoundException coreNamingMissing) { |
|
109 |
// if core JDK classes aren't found, we are probably running in a |
|
110 |
// JDK9 java.base environment and then missing class is OK |
|
111 |
return null; |
|
112 |
} |
|
113 |
throw ex; |
|
114 |
} |
|
43972 | 115 |
for (Method javaMethod : c.getDeclaredMethods()) { |
116 |
if (javaMethod.getName().equals(intrinsic.name)) { |
|
117 |
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(javaMethod); |
|
118 |
if (intrinsic.descriptor.equals("*")) { |
|
119 |
// Signature polymorphic method - name match is enough |
|
120 |
return method; |
|
121 |
} else { |
|
122 |
if (method.getSignature().toMethodDescriptor().equals(intrinsic.descriptor)) { |
|
123 |
return method; |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
return null; |
|
129 |
} |
|
130 |
||
131 |
/** |
|
50609 | 132 |
* The HotSpot intrinsics that: |
133 |
* <ul> |
|
134 |
* <li>will never implemented by Graal (comments must explain why)</li> |
|
135 |
* <li>are implemented without {@link InvocationPlugin}s, or</li> |
|
136 |
* <li>whose {@link InvocationPlugin} registration is guarded by a condition that is false in |
|
137 |
* the current VM context.</li> |
|
138 |
* </ul> |
|
43972 | 139 |
*/ |
50609 | 140 |
public final Set<String> ignore = new TreeSet<>(); |
43972 | 141 |
|
142 |
/** |
|
50609 | 143 |
* The HotSpot intrinsics whose {@link InvocationPlugin} registration is guarded by a condition |
144 |
* too complex to duplicate here. |
|
145 |
* </ul> |
|
43972 | 146 |
*/ |
50609 | 147 |
public final Set<String> complexGuard = new TreeSet<>(); |
148 |
||
149 |
/** |
|
150 |
* The HotSpot intrinsics implemented downstream. |
|
151 |
* </ul> |
|
152 |
*/ |
|
153 |
public final Set<String> downstream = new TreeSet<>(); |
|
154 |
||
155 |
/** |
|
156 |
* The HotSpot intrinsics yet to be implemented or moved to {@link #ignore}. |
|
157 |
*/ |
|
158 |
public final Set<String> toBeInvestigated = new TreeSet<>(); |
|
43972 | 159 |
|
160 |
private static Collection<String> add(Collection<String> c, String... elements) { |
|
161 |
String[] sorted = elements.clone(); |
|
162 |
Arrays.sort(sorted); |
|
163 |
for (int i = 0; i < elements.length; i++) { |
|
164 |
if (!elements[i].equals(sorted[i])) { |
|
165 |
// Let's keep the list sorted for easier visual inspection |
|
166 |
fail("Element %d is out of order, \"%s\"", i, elements[i]); |
|
167 |
} |
|
168 |
} |
|
169 |
c.addAll(Arrays.asList(elements)); |
|
170 |
return c; |
|
171 |
} |
|
172 |
||
50609 | 173 |
public final HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class); |
174 |
public final Architecture arch = rt.getHostBackend().getTarget().arch; |
|
175 |
public final GraalHotSpotVMConfig config = rt.getVMConfig(); |
|
176 |
||
177 |
public CheckGraalIntrinsics() { |
|
48190 | 178 |
// These are dead |
50609 | 179 |
add(ignore, |
43972 | 180 |
"java/lang/Math.atan2(DD)D", |
48190 | 181 |
"jdk/internal/misc/Unsafe.park(ZJ)V", |
182 |
"jdk/internal/misc/Unsafe.unpark(Ljava/lang/Object;)V", |
|
43972 | 183 |
"sun/misc/Unsafe.park(ZJ)V", |
184 |
"sun/misc/Unsafe.prefetchRead(Ljava/lang/Object;J)V", |
|
185 |
"sun/misc/Unsafe.prefetchReadStatic(Ljava/lang/Object;J)V", |
|
186 |
"sun/misc/Unsafe.prefetchWrite(Ljava/lang/Object;J)V", |
|
187 |
"sun/misc/Unsafe.prefetchWriteStatic(Ljava/lang/Object;J)V", |
|
188 |
"sun/misc/Unsafe.unpark(Ljava/lang/Object;)V"); |
|
189 |
||
48190 | 190 |
// These only exist to assist escape analysis in C2 |
50609 | 191 |
add(ignore, |
48190 | 192 |
"java/lang/Throwable.fillInStackTrace()Ljava/lang/Throwable;"); |
193 |
||
194 |
// These are only used for the security handling during stack walking |
|
50609 | 195 |
add(ignore, |
48190 | 196 |
"java/lang/reflect/Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"); |
197 |
||
198 |
// These are marker intrinsic ids only |
|
50609 | 199 |
add(ignore, |
48190 | 200 |
"java/lang/invoke/MethodHandle.<compiledLambdaForm>*", |
201 |
"java/lang/invoke/MethodHandle.invoke*"); |
|
202 |
||
203 |
// These are implemented through lowering |
|
50609 | 204 |
add(ignore, |
48190 | 205 |
"java/lang/ref/Reference.get()Ljava/lang/Object;"); |
206 |
||
207 |
// These are only used by C1 |
|
50609 | 208 |
add(ignore, |
48190 | 209 |
"java/nio/Buffer.checkIndex(I)I"); |
210 |
||
211 |
// These do general compiler optimizations and convert min/max to cmov instructions. We are |
|
212 |
// ignoring them as cmovs are not necessarily beneficial. |
|
50609 | 213 |
add(ignore, |
48190 | 214 |
"java/lang/Math.max(II)I", |
215 |
"java/lang/Math.min(II)I"); |
|
216 |
||
217 |
// These are known to be implemented down stream |
|
50609 | 218 |
add(downstream, |
43972 | 219 |
"java/lang/Integer.toString(I)Ljava/lang/String;", |
220 |
"java/lang/String.<init>(Ljava/lang/String;)V", |
|
221 |
"java/lang/StringBuffer.<init>()V", |
|
222 |
"java/lang/StringBuffer.<init>(I)V", |
|
223 |
"java/lang/StringBuffer.<init>(Ljava/lang/String;)V", |
|
224 |
"java/lang/StringBuffer.append(C)Ljava/lang/StringBuffer;", |
|
225 |
"java/lang/StringBuffer.append(I)Ljava/lang/StringBuffer;", |
|
226 |
"java/lang/StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;", |
|
227 |
"java/lang/StringBuffer.toString()Ljava/lang/String;", |
|
228 |
"java/lang/StringBuilder.<init>()V", |
|
229 |
"java/lang/StringBuilder.<init>(I)V", |
|
230 |
"java/lang/StringBuilder.<init>(Ljava/lang/String;)V", |
|
231 |
"java/lang/StringBuilder.append(C)Ljava/lang/StringBuilder;", |
|
232 |
"java/lang/StringBuilder.append(I)Ljava/lang/StringBuilder;", |
|
233 |
"java/lang/StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;", |
|
234 |
"java/lang/StringBuilder.toString()Ljava/lang/String;", |
|
235 |
"java/util/Arrays.copyOf([Ljava/lang/Object;ILjava/lang/Class;)[Ljava/lang/Object;", |
|
48190 | 236 |
"java/util/Arrays.copyOfRange([Ljava/lang/Object;IILjava/lang/Class;)[Ljava/lang/Object;"); |
43972 | 237 |
|
50609 | 238 |
add(complexGuard, |
43972 | 239 |
"java/lang/Integer.bitCount(I)I", |
240 |
"java/lang/Integer.numberOfLeadingZeros(I)I", |
|
241 |
"java/lang/Integer.numberOfTrailingZeros(I)I", |
|
242 |
"java/lang/Long.bitCount(J)I", |
|
243 |
"java/lang/Long.numberOfLeadingZeros(J)I", |
|
244 |
"java/lang/Long.numberOfTrailingZeros(J)I"); |
|
245 |
||
48190 | 246 |
// Relevant for Java flight recorder |
50609 | 247 |
add(toBeInvestigated, |
48190 | 248 |
"oracle/jrockit/jfr/Timing.counterTime()J", |
249 |
"oracle/jrockit/jfr/VMJFR.classID0(Ljava/lang/Class;)J", |
|
250 |
"oracle/jrockit/jfr/VMJFR.threadID()I"); |
|
251 |
||
50609 | 252 |
add(toBeInvestigated, |
48190 | 253 |
// Similar to addExact |
254 |
"java/lang/Math.negateExact(I)I", |
|
255 |
// Similar to addExact |
|
256 |
"java/lang/Math.negateExact(J)J", |
|
257 |
// HotSpot MacroAssembler-based intrinsic |
|
258 |
"java/lang/String.indexOf(Ljava/lang/String;)I", |
|
259 |
// Can share most implementation parts with with |
|
260 |
// Unsafe.allocateUninitializedArray0 |
|
261 |
"java/lang/reflect/Array.newArray(Ljava/lang/Class;I)Ljava/lang/Object;", |
|
262 |
// HotSpot MacroAssembler-based intrinsic |
|
263 |
"sun/nio/cs/ISO_8859_1$Encoder.encodeISOArray([CI[BII)I", |
|
54084 | 264 |
// We have implemented implCompressMultiBlock0 on JDK9+. Does it worth |
265 |
// backporting as corresponding HotSpot stubs are only generated on SPARC? |
|
48190 | 266 |
"sun/security/provider/DigestBase.implCompressMultiBlock([BII)I"); |
267 |
||
52578 | 268 |
// See JDK-8207146. |
269 |
String oopName = isJDK12OrHigher() ? "Reference" : "Object"; |
|
270 |
||
48190 | 271 |
if (isJDK9OrHigher()) { |
272 |
// Relevant for Java flight recorder |
|
50609 | 273 |
add(toBeInvestigated, |
48190 | 274 |
"jdk/jfr/internal/JVM.counterTime()J", |
275 |
"jdk/jfr/internal/JVM.getBufferWriter()Ljava/lang/Object;", |
|
276 |
"jdk/jfr/internal/JVM.getClassId(Ljava/lang/Class;)J"); |
|
277 |
||
50609 | 278 |
add(toBeInvestigated, |
48190 | 279 |
// Just check if the argument is a compile time constant |
280 |
"java/lang/invoke/MethodHandleImpl.isCompileConstant(Ljava/lang/Object;)Z", |
|
281 |
// Only used as a marker for vectorization? |
|
282 |
"java/util/stream/Streams$RangeIntSpliterator.forEachRemaining(Ljava/util/function/IntConsumer;)V", |
|
283 |
// Only implemented on non-AMD64 platforms (some logic and runtime call) |
|
284 |
"java/util/zip/Adler32.updateByteBuffer(IJII)I", |
|
285 |
// Only implemented on non-AMD64 platforms (some logic and runtime call) |
|
286 |
"java/util/zip/Adler32.updateBytes(I[BII)I", |
|
287 |
// Emits a slow and a fast path and some dispatching logic |
|
288 |
"jdk/internal/misc/Unsafe.allocateUninitializedArray0(Ljava/lang/Class;I)Ljava/lang/Object;", |
|
289 |
||
290 |
// Control flow, deopts, and a cast |
|
291 |
"jdk/internal/util/Preconditions.checkIndex(IILjava/util/function/BiFunction;)I", |
|
292 |
// HotSpot MacroAssembler-based intrinsic |
|
54084 | 293 |
"sun/nio/cs/ISO_8859_1$Encoder.implEncodeISOArray([CI[BII)I"); |
50609 | 294 |
|
48190 | 295 |
/* |
296 |
* Per default, all these operations are mapped to some generic method for which we |
|
297 |
* already have compiler intrinsics. Performance-wise it would be better to support them |
|
298 |
* explicitly as the more generic method might be more restrictive and therefore slower |
|
299 |
* than necessary. |
|
300 |
*/ |
|
52578 | 301 |
|
50609 | 302 |
add(toBeInvestigated, |
48190 | 303 |
// Mapped to compareAndExchange* |
304 |
"jdk/internal/misc/Unsafe.compareAndExchangeByteAcquire(Ljava/lang/Object;JBB)B", |
|
305 |
"jdk/internal/misc/Unsafe.compareAndExchangeByteRelease(Ljava/lang/Object;JBB)B", |
|
306 |
"jdk/internal/misc/Unsafe.compareAndExchangeIntAcquire(Ljava/lang/Object;JII)I", |
|
307 |
"jdk/internal/misc/Unsafe.compareAndExchangeIntRelease(Ljava/lang/Object;JII)I", |
|
308 |
"jdk/internal/misc/Unsafe.compareAndExchangeLongAcquire(Ljava/lang/Object;JJJ)J", |
|
309 |
"jdk/internal/misc/Unsafe.compareAndExchangeLongRelease(Ljava/lang/Object;JJJ)J", |
|
52578 | 310 |
"jdk/internal/misc/Unsafe.compareAndExchange" + oopName + "Acquire(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", |
311 |
"jdk/internal/misc/Unsafe.compareAndExchange" + oopName + "Release(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", |
|
48190 | 312 |
"jdk/internal/misc/Unsafe.compareAndExchangeShortAcquire(Ljava/lang/Object;JSS)S", |
313 |
"jdk/internal/misc/Unsafe.compareAndExchangeShortRelease(Ljava/lang/Object;JSS)S", |
|
314 |
||
315 |
// Mapped to compareAndSet* |
|
316 |
"jdk/internal/misc/Unsafe.weakCompareAndSetByte(Ljava/lang/Object;JBB)Z", |
|
317 |
"jdk/internal/misc/Unsafe.weakCompareAndSetByteAcquire(Ljava/lang/Object;JBB)Z", |
|
318 |
"jdk/internal/misc/Unsafe.weakCompareAndSetBytePlain(Ljava/lang/Object;JBB)Z", |
|
319 |
"jdk/internal/misc/Unsafe.weakCompareAndSetByteRelease(Ljava/lang/Object;JBB)Z", |
|
320 |
"jdk/internal/misc/Unsafe.weakCompareAndSetInt(Ljava/lang/Object;JII)Z", |
|
321 |
"jdk/internal/misc/Unsafe.weakCompareAndSetIntAcquire(Ljava/lang/Object;JII)Z", |
|
322 |
"jdk/internal/misc/Unsafe.weakCompareAndSetIntPlain(Ljava/lang/Object;JII)Z", |
|
323 |
"jdk/internal/misc/Unsafe.weakCompareAndSetIntRelease(Ljava/lang/Object;JII)Z", |
|
324 |
"jdk/internal/misc/Unsafe.weakCompareAndSetLong(Ljava/lang/Object;JJJ)Z", |
|
325 |
"jdk/internal/misc/Unsafe.weakCompareAndSetLongAcquire(Ljava/lang/Object;JJJ)Z", |
|
326 |
"jdk/internal/misc/Unsafe.weakCompareAndSetLongPlain(Ljava/lang/Object;JJJ)Z", |
|
327 |
"jdk/internal/misc/Unsafe.weakCompareAndSetLongRelease(Ljava/lang/Object;JJJ)Z", |
|
52578 | 328 |
"jdk/internal/misc/Unsafe.weakCompareAndSet" + oopName + "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", |
329 |
"jdk/internal/misc/Unsafe.weakCompareAndSet" + oopName + "Acquire(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", |
|
330 |
"jdk/internal/misc/Unsafe.weakCompareAndSet" + oopName + "Plain(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", |
|
331 |
"jdk/internal/misc/Unsafe.weakCompareAndSet" + oopName + "Release(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", |
|
48190 | 332 |
"jdk/internal/misc/Unsafe.weakCompareAndSetShort(Ljava/lang/Object;JSS)Z", |
333 |
"jdk/internal/misc/Unsafe.weakCompareAndSetShortAcquire(Ljava/lang/Object;JSS)Z", |
|
334 |
"jdk/internal/misc/Unsafe.weakCompareAndSetShortPlain(Ljava/lang/Object;JSS)Z", |
|
335 |
"jdk/internal/misc/Unsafe.weakCompareAndSetShortRelease(Ljava/lang/Object;JSS)Z"); |
|
336 |
||
337 |
// Compact string support - HotSpot MacroAssembler-based intrinsic or complex C2 logic. |
|
50609 | 338 |
add(toBeInvestigated, |
48190 | 339 |
"java/lang/StringCoding.hasNegatives([BII)Z", |
54084 | 340 |
"java/lang/StringCoding.implEncodeISOArray([BI[BII)I"); |
341 |
add(ignore, |
|
342 |
// handled through an intrinsic for String.equals itself |
|
343 |
"java/lang/StringLatin1.equals([B[B)Z", |
|
344 |
||
345 |
// handled by an intrinsic for StringLatin1.indexOf([BI[BII)I |
|
48190 | 346 |
"java/lang/StringLatin1.indexOf([B[B)I", |
54084 | 347 |
|
348 |
// handled through an intrinsic for String.equals itself |
|
349 |
"java/lang/StringUTF16.equals([B[B)Z", |
|
350 |
||
351 |
// handled by an intrinsic for StringUTF16.indexOfUnsafe |
|
48190 | 352 |
"java/lang/StringUTF16.indexOf([BI[BII)I", |
353 |
"java/lang/StringUTF16.indexOf([B[B)I", |
|
54084 | 354 |
|
355 |
// handled by an intrinsic for StringUTF16.indexOfCharUnsafe |
|
48190 | 356 |
"java/lang/StringUTF16.indexOfChar([BIII)I", |
54084 | 357 |
|
358 |
// handled by an intrinsic for StringUTF16.indexOfLatin1Unsafe |
|
48190 | 359 |
"java/lang/StringUTF16.indexOfLatin1([BI[BII)I", |
54084 | 360 |
"java/lang/StringUTF16.indexOfLatin1([B[B)I"); |
361 |
||
362 |
if (!config.useAESCTRIntrinsics) { |
|
363 |
add(ignore, |
|
364 |
"com/sun/crypto/provider/CounterMode.implCrypt([BII[BI)I"); |
|
365 |
} |
|
366 |
if (!config.useGHASHIntrinsics()) { |
|
367 |
add(ignore, |
|
368 |
"com/sun/crypto/provider/GHASH.processBlocks([BII[J[J)V"); |
|
369 |
} |
|
370 |
if (!(config.useSHA1Intrinsics() || config.useSHA256Intrinsics() || config.useSHA512Intrinsics())) { |
|
371 |
add(ignore, |
|
372 |
"sun/security/provider/DigestBase.implCompressMultiBlock0([BII)I"); |
|
373 |
} |
|
54914 | 374 |
if (!config.useFMAIntrinsics) { |
375 |
add(ignore, |
|
376 |
"java/lang/Math.fma(DDD)D", |
|
377 |
"java/lang/Math.fma(FFF)F"); |
|
378 |
} else if (!(arch instanceof AMD64)) { |
|
379 |
add(toBeInvestigated, |
|
380 |
"java/lang/Math.fma(DDD)D", |
|
381 |
"java/lang/Math.fma(FFF)F"); |
|
382 |
} |
|
48190 | 383 |
} |
384 |
||
48861 | 385 |
if (isJDK10OrHigher()) { |
50609 | 386 |
add(toBeInvestigated, |
54084 | 387 |
"java/lang/Math.multiplyHigh(JJ)J"); |
48861 | 388 |
} |
389 |
||
50330 | 390 |
if (isJDK11OrHigher()) { |
391 |
// Relevant for Java flight recorder |
|
50609 | 392 |
add(toBeInvestigated, |
55509 | 393 |
"java/lang/CharacterDataLatin1.isDigit(I)Z", |
394 |
"java/lang/CharacterDataLatin1.isLowerCase(I)Z", |
|
395 |
"java/lang/CharacterDataLatin1.isUpperCase(I)Z", |
|
396 |
"java/lang/CharacterDataLatin1.isWhitespace(I)Z", |
|
50330 | 397 |
"jdk/jfr/internal/JVM.getEventWriter()Ljava/lang/Object;"); |
54601 | 398 |
if (!config.useBase64Intrinsics()) { |
399 |
add(ignore, |
|
400 |
"java/util/Base64$Encoder.encodeBlock([BII[BIZ)V"); |
|
401 |
} |
|
50330 | 402 |
} |
403 |
||
53081
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
404 |
if (isJDK13OrHigher()) { |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
405 |
add(toBeInvestigated, |
54750 | 406 |
"java/lang/Math.abs(I)I", |
407 |
"java/lang/Math.abs(J)J", |
|
53081
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
408 |
"java/lang/Math.max(DD)D", |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
409 |
"java/lang/Math.max(FF)F", |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
410 |
"java/lang/Math.min(DD)D", |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
411 |
"java/lang/Math.min(FF)F"); |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
412 |
} |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
413 |
|
50609 | 414 |
if (!config.inlineNotify()) { |
415 |
add(ignore, "java/lang/Object.notify()V"); |
|
416 |
} |
|
417 |
if (!config.inlineNotifyAll()) { |
|
418 |
add(ignore, "java/lang/Object.notifyAll()V"); |
|
419 |
} |
|
420 |
||
421 |
if (!(arch instanceof AMD64)) { |
|
48190 | 422 |
// Can we implement these on non-AMD64 platforms? C2 seems to. |
50609 | 423 |
add(toBeInvestigated, |
424 |
"java/lang/String.compareTo(Ljava/lang/String;)I", |
|
54084 | 425 |
"java/lang/StringLatin1.indexOf([B[B)I", |
52578 | 426 |
"java/lang/StringLatin1.inflate([BI[BII)V", |
427 |
"java/lang/StringLatin1.inflate([BI[CII)V", |
|
428 |
"java/lang/StringUTF16.compress([BI[BII)I", |
|
429 |
"java/lang/StringUTF16.compress([CI[BII)I", |
|
54084 | 430 |
"java/lang/StringUTF16.indexOf([BI[BII)I", |
431 |
"java/lang/StringUTF16.indexOf([B[B)I", |
|
432 |
"java/lang/StringUTF16.indexOfChar([BIII)I", |
|
433 |
"java/lang/StringUTF16.indexOfLatin1([BI[BII)I", |
|
434 |
"java/lang/StringUTF16.indexOfLatin1([B[B)I", |
|
50609 | 435 |
"jdk/internal/misc/Unsafe.compareAndExchangeByte(Ljava/lang/Object;JBB)B", |
436 |
"jdk/internal/misc/Unsafe.compareAndExchangeShort(Ljava/lang/Object;JSS)S", |
|
437 |
"jdk/internal/misc/Unsafe.compareAndSetByte(Ljava/lang/Object;JBB)Z", |
|
438 |
"jdk/internal/misc/Unsafe.compareAndSetShort(Ljava/lang/Object;JSS)Z", |
|
439 |
"jdk/internal/misc/Unsafe.getAndAddByte(Ljava/lang/Object;JB)B", |
|
440 |
"jdk/internal/misc/Unsafe.getAndAddShort(Ljava/lang/Object;JS)S", |
|
441 |
"jdk/internal/misc/Unsafe.getAndSetByte(Ljava/lang/Object;JB)B", |
|
442 |
"jdk/internal/misc/Unsafe.getAndSetShort(Ljava/lang/Object;JS)S", |
|
48190 | 443 |
"sun/misc/Unsafe.getAndAddInt(Ljava/lang/Object;JI)I", |
444 |
"sun/misc/Unsafe.getAndAddLong(Ljava/lang/Object;JJ)J", |
|
445 |
"sun/misc/Unsafe.getAndSetInt(Ljava/lang/Object;JI)I", |
|
446 |
"sun/misc/Unsafe.getAndSetLong(Ljava/lang/Object;JJ)J", |
|
52578 | 447 |
"sun/misc/Unsafe.getAndSet" + oopName + "(Ljava/lang/Object;JLjava/lang/Object;)Ljava/lang/Object;"); |
48190 | 448 |
|
449 |
if (isJDK9OrHigher()) { |
|
50858 | 450 |
if (!(arch instanceof AArch64)) { |
451 |
add(toBeInvestigated, |
|
452 |
"java/lang/StringLatin1.compareTo([B[B)I", |
|
453 |
"java/lang/StringLatin1.compareToUTF16([B[B)I", |
|
454 |
"java/lang/StringUTF16.compareTo([B[B)I", |
|
455 |
"java/lang/StringUTF16.compareToLatin1([B[B)I", |
|
456 |
"jdk/internal/misc/Unsafe.getAndAddInt(Ljava/lang/Object;JI)I", |
|
457 |
"jdk/internal/misc/Unsafe.getAndAddLong(Ljava/lang/Object;JJ)J", |
|
458 |
"jdk/internal/misc/Unsafe.getAndSetInt(Ljava/lang/Object;JI)I", |
|
459 |
"jdk/internal/misc/Unsafe.getAndSetLong(Ljava/lang/Object;JJ)J", |
|
52578 | 460 |
"jdk/internal/misc/Unsafe.getAndSet" + oopName + "(Ljava/lang/Object;JLjava/lang/Object;)Ljava/lang/Object;"); |
50858 | 461 |
} |
50609 | 462 |
add(toBeInvestigated, |
54084 | 463 |
"com/sun/crypto/provider/CounterMode.implCrypt([BII[BI)I", |
52956 | 464 |
"java/lang/Thread.onSpinWait()V", |
54084 | 465 |
"java/util/ArraysSupport.vectorizedMismatch(Ljava/lang/Object;JLjava/lang/Object;JII)I", |
48190 | 466 |
"jdk/internal/misc/Unsafe.getCharUnaligned(Ljava/lang/Object;J)C", |
467 |
"jdk/internal/misc/Unsafe.getIntUnaligned(Ljava/lang/Object;J)I", |
|
468 |
"jdk/internal/misc/Unsafe.getLongUnaligned(Ljava/lang/Object;J)J", |
|
469 |
"jdk/internal/misc/Unsafe.getShortUnaligned(Ljava/lang/Object;J)S", |
|
470 |
"jdk/internal/misc/Unsafe.putCharUnaligned(Ljava/lang/Object;JC)V", |
|
471 |
"jdk/internal/misc/Unsafe.putIntUnaligned(Ljava/lang/Object;JI)V", |
|
472 |
"jdk/internal/misc/Unsafe.putLongUnaligned(Ljava/lang/Object;JJ)V", |
|
473 |
"jdk/internal/misc/Unsafe.putShortUnaligned(Ljava/lang/Object;JS)V"); |
|
474 |
} |
|
54084 | 475 |
if (isJDK10OrHigher()) { |
476 |
add(toBeInvestigated, |
|
477 |
"jdk/internal/util/ArraysSupport.vectorizedMismatch(Ljava/lang/Object;JLjava/lang/Object;JII)I"); |
|
478 |
} |
|
48190 | 479 |
} |
480 |
||
481 |
/* |
|
482 |
* The intrinsics down here are known to be implemented but they are not always enabled on |
|
483 |
* the HotSpot side (e.g., because they require certain CPU features). So, we are ignoring |
|
484 |
* them if the HotSpot config tells us that they can't be used. |
|
485 |
*/ |
|
486 |
||
487 |
// CRC32 intrinsics |
|
43972 | 488 |
if (!config.useCRC32Intrinsics) { |
50609 | 489 |
add(ignore, "java/util/zip/CRC32.update(II)I"); |
48190 | 490 |
if (isJDK9OrHigher()) { |
50609 | 491 |
add(ignore, |
48190 | 492 |
"java/util/zip/CRC32.updateByteBuffer0(IJII)I", |
493 |
"java/util/zip/CRC32.updateBytes0(I[BII)I"); |
|
494 |
} else { |
|
50609 | 495 |
add(ignore, |
43972 | 496 |
"java/util/zip/CRC32.updateByteBuffer(IJII)I", |
497 |
"java/util/zip/CRC32.updateBytes(I[BII)I"); |
|
498 |
} |
|
499 |
} |
|
500 |
||
48398 | 501 |
// CRC32C intrinsics |
502 |
if (!config.useCRC32CIntrinsics) { |
|
50609 | 503 |
add(ignore, |
48398 | 504 |
"java/util/zip/CRC32C.updateBytes(I[BII)I", |
505 |
"java/util/zip/CRC32C.updateDirectByteBuffer(IJII)I"); |
|
506 |
} |
|
507 |
||
57537 | 508 |
boolean implNames = HotSpotGraphBuilderPlugins.cbcUsesImplNames(config); |
509 |
String cbcEncryptName = implNames ? "implEncrypt" : "encrypt"; |
|
510 |
String cbcDecryptName = implNames ? "implDecrypt" : "decrypt"; |
|
511 |
||
48190 | 512 |
// AES intrinsics |
43972 | 513 |
if (!config.useAESIntrinsics) { |
57537 | 514 |
add(ignore, |
515 |
"com/sun/crypto/provider/AESCrypt." + aesDecryptName + "([BI[BI)V", |
|
516 |
"com/sun/crypto/provider/AESCrypt." + aesEncryptName + "([BI[BI)V", |
|
517 |
"com/sun/crypto/provider/CipherBlockChaining." + cbcDecryptName + "([BII[BI)I", |
|
518 |
"com/sun/crypto/provider/CipherBlockChaining." + cbcEncryptName + "([BII[BI)I"); |
|
48190 | 519 |
} |
520 |
||
521 |
// BigInteger intrinsics |
|
522 |
if (!config.useMultiplyToLenIntrinsic()) { |
|
523 |
if (isJDK9OrHigher()) { |
|
50609 | 524 |
add(ignore, "java/math/BigInteger.implMultiplyToLen([II[II[I)[I"); |
43972 | 525 |
} else { |
50609 | 526 |
add(ignore, "java/math/BigInteger.multiplyToLen([II[II[I)[I"); |
43972 | 527 |
} |
528 |
} |
|
48190 | 529 |
if (!config.useMulAddIntrinsic()) { |
50609 | 530 |
add(ignore, "java/math/BigInteger.implMulAdd([I[IIII)I"); |
48190 | 531 |
} |
532 |
if (!config.useMontgomeryMultiplyIntrinsic()) { |
|
50609 | 533 |
add(ignore, "java/math/BigInteger.implMontgomeryMultiply([I[I[IIJ[I)[I"); |
48190 | 534 |
} |
535 |
if (!config.useMontgomerySquareIntrinsic()) { |
|
50609 | 536 |
add(ignore, "java/math/BigInteger.implMontgomerySquare([I[IIJ[I)[I"); |
48190 | 537 |
} |
538 |
if (!config.useSquareToLenIntrinsic()) { |
|
50609 | 539 |
add(ignore, "java/math/BigInteger.implSquareToLen([II[II)[I"); |
48190 | 540 |
} |
541 |
||
542 |
// SHA intrinsics |
|
543 |
if (!config.useSHA1Intrinsics()) { |
|
544 |
if (isJDK9OrHigher()) { |
|
50609 | 545 |
add(ignore, "sun/security/provider/SHA.implCompress0([BI)V"); |
43972 | 546 |
} else { |
50609 | 547 |
add(ignore, "sun/security/provider/SHA.implCompress([BI)V"); |
43972 | 548 |
} |
549 |
} |
|
48190 | 550 |
if (!config.useSHA256Intrinsics()) { |
551 |
if (isJDK9OrHigher()) { |
|
50609 | 552 |
add(ignore, "sun/security/provider/SHA2.implCompress0([BI)V"); |
48190 | 553 |
} else { |
50609 | 554 |
add(ignore, "sun/security/provider/SHA2.implCompress([BI)V"); |
48190 | 555 |
} |
556 |
} |
|
557 |
if (!config.useSHA512Intrinsics()) { |
|
558 |
if (isJDK9OrHigher()) { |
|
50609 | 559 |
add(ignore, "sun/security/provider/SHA5.implCompress0([BI)V"); |
48190 | 560 |
} else { |
50609 | 561 |
add(ignore, "sun/security/provider/SHA5.implCompress([BI)V"); |
48190 | 562 |
} |
563 |
} |
|
564 |
} |
|
565 |
||
566 |
private static boolean isJDK9OrHigher() { |
|
55509 | 567 |
return JavaVersionUtil.JAVA_SPEC >= 9; |
43972 | 568 |
} |
569 |
||
48861 | 570 |
private static boolean isJDK10OrHigher() { |
55509 | 571 |
return JavaVersionUtil.JAVA_SPEC >= 10; |
48861 | 572 |
} |
573 |
||
50330 | 574 |
private static boolean isJDK11OrHigher() { |
55509 | 575 |
return JavaVersionUtil.JAVA_SPEC >= 11; |
50330 | 576 |
} |
577 |
||
52578 | 578 |
private static boolean isJDK12OrHigher() { |
55509 | 579 |
return JavaVersionUtil.JAVA_SPEC >= 12; |
52578 | 580 |
} |
581 |
||
53081
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
582 |
private static boolean isJDK13OrHigher() { |
55509 | 583 |
return JavaVersionUtil.JAVA_SPEC >= 13; |
53081
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
584 |
} |
3791fee4df3b
8215687: [Graal] unit test CheckGraalIntrinsics failed after 8212043
kvn
parents:
53000
diff
changeset
|
585 |
|
50609 | 586 |
public interface Refiner { |
587 |
void refine(CheckGraalIntrinsics checker); |
|
43972 | 588 |
} |
589 |
||
590 |
@Test |
|
591 |
@SuppressWarnings("try") |
|
592 |
public void test() throws ClassNotFoundException { |
|
593 |
HotSpotProviders providers = rt.getHostBackend().getProviders(); |
|
594 |
Plugins graphBuilderPlugins = providers.getGraphBuilderPlugins(); |
|
595 |
InvocationPlugins invocationPlugins = graphBuilderPlugins.getInvocationPlugins(); |
|
596 |
||
50609 | 597 |
HotSpotVMConfigStore store = config.getStore(); |
43972 | 598 |
List<VMIntrinsicMethod> intrinsics = store.getIntrinsics(); |
599 |
||
50609 | 600 |
for (Refiner refiner : ServiceLoader.load(Refiner.class)) { |
601 |
refiner.refine(this); |
|
602 |
} |
|
603 |
||
43972 | 604 |
List<String> missing = new ArrayList<>(); |
50609 | 605 |
List<String> mischaracterizedAsToBeInvestigated = new ArrayList<>(); |
606 |
List<String> mischaracterizedAsIgnored = new ArrayList<>(); |
|
46459 | 607 |
EconomicMap<String, List<Binding>> bindings = invocationPlugins.getBindings(true); |
43972 | 608 |
for (VMIntrinsicMethod intrinsic : intrinsics) { |
46459 | 609 |
InvocationPlugin plugin = findPlugin(bindings, intrinsic); |
50609 | 610 |
String m = String.format("%s.%s%s", intrinsic.declaringClass, intrinsic.name, intrinsic.descriptor); |
46459 | 611 |
if (plugin == null) { |
612 |
ResolvedJavaMethod method = resolveIntrinsic(providers.getMetaAccess(), intrinsic); |
|
43972 | 613 |
if (method != null) { |
46459 | 614 |
IntrinsicMethod intrinsicMethod = providers.getConstantReflection().getMethodHandleAccess().lookupMethodHandleIntrinsic(method); |
43972 | 615 |
if (intrinsicMethod != null) { |
616 |
continue; |
|
617 |
} |
|
618 |
} |
|
50609 | 619 |
if (!toBeInvestigated.contains(m) && !ignore.contains(m) && !complexGuard.contains(m) && !downstream.contains(m)) { |
43972 | 620 |
missing.add(m); |
621 |
} |
|
50609 | 622 |
} else { |
623 |
if (toBeInvestigated.contains(m)) { |
|
624 |
mischaracterizedAsToBeInvestigated.add(m); |
|
625 |
} else if (ignore.contains(m)) { |
|
626 |
mischaracterizedAsIgnored.add(m); |
|
627 |
} |
|
43972 | 628 |
} |
629 |
} |
|
630 |
||
50609 | 631 |
Formatter errorMsgBuf = new Formatter(); |
43972 | 632 |
if (!missing.isEmpty()) { |
633 |
Collections.sort(missing); |
|
634 |
String missingString = missing.stream().collect(Collectors.joining(String.format("%n "))); |
|
50609 | 635 |
errorMsgBuf.format("missing Graal intrinsics for:%n %s%n", missingString); |
636 |
} |
|
637 |
if (!mischaracterizedAsToBeInvestigated.isEmpty()) { |
|
638 |
Collections.sort(mischaracterizedAsToBeInvestigated); |
|
639 |
String missingString = mischaracterizedAsToBeInvestigated.stream().collect(Collectors.joining(String.format("%n "))); |
|
640 |
errorMsgBuf.format("found plugins for intrinsics characterized as toBeInvestigated:%n %s%n", missingString); |
|
641 |
} |
|
642 |
if (!mischaracterizedAsIgnored.isEmpty()) { |
|
643 |
Collections.sort(mischaracterizedAsIgnored); |
|
644 |
String missingString = mischaracterizedAsIgnored.stream().collect(Collectors.joining(String.format("%n "))); |
|
645 |
errorMsgBuf.format("found plugins for intrinsics characterized as IGNORED:%n %s%n", missingString); |
|
646 |
} |
|
647 |
String errorMsg = errorMsgBuf.toString(); |
|
648 |
if (!errorMsg.isEmpty()) { |
|
649 |
fail(errorMsg); |
|
43972 | 650 |
} |
651 |
} |
|
652 |
} |