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