Search in sources :

Example 11 with Pointer

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

the class JniEnv method GetDoubleArrayElements.

@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetDoubleArrayElements(@JavaType(double[].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);
    }
    double[] data = array.unwrap();
    ByteBuffer bytes = allocateDirect(data.length, JavaKind.Double);
    DoubleBuffer elements = bytes.asDoubleBuffer();
    elements.put(data);
    return NativeUtils.byteBufferPointer(bytes);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) 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 12 with Pointer

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

the class JniEnv method GetStringCritical.

/**
 * <h3>const jchar * GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy);</h3>
 * <p>
 * The semantics of these two functions are similar to the existing Get/ReleaseStringChars
 * functions. If possible, the VM returns a pointer to string elements; otherwise, a copy is
 * made.
 *
 * <p>
 * However, there are significant restrictions on how these functions can be used. In a code
 * segment enclosed by Get/ReleaseStringCritical calls, the native code must not issue arbitrary
 * JNI calls, or cause the current thread to block.
 *
 * <p>
 * The restrictions on Get/ReleaseStringCritical are similar to those on
 * Get/ReleasePrimitiveArrayCritical.
 */
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetStringCritical(@JavaType(String.class) StaticObject str, @Pointer TruffleObject isCopyPtr) {
    if (!getUncached().isNull(isCopyPtr)) {
        ByteBuffer isCopyBuf = NativeUtils.directByteBuffer(isCopyPtr, 1);
        // always copy since pinning is not supported
        isCopyBuf.put((byte) 1);
    }
    StaticObject stringChars;
    if (getJavaVersion().compactStringsEnabled()) {
        stringChars = (StaticObject) getMeta().java_lang_String_toCharArray.invokeDirect(str);
    } else {
        stringChars = getMeta().java_lang_String_value.getObject(str);
    }
    int len = stringChars.length();
    // direct byte buffer
    ByteBuffer criticalRegion = allocateDirect(len, JavaKind.Char);
    // (non-relocatable)
    @Pointer TruffleObject address = NativeUtils.byteBufferPointer(criticalRegion);
    GetCharArrayRegion(stringChars, 0, len, address);
    return address;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer) ByteBuffer(java.nio.ByteBuffer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 13 with Pointer

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

the class JniEnv method GetStringUTFChars.

@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetStringUTFChars(@JavaType(String.class) StaticObject str, @Pointer TruffleObject isCopyPtr) {
    if (!getUncached().isNull(isCopyPtr)) {
        ByteBuffer isCopyBuf = NativeUtils.directByteBuffer(isCopyPtr, 1);
        // always copy since pinning is not supported
        isCopyBuf.put((byte) 1);
    }
    byte[] bytes = ModifiedUtf8.asUtf(getMeta().toHostString(str), true);
    ByteBuffer region = allocateDirect(bytes.length);
    region.put(bytes);
    return NativeUtils.byteBufferPointer(region);
}
Also used : 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 14 with Pointer

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

the class JniEnv method GetShortArrayElements.

@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetShortArrayElements(@JavaType(short[].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);
    }
    short[] data = array.unwrap();
    ByteBuffer bytes = allocateDirect(data.length, JavaKind.Short);
    ShortBuffer elements = bytes.asShortBuffer();
    elements.put(data);
    return NativeUtils.byteBufferPointer(bytes);
}
Also used : ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 15 with Pointer

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

the class JniEnv method GetBooleanArrayElements.

// endregion Get/SetObjectArrayElement
// region Get*ArrayElements
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetBooleanArrayElements(@JavaType(boolean[].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);
    }
    byte[] data = array.unwrap();
    ByteBuffer bytes = allocateDirect(data.length, JavaKind.Boolean);
    ByteBuffer elements = bytes;
    elements.put(data);
    return NativeUtils.byteBufferPointer(bytes);
}
Also used : 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)

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