use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class JniEnv method GetStringChars.
/**
* <h3>const jchar * GetStringChars(JNIEnv *env, jstring string, jboolean *isCopy);</h3>
* <p>
* Returns a pointer to the array of Unicode characters of the string. This pointer is valid
* until ReleaseStringChars() is called.
* <p>
* If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to
* JNI_FALSE if no copy is made.
*
* @param string a Java string object.
* @param isCopyPtr a pointer to a boolean. Returns a pointer to a Unicode string, or NULL if
* the operation fails.
*/
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetStringChars(@JavaType(String.class) StaticObject string, @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[] chars;
if (getJavaVersion().compactStringsEnabled()) {
StaticObject wrappedChars = (StaticObject) getMeta().java_lang_String_toCharArray.invokeDirect(string);
chars = wrappedChars.unwrap();
} else {
chars = getMeta().java_lang_String_value.getObject(string).unwrap();
}
// Add one for zero termination.
ByteBuffer bb = allocateDirect(chars.length + 1, JavaKind.Char);
CharBuffer region = bb.asCharBuffer();
region.put(chars);
region.put((char) 0);
return NativeUtils.byteBufferPointer(bb);
}
use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class JniEnv method GetFloatArrayElements.
@JniImpl
@TruffleBoundary
@Pointer
public TruffleObject GetFloatArrayElements(@JavaType(float[].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);
}
float[] data = array.unwrap();
ByteBuffer bytes = allocateDirect(data.length, JavaKind.Float);
FloatBuffer elements = bytes.asFloatBuffer();
elements.put(data);
return NativeUtils.byteBufferPointer(bytes);
}
use of com.oracle.truffle.espresso.ffi.Pointer in project graal by oracle.
the class NFINativeAccess method createNativeClosure.
@Override
@Pointer
public TruffleObject createNativeClosure(TruffleObject executable, NativeSignature nativeSignature) {
assert uncachedInterop.isExecutable(executable);
TruffleObject wrappedExecutable = new JavaToNativeWrapper(executable, nativeSignature);
TruffleObject nativeFn = (TruffleObject) uncachedSignature.createClosure(getOrCreateNFISignature(nativeSignature, false), wrappedExecutable);
assert uncachedInterop.isPointer(nativeFn);
return nativeFn;
}
Aggregations