#include "zcl-extension.h"
#include "zcl-functions.h"
+#include "zcl-jni.h"
// "real" version isn't what cl.h reports
#ifdef VERSION_IS_1_0
/* special constructor for handling buffer */
static jmethodID CLBuffer_new_jb;
-//static jclass CLNative_classid;
-//jfieldID CLNative_p;
-
-//static jclass CLObject_classid;
-
-static jclass CLExtendable_classid;
-jfieldID CLExtendable_apiVersion;
-
-static jclass CLMemory_classid;
-
-static jclass Object_classid;
-static jclass byte_a_classid; /* byte[] / [B */
-
-//static jclass ByteBuffer_classid;
-//static jmethodID ByteBuffer_order;
-//static jmethodID ByteBuffer_positionI;
-//static jmethodID ByteBuffer_position;
-//static jmethodID ByteBuffer_limit;
-//static jobject nativeOrder; // ByteOrder.nativeOrder()
-
-// for primitive boxing
-static jclass Long_classid;
-static jmethodID Long_valueOf;
-static jclass Integer_classid;
-static jmethodID Integer_valueOf;
-
-static jclass CLProperty_classid;
-static jmethodID CLProperty_toIntPtr; // depends on word size, toLong or toInt
-
-static jclass CLContextProperty_classid;
-
-static jclass CLContextProperty_TagValue_classid;
-static jmethodID CLContextProperty_TagValue_new_jj;
-
-static jclass CLDeviceProperty_classid;
-
-static jclass CLDeviceProperty_TagValue_classid;
-static jmethodID CLDeviceProperty_TagValue_new_jj;
-
-static jclass CLDeviceProperty_PartitionByCounts_classid;
-static jmethodID CLDeviceProperty_PartitionByCounts_new_I;
-
-static jclass CLImageDesc_classid;
-static jfieldID CLImageDesc_imageType;
-static jfieldID CLImageDesc_imageWidth;
-static jfieldID CLImageDesc_imageHeight;
-static jfieldID CLImageDesc_imageDepth;
-static jfieldID CLImageDesc_imageArraySize;
-static jfieldID CLImageDesc_imageRowPitch;
-static jfieldID CLImageDesc_imageSlicePitch;
-static jfieldID CLImageDesc_numMipLevels;
-static jfieldID CLImageDesc_numSamples;
-static jfieldID CLImageDesc_memObject;
-
-static jclass CLImageFormat_classid;
-static jfieldID CLImageFormat_channelOrder;
-static jfieldID CLImageFormat_channelDataType;
-static jmethodID CLImageFormat_new_ii;
-
-static jclass CLBufferInfoRegion_classid;
-static jfieldID CLBufferInfoRegion_origin;
-static jfieldID CLBufferInfoRegion_size;
-
-static jclass CLEventList_classid;
-static jfieldID CLEventList_index;
-static jfieldID CLEventList_events;
-static jmethodID CLEventList_add;
-
-static jclass CLContextNotify_classid;
-static jmethodID CLContextNotify_notify;
-
-static jclass CLEventNotify_classid;
-static jmethodID CLEventNotify_notify;
-
-static jclass CLNotify_classid;
-static jmethodID CLNotify_notify;
-
-static jclass CLNativeKernel_classid;
-static jmethodID CLNativeKernel_invoke;
-
-static const NZRefTable reftable[] = {
-
- JCLASS(CLExtendable_classid, "au/notzed/zcl/CLExtendable"),
- JFIELD(CLExtendable_apiVersion, "apiVersion", "I"),
-
- JCLASS(CLMemory_classid, "au/notzed/zcl/CLMemory"),
-
- JCLASS(Object_classid, "java/lang/Object"),
- JCLASS(Long_classid, "java/lang/Long"),
- JSMETHOD(Long_valueOf, "valueOf", "(J)Ljava/lang/Long;"),
- JCLASS(Integer_classid, "java/lang/Integer"),
- JSMETHOD(Integer_valueOf, "valueOf", "(I)Ljava/lang/Integer;"),
- JCLASS(byte_a_classid, "[B"),
-
- JCLASS(CLProperty_classid, "au/notzed/zcl/CLProperty"),
-#if UINTPTR_MAX == 0xffffffffU
- JSMETHOD(CLProperty_toIntPtr, "toInt", "([Ljava/lang/Object;)[I"),
-#else
- JSMETHOD(CLProperty_toIntPtr, "toLong", "([Ljava/lang/Object;)[J"),
-#endif
-
- JCLASS(CLContextProperty_classid, "au/notzed/zcl/CLContextProperty"),
- JCLASS(CLContextProperty_TagValue_classid, "au/notzed/zcl/CLContextProperty$TagValue"),
- JMETHOD(CLContextProperty_TagValue_new_jj, "<init>", "(JJ)V"),
-
- JCLASS(CLDeviceProperty_classid, "au/notzed/zcl/CLDeviceProperty"),
- JCLASS(CLDeviceProperty_TagValue_classid, "au/notzed/zcl/CLDeviceProperty$TagValue"),
- JMETHOD(CLDeviceProperty_TagValue_new_jj, "<init>", "(JJ)V"),
- JCLASS(CLDeviceProperty_PartitionByCounts_classid, "au/notzed/zcl/CLDeviceProperty$PartitionByCounts"),
- JMETHOD(CLDeviceProperty_PartitionByCounts_new_I, "<init>", "([I)V"),
-
- JCLASS(CLImageDesc_classid, "au/notzed/zcl/CLImageDesc"),
- JFIELD(CLImageDesc_imageType, "imageType", "I"),
- JFIELD(CLImageDesc_imageWidth, "imageWidth", "I"),
- JFIELD(CLImageDesc_imageHeight, "imageHeight", "I"),
- JFIELD(CLImageDesc_imageDepth, "imageDepth", "I"),
- JFIELD(CLImageDesc_imageArraySize, "imageArraySize", "I"),
- JFIELD(CLImageDesc_imageRowPitch, "imageRowPitch", "I"),
- JFIELD(CLImageDesc_imageSlicePitch, "imageSlicePitch", "I"),
- JFIELD(CLImageDesc_numMipLevels, "numMipLevels", "I"),
- JFIELD(CLImageDesc_numSamples, "numSamples", "I"),
- JFIELD(CLImageDesc_memObject, "memObject", "Lau/notzed/zcl/CLMemory;"),
-
- JCLASS(CLImageFormat_classid, "au/notzed/zcl/CLImageFormat"),
- JMETHOD(CLImageFormat_new_ii, "<init>", "(II)V"),
- JFIELD(CLImageFormat_channelOrder, "channelOrder", "I"),
- JFIELD(CLImageFormat_channelDataType, "channelDataType", "I"),
-
- JCLASS(CLBufferInfoRegion_classid, "au/notzed/zcl/CLBufferInfo$Region"),
- JFIELD(CLBufferInfoRegion_origin, "origin", "J"),
- JFIELD(CLBufferInfoRegion_size, "size", "J"),
-
- JCLASS(CLEventList_classid, "au/notzed/zcl/CLEventList"),
- JMETHOD(CLEventList_add, "add", "(J)V"),
- JFIELD(CLEventList_index, "index", "I"),
- JFIELD(CLEventList_events, "events", "[J"),
-
- JCLASS(CLContextNotify_classid, "au/notzed/zcl/CLContextNotify"),
- JMETHOD(CLContextNotify_notify, "notify", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)V"),
-
- JCLASS(CLEventNotify_classid, "au/notzed/zcl/CLEventNotify"),
- JMETHOD(CLEventNotify_notify, "notify", "(Lau/notzed/zcl/CLEvent;I)V"),
-
- JCLASS(CLNotify_classid, "au/notzed/zcl/CLNotify"),
- JMETHOD(CLNotify_notify, "notify", "(Ljava/lang/Object;)V"),
-
- JCLASS(CLNativeKernel_classid, "au/notzed/zcl/CLNativeKernel"),
- JMETHOD(CLNativeKernel_invoke, "invoke", "([Ljava/lang/Object;)V"),
-
- JEND
-};
-
static int debug_sync = 0;
/* ********************************************************************** */
if (nativez_OnLoad(vmi, env)
|| init_dynamic(env)
- || nativez_ResolveReferences(env, reftable) != 0)
+ || nativez_ResolveReferences(env, java_names, &java) != 0)
return 0;
char *s = getenv("ZCL_SYNC");
//case au_notzed_zcl_CLObject_CTYPE_BYTE:
case au_notzed_zcl_CLObject_CTYPE_INT:
jarg.i = ((cl_int *)value)[0];
- jres = (*env)->CallStaticObjectMethodA(env, Integer_classid, Integer_valueOf, &jarg);
+ jres = (*env)->CallStaticObjectMethodA(env, Integer_classid, Integer_valueOf_i, &jarg);
break;
case au_notzed_zcl_CLObject_CTYPE_LONG:
jarg.j = ((cl_long *)value)[0];
- jres = (*env)->CallStaticObjectMethodA(env, Long_classid, Long_valueOf, &jarg);
+ jres = (*env)->CallStaticObjectMethodA(env, Long_classid, Long_valueOf_j, &jarg);
break;
case au_notzed_zcl_CLObject_CTYPE_SIZE_T:
jarg.j = ((size_t *)value)[0];
- jres = (*env)->CallStaticObjectMethodA(env, Long_classid, Long_valueOf, &jarg);
+ jres = (*env)->CallStaticObjectMethodA(env, Long_classid, Long_valueOf_j, &jarg);
break;
default:
jres = toCLObject(env, ctype, ((void **)value)[0]);
/* Convert a tag/value property array to a primitive array */
void *fromPropertyArray(JNIEnv *env, jobjectArray jpropArray) {
-#if UINTPTR_MAX == 0xffffffff
+#if UINTPTR_MAX == 0xffffffffU
jint *res = NULL;
if (jpropArray) {
jvalue jargs = { .l = jpropArray };
- jlongArray ptmp = (*env)->CallStaticObjectMethodA(env, CLProperty_classid, CLProperty_toIntPtr, &jargs);
+ jlongArray ptmp = (*env)->CallStaticObjectMethodA(env, CLProperty_classid, CLProperty_toInt__l, &jargs);
if (!(*env)->ExceptionCheck(env)) {
jint plen = (*env)->GetArrayLength(env, ptmp);
if (jpropArray) {
jvalue jargs = { .l = jpropArray };
- jlongArray ptmp = (*env)->CallStaticObjectMethodA(env, CLProperty_classid, CLProperty_toIntPtr, &jargs);
+ jlongArray ptmp = (*env)->CallStaticObjectMethodA(env, CLProperty_classid, CLProperty_toLong__l, &jargs);
if (!(*env)->ExceptionCheck(env)) {
jint plen = (*env)->GetArrayLength(env, ptmp);
if (jevents) {
jvalue arg = { .j = (uintptr_t)einfo->event };
- (*env)->CallVoidMethodA(env, jevents, CLEventList_add, &arg);
+ (*env)->CallVoidMethodA(env, jevents, CLEventList_add_j, &arg);
}
return 0;
/* For linking, this is the first time we've seen the program */
jvalue arg = { .l = toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, prog) };
- (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify, &arg);
+ (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify_l, &arg);
} else if (info->prog == prog) {
jvalue arg = { .l = info->jprog };
- (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify, &arg);
+ (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify_l, &arg);
} else {
fprintf(stderr, "build_notify_hook given wrong cl_program\n");
}
jo = (*env)->NewObject(env,
CLDeviceProperty_PartitionByCounts_classid,
- CLDeviceProperty_PartitionByCounts_new_I,
+ CLDeviceProperty_PartitionByCounts_new__i,
jcounts);
break;
}
if (private_info && private_size)
jprivate_info = nativez_NewDirectBuffer(env, (void *)private_info, private_size);
- (*env)->CallVoidMethod(env, jnotify, CLContextNotify_notify, jerror_info, jprivate_info);
+ jvalue args[2] = {
+ { .l = jerror_info },
+ { .l = jprivate_info }
+ };
+
+ (*env)->CallVoidMethodA(env, jnotify, CLContextNotify_notify_ll, args);
}
JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createContext
if (info->mem == mem) {
jvalue arg = { .l = info->jmem };
- (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify, &arg);
+ (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify_l, &arg);
} else
fprintf(stderr, "destroy_notify_hook given wrong cl_mem\n");
return;
}
- if (info->event == event)
- (*env)->CallVoidMethod(env, info->jnotify, CLEventNotify_notify, info->jevent, status);
- else
+ if (info->event == event) {
+ jvalue args[2] = {
+ { .l = info->jevent },
+ { .i = status }
+ };
+ (*env)->CallVoidMethodA(env, info->jnotify, CLEventNotify_notify_li, args);
+ } else
fprintf(stderr, "destroy_notify_hook given wrong cl_mem\n");
(*env)->DeleteGlobalRef(env, info->jnotify);
}
jvalue arg = { .l = kargs };
- (*env)->CallVoidMethodA(env, info->jkernel, CLNativeKernel_invoke, &arg);
+ (*env)->CallVoidMethodA(env, info->jkernel, CLNativeKernel_invoke__l, &arg);
native_kernel_free(env, info);
}