< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/ex03t001.cpp

Print this page




  24 #include <string.h>
  25 #include "jvmti.h"
  26 #include "agent_common.h"
  27 #include "jni_tools.h"
  28 #include "jvmti_tools.h"
  29 
  30 extern "C" {
  31 
  32 static JNIEnv *jni = NULL;
  33 static jvmtiEnv* jvmti = NULL;
  34 static jlong timeout = 0;
  35 static jboolean eventEnabled = JNI_FALSE;
  36 static volatile jboolean eventReceived1 = JNI_FALSE, eventReceived2 = JNI_FALSE;
  37 static jclass checkedClass;
  38 static jrawMonitorID eventMon;
  39 
  40 
  41 /* ============================================================================= */
  42 
  43 static void JNICALL
  44 ClassUnload(jvmtiEnv* jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass, ...) {
  45     /*
  46      * With the CMS GC the event can be posted on
  47      * a ConcurrentGC thread that is not a JavaThread.
  48      * In this case the thread argument can be NULL, so that,
  49      * we should not expect the thread argument to be non-NULL.
  50      */
  51     if (klass == NULL) {
  52         nsk_jvmti_setFailStatus();
  53         NSK_COMPLAIN0("ClassUnload: 'klass' input parameter is NULL.\n");
  54 

  55     }

  56     NSK_DISPLAY0("Received ClassUnload event.\n");
  57     if (eventEnabled == JNI_TRUE) {
  58         eventReceived1 = JNI_TRUE;
  59     } else {
  60         eventReceived2 = JNI_TRUE;
  61     }
  62 
  63     /* Notify main agent thread */
  64     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(eventMon))) {
  65         nsk_jvmti_setFailStatus();
  66     }
  67     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorNotify(eventMon))) {
  68         nsk_jvmti_setFailStatus();
  69     }
  70     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(eventMon))) {
  71         nsk_jvmti_setFailStatus();
  72     }
  73 }
  74 
  75 jboolean isClassUnloadingEnabled() {


  90         if (strcmp(extList[i].id, (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled") == 0) {
  91             found = JNI_TRUE;
  92 
  93             err = (*extList[i].func)(jvmti, &enabled);
  94             if (err != JVMTI_ERROR_NONE) {
  95                 NSK_COMPLAIN1("Error during invocation of IsClassUnloadingEnabled function: %d\n", err);
  96                 nsk_jvmti_setFailStatus();
  97                 return JNI_FALSE;
  98             }
  99         }
 100     }
 101     if (found == JNI_FALSE) {
 102         NSK_COMPLAIN0("IsClassUnloadingEnabled was not found among extension functions.\n");
 103         nsk_jvmti_setFailStatus();
 104         return JNI_FALSE;
 105     }
 106 
 107     return enabled;
 108 }
 109 














 110 jboolean enableClassUnloadEvent (jboolean enable) {
 111     jint extCount, i;
 112     jvmtiExtensionEventInfo* extList;
 113     jboolean found = JNI_FALSE;
 114 
 115     NSK_DISPLAY0("Get extension events list\n");
 116     if (!NSK_JVMTI_VERIFY(jvmti->GetExtensionEvents(&extCount, &extList))) {
 117         nsk_jvmti_setFailStatus();
 118         return JNI_FALSE;
 119     }
 120 
 121     for (i = 0; i < extCount; i++) {
 122         if (strcmp(extList[i].id, (char*)"com.sun.hotspot.events.ClassUnload") == 0) {
 123             found = JNI_TRUE;








 124 
 125             if (!NSK_JVMTI_VERIFY(
 126                     jvmti->SetExtensionEventCallback(extList[i].extension_event_index,
 127                                                      enable ? (jvmtiExtensionEvent)ClassUnload : NULL))) {
 128                 nsk_jvmti_setFailStatus();
 129                 return JNI_FALSE;
 130             }
 131             eventEnabled = enable;
 132             if (enable == JNI_TRUE) {
 133                 NSK_DISPLAY1("%s callback enabled\n", extList[i].id);
 134             } else {
 135                 NSK_DISPLAY1("%s callback disabled\n", extList[i].id);
 136             }
 137         }
 138     }
 139     if (found == JNI_FALSE) {
 140         NSK_COMPLAIN0("ClassUnload event was not found among extension events.\n");
 141         nsk_jvmti_setFailStatus();
 142         return JNI_FALSE;
 143     }




  24 #include <string.h>
  25 #include "jvmti.h"
  26 #include "agent_common.h"
  27 #include "jni_tools.h"
  28 #include "jvmti_tools.h"
  29 
  30 extern "C" {
  31 
  32 static JNIEnv *jni = NULL;
  33 static jvmtiEnv* jvmti = NULL;
  34 static jlong timeout = 0;
  35 static jboolean eventEnabled = JNI_FALSE;
  36 static volatile jboolean eventReceived1 = JNI_FALSE, eventReceived2 = JNI_FALSE;
  37 static jclass checkedClass;
  38 static jrawMonitorID eventMon;
  39 
  40 
  41 /* ============================================================================= */
  42 
  43 static void JNICALL
  44 ClassUnload(jvmtiEnv* jvmti_env, JNIEnv* jni_env, const char* name, ...) {
  45     // The name argument should never be null
  46     if (name == NULL) {





  47         nsk_jvmti_setFailStatus();
  48         NSK_COMPLAIN0("ClassUnload: 'name' input parameter is NULL.\n");
  49     } else {
  50         NSK_DISPLAY1("Class unloaded %s\n", name);
  51     }
  52 
  53     NSK_DISPLAY0("Received ClassUnload event.\n");
  54     if (eventEnabled == JNI_TRUE) {
  55         eventReceived1 = JNI_TRUE;
  56     } else {
  57         eventReceived2 = JNI_TRUE;
  58     }
  59 
  60     /* Notify main agent thread */
  61     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(eventMon))) {
  62         nsk_jvmti_setFailStatus();
  63     }
  64     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorNotify(eventMon))) {
  65         nsk_jvmti_setFailStatus();
  66     }
  67     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(eventMon))) {
  68         nsk_jvmti_setFailStatus();
  69     }
  70 }
  71 
  72 jboolean isClassUnloadingEnabled() {


  87         if (strcmp(extList[i].id, (char*)"com.sun.hotspot.functions.IsClassUnloadingEnabled") == 0) {
  88             found = JNI_TRUE;
  89 
  90             err = (*extList[i].func)(jvmti, &enabled);
  91             if (err != JVMTI_ERROR_NONE) {
  92                 NSK_COMPLAIN1("Error during invocation of IsClassUnloadingEnabled function: %d\n", err);
  93                 nsk_jvmti_setFailStatus();
  94                 return JNI_FALSE;
  95             }
  96         }
  97     }
  98     if (found == JNI_FALSE) {
  99         NSK_COMPLAIN0("IsClassUnloadingEnabled was not found among extension functions.\n");
 100         nsk_jvmti_setFailStatus();
 101         return JNI_FALSE;
 102     }
 103 
 104     return enabled;
 105 }
 106 
 107 jboolean checkParams(jvmtiExtensionEventInfo event) {
 108     // Check parameters are:
 109     // JNIEnv *jni_env, const char* name
 110     if (event.param_count != 2 ||
 111           event.params[0].kind != JVMTI_KIND_IN_PTR ||
 112           event.params[0].base_type != JVMTI_TYPE_JNIENV ||
 113           event.params[1].kind != JVMTI_KIND_IN_PTR ||
 114           event.params[1].base_type != JVMTI_TYPE_CCHAR) {
 115         return JNI_FALSE;
 116     } else {
 117         return JNI_TRUE;
 118     }
 119 }
 120 
 121 jboolean enableClassUnloadEvent (jboolean enable) {
 122     jint extCount, i;
 123     jvmtiExtensionEventInfo* extList;
 124     jboolean found = JNI_FALSE;
 125 
 126     NSK_DISPLAY0("Get extension events list\n");
 127     if (!NSK_JVMTI_VERIFY(jvmti->GetExtensionEvents(&extCount, &extList))) {
 128         nsk_jvmti_setFailStatus();
 129         return JNI_FALSE;
 130     }
 131 
 132     for (i = 0; i < extCount; i++) {
 133         if (strcmp(extList[i].id, (char*)"com.sun.hotspot.events.ClassUnload") == 0) {
 134             found = JNI_TRUE;
 135 
 136             NSK_DISPLAY1("%s", extList[i].short_description);
 137 
 138             if (!checkParams(extList[i])) {
 139                 NSK_COMPLAIN0("ClassUnload event has wrong parameters.");
 140                 nsk_jvmti_setFailStatus();
 141                 return JNI_FALSE;
 142             }
 143 
 144             if (!NSK_JVMTI_VERIFY(
 145                     jvmti->SetExtensionEventCallback(extList[i].extension_event_index,
 146                                                      enable ? (jvmtiExtensionEvent)ClassUnload : NULL))) {
 147                 nsk_jvmti_setFailStatus();
 148                 return JNI_FALSE;
 149             }
 150             eventEnabled = enable;
 151             if (enable == JNI_TRUE) {
 152                 NSK_DISPLAY1("%s callback enabled\n", extList[i].id);
 153             } else {
 154                 NSK_DISPLAY1("%s callback disabled\n", extList[i].id);
 155             }
 156         }
 157     }
 158     if (found == JNI_FALSE) {
 159         NSK_COMPLAIN0("ClassUnload event was not found among extension events.\n");
 160         nsk_jvmti_setFailStatus();
 161         return JNI_FALSE;
 162     }


< prev index next >