1 /*
   2  * Copyright (c) 2014, 2017, 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 package org.graalvm.compiler.hotspot.test;
  24 
  25 import static org.graalvm.compiler.core.common.util.Util.JAVA_SPECIFICATION_VERSION;
  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.HashMap;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 import java.util.TreeSet;
  37 import java.util.stream.Collectors;
  38 
  39 import org.junit.Test;
  40 
  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;
  48 import org.graalvm.compiler.runtime.RuntimeProvider;
  49 import org.graalvm.compiler.test.GraalTest;
  50 
  51 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
  52 import jdk.vm.ci.hotspot.VMIntrinsicMethod;
  53 import jdk.vm.ci.meta.MetaAccessProvider;
  54 import jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod;
  55 import jdk.vm.ci.meta.ResolvedJavaMethod;
  56 
  57 /**
  58  * Checks the set of intrinsics implemented by Graal against the set of intrinsics declared by
  59  * HotSpot. The purpose of this test is to detect when new intrinsics are added to HotSpot and
  60  * process them appropriately in Graal. This will be achieved by working through
  61  * {@link #TO_BE_INVESTIGATED} and either implementing the intrinsic or moving it to {@link #IGNORE}
  62  * .
  63  */
  64 public class CheckGraalIntrinsics extends GraalTest {
  65 
  66     public static boolean match(ResolvedJavaMethod method, VMIntrinsicMethod intrinsic) {
  67         if (intrinsic.name.equals(method.getName())) {
  68             if (intrinsic.descriptor.equals(method.getSignature().toMethodDescriptor())) {
  69                 String declaringClass = method.getDeclaringClass().toClassName().replace('.', '/');
  70                 if (declaringClass.equals(intrinsic.declaringClass)) {
  71                     return true;
  72                 }
  73             }
  74         }
  75         return false;
  76     }
  77 
  78     private static ResolvedJavaMethod findMethod(Set<ResolvedJavaMethod> methods, VMIntrinsicMethod intrinsic) {
  79         for (ResolvedJavaMethod method : methods) {
  80             if (match(method, intrinsic)) {
  81                 return method;
  82             }
  83         }
  84         return null;
  85     }
  86 
  87     private static ResolvedJavaMethod resolveIntrinsic(MetaAccessProvider metaAccess, VMIntrinsicMethod intrinsic) throws ClassNotFoundException {
  88         Class<?> c = Class.forName(intrinsic.declaringClass.replace('/', '.'), false, CheckGraalIntrinsics.class.getClassLoader());
  89         for (Method javaMethod : c.getDeclaredMethods()) {
  90             if (javaMethod.getName().equals(intrinsic.name)) {
  91                 ResolvedJavaMethod method = metaAccess.lookupJavaMethod(javaMethod);
  92                 if (intrinsic.descriptor.equals("*")) {
  93                     // Signature polymorphic method - name match is enough
  94                     return method;
  95                 } else {
  96                     if (method.getSignature().toMethodDescriptor().equals(intrinsic.descriptor)) {
  97                         return method;
  98                     }
  99                 }
 100             }
 101         }
 102         return null;
 103     }
 104 
 105     /**
 106      * The HotSpot intrinsics implemented without {@link InvocationPlugin}s or whose
 107      * {@link InvocationPlugin} registration is guarded by a condition that is false in the current
 108      * VM context.
 109      */
 110     private static final Set<String> IGNORE = new TreeSet<>();
 111 
 112     /**
 113      * The HotSpot intrinsics yet to be implemented or moved to {@link #IGNORE}.
 114      */
 115     private static final Set<String> TO_BE_INVESTIGATED = new TreeSet<>();
 116 
 117     private static Collection<String> add(Collection<String> c, String... elements) {
 118         String[] sorted = elements.clone();
 119         Arrays.sort(sorted);
 120         for (int i = 0; i < elements.length; i++) {
 121             if (!elements[i].equals(sorted[i])) {
 122                 // Let's keep the list sorted for easier visual inspection
 123                 fail("Element %d is out of order, \"%s\"", i, elements[i]);
 124             }
 125         }
 126         c.addAll(Arrays.asList(elements));
 127         return c;
 128     }
 129 
 130     static {
 131         add(IGNORE,
 132                         // dead
 133                         "java/lang/Math.atan2(DD)D",
 134                         // Used during stack walking
 135                         "java/lang/Throwable.fillInStackTrace()Ljava/lang/Throwable;",
 136                         // Marker intrinsic id
 137                         "java/lang/invoke/MethodHandle.<compiledLambdaForm>*",
 138                         // Marker intrinsic id
 139                         "java/lang/invoke/MethodHandle.invoke*",
 140                         // Implemented through lowering
 141                         "java/lang/ref/Reference.get()Ljava/lang/Object;",
 142                         // Used during stack walk
 143                         "java/lang/reflect/Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;",
 144                         // Only used by C1
 145                         "java/nio/Buffer.checkIndex(I)I",
 146                         // dead
 147                         "sun/misc/Unsafe.park(ZJ)V",
 148                         // dead
 149                         "sun/misc/Unsafe.prefetchRead(Ljava/lang/Object;J)V",
 150                         // dead
 151                         "sun/misc/Unsafe.prefetchReadStatic(Ljava/lang/Object;J)V",
 152                         // dead
 153                         "sun/misc/Unsafe.prefetchWrite(Ljava/lang/Object;J)V",
 154                         // dead
 155                         "sun/misc/Unsafe.prefetchWriteStatic(Ljava/lang/Object;J)V",
 156                         // dead
 157                         "sun/misc/Unsafe.unpark(Ljava/lang/Object;)V");
 158 
 159         add(TO_BE_INVESTIGATED,
 160                         // JDK 8
 161                         "java/lang/Double.doubleToLongBits(D)J",
 162                         "java/lang/Float.floatToIntBits(F)I",
 163                         "java/lang/Integer.toString(I)Ljava/lang/String;",
 164                         "java/lang/Math.decrementExact(I)I",
 165                         "java/lang/Math.decrementExact(J)J",
 166                         "java/lang/Math.incrementExact(I)I",
 167                         "java/lang/Math.incrementExact(J)J",
 168                         "java/lang/Math.max(II)I",
 169                         "java/lang/Math.min(II)I",
 170                         "java/lang/Math.negateExact(I)I",
 171                         "java/lang/Math.negateExact(J)J",
 172                         "java/lang/String.<init>(Ljava/lang/String;)V",
 173                         "java/lang/String.compareTo(Ljava/lang/String;)I",
 174                         "java/lang/String.indexOf(Ljava/lang/String;)I",
 175                         "java/lang/StringBuffer.<init>()V",
 176                         "java/lang/StringBuffer.<init>(I)V",
 177                         "java/lang/StringBuffer.<init>(Ljava/lang/String;)V",
 178                         "java/lang/StringBuffer.append(C)Ljava/lang/StringBuffer;",
 179                         "java/lang/StringBuffer.append(I)Ljava/lang/StringBuffer;",
 180                         "java/lang/StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;",
 181                         "java/lang/StringBuffer.toString()Ljava/lang/String;",
 182                         "java/lang/StringBuilder.<init>()V",
 183                         "java/lang/StringBuilder.<init>(I)V",
 184                         "java/lang/StringBuilder.<init>(Ljava/lang/String;)V",
 185                         "java/lang/StringBuilder.append(C)Ljava/lang/StringBuilder;",
 186                         "java/lang/StringBuilder.append(I)Ljava/lang/StringBuilder;",
 187                         "java/lang/StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;",
 188                         "java/lang/StringBuilder.toString()Ljava/lang/String;",
 189                         "java/lang/reflect/Array.newArray(Ljava/lang/Class;I)Ljava/lang/Object;",
 190                         "java/util/Arrays.copyOf([Ljava/lang/Object;ILjava/lang/Class;)[Ljava/lang/Object;",
 191                         "java/util/Arrays.copyOfRange([Ljava/lang/Object;IILjava/lang/Class;)[Ljava/lang/Object;",
 192                         "oracle/jrockit/jfr/Timing.counterTime()J",
 193                         "oracle/jrockit/jfr/VMJFR.classID0(Ljava/lang/Class;)J",
 194                         "oracle/jrockit/jfr/VMJFR.threadID()I",
 195                         "sun/misc/Unsafe.copyMemory(Ljava/lang/Object;JLjava/lang/Object;JJ)V",
 196                         "sun/nio/cs/ISO_8859_1$Encoder.encodeISOArray([CI[BII)I",
 197                         "sun/security/provider/DigestBase.implCompressMultiBlock([BII)I",
 198                         "sun/security/provider/SHA.implCompress([BI)V",
 199                         "sun/security/provider/SHA2.implCompress([BI)V",
 200                         "sun/security/provider/SHA5.implCompress([BI)V");
 201 
 202         add(TO_BE_INVESTIGATED,
 203                         // JDK 9
 204                         "com/sun/crypto/provider/CounterMode.implCrypt([BII[BI)I",
 205                         "com/sun/crypto/provider/GHASH.processBlocks([BII[J[J)V",
 206                         "java/lang/Math.fma(DDD)D",
 207                         "java/lang/Math.fma(FFF)F",
 208                         "java/lang/Object.notify()V",
 209                         "java/lang/Object.notifyAll()V",
 210                         "java/lang/StringCoding.hasNegatives([BII)Z",
 211                         "java/lang/StringCoding.implEncodeISOArray([BI[BII)I",
 212                         "java/lang/StringLatin1.compareTo([B[B)I",
 213                         "java/lang/StringLatin1.compareToUTF16([B[B)I",
 214                         "java/lang/StringLatin1.equals([B[B)Z",
 215                         "java/lang/StringLatin1.indexOf([BI[BII)I",
 216                         "java/lang/StringLatin1.indexOf([B[B)I",
 217                         "java/lang/StringLatin1.inflate([BI[BII)V",
 218                         "java/lang/StringLatin1.inflate([BI[CII)V",
 219                         "java/lang/StringUTF16.compareTo([B[B)I",
 220                         "java/lang/StringUTF16.compareToLatin1([B[B)I",
 221                         "java/lang/StringUTF16.compress([BI[BII)I",
 222                         "java/lang/StringUTF16.compress([CI[BII)I",
 223                         "java/lang/StringUTF16.equals([B[B)Z",
 224                         "java/lang/StringUTF16.getChar([BI)C",
 225                         "java/lang/StringUTF16.getChars([BII[CI)V",
 226                         "java/lang/StringUTF16.indexOf([BI[BII)I",
 227                         "java/lang/StringUTF16.indexOf([B[B)I",
 228                         "java/lang/StringUTF16.indexOfChar([BIII)I",
 229                         "java/lang/StringUTF16.indexOfLatin1([BI[BII)I",
 230                         "java/lang/StringUTF16.indexOfLatin1([B[B)I",
 231                         "java/lang/StringUTF16.putChar([BII)V",
 232                         "java/lang/StringUTF16.toBytes([CII)[B",
 233                         "java/lang/Thread.onSpinWait()V",
 234                         "java/lang/invoke/MethodHandleImpl.isCompileConstant(Ljava/lang/Object;)Z",
 235                         "java/math/BigInteger.implMontgomeryMultiply([I[I[IIJ[I)[I",
 236                         "java/math/BigInteger.implMontgomerySquare([I[IIJ[I)[I",
 237                         "java/math/BigInteger.implMulAdd([I[IIII)I",
 238                         "java/math/BigInteger.implSquareToLen([II[II)[I",
 239                         "java/util/ArraysSupport.vectorizedMismatch(Ljava/lang/Object;JLjava/lang/Object;JII)I",
 240                         "java/util/stream/Streams$RangeIntSpliterator.forEachRemaining(Ljava/util/function/IntConsumer;)V",
 241                         "java/util/zip/Adler32.updateByteBuffer(IJII)I",
 242                         "java/util/zip/Adler32.updateBytes(I[BII)I",
 243                         "jdk/internal/misc/Unsafe.allocateUninitializedArray0(Ljava/lang/Class;I)Ljava/lang/Object;",
 244                         "jdk/internal/misc/Unsafe.compareAndExchangeByteAcquire(Ljava/lang/Object;JBB)B",
 245                         "jdk/internal/misc/Unsafe.compareAndExchangeByteRelease(Ljava/lang/Object;JBB)B",
 246                         "jdk/internal/misc/Unsafe.compareAndExchangeByte(Ljava/lang/Object;JBB)B",
 247                         "jdk/internal/misc/Unsafe.compareAndExchangeIntAcquire(Ljava/lang/Object;JII)I",
 248                         "jdk/internal/misc/Unsafe.compareAndExchangeIntRelease(Ljava/lang/Object;JII)I",
 249                         "jdk/internal/misc/Unsafe.compareAndExchangeInt(Ljava/lang/Object;JII)I",
 250                         "jdk/internal/misc/Unsafe.compareAndExchangeLongAcquire(Ljava/lang/Object;JJJ)J",
 251                         "jdk/internal/misc/Unsafe.compareAndExchangeLongRelease(Ljava/lang/Object;JJJ)J",
 252                         "jdk/internal/misc/Unsafe.compareAndExchangeLong(Ljava/lang/Object;JJJ)J",
 253                         "jdk/internal/misc/Unsafe.compareAndExchangeObjectAcquire(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
 254                         "jdk/internal/misc/Unsafe.compareAndExchangeObjectRelease(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
 255                         "jdk/internal/misc/Unsafe.compareAndExchangeObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
 256                         "jdk/internal/misc/Unsafe.compareAndExchangeShortAcquire(Ljava/lang/Object;JSS)S",
 257                         "jdk/internal/misc/Unsafe.compareAndExchangeShortRelease(Ljava/lang/Object;JSS)S",
 258                         "jdk/internal/misc/Unsafe.compareAndExchangeShort(Ljava/lang/Object;JSS)S",
 259                         "jdk/internal/misc/Unsafe.compareAndSetByte(Ljava/lang/Object;JBB)Z",
 260                         "jdk/internal/misc/Unsafe.compareAndSetShort(Ljava/lang/Object;JSS)Z",
 261                         "jdk/internal/misc/Unsafe.copyMemory0(Ljava/lang/Object;JLjava/lang/Object;JJ)V",
 262                         "jdk/internal/misc/Unsafe.getAndAddByte(Ljava/lang/Object;JB)B",
 263                         "jdk/internal/misc/Unsafe.getAndAddShort(Ljava/lang/Object;JS)S",
 264                         "jdk/internal/misc/Unsafe.getAndSetByte(Ljava/lang/Object;JB)B",
 265                         "jdk/internal/misc/Unsafe.getAndSetShort(Ljava/lang/Object;JS)S",
 266                         "jdk/internal/misc/Unsafe.getBooleanAcquire(Ljava/lang/Object;J)Z",
 267                         "jdk/internal/misc/Unsafe.getBooleanOpaque(Ljava/lang/Object;J)Z",
 268                         "jdk/internal/misc/Unsafe.getByteAcquire(Ljava/lang/Object;J)B",
 269                         "jdk/internal/misc/Unsafe.getByteOpaque(Ljava/lang/Object;J)B",
 270                         "jdk/internal/misc/Unsafe.getCharAcquire(Ljava/lang/Object;J)C",
 271                         "jdk/internal/misc/Unsafe.getCharOpaque(Ljava/lang/Object;J)C",
 272                         "jdk/internal/misc/Unsafe.getDoubleAcquire(Ljava/lang/Object;J)D",
 273                         "jdk/internal/misc/Unsafe.getDoubleOpaque(Ljava/lang/Object;J)D",
 274                         "jdk/internal/misc/Unsafe.getFloatAcquire(Ljava/lang/Object;J)F",
 275                         "jdk/internal/misc/Unsafe.getFloatOpaque(Ljava/lang/Object;J)F",
 276                         "jdk/internal/misc/Unsafe.getIntAcquire(Ljava/lang/Object;J)I",
 277                         "jdk/internal/misc/Unsafe.getIntOpaque(Ljava/lang/Object;J)I",
 278                         "jdk/internal/misc/Unsafe.getLongAcquire(Ljava/lang/Object;J)J",
 279                         "jdk/internal/misc/Unsafe.getLongOpaque(Ljava/lang/Object;J)J",
 280                         "jdk/internal/misc/Unsafe.getObjectAcquire(Ljava/lang/Object;J)Ljava/lang/Object;",
 281                         "jdk/internal/misc/Unsafe.getObjectOpaque(Ljava/lang/Object;J)Ljava/lang/Object;",
 282                         "jdk/internal/misc/Unsafe.getShortAcquire(Ljava/lang/Object;J)S",
 283                         "jdk/internal/misc/Unsafe.getShortOpaque(Ljava/lang/Object;J)S",
 284                         "jdk/internal/misc/Unsafe.park(ZJ)V",
 285                         "jdk/internal/misc/Unsafe.putBooleanOpaque(Ljava/lang/Object;JZ)V",
 286                         "jdk/internal/misc/Unsafe.putByteOpaque(Ljava/lang/Object;JB)V",
 287                         "jdk/internal/misc/Unsafe.putCharOpaque(Ljava/lang/Object;JC)V",
 288                         "jdk/internal/misc/Unsafe.putDoubleOpaque(Ljava/lang/Object;JD)V",
 289                         "jdk/internal/misc/Unsafe.putFloatOpaque(Ljava/lang/Object;JF)V",
 290                         "jdk/internal/misc/Unsafe.putIntOpaque(Ljava/lang/Object;JI)V",
 291                         "jdk/internal/misc/Unsafe.putLongOpaque(Ljava/lang/Object;JJ)V",
 292                         "jdk/internal/misc/Unsafe.putObjectOpaque(Ljava/lang/Object;JLjava/lang/Object;)V",
 293                         "jdk/internal/misc/Unsafe.putShortOpaque(Ljava/lang/Object;JS)V",
 294                         "jdk/internal/misc/Unsafe.unpark(Ljava/lang/Object;)V",
 295                         "jdk/internal/misc/Unsafe.weakCompareAndSetBytePlain(Ljava/lang/Object;JBB)Z",
 296                         "jdk/internal/misc/Unsafe.weakCompareAndSetByteAcquire(Ljava/lang/Object;JBB)Z",
 297                         "jdk/internal/misc/Unsafe.weakCompareAndSetByteRelease(Ljava/lang/Object;JBB)Z",
 298                         "jdk/internal/misc/Unsafe.weakCompareAndSetByte(Ljava/lang/Object;JBB)Z",
 299                         "jdk/internal/misc/Unsafe.weakCompareAndSetIntPlain(Ljava/lang/Object;JII)Z",
 300                         "jdk/internal/misc/Unsafe.weakCompareAndSetIntAcquire(Ljava/lang/Object;JII)Z",
 301                         "jdk/internal/misc/Unsafe.weakCompareAndSetIntRelease(Ljava/lang/Object;JII)Z",
 302                         "jdk/internal/misc/Unsafe.weakCompareAndSetInt(Ljava/lang/Object;JII)Z",
 303                         "jdk/internal/misc/Unsafe.weakCompareAndSetLongPlain(Ljava/lang/Object;JJJ)Z",
 304                         "jdk/internal/misc/Unsafe.weakCompareAndSetLongAcquire(Ljava/lang/Object;JJJ)Z",
 305                         "jdk/internal/misc/Unsafe.weakCompareAndSetLongRelease(Ljava/lang/Object;JJJ)Z",
 306                         "jdk/internal/misc/Unsafe.weakCompareAndSetLong(Ljava/lang/Object;JJJ)Z",
 307                         "jdk/internal/misc/Unsafe.weakCompareAndSetObjectPlain(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z",
 308                         "jdk/internal/misc/Unsafe.weakCompareAndSetObjectAcquire(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z",
 309                         "jdk/internal/misc/Unsafe.weakCompareAndSetObjectRelease(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z",
 310                         "jdk/internal/misc/Unsafe.weakCompareAndSetObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z",
 311                         "jdk/internal/misc/Unsafe.weakCompareAndSetShortPlain(Ljava/lang/Object;JSS)Z",
 312                         "jdk/internal/misc/Unsafe.weakCompareAndSetShortAcquire(Ljava/lang/Object;JSS)Z",
 313                         "jdk/internal/misc/Unsafe.weakCompareAndSetShortRelease(Ljava/lang/Object;JSS)Z",
 314                         "jdk/internal/misc/Unsafe.weakCompareAndSetShort(Ljava/lang/Object;JSS)Z",
 315                         "jdk/internal/util/Preconditions.checkIndex(IILjava/util/function/BiFunction;)I",
 316                         "jdk/jfr/internal/JVM.counterTime()J",
 317                         "jdk/jfr/internal/JVM.getBufferWriter()Ljava/lang/Object;",
 318                         "jdk/jfr/internal/JVM.getClassId(Ljava/lang/Class;)J",
 319                         "sun/nio/cs/ISO_8859_1$Encoder.implEncodeISOArray([CI[BII)I",
 320                         "sun/security/provider/DigestBase.implCompressMultiBlock0([BII)I",
 321                         "sun/security/provider/SHA.implCompress0([BI)V",
 322                         "sun/security/provider/SHA2.implCompress0([BI)V",
 323                         "sun/security/provider/SHA5.implCompress0([BI)V");
 324 
 325         if (!getHostArchitectureName().equals("amd64")) {
 326             add(TO_BE_INVESTIGATED,
 327                             // Can we implement these on non-AMD64 platforms? C2 seems to.
 328                             "sun/misc/Unsafe.getAndAddInt(Ljava/lang/Object;JI)I",
 329                             "sun/misc/Unsafe.getAndAddLong(Ljava/lang/Object;JJ)J",
 330                             "sun/misc/Unsafe.getAndSetInt(Ljava/lang/Object;JI)I",
 331                             "sun/misc/Unsafe.getAndSetLong(Ljava/lang/Object;JJ)J",
 332                             "sun/misc/Unsafe.getAndSetObject(Ljava/lang/Object;JLjava/lang/Object;)Ljava/lang/Object;");
 333             // JDK 9
 334             add(TO_BE_INVESTIGATED,
 335                             "jdk/internal/misc/Unsafe.getAndAddInt(Ljava/lang/Object;JI)I",
 336                             "jdk/internal/misc/Unsafe.getAndAddLong(Ljava/lang/Object;JJ)J",
 337                             "jdk/internal/misc/Unsafe.getAndSetInt(Ljava/lang/Object;JI)I",
 338                             "jdk/internal/misc/Unsafe.getAndSetLong(Ljava/lang/Object;JJ)J",
 339                             "jdk/internal/misc/Unsafe.getAndSetObject(Ljava/lang/Object;JLjava/lang/Object;)Ljava/lang/Object;",
 340                             "jdk/internal/misc/Unsafe.getCharUnaligned(Ljava/lang/Object;J)C",
 341                             "jdk/internal/misc/Unsafe.getIntUnaligned(Ljava/lang/Object;J)I",
 342                             "jdk/internal/misc/Unsafe.getLongUnaligned(Ljava/lang/Object;J)J",
 343                             "jdk/internal/misc/Unsafe.getShortUnaligned(Ljava/lang/Object;J)S",
 344                             "jdk/internal/misc/Unsafe.putCharUnaligned(Ljava/lang/Object;JC)V",
 345                             "jdk/internal/misc/Unsafe.putIntUnaligned(Ljava/lang/Object;JI)V",
 346                             "jdk/internal/misc/Unsafe.putLongUnaligned(Ljava/lang/Object;JJ)V",
 347                             "jdk/internal/misc/Unsafe.putShortUnaligned(Ljava/lang/Object;JS)V");
 348         }
 349 
 350         HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
 351         GraalHotSpotVMConfig config = rt.getVMConfig();
 352 
 353         /*
 354          * These are known to be implemented but the platform dependent conditions for when they are
 355          * enabled are complex so just ignore them all the time.
 356          */
 357         add(IGNORE,
 358                         "java/lang/Integer.bitCount(I)I",
 359                         "java/lang/Integer.numberOfLeadingZeros(I)I",
 360                         "java/lang/Integer.numberOfTrailingZeros(I)I",
 361                         "java/lang/Long.bitCount(J)I",
 362                         "java/lang/Long.numberOfLeadingZeros(J)I",
 363                         "java/lang/Long.numberOfTrailingZeros(J)I");
 364 
 365         if (!config.useCRC32Intrinsics) {
 366             // Registration of the CRC32 plugins is guarded by UseCRC32Intrinsics
 367             add(IGNORE, "java/util/zip/CRC32.update(II)I");
 368             if (JAVA_SPECIFICATION_VERSION < 9) {
 369                 add(IGNORE,
 370                                 "java/util/zip/CRC32.updateByteBuffer(IJII)I",
 371                                 "java/util/zip/CRC32.updateBytes(I[BII)I");
 372             } else {
 373                 add(IGNORE,
 374                                 "java/util/zip/CRC32.updateByteBuffer0(IJII)I",
 375                                 "java/util/zip/CRC32.updateBytes0(I[BII)I",
 376                                 "java/util/zip/CRC32C.updateBytes(I[BII)I",
 377                                 "java/util/zip/CRC32C.updateDirectByteBuffer(IJII)I");
 378             }
 379         } else {
 380             if (JAVA_SPECIFICATION_VERSION >= 9) {
 381                 add(TO_BE_INVESTIGATED,
 382                                 "java/util/zip/CRC32C.updateBytes(I[BII)I",
 383                                 "java/util/zip/CRC32C.updateDirectByteBuffer(IJII)I");
 384             }
 385         }
 386 
 387         if (!config.useAESIntrinsics) {
 388             // Registration of the AES plugins is guarded by UseAESIntrinsics
 389             if (JAVA_SPECIFICATION_VERSION < 9) {
 390                 add(IGNORE,
 391                                 "com/sun/crypto/provider/AESCrypt.decryptBlock([BI[BI)V",
 392                                 "com/sun/crypto/provider/AESCrypt.encryptBlock([BI[BI)V",
 393                                 "com/sun/crypto/provider/CipherBlockChaining.decrypt([BII[BI)I",
 394                                 "com/sun/crypto/provider/CipherBlockChaining.encrypt([BII[BI)I");
 395             } else {
 396                 add(IGNORE,
 397                                 "com/sun/crypto/provider/AESCrypt.implDecryptBlock([BI[BI)V",
 398                                 "com/sun/crypto/provider/AESCrypt.implEncryptBlock([BI[BI)V",
 399                                 "com/sun/crypto/provider/CipherBlockChaining.implDecrypt([BII[BI)I",
 400                                 "com/sun/crypto/provider/CipherBlockChaining.implEncrypt([BII[BI)I");
 401             }
 402         }
 403         if (!config.useMultiplyToLenIntrinsic()) {
 404             // Registration of the AES plugins is guarded by UseAESIntrinsics
 405             if (JAVA_SPECIFICATION_VERSION < 9) {
 406                 add(IGNORE, "java/math/BigInteger.multiplyToLen([II[II[I)[I");
 407             } else {
 408                 add(IGNORE, "java/math/BigInteger.implMultiplyToLen([II[II[I)[I");
 409             }
 410         }
 411     }
 412 
 413     private static String getHostArchitectureName() {
 414         String arch = System.getProperty("os.arch");
 415         if (arch.equals("x86_64")) {
 416             arch = "amd64";
 417         } else if (arch.equals("sparcv9")) {
 418             arch = "sparc";
 419         }
 420         return arch;
 421     }
 422 
 423     @Test
 424     @SuppressWarnings("try")
 425     public void test() throws ClassNotFoundException {
 426         HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
 427         HotSpotProviders providers = rt.getHostBackend().getProviders();
 428         Map<ResolvedJavaMethod, Object> impl = new HashMap<>();
 429         Plugins graphBuilderPlugins = providers.getGraphBuilderPlugins();
 430         InvocationPlugins invocationPlugins = graphBuilderPlugins.getInvocationPlugins();
 431         for (ResolvedJavaMethod method : invocationPlugins.getMethods()) {
 432             InvocationPlugin plugin = invocationPlugins.lookupInvocation(method);
 433             assert plugin != null;
 434             impl.put(method, plugin);
 435         }
 436 
 437         Set<ResolvedJavaMethod> methods = invocationPlugins.getMethods();
 438         HotSpotVMConfigStore store = rt.getVMConfig().getStore();
 439         List<VMIntrinsicMethod> intrinsics = store.getIntrinsics();
 440 
 441         List<String> missing = new ArrayList<>();
 442         for (VMIntrinsicMethod intrinsic : intrinsics) {
 443             ResolvedJavaMethod method = findMethod(methods, intrinsic);
 444             if (method == null) {
 445                 method = resolveIntrinsic(providers.getMetaAccess(), intrinsic);
 446 
 447                 IntrinsicMethod intrinsicMethod = null;
 448                 if (method != null) {
 449                     intrinsicMethod = providers.getConstantReflection().getMethodHandleAccess().lookupMethodHandleIntrinsic(method);
 450                     if (intrinsicMethod != null) {
 451                         continue;
 452                     }
 453                 }
 454                 String m = String.format("%s.%s%s", intrinsic.declaringClass, intrinsic.name, intrinsic.descriptor);
 455                 if (!TO_BE_INVESTIGATED.contains(m) && !IGNORE.contains(m)) {
 456                     missing.add(m);
 457                 }
 458             }
 459         }
 460 
 461         if (!missing.isEmpty()) {
 462             Collections.sort(missing);
 463             String missingString = missing.stream().collect(Collectors.joining(String.format("%n    ")));
 464             fail("missing Graal intrinsics for:%n    %s", missingString);
 465         }
 466     }
 467 }