Search in sources :

Example 6 with Pointer

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

the class NFINativeAccess method loadLibraryHelper.

@Pointer
protected TruffleObject loadLibraryHelper(String nfiSource) {
    Source source = Source.newBuilder("nfi", nfiSource, "loadLibrary").build();
    CallTarget target = env.parseInternal(source);
    try {
        return (TruffleObject) target.call();
    } catch (IllegalArgumentException e) {
        getLogger().log(Level.SEVERE, "TruffleNFI native library isolation is not supported", e);
        throw EspressoError.shouldNotReachHere(e);
    } catch (AbstractTruffleException e) {
        // TODO(peterssen): Remove assert once GR-27045 reaches a definitive consensus.
        assert isExpectedException(e);
        // AbstractTruffleException is treated as if it were an UnsatisfiedLinkError.
        getLogger().fine("AbstractTruffleException while loading library though NFI (" + nfiSource + ") : " + e.getMessage());
        return null;
    }
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) AbstractTruffleException(com.oracle.truffle.api.exception.AbstractTruffleException) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 7 with Pointer

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

the class VM method JVM_FindLibraryEntry.

@VmImpl
@TruffleBoundary
@SuppressFBWarnings(value = "AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", justification = "benign race")
@Pointer
public TruffleObject JVM_FindLibraryEntry(@Pointer TruffleObject libraryPtr, @Pointer TruffleObject namePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    long nativePtr = NativeUtils.interopAsPointer(libraryPtr);
    TruffleObject library = handle2Lib.get(nativePtr);
    if (library == null) {
        if (nativePtr == rtldDefaultValue || nativePtr == processHandleValue) {
            library = getNativeAccess().loadDefaultLibrary();
            if (library == null) {
                getLogger().warning("JVM_FindLibraryEntry from default/global namespace is not supported: " + name);
                return RawPointer.nullInstance();
            }
            handle2Lib.put(nativePtr, library);
        } else {
            getLogger().warning("JVM_FindLibraryEntry with unknown handle (" + libraryPtr + " / " + Long.toHexString(nativePtr) + "): " + name);
            return RawPointer.nullInstance();
        }
    }
    try {
        TruffleObject function = getNativeAccess().lookupSymbol(library, name);
        if (function == null) {
            // not found
            return RawPointer.nullInstance();
        }
        if (!getUncached().isPointer(function)) {
            getUncached().toNative(function);
        }
        long handle = getUncached().asPointer(function);
        handle2Sym.put(handle, function);
        return function;
    } catch (UnsupportedMessageException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) SuppressFBWarnings(com.oracle.truffle.espresso.impl.SuppressFBWarnings) Pointer(com.oracle.truffle.espresso.ffi.Pointer) RawPointer(com.oracle.truffle.espresso.ffi.RawPointer)

Example 8 with Pointer

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

the class VM method JVM_LoadLibrary.

@VmImpl
@TruffleBoundary
@Pointer
public TruffleObject JVM_LoadLibrary(@Pointer TruffleObject namePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    getLogger().fine(String.format("JVM_LoadLibrary: '%s'", name));
    TruffleObject lib = getNativeAccess().loadLibrary(Paths.get(name));
    if (lib == null) {
        Meta meta = getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_UnsatisfiedLinkError, name);
    }
    long handle = getLibraryHandle(lib);
    handle2Lib.put(handle, lib);
    getLogger().fine(String.format("JVM_LoadLibrary: Successfully loaded '%s' with handle %x", name, handle));
    return RawPointer.create(handle);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) 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 9 with Pointer

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

the class JniEnv method GetCharArrayElements.

@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetCharArrayElements(@JavaType(char[].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);
    }
    char[] data = array.unwrap();
    ByteBuffer bytes = allocateDirect(data.length, JavaKind.Char);
    CharBuffer elements = bytes.asCharBuffer();
    elements.put(data);
    return NativeUtils.byteBufferPointer(bytes);
}
Also used : 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 10 with Pointer

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

the class JniEnv method GetByteArrayElements.

@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetByteArrayElements(@JavaType(byte[].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.Byte);
    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