< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java

Print this page


   1 /*
   2  * Copyright (c) 2013, 2018, 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.meta;
  26 
  27 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall;
  28 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  29 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_DREM;
  30 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_FREM;
  31 import static org.graalvm.compiler.hotspot.HotSpotBackend.BACKEDGE_EVENT;

  32 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT;
  33 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK;
  34 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK_WITH_ORIGINAL_KEY;
  35 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_WITH_ORIGINAL_KEY;
  36 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT;
  37 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT_BLOCK;
  38 import static org.graalvm.compiler.hotspot.HotSpotBackend.EXCEPTION_HANDLER;

  39 import static org.graalvm.compiler.hotspot.HotSpotBackend.IC_MISS_HANDLER;
  40 import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL;
  41 import static org.graalvm.compiler.hotspot.HotSpotBackend.INVOCATION_EVENT;
  42 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_MULTIPLY;
  43 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_SQUARE;
  44 import static org.graalvm.compiler.hotspot.HotSpotBackend.MULTIPLY_TO_LEN;
  45 import static org.graalvm.compiler.hotspot.HotSpotBackend.MUL_ADD;
  46 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY;
  47 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY_OR_NULL;
  48 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE;
  49 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE_OR_NULL;
  50 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY;
  51 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY_OR_NULL;
  52 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE;
  53 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL;
  54 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS;
  55 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL;
  56 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA2_IMPL_COMPRESS;

  57 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA5_IMPL_COMPRESS;

  58 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA_IMPL_COMPRESS;

  59 import static org.graalvm.compiler.hotspot.HotSpotBackend.SQUARE_TO_LEN;
  60 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNWIND_EXCEPTION_TO_CALLER;

  61 import static org.graalvm.compiler.hotspot.HotSpotBackend.VM_ERROR;
  62 import static org.graalvm.compiler.hotspot.HotSpotBackend.WRONG_METHOD_HANDLER;
  63 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability.NOT_REEXECUTABLE;
  64 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability.REEXECUTABLE;
  65 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability.REEXECUTABLE_ONLY_AFTER_EXCEPTION;
  66 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_REGISTERS;
  67 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.PRESERVES_REGISTERS;
  68 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF;
  69 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF_NOFP;
  70 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.SAFEPOINT;
  71 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.STACK_INSPECTABLE_LEAF;
  72 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.DEOPTIMIZATION_HANDLER;
  73 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.ENABLE_STACK_RESERVED_ZONE;
  74 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.THROW_DELAYED_STACKOVERFLOW_ERROR;
  75 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER;
  76 import static org.graalvm.compiler.hotspot.replacements.AssertionSnippets.ASSERTION_VM_MESSAGE_C;
  77 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.MARK_WORD_LOCATION;
  78 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_END_LOCATION;
  79 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_TOP_LOCATION;
  80 import static org.graalvm.compiler.hotspot.replacements.MonitorSnippets.MONITORENTER;


 152         super(jvmciRuntime, runtime, metaAccess, codeCache, wordTypes);
 153     }
 154 
 155     protected static void link(Stub stub) {
 156         stub.getLinkage().setCompiledStub(stub);
 157     }
 158 
 159     @Override
 160     public ForeignCallDescriptor lookupCheckcastArraycopyDescriptor(boolean uninit) {
 161         return checkcastArraycopyDescriptors[uninit ? 1 : 0];
 162     }
 163 
 164     @Override
 165     public ForeignCallDescriptor lookupArraycopyDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny) {
 166         if (uninit) {
 167             assert kind == JavaKind.Object;
 168             assert !killAny : "unsupported";
 169             return uninitObjectArraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0];
 170         }
 171         if (killAny) {
 172             assert kind == JavaKind.Object;
 173             return objectArraycopyDescriptorsKillAny[aligned ? 1 : 0][disjoint ? 1 : 0];
 174         }
 175         return arraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0].get(kind);
 176     }
 177 
 178     @SuppressWarnings({"unchecked"}) private static final EnumMap<JavaKind, ForeignCallDescriptor>[][] arraycopyDescriptors = (EnumMap<JavaKind, ForeignCallDescriptor>[][]) new EnumMap<?, ?>[2][2];

 179 
 180     private static final ForeignCallDescriptor[][] uninitObjectArraycopyDescriptors = new ForeignCallDescriptor[2][2];
 181     private static final ForeignCallDescriptor[] checkcastArraycopyDescriptors = new ForeignCallDescriptor[2];
 182     private static ForeignCallDescriptor[][] objectArraycopyDescriptorsKillAny = new ForeignCallDescriptor[2][2];
 183 
 184     static {
 185         // Populate the EnumMap instances
 186         for (int i = 0; i < arraycopyDescriptors.length; i++) {
 187             for (int j = 0; j < arraycopyDescriptors[i].length; j++) {
 188                 arraycopyDescriptors[i][j] = new EnumMap<>(JavaKind.class);

 189             }
 190         }
 191     }
 192 
 193     private void registerArraycopyDescriptor(EconomicMap<Long, ForeignCallDescriptor> descMap, JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
 194         ForeignCallDescriptor desc = descMap.get(routine);
 195         if (desc == null) {
 196             desc = buildDescriptor(kind, aligned, disjoint, uninit, killAny, routine);
 197             descMap.put(routine, desc);
 198         }
 199         if (uninit) {
 200             assert kind == JavaKind.Object;
 201             uninitObjectArraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0] = desc;


 202         } else {
 203             arraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0].put(kind, desc);
 204         }
 205     }
 206 
 207     private ForeignCallDescriptor buildDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
 208         assert !killAny || kind == JavaKind.Object;
 209         String name = kind + (aligned ? "Aligned" : "") + (disjoint ? "Disjoint" : "") + (uninit ? "Uninit" : "") + "Arraycopy" + (killAny ? "KillAny" : "");
 210         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, void.class, Word.class, Word.class, Word.class);
 211         LocationIdentity killed = killAny ? LocationIdentity.any() : NamedLocationIdentity.getArrayLocation(kind);
 212         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 213         return desc;
 214     }
 215 
 216     private void registerCheckcastArraycopyDescriptor(boolean uninit, long routine) {
 217         String name = "Object" + (uninit ? "Uninit" : "") + "CheckcastArraycopy";
 218         // Input:
 219         // c_rarg0 - source array address
 220         // c_rarg1 - destination array address
 221         // c_rarg2 - element count, treated as ssize_t, can be zero
 222         // c_rarg3 - size_t ckoff (super_check_offset)
 223         // c_rarg4 - oop ckval (super_klass)
 224         // return: 0 = success, n = number of copied elements xor'd with -1.
 225         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, int.class, Word.class, Word.class, Word.class, Word.class, Word.class);
 226         LocationIdentity killed = NamedLocationIdentity.any();
 227         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 228         checkcastArraycopyDescriptors[uninit ? 1 : 0] = desc;


 236         registerArrayCopy(kind, routine, alignedRoutine, disjointRoutine, alignedDisjointRoutine, false);
 237     }
 238 
 239     private void registerArrayCopy(JavaKind kind,
 240                     long routine,
 241                     long alignedRoutine,
 242                     long disjointRoutine,
 243                     long alignedDisjointRoutine,
 244                     boolean uninit) {
 245         /*
 246          * Sometimes the same function is used for multiple cases so share them when that's the case
 247          * but only within the same Kind. For instance short and char are the same copy routines but
 248          * they kill different memory so they still have to be distinct.
 249          */
 250         EconomicMap<Long, ForeignCallDescriptor> descMap = EconomicMap.create();
 251         registerArraycopyDescriptor(descMap, kind, false, false, uninit, false, routine);
 252         registerArraycopyDescriptor(descMap, kind, true, false, uninit, false, alignedRoutine);
 253         registerArraycopyDescriptor(descMap, kind, false, true, uninit, false, disjointRoutine);
 254         registerArraycopyDescriptor(descMap, kind, true, true, uninit, false, alignedDisjointRoutine);
 255 
 256         if (kind == JavaKind.Object && !uninit) {
 257             objectArraycopyDescriptorsKillAny[0][0] = buildDescriptor(kind, false, false, uninit, true, routine);
 258             objectArraycopyDescriptorsKillAny[1][0] = buildDescriptor(kind, true, false, uninit, true, alignedRoutine);
 259             objectArraycopyDescriptorsKillAny[0][1] = buildDescriptor(kind, false, true, uninit, true, disjointRoutine);
 260             objectArraycopyDescriptorsKillAny[1][1] = buildDescriptor(kind, true, true, uninit, true, alignedDisjointRoutine);

 261         }
 262     }
 263 
 264     public void initialize(HotSpotProviders providers, OptionValues options) {
 265         GraalHotSpotVMConfig c = runtime.getVMConfig();
 266         registerForeignCall(DEOPTIMIZATION_HANDLER, c.handleDeoptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 267         registerForeignCall(UNCOMMON_TRAP_HANDLER, c.uncommonTrapStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 268         registerForeignCall(IC_MISS_HANDLER, c.inlineCacheMissStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 269 
 270         if (c.enableStackReservedZoneAddress != 0) {
 271             assert c.throwDelayedStackOverflowErrorEntry != 0 : "both must exist";
 272             registerForeignCall(ENABLE_STACK_RESERVED_ZONE, c.enableStackReservedZoneAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 273             registerForeignCall(THROW_DELAYED_STACKOVERFLOW_ERROR, c.throwDelayedStackOverflowErrorEntry, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 274         }
 275 
 276         registerForeignCall(JAVA_TIME_MILLIS, c.javaTimeMillisAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 277         registerForeignCall(JAVA_TIME_NANOS, c.javaTimeNanosAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 278         registerForeignCall(SIN.foreignCallDescriptor, c.arithmeticSinAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 279         registerForeignCall(COS.foreignCallDescriptor, c.arithmeticCosAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 280         registerForeignCall(TAN.foreignCallDescriptor, c.arithmeticTanAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 281         registerForeignCall(EXP.foreignCallDescriptor, c.arithmeticExpAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 282         registerForeignCall(LOG.foreignCallDescriptor, c.arithmeticLogAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 283         registerForeignCall(LOG10.foreignCallDescriptor, c.arithmeticLog10Address, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 284         registerForeignCall(POW.foreignCallDescriptor, c.arithmeticPowAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 285         registerForeignCall(ARITHMETIC_FREM, c.fremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 286         registerForeignCall(ARITHMETIC_DREM, c.dremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 287 
 288         registerForeignCall(LOAD_AND_CLEAR_EXCEPTION, c.loadAndClearExceptionAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, any());
 289 
 290         registerForeignCall(EXCEPTION_HANDLER_FOR_PC, c.exceptionHandlerForPcAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
 291         registerForeignCall(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, c.exceptionHandlerForReturnAddressAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
 292 
 293         CreateExceptionStub.registerForeignCalls(c, this);
 294 
 295         /*
 296          * This message call is registered twice, where the second one must only be used for calls
 297          * that do not return, i.e., that exit the VM.
 298          */
 299         registerForeignCall(VM_MESSAGE_C, c.vmMessageAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
 300         registerForeignCall(ASSERTION_VM_MESSAGE_C, c.vmMessageAddress, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 301 
 302         linkForeignCall(options, providers, NEW_INSTANCE, c.newInstanceAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
 303         linkForeignCall(options, providers, NEW_ARRAY, c.newArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
 304         linkForeignCall(options, providers, NEW_MULTI_ARRAY, c.newMultiArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);


 360         registerArrayCopy(JavaKind.Boolean, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
 361         registerArrayCopy(JavaKind.Char, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 362         registerArrayCopy(JavaKind.Short, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 363         registerArrayCopy(JavaKind.Int, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 364         registerArrayCopy(JavaKind.Float, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 365         registerArrayCopy(JavaKind.Long, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 366         registerArrayCopy(JavaKind.Double, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 367         registerArrayCopy(JavaKind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy);
 368         registerArrayCopy(JavaKind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true);
 369 
 370         registerCheckcastArraycopyDescriptor(true, c.checkcastArraycopyUninit);
 371         registerCheckcastArraycopyDescriptor(false, c.checkcastArraycopy);
 372 
 373         registerForeignCall(GENERIC_ARRAYCOPY, c.genericArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 374         registerForeignCall(UNSAFE_ARRAYCOPY, c.unsafeArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 375 
 376         if (c.useMultiplyToLenIntrinsic()) {
 377             registerForeignCall(MULTIPLY_TO_LEN, c.multiplyToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 378                             NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 379         }

 380         if (c.useSHA1Intrinsics()) {
 381             registerForeignCall(SHA_IMPL_COMPRESS, c.sha1ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());

 382         }
 383         if (c.useSHA256Intrinsics()) {
 384             registerForeignCall(SHA2_IMPL_COMPRESS, c.sha256ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());

 385         }
 386         if (c.useSHA512Intrinsics()) {
 387             registerForeignCall(SHA5_IMPL_COMPRESS, c.sha512ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());




 388         }
 389         if (c.useMulAddIntrinsic()) {
 390             registerForeignCall(MUL_ADD, c.mulAdd, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 391         }
 392         if (c.useMontgomeryMultiplyIntrinsic()) {
 393             registerForeignCall(MONTGOMERY_MULTIPLY, c.montgomeryMultiply, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 394                             NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 395         }
 396         if (c.useMontgomerySquareIntrinsic()) {
 397             registerForeignCall(MONTGOMERY_SQUARE, c.montgomerySquare, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 398                             NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 399         }
 400         if (c.useSquareToLenIntrinsic()) {
 401             registerForeignCall(SQUARE_TO_LEN, c.squareToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 402         }
 403 
 404         if (c.useAESIntrinsics) {
 405             /*
 406              * When the java.ext.dirs property is modified then the crypto classes might not be
 407              * found. If that's the case we ignore the ClassNotFoundException and continue since we
 408              * cannot replace a non-existing method anyway.
 409              */
 410             try {
 411                 // These stubs do callee saving
 412                 registerForeignCall(ENCRYPT_BLOCK, c.aescryptEncryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 413                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 414                 registerForeignCall(DECRYPT_BLOCK, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 415                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 416                 registerForeignCall(DECRYPT_BLOCK_WITH_ORIGINAL_KEY, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 417                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 418             } catch (GraalError e) {
 419                 if (!(e.getCause() instanceof ClassNotFoundException)) {
 420                     throw e;
 421                 }
 422             }
 423             try {
 424                 // These stubs do callee saving
 425                 registerForeignCall(ENCRYPT, c.cipherBlockChainingEncryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 426                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 427                 registerForeignCall(DECRYPT, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 428                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 429                 registerForeignCall(DECRYPT_WITH_ORIGINAL_KEY, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 430                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 431             } catch (GraalError e) {
 432                 if (!(e.getCause() instanceof ClassNotFoundException)) {
 433                     throw e;
 434                 }
 435             }
 436         }













 437     }
 438 
 439     public HotSpotForeignCallLinkage getForeignCall(ForeignCallDescriptor descriptor) {
 440         assert foreignCalls != null : descriptor;
 441         return foreignCalls.get(descriptor);











 442     }
 443 }
   1 /*
   2  * Copyright (c) 2013, 2019, 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.meta;
  26 
  27 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall;
  28 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  29 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_DREM;
  30 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_FREM;
  31 import static org.graalvm.compiler.hotspot.HotSpotBackend.BACKEDGE_EVENT;
  32 import static org.graalvm.compiler.hotspot.HotSpotBackend.COUNTERMODE_IMPL_CRYPT;
  33 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT;
  34 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK;
  35 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK_WITH_ORIGINAL_KEY;
  36 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_WITH_ORIGINAL_KEY;
  37 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT;
  38 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT_BLOCK;
  39 import static org.graalvm.compiler.hotspot.HotSpotBackend.EXCEPTION_HANDLER;
  40 import static org.graalvm.compiler.hotspot.HotSpotBackend.GHASH_PROCESS_BLOCKS;
  41 import static org.graalvm.compiler.hotspot.HotSpotBackend.IC_MISS_HANDLER;
  42 import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL;
  43 import static org.graalvm.compiler.hotspot.HotSpotBackend.INVOCATION_EVENT;
  44 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_MULTIPLY;
  45 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_SQUARE;
  46 import static org.graalvm.compiler.hotspot.HotSpotBackend.MULTIPLY_TO_LEN;
  47 import static org.graalvm.compiler.hotspot.HotSpotBackend.MUL_ADD;
  48 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY;
  49 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY_OR_NULL;
  50 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE;
  51 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE_OR_NULL;
  52 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY;
  53 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY_OR_NULL;
  54 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE;
  55 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL;
  56 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS;
  57 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL;
  58 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA2_IMPL_COMPRESS;
  59 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA2_IMPL_COMPRESS_MB;
  60 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA5_IMPL_COMPRESS;
  61 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA5_IMPL_COMPRESS_MB;
  62 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA_IMPL_COMPRESS;
  63 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA_IMPL_COMPRESS_MB;
  64 import static org.graalvm.compiler.hotspot.HotSpotBackend.SQUARE_TO_LEN;
  65 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNWIND_EXCEPTION_TO_CALLER;
  66 import static org.graalvm.compiler.hotspot.HotSpotBackend.VECTORIZED_MISMATCHED;
  67 import static org.graalvm.compiler.hotspot.HotSpotBackend.VM_ERROR;
  68 import static org.graalvm.compiler.hotspot.HotSpotBackend.WRONG_METHOD_HANDLER;
  69 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability.NOT_REEXECUTABLE;
  70 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability.REEXECUTABLE;
  71 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability.REEXECUTABLE_ONLY_AFTER_EXCEPTION;
  72 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_REGISTERS;
  73 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.PRESERVES_REGISTERS;
  74 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF;
  75 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF_NOFP;
  76 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.SAFEPOINT;
  77 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.STACK_INSPECTABLE_LEAF;
  78 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.DEOPTIMIZATION_HANDLER;
  79 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.ENABLE_STACK_RESERVED_ZONE;
  80 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.THROW_DELAYED_STACKOVERFLOW_ERROR;
  81 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER;
  82 import static org.graalvm.compiler.hotspot.replacements.AssertionSnippets.ASSERTION_VM_MESSAGE_C;
  83 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.MARK_WORD_LOCATION;
  84 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_END_LOCATION;
  85 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_TOP_LOCATION;
  86 import static org.graalvm.compiler.hotspot.replacements.MonitorSnippets.MONITORENTER;


 158         super(jvmciRuntime, runtime, metaAccess, codeCache, wordTypes);
 159     }
 160 
 161     protected static void link(Stub stub) {
 162         stub.getLinkage().setCompiledStub(stub);
 163     }
 164 
 165     @Override
 166     public ForeignCallDescriptor lookupCheckcastArraycopyDescriptor(boolean uninit) {
 167         return checkcastArraycopyDescriptors[uninit ? 1 : 0];
 168     }
 169 
 170     @Override
 171     public ForeignCallDescriptor lookupArraycopyDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny) {
 172         if (uninit) {
 173             assert kind == JavaKind.Object;
 174             assert !killAny : "unsupported";
 175             return uninitObjectArraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0];
 176         }
 177         if (killAny) {
 178             return arraycopyDescriptorsKillAny[aligned ? 1 : 0][disjoint ? 1 : 0].get(kind);

 179         }
 180         return arraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0].get(kind);
 181     }
 182 
 183     @SuppressWarnings("unchecked") private static final EnumMap<JavaKind, ForeignCallDescriptor>[][] arraycopyDescriptors = (EnumMap<JavaKind, ForeignCallDescriptor>[][]) new EnumMap<?, ?>[2][2];
 184     @SuppressWarnings("unchecked") private static final EnumMap<JavaKind, ForeignCallDescriptor>[][] arraycopyDescriptorsKillAny = (EnumMap<JavaKind, ForeignCallDescriptor>[][]) new EnumMap<?, ?>[2][2];
 185 
 186     private static final ForeignCallDescriptor[][] uninitObjectArraycopyDescriptors = new ForeignCallDescriptor[2][2];
 187     private static final ForeignCallDescriptor[] checkcastArraycopyDescriptors = new ForeignCallDescriptor[2];

 188 
 189     static {
 190         // Populate the EnumMap instances
 191         for (int i = 0; i < arraycopyDescriptors.length; i++) {
 192             for (int j = 0; j < arraycopyDescriptors[i].length; j++) {
 193                 arraycopyDescriptors[i][j] = new EnumMap<>(JavaKind.class);
 194                 arraycopyDescriptorsKillAny[i][j] = new EnumMap<>(JavaKind.class);
 195             }
 196         }
 197     }
 198 
 199     private void registerArraycopyDescriptor(EconomicMap<Long, ForeignCallDescriptor> descMap, JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
 200         ForeignCallDescriptor desc = descMap.get(routine);
 201         if (desc == null) {
 202             desc = buildDescriptor(kind, aligned, disjoint, uninit, killAny, routine);
 203             descMap.put(routine, desc);
 204         }
 205         if (uninit) {
 206             assert kind == JavaKind.Object;
 207             uninitObjectArraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0] = desc;
 208         } else if (killAny) {
 209             arraycopyDescriptorsKillAny[aligned ? 1 : 0][disjoint ? 1 : 0].put(kind, desc);
 210         } else {
 211             arraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0].put(kind, desc);
 212         }
 213     }
 214 
 215     private ForeignCallDescriptor buildDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
 216         assert !uninit || kind == JavaKind.Object;
 217         String name = kind + (aligned ? "Aligned" : "") + (disjoint ? "Disjoint" : "") + (uninit ? "Uninit" : "") + "Arraycopy" + (killAny ? "KillAny" : "");
 218         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, void.class, Word.class, Word.class, Word.class);
 219         LocationIdentity killed = killAny ? LocationIdentity.any() : NamedLocationIdentity.getArrayLocation(kind);
 220         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 221         return desc;
 222     }
 223 
 224     private void registerCheckcastArraycopyDescriptor(boolean uninit, long routine) {
 225         String name = "Object" + (uninit ? "Uninit" : "") + "CheckcastArraycopy";
 226         // Input:
 227         // c_rarg0 - source array address
 228         // c_rarg1 - destination array address
 229         // c_rarg2 - element count, treated as ssize_t, can be zero
 230         // c_rarg3 - size_t ckoff (super_check_offset)
 231         // c_rarg4 - oop ckval (super_klass)
 232         // return: 0 = success, n = number of copied elements xor'd with -1.
 233         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, int.class, Word.class, Word.class, Word.class, Word.class, Word.class);
 234         LocationIdentity killed = NamedLocationIdentity.any();
 235         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 236         checkcastArraycopyDescriptors[uninit ? 1 : 0] = desc;


 244         registerArrayCopy(kind, routine, alignedRoutine, disjointRoutine, alignedDisjointRoutine, false);
 245     }
 246 
 247     private void registerArrayCopy(JavaKind kind,
 248                     long routine,
 249                     long alignedRoutine,
 250                     long disjointRoutine,
 251                     long alignedDisjointRoutine,
 252                     boolean uninit) {
 253         /*
 254          * Sometimes the same function is used for multiple cases so share them when that's the case
 255          * but only within the same Kind. For instance short and char are the same copy routines but
 256          * they kill different memory so they still have to be distinct.
 257          */
 258         EconomicMap<Long, ForeignCallDescriptor> descMap = EconomicMap.create();
 259         registerArraycopyDescriptor(descMap, kind, false, false, uninit, false, routine);
 260         registerArraycopyDescriptor(descMap, kind, true, false, uninit, false, alignedRoutine);
 261         registerArraycopyDescriptor(descMap, kind, false, true, uninit, false, disjointRoutine);
 262         registerArraycopyDescriptor(descMap, kind, true, true, uninit, false, alignedDisjointRoutine);
 263 
 264         if (!uninit) {
 265             EconomicMap<Long, ForeignCallDescriptor> killAnyDescMap = EconomicMap.create();
 266             registerArraycopyDescriptor(killAnyDescMap, kind, false, false, uninit, true, routine);
 267             registerArraycopyDescriptor(killAnyDescMap, kind, true, false, uninit, true, alignedRoutine);
 268             registerArraycopyDescriptor(killAnyDescMap, kind, false, true, uninit, true, disjointRoutine);
 269             registerArraycopyDescriptor(killAnyDescMap, kind, true, true, uninit, true, alignedDisjointRoutine);
 270         }
 271     }
 272 
 273     public void initialize(HotSpotProviders providers, OptionValues options) {
 274         GraalHotSpotVMConfig c = runtime.getVMConfig();
 275         registerForeignCall(DEOPTIMIZATION_HANDLER, c.handleDeoptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 276         registerForeignCall(UNCOMMON_TRAP_HANDLER, c.uncommonTrapStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 277         registerForeignCall(IC_MISS_HANDLER, c.inlineCacheMissStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 278 
 279         if (c.enableStackReservedZoneAddress != 0) {
 280             assert c.throwDelayedStackOverflowErrorEntry != 0 : "both must exist";
 281             registerForeignCall(ENABLE_STACK_RESERVED_ZONE, c.enableStackReservedZoneAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 282             registerForeignCall(THROW_DELAYED_STACKOVERFLOW_ERROR, c.throwDelayedStackOverflowErrorEntry, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 283         }
 284 
 285         registerForeignCall(JAVA_TIME_MILLIS, c.javaTimeMillisAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 286         registerForeignCall(JAVA_TIME_NANOS, c.javaTimeNanosAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
 287 
 288         registerMathStubs(c, providers, options);
 289 




 290         registerForeignCall(ARITHMETIC_FREM, c.fremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 291         registerForeignCall(ARITHMETIC_DREM, c.dremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 292 
 293         registerForeignCall(LOAD_AND_CLEAR_EXCEPTION, c.loadAndClearExceptionAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, any());
 294 
 295         registerForeignCall(EXCEPTION_HANDLER_FOR_PC, c.exceptionHandlerForPcAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
 296         registerForeignCall(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, c.exceptionHandlerForReturnAddressAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
 297 
 298         CreateExceptionStub.registerForeignCalls(c, this);
 299 
 300         /*
 301          * This message call is registered twice, where the second one must only be used for calls
 302          * that do not return, i.e., that exit the VM.
 303          */
 304         registerForeignCall(VM_MESSAGE_C, c.vmMessageAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
 305         registerForeignCall(ASSERTION_VM_MESSAGE_C, c.vmMessageAddress, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 306 
 307         linkForeignCall(options, providers, NEW_INSTANCE, c.newInstanceAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
 308         linkForeignCall(options, providers, NEW_ARRAY, c.newArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
 309         linkForeignCall(options, providers, NEW_MULTI_ARRAY, c.newMultiArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);


 365         registerArrayCopy(JavaKind.Boolean, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
 366         registerArrayCopy(JavaKind.Char, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 367         registerArrayCopy(JavaKind.Short, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 368         registerArrayCopy(JavaKind.Int, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 369         registerArrayCopy(JavaKind.Float, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 370         registerArrayCopy(JavaKind.Long, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 371         registerArrayCopy(JavaKind.Double, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 372         registerArrayCopy(JavaKind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy);
 373         registerArrayCopy(JavaKind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true);
 374 
 375         registerCheckcastArraycopyDescriptor(true, c.checkcastArraycopyUninit);
 376         registerCheckcastArraycopyDescriptor(false, c.checkcastArraycopy);
 377 
 378         registerForeignCall(GENERIC_ARRAYCOPY, c.genericArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 379         registerForeignCall(UNSAFE_ARRAYCOPY, c.unsafeArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 380 
 381         if (c.useMultiplyToLenIntrinsic()) {
 382             registerForeignCall(MULTIPLY_TO_LEN, c.multiplyToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 383                             NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 384         }
 385 
 386         if (c.useSHA1Intrinsics()) {
 387             registerForeignCall(SHA_IMPL_COMPRESS, c.sha1ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 388             registerForeignCall(SHA_IMPL_COMPRESS_MB, c.sha1ImplCompressMultiBlock, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 389         }
 390         if (c.useSHA256Intrinsics()) {
 391             registerForeignCall(SHA2_IMPL_COMPRESS, c.sha256ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 392             registerForeignCall(SHA2_IMPL_COMPRESS_MB, c.sha256ImplCompressMultiBlock, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 393         }
 394         if (c.useSHA512Intrinsics()) {
 395             registerForeignCall(SHA5_IMPL_COMPRESS, c.sha512ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 396             registerForeignCall(SHA5_IMPL_COMPRESS_MB, c.sha512ImplCompressMultiBlock, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 397         }
 398         if (c.useGHASHIntrinsics()) {
 399             registerForeignCall(GHASH_PROCESS_BLOCKS, c.ghashProcessBlocks, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.any());
 400         }
 401         if (c.useMulAddIntrinsic()) {
 402             registerForeignCall(MUL_ADD, c.mulAdd, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 403         }
 404         if (c.useMontgomeryMultiplyIntrinsic()) {
 405             registerForeignCall(MONTGOMERY_MULTIPLY, c.montgomeryMultiply, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 406                             NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 407         }
 408         if (c.useMontgomerySquareIntrinsic()) {
 409             registerForeignCall(MONTGOMERY_SQUARE, c.montgomerySquare, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 410                             NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 411         }
 412         if (c.useSquareToLenIntrinsic()) {
 413             registerForeignCall(SQUARE_TO_LEN, c.squareToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE_ONLY_AFTER_EXCEPTION, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 414         }
 415 
 416         if (c.useAESIntrinsics) {
 417             /*
 418              * When the java.ext.dirs property is modified then the crypto classes might not be
 419              * found. If that's the case we ignore the ClassNotFoundException and continue since we
 420              * cannot replace a non-existing method anyway.
 421              */
 422             try {
 423                 // These stubs do callee saving
 424                 registerForeignCall(ENCRYPT_BLOCK, c.aescryptEncryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 425                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 426                 registerForeignCall(DECRYPT_BLOCK, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 427                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 428                 registerForeignCall(DECRYPT_BLOCK_WITH_ORIGINAL_KEY, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 429                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 430             } catch (GraalError e) {
 431                 if (!(e.getCause() instanceof ClassNotFoundException)) {
 432                     throw e;
 433                 }
 434             }
 435             try {
 436                 // These stubs do callee saving
 437                 registerForeignCall(ENCRYPT, c.cipherBlockChainingEncryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 438                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 439                 registerForeignCall(DECRYPT, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 440                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 441                 registerForeignCall(DECRYPT_WITH_ORIGINAL_KEY, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 442                                 NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
 443             } catch (GraalError e) {
 444                 if (!(e.getCause() instanceof ClassNotFoundException)) {
 445                     throw e;
 446                 }
 447             }
 448         }
 449 
 450         if (c.useAESCTRIntrinsics) {
 451             assert (c.counterModeAESCrypt != 0L);
 452             registerForeignCall(COUNTERMODE_IMPL_CRYPT, c.counterModeAESCrypt, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 453                             NamedLocationIdentity.any());
 454         }
 455 
 456         if (c.useVectorizedMismatchIntrinsic) {
 457             assert (c.vectorizedMismatch != 0L);
 458             registerForeignCall(VECTORIZED_MISMATCHED, c.vectorizedMismatch, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE_ONLY_AFTER_EXCEPTION,
 459                             NamedLocationIdentity.any());
 460 
 461         }
 462     }
 463 
 464     public HotSpotForeignCallLinkage getForeignCall(ForeignCallDescriptor descriptor) {
 465         assert foreignCalls != null : descriptor;
 466         return foreignCalls.get(descriptor);
 467     }
 468 
 469     @SuppressWarnings("unused")
 470     protected void registerMathStubs(GraalHotSpotVMConfig hotSpotVMConfig, HotSpotProviders providers, OptionValues options) {
 471         registerForeignCall(SIN.foreignCallDescriptor, hotSpotVMConfig.arithmeticSinAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 472         registerForeignCall(COS.foreignCallDescriptor, hotSpotVMConfig.arithmeticCosAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 473         registerForeignCall(TAN.foreignCallDescriptor, hotSpotVMConfig.arithmeticTanAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 474         registerForeignCall(EXP.foreignCallDescriptor, hotSpotVMConfig.arithmeticExpAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 475         registerForeignCall(LOG.foreignCallDescriptor, hotSpotVMConfig.arithmeticLogAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 476         registerForeignCall(LOG10.foreignCallDescriptor, hotSpotVMConfig.arithmeticLog10Address, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 477         registerForeignCall(POW.foreignCallDescriptor, hotSpotVMConfig.arithmeticPowAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
 478     }
 479 }
< prev index next >