use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method ToReflectedMethod.
/*
* jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle ToReflectedMethod(JNIEnvironment env, JNIObjectHandle classHandle, JNIMethodId methodId, boolean isStatic) {
Executable result = null;
if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
JNIAccessibleMethod jniMethod = JNIReflectionDictionary.getMethodByID(methodId);
JNIAccessibleMethodDescriptor descriptor = JNIReflectionDictionary.getMethodDescriptor(jniMethod);
if (descriptor != null) {
Class<?> clazz = jniMethod.getDeclaringClass().getClassObject();
if (descriptor.isConstructor()) {
for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
if (descriptor.equals(JNIAccessibleMethodDescriptor.of(ctor))) {
result = ctor;
break;
}
}
} else {
for (Method method : clazz.getDeclaredMethods()) {
if (descriptor.getName().equals(method.getName())) {
if (descriptor.equals(JNIAccessibleMethodDescriptor.of(method))) {
result = method;
break;
}
}
}
}
}
}
return JNIThreadLocalHandles.get().create(result);
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method GetDirectBufferAddress.
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static WordPointer GetDirectBufferAddress(JNIEnvironment env, JNIObjectHandle handle) {
WordPointer address = WordFactory.nullPointer();
Object obj = JNIObjectHandles.getObject(handle);
if (obj instanceof Target_java_nio_Buffer) {
Target_java_nio_Buffer buf = (Target_java_nio_Buffer) obj;
address = Word.pointer(buf.address);
}
return address;
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method RegisterNatives.
/*
* jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint
* nMethods);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnJniErr.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int RegisterNatives(JNIEnvironment env, JNIObjectHandle hclazz, JNINativeMethod methods, int nmethods) {
Class<?> clazz = JNIObjectHandles.getObject(hclazz);
Pointer p = (Pointer) methods;
for (int i = 0; i < nmethods; i++) {
JNINativeMethod entry = (JNINativeMethod) p;
String name = CTypeConversion.toJavaString(entry.name());
String signature = CTypeConversion.toJavaString(entry.signature());
CFunctionPointer fnPtr = entry.fnPtr();
String declaringClass = MetaUtil.toInternalName(clazz.getName());
JNINativeLinkage linkage = JNIReflectionDictionary.singleton().getLinkage(declaringClass, name, signature);
if (linkage != null) {
linkage.setEntryPoint(fnPtr);
} else {
return JNIErrors.JNI_ERR();
}
p = p.add(SizeOf.get(JNINativeMethod.class));
}
return JNIErrors.JNI_OK();
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIInvocationInterface method DetachCurrentThread.
/*
* jint DetachCurrentThread(JavaVM *vm);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIJavaVMEnterAttachThreadPrologue.class, epilogue = LeaveDetachThreadEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int DetachCurrentThread(JNIJavaVM vm) {
int result = JNIErrors.JNI_OK();
if (!vm.equal(JNIFunctionTables.singleton().getGlobalJavaVM())) {
result = JNIErrors.JNI_ERR();
}
// JNI specification requires releasing all owned monitors
Support.releaseCurrentThreadOwnedMonitors();
return result;
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class NativeAPIImpl method isSameObject.
@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int isSameObject(@SuppressWarnings("unused") NativeTruffleEnv env, TruffleObjectHandle handle1, TruffleObjectHandle handle2) {
TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
Object object1 = support.resolveHandle(handle1);
Object object2 = support.resolveHandle(handle2);
return object1 == object2 ? 1 : 0;
}
Aggregations