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