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;
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations