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