1 /* 2 * Copyright (c) 2013, 2016, 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.meta; 24 25 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; 26 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_DREM; 27 import static org.graalvm.compiler.core.target.Backend.ARITHMETIC_FREM; 28 import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL; 29 import static org.graalvm.compiler.hotspot.HotSpotBackend.BACKEDGE_EVENT; 30 import static org.graalvm.compiler.hotspot.HotSpotBackend.INVOCATION_EVENT; 31 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL; 32 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS; 33 import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL; 34 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT; 35 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK; 36 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_BLOCK_WITH_ORIGINAL_KEY; 37 import static org.graalvm.compiler.hotspot.HotSpotBackend.DECRYPT_WITH_ORIGINAL_KEY; 38 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT; 39 import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT_BLOCK; 40 import static org.graalvm.compiler.hotspot.HotSpotBackend.EXCEPTION_HANDLER; 41 import static org.graalvm.compiler.hotspot.HotSpotBackend.FETCH_UNROLL_INFO; 42 import static org.graalvm.compiler.hotspot.HotSpotBackend.IC_MISS_HANDLER; 43 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_MULTIPLY; 44 import static org.graalvm.compiler.hotspot.HotSpotBackend.MONTGOMERY_SQUARE; 45 import static org.graalvm.compiler.hotspot.HotSpotBackend.MULTIPLY_TO_LEN; 46 import static org.graalvm.compiler.hotspot.HotSpotBackend.MUL_ADD; 47 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY; 48 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE; 49 import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY; 50 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA2_IMPL_COMPRESS; 51 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA5_IMPL_COMPRESS; 52 import static org.graalvm.compiler.hotspot.HotSpotBackend.SHA_IMPL_COMPRESS; 53 import static org.graalvm.compiler.hotspot.HotSpotBackend.SQUARE_TO_LEN; 54 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNCOMMON_TRAP; 55 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNPACK_FRAMES; 56 import static org.graalvm.compiler.hotspot.HotSpotBackend.UNWIND_EXCEPTION_TO_CALLER; 57 import static org.graalvm.compiler.hotspot.HotSpotBackend.VM_ERROR; 58 import static org.graalvm.compiler.hotspot.HotSpotBackend.WRONG_METHOD_HANDLER; 59 import static org.graalvm.compiler.hotspot.HotSpotBackend.Options.PreferGraalStubs; 60 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_REGISTERS; 61 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.PRESERVES_REGISTERS; 62 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF; 63 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF_NOFP; 64 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.SAFEPOINT; 65 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.STACK_INSPECTABLE_LEAF; 66 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.DEOPTIMIZATION_HANDLER; 67 import static org.graalvm.compiler.hotspot.HotSpotHostBackend.UNCOMMON_TRAP_HANDLER; 68 import static org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.RuntimeCalls.CREATE_ARRAY_STORE_EXCEPTION; 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.NewObjectSnippets.INIT_LOCATION; 81 import static org.graalvm.compiler.hotspot.replacements.ThreadSubstitutions.THREAD_IS_INTERRUPTED; 82 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.G1WBPOSTCALL; 83 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.G1WBPRECALL; 84 import static org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets.VALIDATE_OBJECT; 85 import static org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub.EXCEPTION_HANDLER_FOR_PC; 86 import static org.graalvm.compiler.hotspot.stubs.NewArrayStub.NEW_ARRAY_C; 87 import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.NEW_INSTANCE_C; 88 import static org.graalvm.compiler.hotspot.stubs.StubUtil.VM_MESSAGE_C; 89 import static org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub.EXCEPTION_HANDLER_FOR_RETURN_ADDRESS; 90 import static org.graalvm.compiler.nodes.NamedLocationIdentity.any; 91 import static org.graalvm.compiler.nodes.java.ForeignCallDescriptors.REGISTER_FINALIZER; 92 import static org.graalvm.compiler.replacements.Log.LOG_OBJECT; 93 import static org.graalvm.compiler.replacements.Log.LOG_PRIMITIVE; 94 import static org.graalvm.compiler.replacements.Log.LOG_PRINTF; 95 import static org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation.POW; 96 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.COS; 97 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.EXP; 98 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG; 99 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG10; 100 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.SIN; 101 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.TAN; 102 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall; 103 104 import java.util.EnumMap; 105 import java.util.HashMap; 106 import java.util.Map; 107 108 import org.graalvm.compiler.core.common.LocationIdentity; 109 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; 110 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; 111 import org.graalvm.compiler.debug.GraalError; 112 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 113 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; 114 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; 115 import org.graalvm.compiler.hotspot.CompilerRuntimeHotSpotVMConfig; 116 import org.graalvm.compiler.hotspot.stubs.ArrayStoreExceptionStub; 117 import org.graalvm.compiler.hotspot.stubs.ClassCastExceptionStub; 118 import org.graalvm.compiler.hotspot.stubs.CreateExceptionStub; 119 import org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub; 120 import org.graalvm.compiler.hotspot.stubs.NewArrayStub; 121 import org.graalvm.compiler.hotspot.stubs.NewInstanceStub; 122 import org.graalvm.compiler.hotspot.stubs.NullPointerExceptionStub; 123 import org.graalvm.compiler.hotspot.stubs.OutOfBoundsExceptionStub; 124 import org.graalvm.compiler.hotspot.stubs.Stub; 125 import org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub; 126 import org.graalvm.compiler.hotspot.stubs.VerifyOopStub; 127 import org.graalvm.compiler.nodes.NamedLocationIdentity; 128 import org.graalvm.compiler.word.Word; 129 import org.graalvm.compiler.word.WordTypes; 130 131 import jdk.vm.ci.code.CodeCacheProvider; 132 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; 133 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider; 134 import jdk.vm.ci.meta.JavaKind; 135 import jdk.vm.ci.meta.MetaAccessProvider; 136 137 /** 138 * HotSpot implementation of {@link ForeignCallsProvider}. 139 */ 140 public abstract class HotSpotHostForeignCallsProvider extends HotSpotForeignCallsProviderImpl { 141 142 public static final ForeignCallDescriptor JAVA_TIME_MILLIS = new ForeignCallDescriptor("javaTimeMillis", long.class); 143 public static final ForeignCallDescriptor JAVA_TIME_NANOS = new ForeignCallDescriptor("javaTimeNanos", long.class); 144 145 public HotSpotHostForeignCallsProvider(HotSpotJVMCIRuntimeProvider jvmciRuntime, HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache, 146 WordTypes wordTypes) { 147 super(jvmciRuntime, runtime, metaAccess, codeCache, wordTypes); 148 } 149 150 protected static void link(Stub stub) { 151 stub.getLinkage().setCompiledStub(stub); 152 } 153 154 public static ForeignCallDescriptor lookupCheckcastArraycopyDescriptor(boolean uninit) { 155 return checkcastArraycopyDescriptors[uninit ? 1 : 0]; 156 } 157 158 public static ForeignCallDescriptor lookupArraycopyDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny) { 159 if (uninit) { 160 assert kind == JavaKind.Object; 161 assert !killAny : "unsupported"; 162 return uninitObjectArraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0]; 163 } 164 if (killAny) { 165 assert kind == JavaKind.Object; 166 return objectArraycopyDescriptorsKillAny[aligned ? 1 : 0][disjoint ? 1 : 0]; 167 } 168 return arraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0].get(kind); 169 } 170 171 @SuppressWarnings({"unchecked"}) private static final EnumMap<JavaKind, ForeignCallDescriptor>[][] arraycopyDescriptors = (EnumMap<JavaKind, ForeignCallDescriptor>[][]) new EnumMap<?, ?>[2][2]; 172 173 private static final ForeignCallDescriptor[][] uninitObjectArraycopyDescriptors = new ForeignCallDescriptor[2][2]; 174 private static final ForeignCallDescriptor[] checkcastArraycopyDescriptors = new ForeignCallDescriptor[2]; 175 private static ForeignCallDescriptor[][] objectArraycopyDescriptorsKillAny = new ForeignCallDescriptor[2][2]; 176 177 static { 178 // Populate the EnumMap instances 179 for (int i = 0; i < arraycopyDescriptors.length; i++) { 180 for (int j = 0; j < arraycopyDescriptors[i].length; j++) { 181 arraycopyDescriptors[i][j] = new EnumMap<>(JavaKind.class); 182 } 183 } 184 } 185 186 private void registerArraycopyDescriptor(Map<Long, ForeignCallDescriptor> descMap, JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) { 187 ForeignCallDescriptor desc = descMap.get(routine); 188 if (desc == null) { 189 desc = buildDescriptor(kind, aligned, disjoint, uninit, killAny, routine); 190 descMap.put(routine, desc); 191 } 192 if (uninit) { 193 assert kind == JavaKind.Object; 194 uninitObjectArraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0] = desc; 195 } else { 196 arraycopyDescriptors[aligned ? 1 : 0][disjoint ? 1 : 0].put(kind, desc); 197 } 198 } 199 200 private ForeignCallDescriptor buildDescriptor(JavaKind kind, boolean aligned, boolean disjoint, boolean uninit, boolean killAny, long routine) { 201 assert !killAny || kind == JavaKind.Object; 202 String name = kind + (aligned ? "Aligned" : "") + (disjoint ? "Disjoint" : "") + (uninit ? "Uninit" : "") + "Arraycopy" + (killAny ? "KillAny" : ""); 203 ForeignCallDescriptor desc = new ForeignCallDescriptor(name, void.class, Word.class, Word.class, Word.class); 204 LocationIdentity killed = killAny ? LocationIdentity.any() : NamedLocationIdentity.getArrayLocation(kind); 205 registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed); 206 return desc; 207 } 208 209 private void registerCheckcastArraycopyDescriptor(boolean uninit, long routine) { 210 String name = "Object" + (uninit ? "Uninit" : "") + "Checkcast"; 211 // Input: 212 // c_rarg0 - source array address 213 // c_rarg1 - destination array address 214 // c_rarg2 - element count, treated as ssize_t, can be zero 215 // c_rarg3 - size_t ckoff (super_check_offset) 216 // c_rarg4 - oop ckval (super_klass) 217 // return: 0 = success, n = number of copied elements xor'd with -1. 218 ForeignCallDescriptor desc = new ForeignCallDescriptor(name, int.class, Word.class, Word.class, Word.class, Word.class, Word.class); 219 LocationIdentity killed = NamedLocationIdentity.getArrayLocation(JavaKind.Object); 220 registerForeignCall(desc, routine, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, killed); 221 checkcastArraycopyDescriptors[uninit ? 1 : 0] = desc; 222 } 223 224 private void registerArrayCopy(JavaKind kind, long routine, long alignedRoutine, long disjointRoutine, long alignedDisjointRoutine) { 225 registerArrayCopy(kind, routine, alignedRoutine, disjointRoutine, alignedDisjointRoutine, false); 226 } 227 228 private void registerArrayCopy(JavaKind kind, long routine, long alignedRoutine, long disjointRoutine, long alignedDisjointRoutine, boolean uninit) { 229 /* 230 * Sometimes the same function is used for multiple cases so share them when that's the case 231 * but only within the same Kind. For instance short and char are the same copy routines but 232 * they kill different memory so they still have to be distinct. 233 */ 234 Map<Long, ForeignCallDescriptor> descMap = new HashMap<>(); 235 registerArraycopyDescriptor(descMap, kind, false, false, uninit, false, routine); 236 registerArraycopyDescriptor(descMap, kind, true, false, uninit, false, alignedRoutine); 237 registerArraycopyDescriptor(descMap, kind, false, true, uninit, false, disjointRoutine); 238 registerArraycopyDescriptor(descMap, kind, true, true, uninit, false, alignedDisjointRoutine); 239 240 if (kind == JavaKind.Object && !uninit) { 241 objectArraycopyDescriptorsKillAny[0][0] = buildDescriptor(kind, false, false, uninit, true, routine); 242 objectArraycopyDescriptorsKillAny[1][0] = buildDescriptor(kind, true, false, uninit, true, alignedRoutine); 243 objectArraycopyDescriptorsKillAny[0][1] = buildDescriptor(kind, false, true, uninit, true, disjointRoutine); 244 objectArraycopyDescriptorsKillAny[1][1] = buildDescriptor(kind, true, true, uninit, true, alignedDisjointRoutine); 245 } 246 } 247 248 public void initialize(HotSpotProviders providers) { 249 GraalHotSpotVMConfig c = runtime.getVMConfig(); 250 if (!PreferGraalStubs.getValue()) { 251 registerForeignCall(DEOPTIMIZATION_HANDLER, c.handleDeoptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 252 registerForeignCall(UNCOMMON_TRAP_HANDLER, c.uncommonTrapStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 253 } 254 registerForeignCall(IC_MISS_HANDLER, c.inlineCacheMissStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 255 256 registerForeignCall(JAVA_TIME_MILLIS, c.javaTimeMillisAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 257 registerForeignCall(JAVA_TIME_NANOS, c.javaTimeNanosAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 258 registerForeignCall(SIN.foreignCallDescriptor, c.arithmeticSinAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 259 registerForeignCall(COS.foreignCallDescriptor, c.arithmeticCosAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 260 registerForeignCall(TAN.foreignCallDescriptor, c.arithmeticTanAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 261 registerForeignCall(EXP.foreignCallDescriptor, c.arithmeticExpAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 262 registerForeignCall(LOG.foreignCallDescriptor, c.arithmeticLogAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 263 registerForeignCall(LOG10.foreignCallDescriptor, c.arithmeticLog10Address, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 264 registerForeignCall(POW.foreignCallDescriptor, c.arithmeticPowAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 265 registerForeignCall(ARITHMETIC_FREM, c.fremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 266 registerForeignCall(ARITHMETIC_DREM, c.dremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 267 268 registerForeignCall(LOAD_AND_CLEAR_EXCEPTION, c.loadAndClearExceptionAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, any()); 269 270 registerForeignCall(EXCEPTION_HANDLER_FOR_PC, c.exceptionHandlerForPcAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any()); 271 registerForeignCall(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, c.exceptionHandlerForReturnAddressAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any()); 272 registerForeignCall(FETCH_UNROLL_INFO, c.deoptimizationFetchUnrollInfo, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any()); 273 registerForeignCall(NEW_ARRAY_C, c.newArrayAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any()); 274 registerForeignCall(NEW_INSTANCE_C, c.newInstanceAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any()); 275 registerForeignCall(UNCOMMON_TRAP, c.deoptimizationUncommonTrap, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, NOT_REEXECUTABLE, any()); 276 277 /* 278 * We cannot use LEAF_SP here because on some architectures we have to align the stack 279 * manually before calling into the VM. See {@link 280 * AMD64HotSpotEnterUnpackFramesStackFrameOp#emitCode}. 281 */ 282 registerForeignCall(UNPACK_FRAMES, c.deoptimizationUnpackFrames, NativeCall, DESTROYS_REGISTERS, LEAF, NOT_REEXECUTABLE, any()); 283 284 CreateExceptionStub.registerForeignCalls(c, this); 285 286 /* 287 * This message call is registered twice, where the second one must only be used for calls 288 * that do not return, i.e., that exit the VM. 289 */ 290 registerForeignCall(VM_MESSAGE_C, c.vmMessageAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS); 291 registerForeignCall(ASSERTION_VM_MESSAGE_C, c.vmMessageAddress, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS); 292 293 link(new NewInstanceStub(providers, registerStubCall(NEW_INSTANCE, REEXECUTABLE, SAFEPOINT, INIT_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION))); 294 link(new NewArrayStub(providers, registerStubCall(NEW_ARRAY, REEXECUTABLE, SAFEPOINT, INIT_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION))); 295 link(new ExceptionHandlerStub(providers, foreignCalls.get(EXCEPTION_HANDLER))); 296 link(new UnwindExceptionToCallerStub(providers, registerStubCall(UNWIND_EXCEPTION_TO_CALLER, NOT_REEXECUTABLE, SAFEPOINT, any()))); 297 link(new VerifyOopStub(providers, registerStubCall(VERIFY_OOP, REEXECUTABLE, LEAF_NOFP, NO_LOCATIONS))); 298 link(new ArrayStoreExceptionStub(providers, registerStubCall(CREATE_ARRAY_STORE_EXCEPTION, REEXECUTABLE, SAFEPOINT, any()))); 299 link(new ClassCastExceptionStub(providers, registerStubCall(CREATE_CLASS_CAST_EXCEPTION, REEXECUTABLE, SAFEPOINT, any()))); 300 link(new NullPointerExceptionStub(providers, registerStubCall(CREATE_NULL_POINTER_EXCEPTION, REEXECUTABLE, SAFEPOINT, any()))); 301 link(new OutOfBoundsExceptionStub(providers, registerStubCall(CREATE_OUT_OF_BOUNDS_EXCEPTION, REEXECUTABLE, SAFEPOINT, any()))); 302 303 linkForeignCall(providers, IDENTITY_HASHCODE, c.identityHashCodeAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, MARK_WORD_LOCATION); 304 linkForeignCall(providers, REGISTER_FINALIZER, c.registerFinalizerAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any()); 305 linkForeignCall(providers, MONITORENTER, c.monitorenterAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any()); 306 linkForeignCall(providers, MONITOREXIT, c.monitorexitAddress, PREPEND_THREAD, STACK_INSPECTABLE_LEAF, NOT_REEXECUTABLE, any()); 307 linkForeignCall(providers, NEW_MULTI_ARRAY, c.newMultiArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, INIT_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION); 308 linkForeignCall(providers, DYNAMIC_NEW_ARRAY, c.dynamicNewArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, INIT_LOCATION); 309 linkForeignCall(providers, DYNAMIC_NEW_INSTANCE, c.dynamicNewInstanceAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, INIT_LOCATION); 310 linkForeignCall(providers, LOG_PRINTF, c.logPrintfAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS); 311 linkForeignCall(providers, LOG_OBJECT, c.logObjectAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS); 312 linkForeignCall(providers, LOG_PRIMITIVE, c.logPrimitiveAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS); 313 linkForeignCall(providers, VM_ERROR, c.vmErrorAddress, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 314 linkForeignCall(providers, OSR_MIGRATION_END, c.osrMigrationEndAddress, DONT_PREPEND_THREAD, LEAF_NOFP, NOT_REEXECUTABLE, NO_LOCATIONS); 315 linkForeignCall(providers, G1WBPRECALL, c.writeBarrierPreAddress, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 316 linkForeignCall(providers, G1WBPOSTCALL, c.writeBarrierPostAddress, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 317 linkForeignCall(providers, VALIDATE_OBJECT, c.validateObject, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 318 319 if (GeneratePIC.getValue()) { 320 registerForeignCall(WRONG_METHOD_HANDLER, c.handleWrongMethodStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS); 321 CompilerRuntimeHotSpotVMConfig cr = new CompilerRuntimeHotSpotVMConfig(HotSpotJVMCIRuntime.runtime().getConfigStore()); 322 linkForeignCall(providers, RESOLVE_STRING_BY_SYMBOL, cr.resolveStringBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, INIT_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION); 323 linkForeignCall(providers, RESOLVE_KLASS_BY_SYMBOL, cr.resolveKlassBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any()); 324 linkForeignCall(providers, RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, cr.resolveMethodBySymbolAndLoadCounters, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS); 325 linkForeignCall(providers, INITIALIZE_KLASS_BY_SYMBOL, cr.initializeKlassBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any()); 326 linkForeignCall(providers, INVOCATION_EVENT, cr.invocationEvent, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS); 327 linkForeignCall(providers, BACKEDGE_EVENT, cr.backedgeEvent, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS); 328 } 329 330 // Cannot be a leaf as VM acquires Thread_lock which requires thread_in_vm state 331 linkForeignCall(providers, THREAD_IS_INTERRUPTED, c.threadIsInterruptedAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any()); 332 333 linkForeignCall(providers, TEST_DEOPTIMIZE_CALL_INT, c.testDeoptimizeCallInt, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any()); 334 335 registerArrayCopy(JavaKind.Byte, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy); 336 registerArrayCopy(JavaKind.Boolean, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy); 337 registerArrayCopy(JavaKind.Char, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy); 338 registerArrayCopy(JavaKind.Short, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy); 339 registerArrayCopy(JavaKind.Int, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy); 340 registerArrayCopy(JavaKind.Float, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy); 341 registerArrayCopy(JavaKind.Long, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy); 342 registerArrayCopy(JavaKind.Double, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy); 343 registerArrayCopy(JavaKind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy); 344 registerArrayCopy(JavaKind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true); 345 346 registerCheckcastArraycopyDescriptor(true, c.checkcastArraycopyUninit); 347 registerCheckcastArraycopyDescriptor(false, c.checkcastArraycopy); 348 349 if (c.useMultiplyToLenIntrinsic()) { 350 registerForeignCall(MULTIPLY_TO_LEN, c.multiplyToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int)); 351 } 352 if (c.useSHA1Intrinsics()) { 353 registerForeignCall(SHA_IMPL_COMPRESS, c.sha1ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any()); 354 } 355 if (c.useSHA256Intrinsics()) { 356 registerForeignCall(SHA2_IMPL_COMPRESS, c.sha256ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any()); 357 } 358 if (c.useSHA512Intrinsics()) { 359 registerForeignCall(SHA5_IMPL_COMPRESS, c.sha512ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any()); 360 } 361 if (c.useMulAddIntrinsic()) { 362 registerForeignCall(MUL_ADD, c.mulAdd, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int)); 363 } 364 if (c.useMontgomeryMultiplyIntrinsic()) { 365 registerForeignCall(MONTGOMERY_MULTIPLY, c.montgomeryMultiply, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int)); 366 } 367 if (c.useMontgomerySquareIntrinsic()) { 368 registerForeignCall(MONTGOMERY_SQUARE, c.montgomerySquare, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int)); 369 } 370 if (c.useSquareToLenIntrinsic()) { 371 registerForeignCall(SQUARE_TO_LEN, c.squareToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int)); 372 } 373 374 if (c.useAESIntrinsics) { 375 /* 376 * When the java.ext.dirs property is modified then the crypto classes might not be 377 * found. If that's the case we ignore the ClassNotFoundException and continue since we 378 * cannot replace a non-existing method anyway. 379 */ 380 try { 381 // These stubs do callee saving 382 registerForeignCall(ENCRYPT_BLOCK, c.aescryptEncryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte)); 383 registerForeignCall(DECRYPT_BLOCK, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte)); 384 registerForeignCall(DECRYPT_BLOCK_WITH_ORIGINAL_KEY, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, 385 NamedLocationIdentity.getArrayLocation(JavaKind.Byte)); 386 } catch (GraalError e) { 387 if (!(e.getCause() instanceof ClassNotFoundException)) { 388 throw e; 389 } 390 } 391 try { 392 // These stubs do callee saving 393 registerForeignCall(ENCRYPT, c.cipherBlockChainingEncryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, 394 NamedLocationIdentity.getArrayLocation(JavaKind.Byte)); 395 registerForeignCall(DECRYPT, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, 396 NamedLocationIdentity.getArrayLocation(JavaKind.Byte)); 397 registerForeignCall(DECRYPT_WITH_ORIGINAL_KEY, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, 398 NamedLocationIdentity.getArrayLocation(JavaKind.Byte)); 399 } catch (GraalError e) { 400 if (!(e.getCause() instanceof ClassNotFoundException)) { 401 throw e; 402 } 403 } 404 } 405 } 406 407 public HotSpotForeignCallLinkage getForeignCall(ForeignCallDescriptor descriptor) { 408 assert foreignCalls != null : descriptor; 409 return foreignCalls.get(descriptor); 410 } 411 }