use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class StructsAccess method initializeStructs.
@SuppressWarnings("try")
private static Structs initializeStructs(EspressoContext context, TruffleObject initializeStructs, TruffleObject lookupMemberOffset) {
try (DebugCloseable timer = STRUCTS_TIMER.scope(context.getTimers())) {
Structs[] box = new Structs[1];
Callback doInitStructs = new Callback(1, new Callback.Function() {
@Override
@CompilerDirectives.TruffleBoundary
public Object call(Object... args) {
TruffleObject memberInfoPtr = (TruffleObject) args[0];
box[0] = new Structs(context.getJNI(), memberInfoPtr, lookupMemberOffset);
return RawPointer.nullInstance();
}
});
/*
* Go down to native to initialize the data structure storing the offsets of used
* structs (The memberInfoPtr seen in the callback). This will get back to java code
* once the data structure is created. Once we get out of the native call, the structure
* is freed and cannot be used anymore.
*/
@Pointer TruffleObject closure = context.getNativeAccess().createNativeClosure(doInitStructs, NativeSignature.create(NativeType.VOID, NativeType.POINTER));
try {
InteropLibrary.getUncached().execute(initializeStructs, closure);
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
throw EspressoError.shouldNotReachHere();
}
return box[0];
}
}
use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class JniEnv method GetPrimitiveArrayCritical.
@JniImpl
@Pointer
public TruffleObject GetPrimitiveArrayCritical(@JavaType(Object.class) StaticObject object, @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 array = object;
StaticObject clazz = GetObjectClass(array);
JavaKind componentKind = ((ArrayKlass) clazz.getMirrorKlass()).getComponentType().getJavaKind();
assert componentKind.isPrimitive();
int length = GetArrayLength(array);
ByteBuffer region = allocateDirect(length, componentKind);
@Pointer TruffleObject addressPtr = NativeUtils.byteBufferPointer(region);
// @formatter:off
switch(componentKind) {
case Boolean:
GetBooleanArrayRegion(array, 0, length, addressPtr);
break;
case Byte:
GetByteArrayRegion(array, 0, length, addressPtr);
break;
case Short:
GetShortArrayRegion(array, 0, length, addressPtr);
break;
case Char:
GetCharArrayRegion(array, 0, length, addressPtr);
break;
case Int:
GetIntArrayRegion(array, 0, length, addressPtr);
break;
case Float:
GetFloatArrayRegion(array, 0, length, addressPtr);
break;
case Long:
GetLongArrayRegion(array, 0, length, addressPtr);
break;
case Double:
GetDoubleArrayRegion(array, 0, length, addressPtr);
break;
// fall through
case Object:
// fall through
case Void:
// fall through
case Illegal:
default:
throw EspressoError.shouldNotReachHere();
}
return addressPtr;
}
use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class JniEnv method GetLongArrayElements.
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetLongArrayElements(@JavaType(long[].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);
}
long[] data = array.unwrap();
ByteBuffer bytes = allocateDirect(data.length, JavaKind.Long);
LongBuffer elements = bytes.asLongBuffer();
elements.put(data);
return NativeUtils.byteBufferPointer(bytes);
}
use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class JniEnv method GetIntArrayElements.
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetIntArrayElements(@JavaType(int[].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);
}
int[] data = array.unwrap();
ByteBuffer bytes = allocateDirect(data.length, JavaKind.Int);
IntBuffer elements = bytes.asIntBuffer();
elements.put(data);
return NativeUtils.byteBufferPointer(bytes);
}
use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class NativeEnv method createNativeClosureForFactory.
@TruffleBoundary
private TruffleObject createNativeClosureForFactory(CallableFromNative.Factory factory, String methodName) {
// Dummy placeholder for unimplemented/unknown methods.
if (factory == null) {
String envName = NativeEnv.this.getClass().getSimpleName();
getLogger().log(Level.FINER, "Fetching unknown/unimplemented {0} method: {1}", new Object[] { envName, methodName });
@Pointer TruffleObject errorClosure = getNativeAccess().createNativeClosure(new Callback(0, new Callback.Function() {
@Override
public Object call(Object... args) {
CompilerDirectives.transferToInterpreter();
getLogger().log(Level.SEVERE, "Calling unimplemented {0} method: {1}", new Object[] { envName, methodName });
throw EspressoError.unimplemented(envName + " method: " + methodName);
}
}), NativeSignature.create(NativeType.VOID));
nativeClosures.add(errorClosure);
return errorClosure;
}
NativeSignature signature = factory.jniNativeSignature();
Callback target = intrinsicWrapper(factory);
@Pointer TruffleObject nativeClosure = getNativeAccess().createNativeClosure(target, signature);
nativeClosures.add(nativeClosure);
return nativeClosure;
}
Aggregations