@CEntryPoint @CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static NativeTruffleContext getTruffleContext(NativeTruffleEnv env) { return env.context(); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnNullWord.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static CShortPointer GetStringChars(JNIEnvironment env, JNIObjectHandle hstr, CCharPointer isCopy) { return Support.pinStringAndGetChars(hstr, isCopy); }
@CEntryPoint @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static JNIObjectRefType GetObjectRefType(JNIEnvironment env, JNIObjectHandle handle) { try { return JNIObjectHandles.getHandleType(handle); } catch (Throwable t) { return JNIObjectRefType.Invalid; } }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerVoid.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static void ExceptionClear(JNIEnvironment env) { JNIThreadLocalPendingException.clear(); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerVoid.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static void Throw(JNIEnvironment env, JNIObjectHandle handle) throws Throwable { throw (Throwable) JNIObjectHandles.getObject(handle); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnMinusOne.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static long GetDirectBufferCapacity(JNIEnvironment env, JNIObjectHandle hbuf) { Buffer buffer = JNIObjectHandles.getObject(hbuf); return buffer.capacity(); }
@CEntryPoint @CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static void releaseObjectRef(@SuppressWarnings("unused") NativeTruffleEnv env, TruffleObjectHandle handle) { ImageSingletons.lookup(TruffleNFISupport.class).destroyGlobalHandle(handle); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerVoid.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static void DeleteLocalRef(JNIEnvironment env, JNIObjectHandle localRef) { JNIThreadLocalHandles.get().delete(localRef); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnNullHandle.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static JNIObjectHandle NewString(JNIEnvironment env, CShortPointer unicode, int len) { String str; char[] chars = new char[len]; for (int i = 0; i < chars.length; i++) { int value = Short.toUnsignedInt(unicode.read(i)); chars[i] = (char) value; } str = new String(chars); return JNIThreadLocalHandles.get().create(str); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnJniErr.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static int PushLocalFrame(JNIEnvironment env, int capacity) { if (capacity < 0) { return JNIErrors.JNI_ERR(); } JNIThreadLocalHandles.get().pushFrame(capacity); return 0; }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnNullHandle.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static JNIObjectHandle GetObjectArrayElement(JNIEnvironment env, JNIObjectHandle harray, int index) { Object[] array = JNIObjectHandles.getObject(harray); Object value = array[index]; return JNIThreadLocalHandles.get().create(value); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnJniErr.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static int EnsureLocalCapacity(JNIEnvironment env, int capacity) { if (capacity < 0) { return JNIErrors.JNI_ERR(); } JNIThreadLocalHandles.get().ensureCapacity(capacity); return 0; }
@CEntryPoint @CEntryPointOptions(prologue = PthreadStartRoutinePrologue.class, epilogue = LeaveDetachThreadEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static WordBase pthreadStartRoutine(ThreadStartData data) { ObjectHandle threadHandle = data.getThreadHandle(); UnmanagedMemory.free(data); threadStartRoutine(threadHandle); return WordFactory.nullPointer(); }
@CEntryPoint @CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static void newClosureRef(NativeTruffleEnv env, PointerBase closure) { Target_com_oracle_truffle_nfi_impl_NFIContext context = lookupContext(env.context()); context.newClosureRef(closure.rawValue()); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnNullHandle.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static JNIObjectHandle AllocObject(JNIEnvironment env, JNIObjectHandle classHandle) { Class<?> clazz = JNIObjectHandles.getObject(classHandle); Object instance; try { instance = UnsafeAccess.UNSAFE.allocateInstance(clazz); } catch (InstantiationException e) { instance = null; } return JNIThreadLocalHandles.get().create(instance); }
@CEntryPoint @CEntryPointOptions(prologue = AttachCurrentThreadPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static NativeTruffleEnv attachCurrentThread(NativeTruffleContext context) { TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class); Target_com_oracle_truffle_nfi_impl_NFIContext ctx = support.resolveContextHandle(context.contextHandle()); return WordFactory.pointer(ctx.getNativeEnv()); }
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnNullWord.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static WordPointer GetPrimitiveArrayCritical(JNIEnvironment env, JNIObjectHandle harray, CIntPointer isCopy) { Object array = JNIObjectHandles.getObject(harray); if (array == null) { return WordFactory.nullPointer(); } if (isCopy.isNonNull()) { isCopy.write((byte) 0); } return JNIThreadLocalPinnedObjects.pinArrayAndGetAddress(array); }
@CEntryPoint @CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static TruffleObjectHandle getClosureObject(NativeTruffleEnv env, PointerBase closure) { TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class); Target_com_oracle_truffle_nfi_impl_NFIContext context = lookupContext(env.context()); TruffleObject ret = context.getClosureObject(closure.rawValue()); return support.createGlobalHandle(ret); }
@CEntryPoint @CEntryPointOptions(prologue = JNIJavaVMEnterAttachThreadPrologue.class, epilogue = LeaveDetachThreadEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static int DetachCurrentThread(JNIJavaVM vm) { int result = JNIErrors.JNI_OK(); if (!vm.equal(JNIFunctionTables.singleton().getGlobalJavaVM())) { result = JNIErrors.JNI_ERR(); } // JNI specification requires releasing all owned monitors Support.releaseCurrentThreadOwnedMonitors(); return result; }
@CEntryPoint @CEntryPointOptions(prologue = EnterClosureDataIsolatePrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static void invokeClosureVoidRet(@SuppressWarnings("unused") ffi_cif cif, @SuppressWarnings("unused") WordPointer ret, WordPointer args, ClosureData user) { CIntPointer errnoMirror = ErrnoMirror.getErrnoMirrorLocation(); errnoMirror.write(Errno.errno()); try { lookup(user).call(args, null); } finally { Errno.set_errno(errnoMirror.read()); } }