< prev index next >

test/micro/org/openjdk/bench/jdk/incubator/foreign/libUpcallsJNI.c

Print this page
*** 20,50 ***
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  #include <jni.h>
  #include <stdlib.h>
- #include "jlong.h"
- 
- typedef struct {
-     jclass holder;
-     jmethodID mid;
- } *JNICB;
- 
- #define CHECK_NULL(thing, message) \
-     if (thing == NULL) { \
-         jclass cls = (*env)->FindClass(env, "java/lang/Exception"); \
-         (*env)->ThrowNew(env, cls, message); \
-         return 0; \
-     }
- 
- JNIEXPORT jlong JNICALL Java_org_openjdk_bench_jdk_incubator_foreign_Upcalls_makeCB
-   (JNIEnv *env, jclass cls, jstring holderName, jstring methodName, jstring descriptor) {
- 
-   const char* holderNameC = (*env)->GetStringUTFChars(env, holderName, NULL);
-   const char* methodNameC = (*env)->GetStringUTFChars(env, methodName, NULL);
-   const char* descriptorC = (*env)->GetStringUTFChars(env, descriptor, NULL);
  
!   JNICB cb = malloc(sizeof *cb);
!   CHECK_NULL(cb, "Can not allocate cb");
- 
-   jclass holder = (*env)->FindClass(env, holderNameC);
-   CHECK_NULL(holder, "Can not find class");
-   holder = (jclass) (*env)->NewGlobalRef(env, holder);
-   cb->holder = holder;
- 
-   jmethodID methodID = (*env)->GetStaticMethodID(env, holder, methodNameC, descriptorC);
-   CHECK_NULL(methodID, "Can not find method");
-   //methodID = (jmethodID) (*env)->NewGlobalRef(env, methodID); // DON'T DO THIS! -> Crashes GC
-   cb->mid = methodID;
- 
-   (*env)->ReleaseStringUTFChars(env, holderName, holderNameC);
-   (*env)->ReleaseStringUTFChars(env, methodName, methodNameC);
-   (*env)->ReleaseStringUTFChars(env, descriptor, descriptorC);
- 
-   return ptr_to_jlong(cb);
- }
  
  JNIEXPORT void JNICALL Java_org_openjdk_bench_jdk_incubator_foreign_Upcalls_blank
    (JNIEnv *env, jclass cls, jlong cb) {
      JNICB jniCb = jlong_to_ptr(cb);
      (*env)->CallStaticVoidMethod(env, jniCb->holder, jniCb->mid);
--- 20,13 ---
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  #include <jni.h>
  #include <stdlib.h>
  
! #include "jlong.h"
! #include "JNICB.h"
  
  JNIEXPORT void JNICALL Java_org_openjdk_bench_jdk_incubator_foreign_Upcalls_blank
    (JNIEnv *env, jclass cls, jlong cb) {
      JNICB jniCb = jlong_to_ptr(cb);
      (*env)->CallStaticVoidMethod(env, jniCb->holder, jniCb->mid);
< prev index next >