< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach045/attach045Agent03.cpp

Print this page
rev 51942 : [mq]: refactor


  51 VMObjectAllocHandler(jvmtiEnv *jvmti,
  52         JNIEnv* jni,
  53         jthread thread,
  54         jobject object,
  55         jclass object_klass,
  56         jlong size) {
  57     char threadName[MAX_STRING_LENGTH];
  58     char className[MAX_STRING_LENGTH];
  59     int success = 1;
  60 
  61     if (!nsk_jvmti_aod_getClassName(jvmti, object_klass, className)) {
  62         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
  63         return;
  64     }
  65 
  66     if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) {
  67         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
  68         return;
  69     }
  70 
  71     if (NSK_JVMTI_VERIFY(NSK_CPP_STUB2(
  72             RawMonitorEnter, jvmti, eventsCounterMonitor))) {
  73 
  74         eventsCounter++;
  75 
  76         NSK_DISPLAY4("%s: VMObjectAlloc received in thread '%s' for instance of '%s' (eventsCounter: %d)\n",
  77                 agentName, threadName, className, eventsCounter);
  78 
  79         if ((eventsCounter % 10) == 0) {
  80             NSK_DISPLAY1("%s: force garbage collection\n", agentName);
  81 
  82             if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB1(ForceGarbageCollection, jvmti)))
  83                 success = 0;
  84         }
  85 
  86         if (eventsCounter == EXPECTED_EVENTS_NUMBER) {
  87             NSK_DISPLAY2("%s: all expected events were received (eventsCounter: %d)\n", agentName, eventsCounter);
  88 
  89             nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni);
  90         }
  91 
  92         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, eventsCounterMonitor))) {
  93             success = 0;
  94         }
  95     } else {
  96         success = 0;
  97     }
  98 
  99     if (!success) {
 100         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
 101     }
 102 }
 103 
 104 #ifdef STATIC_BUILD
 105 JNIEXPORT jint JNI_OnLoad_attach045Agent03(JavaVM *jvm, char *options, void *reserved) {
 106     return JNI_VERSION_1_8;
 107 }
 108 #endif
 109 
 110 JNIEXPORT jint JNICALL
 111 #ifdef STATIC_BUILD
 112 Agent_OnAttach_attach045Agent03(JavaVM *vm, char *optionsString, void *reserved)
 113 #else
 114 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
 115 #endif
 116 {
 117     jvmtiEventCallbacks eventCallbacks;
 118     jvmtiEnv* jvmti;
 119     jvmtiCapabilities caps;
 120     JNIEnv* jni;
 121 
 122     if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL))
 123         return JNI_ERR;
 124 
 125     agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
 126 
 127     if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
 128         return JNI_ERR;
 129 
 130     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL))
 131         return JNI_ERR;
 132 
 133     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor, jvmti, "attach045-agent03-eventsCounterMonitor", &eventsCounterMonitor))) {
 134         return JNI_ERR;
 135     }
 136 
 137     memset(&caps, 0, sizeof(caps));
 138     caps.can_generate_vm_object_alloc_events = 1;
 139     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)) ) {
 140         return JNI_ERR;
 141     }
 142 
 143     memset(&eventCallbacks,0, sizeof(eventCallbacks));
 144     eventCallbacks.VMObjectAlloc = VMObjectAllocHandler;
 145     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti, &eventCallbacks, sizeof(eventCallbacks))) ) {
 146         return JNI_ERR;
 147     }
 148 
 149     if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
 150         return JNI_ERR;
 151     }
 152 
 153     NSK_DISPLAY1("%s: initialization was done\n", agentName);
 154 
 155     if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
 156         return JNI_ERR;
 157 
 158     return JNI_OK;
 159 }
 160 
 161 
 162 }


  51 VMObjectAllocHandler(jvmtiEnv *jvmti,
  52         JNIEnv* jni,
  53         jthread thread,
  54         jobject object,
  55         jclass object_klass,
  56         jlong size) {
  57     char threadName[MAX_STRING_LENGTH];
  58     char className[MAX_STRING_LENGTH];
  59     int success = 1;
  60 
  61     if (!nsk_jvmti_aod_getClassName(jvmti, object_klass, className)) {
  62         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
  63         return;
  64     }
  65 
  66     if (!nsk_jvmti_aod_getThreadName(jvmti, thread, threadName)) {
  67         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
  68         return;
  69     }
  70 
  71     if (NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(eventsCounterMonitor))) {

  72 
  73         eventsCounter++;
  74 
  75         NSK_DISPLAY4("%s: VMObjectAlloc received in thread '%s' for instance of '%s' (eventsCounter: %d)\n",
  76                 agentName, threadName, className, eventsCounter);
  77 
  78         if ((eventsCounter % 10) == 0) {
  79             NSK_DISPLAY1("%s: force garbage collection\n", agentName);
  80 
  81             if (!NSK_JVMTI_VERIFY(jvmti->ForceGarbageCollection()))
  82                 success = 0;
  83         }
  84 
  85         if (eventsCounter == EXPECTED_EVENTS_NUMBER) {
  86             NSK_DISPLAY2("%s: all expected events were received (eventsCounter: %d)\n", agentName, eventsCounter);
  87 
  88             nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni);
  89         }
  90 
  91         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(eventsCounterMonitor))) {
  92             success = 0;
  93         }
  94     } else {
  95         success = 0;
  96     }
  97 
  98     if (!success) {
  99         nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, 0, jvmti, jni);
 100     }
 101 }
 102 
 103 #ifdef STATIC_BUILD
 104 JNIEXPORT jint JNI_OnLoad_attach045Agent03(JavaVM *jvm, char *options, void *reserved) {
 105     return JNI_VERSION_1_8;
 106 }
 107 #endif
 108 
 109 JNIEXPORT jint JNICALL
 110 #ifdef STATIC_BUILD
 111 Agent_OnAttach_attach045Agent03(JavaVM *vm, char *optionsString, void *reserved)
 112 #else
 113 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
 114 #endif
 115 {
 116     jvmtiEventCallbacks eventCallbacks;
 117     jvmtiEnv* jvmti;
 118     jvmtiCapabilities caps;
 119     JNIEnv* jni;
 120 
 121     if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL))
 122         return JNI_ERR;
 123 
 124     agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
 125 
 126     if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
 127         return JNI_ERR;
 128 
 129     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL))
 130         return JNI_ERR;
 131 
 132     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("attach045-agent03-eventsCounterMonitor", &eventsCounterMonitor))) {
 133         return JNI_ERR;
 134     }
 135 
 136     memset(&caps, 0, sizeof(caps));
 137     caps.can_generate_vm_object_alloc_events = 1;
 138     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)) ) {
 139         return JNI_ERR;
 140     }
 141 
 142     memset(&eventCallbacks,0, sizeof(eventCallbacks));
 143     eventCallbacks.VMObjectAlloc = VMObjectAllocHandler;
 144     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))) ) {
 145         return JNI_ERR;
 146     }
 147 
 148     if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
 149         return JNI_ERR;
 150     }
 151 
 152     NSK_DISPLAY1("%s: initialization was done\n", agentName);
 153 
 154     if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
 155         return JNI_ERR;
 156 
 157     return JNI_OK;
 158 }
 159 
 160 
 161 }
< prev index next >