< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.cpp

Print this page
rev 52050 : [mq]: refactor


  64 static volatile int verbose = 0;
  65 
  66 static volatile jint result = PASSED;
  67 static volatile int monEntered = 0; /* the monitor entered */
  68 static volatile int thrStarted[MAX_THREADS]; /* a thread started */
  69 static volatile int releaseMon = 0; /* flag to release the monitor */
  70 
  71 static volatile jobject clsObj;
  72 static jrawMonitorID countLock;
  73 
  74 /* the original JNI function table */
  75 static jniNativeInterface *orig_jni_functions = NULL;
  76 
  77 /* the redirected JNI function table */
  78 static jniNativeInterface *redir_jni_functions = NULL;
  79 
  80 /* number of the redirected JNI function calls */
  81 static volatile int monent_calls = 0;
  82 
  83 static void lock() {
  84     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter,
  85             jvmti, countLock)))
  86         exit(STATUS_FAILED);
  87 }
  88 
  89 static void unlock() {
  90     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit,
  91             jvmti, countLock)))
  92         exit(STATUS_FAILED);
  93 }
  94 
  95 /** redirected JNI functions **/
  96 jint JNICALL MyMonitorEnter(JNIEnv *env, jobject obj) {
  97     lock();
  98     monent_calls++;
  99     unlock();
 100 
 101     NSK_DISPLAY1("MyMonitorEnter: the function called successfully: number of calls=%d\n",
 102         monent_calls);
 103 
 104     return orig_jni_functions->MonitorEnter(env, obj);
 105 }
 106 /*****************************/
 107 
 108 static jint enterMonitor(JNIEnv *env, const char *thr) {
 109     jint result;
 110 
 111     if ((result = env->MonitorEnter(clsObj)) != 0) {


 465 }
 466 JNIEXPORT jint JNICALL Agent_OnAttach_ji06t001(JavaVM *jvm, char *options, void *reserved) {
 467     return Agent_Initialize(jvm, options, reserved);
 468 }
 469 JNIEXPORT jint JNI_OnLoad_ji06t001(JavaVM *jvm, char *options, void *reserved) {
 470     return JNI_VERSION_1_8;
 471 }
 472 #endif
 473 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 474     /* init framework and parse options */
 475     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 476         return JNI_ERR;
 477 
 478     /* create JVMTI environment */
 479     if (!NSK_VERIFY((jvmti =
 480             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 481         return JNI_ERR;
 482 
 483     vm = jvm;
 484 
 485     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor,
 486             jvmti, "_counter_lock", &countLock)))
 487         return JNI_ERR;
 488 
 489     return JNI_OK;
 490 }
 491 
 492 }


  64 static volatile int verbose = 0;
  65 
  66 static volatile jint result = PASSED;
  67 static volatile int monEntered = 0; /* the monitor entered */
  68 static volatile int thrStarted[MAX_THREADS]; /* a thread started */
  69 static volatile int releaseMon = 0; /* flag to release the monitor */
  70 
  71 static volatile jobject clsObj;
  72 static jrawMonitorID countLock;
  73 
  74 /* the original JNI function table */
  75 static jniNativeInterface *orig_jni_functions = NULL;
  76 
  77 /* the redirected JNI function table */
  78 static jniNativeInterface *redir_jni_functions = NULL;
  79 
  80 /* number of the redirected JNI function calls */
  81 static volatile int monent_calls = 0;
  82 
  83 static void lock() {
  84     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(countLock)))

  85         exit(STATUS_FAILED);
  86 }
  87 
  88 static void unlock() {
  89     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(countLock)))

  90         exit(STATUS_FAILED);
  91 }
  92 
  93 /** redirected JNI functions **/
  94 jint JNICALL MyMonitorEnter(JNIEnv *env, jobject obj) {
  95     lock();
  96     monent_calls++;
  97     unlock();
  98 
  99     NSK_DISPLAY1("MyMonitorEnter: the function called successfully: number of calls=%d\n",
 100         monent_calls);
 101 
 102     return orig_jni_functions->MonitorEnter(env, obj);
 103 }
 104 /*****************************/
 105 
 106 static jint enterMonitor(JNIEnv *env, const char *thr) {
 107     jint result;
 108 
 109     if ((result = env->MonitorEnter(clsObj)) != 0) {


 463 }
 464 JNIEXPORT jint JNICALL Agent_OnAttach_ji06t001(JavaVM *jvm, char *options, void *reserved) {
 465     return Agent_Initialize(jvm, options, reserved);
 466 }
 467 JNIEXPORT jint JNI_OnLoad_ji06t001(JavaVM *jvm, char *options, void *reserved) {
 468     return JNI_VERSION_1_8;
 469 }
 470 #endif
 471 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 472     /* init framework and parse options */
 473     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 474         return JNI_ERR;
 475 
 476     /* create JVMTI environment */
 477     if (!NSK_VERIFY((jvmti =
 478             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 479         return JNI_ERR;
 480 
 481     vm = jvm;
 482 
 483     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_counter_lock", &countLock)))

 484         return JNI_ERR;
 485 
 486     return JNI_OK;
 487 }
 488 
 489 }
< prev index next >