Search in sources :

Example 16 with Pointer

use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.

the class JniEnv method GetStringChars.

/**
 * <h3>const jchar * GetStringChars(JNIEnv *env, jstring string, jboolean *isCopy);</h3>
 * <p>
 * Returns a pointer to the array of Unicode characters of the string. This pointer is valid
 * until ReleaseStringChars() is called.
 * <p>
 * If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to
 * JNI_FALSE if no copy is made.
 *
 * @param string a Java string object.
 * @param isCopyPtr a pointer to a boolean. Returns a pointer to a Unicode string, or NULL if
 *            the operation fails.
 */
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetStringChars(@JavaType(String.class) StaticObject string, @Pointer TruffleObject isCopyPtr) {
    if (!getUncached().isNull(isCopyPtr)) {
        ByteBuffer isCopyBuf = NativeUtils.directByteBuffer(isCopyPtr, 1);
        // always copy since pinning is not supported
        isCopyBuf.put((byte) 1);
    }
    char[] chars;
    if (getJavaVersion().compactStringsEnabled()) {
        StaticObject wrappedChars = (StaticObject) getMeta().java_lang_String_toCharArray.invokeDirect(string);
        chars = wrappedChars.unwrap();
    } else {
        chars = getMeta().java_lang_String_value.getObject(string).unwrap();
    }
    // Add one for zero termination.
    ByteBuffer bb = allocateDirect(chars.length + 1, JavaKind.Char);
    CharBuffer region = bb.asCharBuffer();
    region.put(chars);
    region.put((char) 0);
    return NativeUtils.byteBufferPointer(bb);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) CharBuffer(java.nio.CharBuffer) ByteBuffer(java.nio.ByteBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 17 with Pointer

use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.

the class JniEnv method GetFloatArrayElements.

@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetFloatArrayElements(@JavaType(float[].class) StaticObject array, @Pointer TruffleObject isCopyPtr) {
    if (!getUncached().isNull(isCopyPtr)) {
        ByteBuffer isCopyBuf = NativeUtils.directByteBuffer(isCopyPtr, 1);
        // Always copy since pinning is not supported.
        isCopyBuf.put((byte) 1);
    }
    float[] data = array.unwrap();
    ByteBuffer bytes = allocateDirect(data.length, JavaKind.Float);
    FloatBuffer elements = bytes.asFloatBuffer();
    elements.put(data);
    return NativeUtils.byteBufferPointer(bytes);
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 18 with Pointer

use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.

the class NFINativeAccess method createNativeClosure.

@Override
@Pointer
public TruffleObject createNativeClosure(TruffleObject executable, NativeSignature nativeSignature) {
    assert uncachedInterop.isExecutable(executable);
    TruffleObject wrappedExecutable = new JavaToNativeWrapper(executable, nativeSignature);
    TruffleObject nativeFn = (TruffleObject) uncachedSignature.createClosure(getOrCreateNFISignature(nativeSignature, false), wrappedExecutable);
    assert uncachedInterop.isPointer(nativeFn);
    return nativeFn;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Aggregations

Pointer (com.oracle.truffle.espresso.ffi.Pointer)18 RawPointer (com.oracle.truffle.espresso.ffi.RawPointer)18 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)14 ByteBuffer (java.nio.ByteBuffer)12 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 CharBuffer (java.nio.CharBuffer)2 CallTarget (com.oracle.truffle.api.CallTarget)1 AbstractTruffleException (com.oracle.truffle.api.exception.AbstractTruffleException)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 Source (com.oracle.truffle.api.source.Source)1 NativeSignature (com.oracle.truffle.espresso.ffi.NativeSignature)1 SuppressFBWarnings (com.oracle.truffle.espresso.impl.SuppressFBWarnings)1 Callback (com.oracle.truffle.espresso.jni.Callback)1 JavaKind (com.oracle.truffle.espresso.meta.JavaKind)1 Meta (com.oracle.truffle.espresso.meta.Meta)1 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)1 DoubleBuffer (java.nio.DoubleBuffer)1