< 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




  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.meta;
  24 
  25 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall;
  26 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  27 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_DREM;
  28 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_FREM;
  29 import static org.graalvm.compiler.hotspot.HotSpotBackend.BACKEDGE_EVENT;
  30 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT;
  31 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK;
  32 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK_WITH_ORIGINAL_KEY;
  33 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_WITH_ORIGINAL_KEY;
  34 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT;
  35 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT_BLOCK;
  36 import static org.graalvm.compiler.hotspot.HotSpotBackend.EXCEPTION_HANDLER;

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


  68 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_CLASS_CAST_EXCEPTION;
  69 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_NULL_POINTER_EXCEPTION;
  70 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_OUT_OF_BOUNDS_EXCEPTION;
  71 import static org.graalvm.compiler.hotspot.replacements.AssertionSnippets.ASSERTION_VM_MESSAGE_C;
  72 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.MARK_WORD_LOCATION;
  73 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_END_LOCATION;
  74 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_TOP_LOCATION;
  75 import static org.graalvm.compiler.hotspot.replacements.MonitorSnippets.MONITORENTER;
  76 import static org.graalvm.compiler.hotspot.replacements.MonitorSnippets.MONITOREXIT;
  77 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.DYNAMIC_NEW_ARRAY;
  78 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.DYNAMIC_NEW_INSTANCE;
  79 import static org.graalvm.compiler.hotspot.replacements.ThreadSubstitutions.THREAD_IS_INTERRUPTED;
  80 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.G1WBPOSTCALL;
  81 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.G1WBPRECALL;
  82 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.VALIDATE_OBJECT;
  83 import static org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub.EXCEPTION_HANDLER_FOR_PC;
  84 import static org.graalvm.compiler.hotspot.stubs.NewArrayStub.NEW_ARRAY_C;
  85 import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.NEW_INSTANCE_C;
  86 import static org.graalvm.compiler.hotspot.stubs.StubUtil.VM_MESSAGE_C;
  87 import static org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub.EXCEPTION_HANDLER_FOR_RETURN_ADDRESS;
  88 import static org.graalvm.compiler.nodes.NamedLocationIdentity.any;
  89 import static org.graalvm.compiler.nodes.java.ForeignCallDescriptors.REGISTER_FINALIZER;
  90 import static org.graalvm.compiler.replacements.Log.LOG_OBJECT;
  91 import static org.graalvm.compiler.replacements.Log.LOG_PRIMITIVE;
  92 import static org.graalvm.compiler.replacements.Log.LOG_PRINTF;
  93 import static org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation.POW;
  94 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.COS;
  95 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.EXP;
  96 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG;
  97 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG10;
  98 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.SIN;
  99 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.TAN;

 100 
 101 import java.util.EnumMap;
 102 
 103 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
 104 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
 105 import org.graalvm.compiler.debug.GraalError;
 106 import org.graalvm.compiler.hotspot.CompilerRuntimeHotSpotVMConfig;
 107 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
 108 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
 109 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
 110 import org.graalvm.compiler.hotspot.stubs.ArrayStoreExceptionStub;
 111 import org.graalvm.compiler.hotspot.stubs.ClassCastExceptionStub;
 112 import org.graalvm.compiler.hotspot.stubs.CreateExceptionStub;
 113 import org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub;
 114 import org.graalvm.compiler.hotspot.stubs.NewArrayStub;
 115 import org.graalvm.compiler.hotspot.stubs.NewInstanceStub;
 116 import org.graalvm.compiler.hotspot.stubs.NullPointerExceptionStub;
 117 import org.graalvm.compiler.hotspot.stubs.OutOfBoundsExceptionStub;
 118 import org.graalvm.compiler.hotspot.stubs.Stub;
 119 import org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub;


 196 
 197     private ForeignCallDescriptor buildDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
 198         assert !killAny || kind == JavaKind.Object;
 199         String name = kind + (aligned ? "Aligned" : "") + (disjoint ? "Disjoint" : "") + (uninit ? "Uninit" : "") + "Arraycopy" + (killAny ? "KillAny" : "");
 200         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, void.class, Word.class, Word.class, Word.class);
 201         LocationIdentity killed = killAny ? LocationIdentity.any() : NamedLocationIdentity.getArrayLocation(kind);
 202         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 203         return desc;
 204     }
 205 
 206     private void registerCheckcastArraycopyDescriptor(boolean uninit, long routine) {
 207         String name = "Object" + (uninit ? "Uninit" : "") + "Checkcast";
 208         // Input:
 209         // c_rarg0 - source array address
 210         // c_rarg1 - destination array address
 211         // c_rarg2 - element count, treated as ssize_t, can be zero
 212         // c_rarg3 - size_t ckoff (super_check_offset)
 213         // c_rarg4 - oop ckval (super_klass)
 214         // return: 0 = success, n = number of copied elements xor'd with -1.
 215         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, int.class, Word.class, Word.class, Word.class, Word.class, Word.class);
 216         LocationIdentity killed = NamedLocationIdentity.getArrayLocation(JavaKind.Object);
 217         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 218         checkcastArraycopyDescriptors[uninit ? 1 : 0] = desc;
 219     }
 220 
 221     private void registerArrayCopy(JavaKind kind, long routine, long alignedRoutine, long disjointRoutine, long alignedDisjointRoutine) {
 222         registerArrayCopy(kind, routine, alignedRoutine, disjointRoutine, alignedDisjointRoutine, false);
 223     }
 224 
 225     private void registerArrayCopy(JavaKind kind, long routine, long alignedRoutine, long disjointRoutine, long alignedDisjointRoutine, boolean uninit) {
 226         /*
 227          * Sometimes the same function is used for multiple cases so share them when that's the case
 228          * but only within the same Kind. For instance short and char are the same copy routines but
 229          * they kill different memory so they still have to be distinct.
 230          */
 231         EconomicMap<Long, ForeignCallDescriptor> descMap = EconomicMap.create();
 232         registerArraycopyDescriptor(descMap, kind, false, false, uninit, false, routine);
 233         registerArraycopyDescriptor(descMap, kind, true, false, uninit, false, alignedRoutine);
 234         registerArraycopyDescriptor(descMap, kind, false, true, uninit, false, disjointRoutine);
 235         registerArraycopyDescriptor(descMap, kind, true, true, uninit, false, alignedDisjointRoutine);
 236 


 316 
 317         // Cannot be a leaf as VM acquires Thread_lock which requires thread_in_vm state
 318         linkForeignCall(options, providers, THREAD_IS_INTERRUPTED, c.threadIsInterruptedAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any());
 319 
 320         linkForeignCall(options, providers, TEST_DEOPTIMIZE_CALL_INT, c.testDeoptimizeCallInt, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
 321 
 322         registerArrayCopy(JavaKind.Byte, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
 323         registerArrayCopy(JavaKind.Boolean, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
 324         registerArrayCopy(JavaKind.Char, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 325         registerArrayCopy(JavaKind.Short, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 326         registerArrayCopy(JavaKind.Int, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 327         registerArrayCopy(JavaKind.Float, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 328         registerArrayCopy(JavaKind.Long, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 329         registerArrayCopy(JavaKind.Double, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 330         registerArrayCopy(JavaKind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy);
 331         registerArrayCopy(JavaKind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true);
 332 
 333         registerCheckcastArraycopyDescriptor(true, c.checkcastArraycopyUninit);
 334         registerCheckcastArraycopyDescriptor(false, c.checkcastArraycopy);
 335 

 336         registerForeignCall(UNSAFE_ARRAYCOPY, c.unsafeArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 337 
 338         if (c.useMultiplyToLenIntrinsic()) {
 339             registerForeignCall(MULTIPLY_TO_LEN, c.multiplyToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 340         }
 341         if (c.useSHA1Intrinsics()) {
 342             registerForeignCall(SHA_IMPL_COMPRESS, c.sha1ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 343         }
 344         if (c.useSHA256Intrinsics()) {
 345             registerForeignCall(SHA2_IMPL_COMPRESS, c.sha256ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 346         }
 347         if (c.useSHA512Intrinsics()) {
 348             registerForeignCall(SHA5_IMPL_COMPRESS, c.sha512ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 349         }
 350         if (c.useMulAddIntrinsic()) {
 351             registerForeignCall(MUL_ADD, c.mulAdd, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 352         }
 353         if (c.useMontgomeryMultiplyIntrinsic()) {
 354             registerForeignCall(MONTGOMERY_MULTIPLY, c.montgomeryMultiply, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 355         }




  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.meta;
  24 
  25 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall;
  26 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  27 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_DREM;
  28 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_FREM;
  29 import static org.graalvm.compiler.hotspot.HotSpotBackend.BACKEDGE_EVENT;
  30 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT;
  31 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK;
  32 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK_WITH_ORIGINAL_KEY;
  33 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_WITH_ORIGINAL_KEY;
  34 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT;
  35 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT_BLOCK;
  36 import static org.graalvm.compiler.hotspot.HotSpotBackend.EXCEPTION_HANDLER;
  37 import static org.graalvm.compiler.hotspot.HotSpotBackend.GENERIC_ARRAYCOPY;
  38 import static org.graalvm.compiler.hotspot.HotSpotBackend.IC_MISS_HANDLER;
  39 import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL;
  40 import static org.graalvm.compiler.hotspot.HotSpotBackend.INVOCATION_EVENT;
  41 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_MULTIPLY;
  42 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_SQUARE;
  43 import static org.graalvm.compiler.hotspot.HotSpotBackend.MULTIPLY_TO_LEN;
  44 import static org.graalvm.compiler.hotspot.HotSpotBackend.MUL_ADD;
  45 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY;
  46 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE;
  47 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY;
  48 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE;
  49 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL;
  50 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS;
  51 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL;
  52 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA2_IMPL_COMPRESS;
  53 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA5_IMPL_COMPRESS;
  54 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA_IMPL_COMPRESS;
  55 import static org.graalvm.compiler.hotspot.HotSpotBackend.SQUARE_TO_LEN;
  56 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNSAFE_ARRAYCOPY;
  57 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNWIND_EXCEPTION_TO_CALLER;


  69 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_CLASS_CAST_EXCEPTION;
  70 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_NULL_POINTER_EXCEPTION;
  71 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_OUT_OF_BOUNDS_EXCEPTION;
  72 import static org.graalvm.compiler.hotspot.replacements.AssertionSnippets.ASSERTION_VM_MESSAGE_C;
  73 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.MARK_WORD_LOCATION;
  74 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_END_LOCATION;
  75 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_TOP_LOCATION;
  76 import static org.graalvm.compiler.hotspot.replacements.MonitorSnippets.MONITORENTER;
  77 import static org.graalvm.compiler.hotspot.replacements.MonitorSnippets.MONITOREXIT;
  78 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.DYNAMIC_NEW_ARRAY;
  79 import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.DYNAMIC_NEW_INSTANCE;
  80 import static org.graalvm.compiler.hotspot.replacements.ThreadSubstitutions.THREAD_IS_INTERRUPTED;
  81 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.G1WBPOSTCALL;
  82 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.G1WBPRECALL;
  83 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.VALIDATE_OBJECT;
  84 import static org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub.EXCEPTION_HANDLER_FOR_PC;
  85 import static org.graalvm.compiler.hotspot.stubs.NewArrayStub.NEW_ARRAY_C;
  86 import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.NEW_INSTANCE_C;
  87 import static org.graalvm.compiler.hotspot.stubs.StubUtil.VM_MESSAGE_C;
  88 import static org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub.EXCEPTION_HANDLER_FOR_RETURN_ADDRESS;

  89 import static org.graalvm.compiler.nodes.java.ForeignCallDescriptors.REGISTER_FINALIZER;
  90 import static org.graalvm.compiler.replacements.Log.LOG_OBJECT;
  91 import static org.graalvm.compiler.replacements.Log.LOG_PRIMITIVE;
  92 import static org.graalvm.compiler.replacements.Log.LOG_PRINTF;
  93 import static org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation.POW;
  94 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.COS;
  95 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.EXP;
  96 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG;
  97 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG10;
  98 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.SIN;
  99 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.TAN;
 100 import static org.graalvm.word.LocationIdentity.any;
 101 
 102 import java.util.EnumMap;
 103 
 104 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
 105 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
 106 import org.graalvm.compiler.debug.GraalError;
 107 import org.graalvm.compiler.hotspot.CompilerRuntimeHotSpotVMConfig;
 108 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
 109 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
 110 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
 111 import org.graalvm.compiler.hotspot.stubs.ArrayStoreExceptionStub;
 112 import org.graalvm.compiler.hotspot.stubs.ClassCastExceptionStub;
 113 import org.graalvm.compiler.hotspot.stubs.CreateExceptionStub;
 114 import org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub;
 115 import org.graalvm.compiler.hotspot.stubs.NewArrayStub;
 116 import org.graalvm.compiler.hotspot.stubs.NewInstanceStub;
 117 import org.graalvm.compiler.hotspot.stubs.NullPointerExceptionStub;
 118 import org.graalvm.compiler.hotspot.stubs.OutOfBoundsExceptionStub;
 119 import org.graalvm.compiler.hotspot.stubs.Stub;
 120 import org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub;


 197 
 198     private ForeignCallDescriptor buildDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) {
 199         assert !killAny || kind == JavaKind.Object;
 200         String name = kind + (aligned ? "Aligned" : "") + (disjoint ? "Disjoint" : "") + (uninit ? "Uninit" : "") + "Arraycopy" + (killAny ? "KillAny" : "");
 201         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, void.class, Word.class, Word.class, Word.class);
 202         LocationIdentity killed = killAny ? LocationIdentity.any() : NamedLocationIdentity.getArrayLocation(kind);
 203         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 204         return desc;
 205     }
 206 
 207     private void registerCheckcastArraycopyDescriptor(boolean uninit, long routine) {
 208         String name = "Object" + (uninit ? "Uninit" : "") + "Checkcast";
 209         // Input:
 210         // c_rarg0 - source array address
 211         // c_rarg1 - destination array address
 212         // c_rarg2 - element count, treated as ssize_t, can be zero
 213         // c_rarg3 - size_t ckoff (super_check_offset)
 214         // c_rarg4 - oop ckval (super_klass)
 215         // return: 0 = success, n = number of copied elements xor'd with -1.
 216         ForeignCallDescriptor desc = new ForeignCallDescriptor(name, int.class, Word.class, Word.class, Word.class, Word.class, Word.class);
 217         LocationIdentity killed = NamedLocationIdentity.any();
 218         registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed);
 219         checkcastArraycopyDescriptors[uninit ? 1 : 0] = desc;
 220     }
 221 
 222     private void registerArrayCopy(JavaKind kind, long routine, long alignedRoutine, long disjointRoutine, long alignedDisjointRoutine) {
 223         registerArrayCopy(kind, routine, alignedRoutine, disjointRoutine, alignedDisjointRoutine, false);
 224     }
 225 
 226     private void registerArrayCopy(JavaKind kind, long routine, long alignedRoutine, long disjointRoutine, long alignedDisjointRoutine, boolean uninit) {
 227         /*
 228          * Sometimes the same function is used for multiple cases so share them when that's the case
 229          * but only within the same Kind. For instance short and char are the same copy routines but
 230          * they kill different memory so they still have to be distinct.
 231          */
 232         EconomicMap<Long, ForeignCallDescriptor> descMap = EconomicMap.create();
 233         registerArraycopyDescriptor(descMap, kind, false, false, uninit, false, routine);
 234         registerArraycopyDescriptor(descMap, kind, true, false, uninit, false, alignedRoutine);
 235         registerArraycopyDescriptor(descMap, kind, false, true, uninit, false, disjointRoutine);
 236         registerArraycopyDescriptor(descMap, kind, true, true, uninit, false, alignedDisjointRoutine);
 237 


 317 
 318         // Cannot be a leaf as VM acquires Thread_lock which requires thread_in_vm state
 319         linkForeignCall(options, providers, THREAD_IS_INTERRUPTED, c.threadIsInterruptedAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any());
 320 
 321         linkForeignCall(options, providers, TEST_DEOPTIMIZE_CALL_INT, c.testDeoptimizeCallInt, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
 322 
 323         registerArrayCopy(JavaKind.Byte, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
 324         registerArrayCopy(JavaKind.Boolean, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
 325         registerArrayCopy(JavaKind.Char, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 326         registerArrayCopy(JavaKind.Short, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
 327         registerArrayCopy(JavaKind.Int, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 328         registerArrayCopy(JavaKind.Float, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
 329         registerArrayCopy(JavaKind.Long, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 330         registerArrayCopy(JavaKind.Double, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
 331         registerArrayCopy(JavaKind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy);
 332         registerArrayCopy(JavaKind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true);
 333 
 334         registerCheckcastArraycopyDescriptor(true, c.checkcastArraycopyUninit);
 335         registerCheckcastArraycopyDescriptor(false, c.checkcastArraycopy);
 336 
 337         registerForeignCall(GENERIC_ARRAYCOPY, c.genericArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 338         registerForeignCall(UNSAFE_ARRAYCOPY, c.unsafeArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 339 
 340         if (c.useMultiplyToLenIntrinsic()) {
 341             registerForeignCall(MULTIPLY_TO_LEN, c.multiplyToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 342         }
 343         if (c.useSHA1Intrinsics()) {
 344             registerForeignCall(SHA_IMPL_COMPRESS, c.sha1ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 345         }
 346         if (c.useSHA256Intrinsics()) {
 347             registerForeignCall(SHA2_IMPL_COMPRESS, c.sha256ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 348         }
 349         if (c.useSHA512Intrinsics()) {
 350             registerForeignCall(SHA5_IMPL_COMPRESS, c.sha512ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
 351         }
 352         if (c.useMulAddIntrinsic()) {
 353             registerForeignCall(MUL_ADD, c.mulAdd, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 354         }
 355         if (c.useMontgomeryMultiplyIntrinsic()) {
 356             registerForeignCall(MONTGOMERY_MULTIPLY, c.montgomeryMultiply, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
 357         }


< prev index next >