< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS202/hs202t002/hs202t002.cpp

Print this page
rev 52215 : 8212770: Remove spaces before/after () for vmTestbase/jvmti/[s-u]
Summary:
Reviewed-by:


  40 #define DIR_NAME "newclass"
  41 #define METHOD_NAME "display"
  42 
  43 static jint redefineNumber = 0;
  44 static jvmtiEnv * jvmti = NULL;
  45 
  46 typedef enum {
  47   suspend_error = -1,
  48   not_suspended,
  49   suspended
  50 } thread_suspend_status_t;
  51 
  52 static volatile thread_suspend_status_t thread_suspend_status = not_suspended;
  53 
  54 void JNICALL callbackMethodExit(jvmtiEnv *jvmti_env,
  55                                 JNIEnv* jni_env,
  56                                 jthread thread,
  57                                 jmethodID method,
  58                                 jboolean was_popped_by_exception,
  59                                 jvalue return_value) {
  60     if ( was_popped_by_exception ) {
  61         char * name;
  62         char * signature;
  63         char * generic ;
  64         jvmtiError err;
  65         err= JVMTI_ERROR_NONE;
  66         jvmti_env->GetMethodName(method, &name, &signature, &generic);
  67         if (strcmp(name,METHOD_NAME) == 0) {
  68             jclass cls;
  69             char fileName[512];
  70             nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName,
  71                                   sizeof(fileName)/sizeof(char));
  72             jvmti_env->GetMethodDeclaringClass(method, &cls);
  73             if ( nsk_jvmti_redefineClass(jvmti_env, cls,fileName) == NSK_TRUE ) {
  74                 nsk_printf(" Agent:: redefine class success ..\n");
  75                 nsk_printf("Agent::SUSPENDING>> \n");
  76                 err=jvmti_env->SuspendThread(thread);
  77                 if (err ==  JVMTI_ERROR_NONE) {
  78                     thread_suspend_status = suspended;
  79                     nsk_printf("Agent:: Thread successfully suspended..\n");
  80                 } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) {
  81                     thread_suspend_status = suspend_error;
  82                     nsk_printf(" ## Error occured %s \n",TranslateError(err));
  83                 }
  84             }
  85         }
  86     }
  87 }
  88 
  89 #ifdef STATIC_BUILD
  90 JNIEXPORT jint JNICALL Agent_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) {
  91     return Agent_Initialize(jvm, options, reserved);
  92 }
  93 JNIEXPORT jint JNICALL Agent_OnAttach_hs202t002(JavaVM *jvm, char *options, void *reserved) {
  94     return Agent_Initialize(jvm, options, reserved);
  95 }
  96 JNIEXPORT jint JNI_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) {
  97     return JNI_VERSION_1_8;
  98 }
  99 #endif
 100 jint  Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
 101     jint rc ;
 102     nsk_printf("Agent:: VM.. Started..\n");
 103     redefineNumber=0;
 104     rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1);
 105     if ( rc!= JNI_OK ) {
 106         nsk_printf("Agent:: Could not load JVMTI interface \n");
 107         return JNI_ERR;
 108     } else {
 109         jvmtiCapabilities caps;
 110         jvmtiEventCallbacks eventCallbacks;
 111         memset(&caps, 0, sizeof(caps));
 112         if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) {
 113             nsk_printf("# error agent Failed to parse options \n");
 114             return JNI_ERR;
 115         }
 116         caps.can_redefine_classes = 1;
 117         caps.can_suspend = 1;
 118         caps.can_pop_frame = 1;
 119         caps.can_generate_method_exit_events = 1;
 120         jvmti->AddCapabilities(&caps);
 121         memset(&eventCallbacks, 0, sizeof(eventCallbacks));
 122         eventCallbacks.MethodExit = callbackMethodExit;
 123         rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks));
 124         if (rc != JVMTI_ERROR_NONE) {
 125             nsk_printf(" Agent:: Error occured while setting event callbacks \n");
 126             return JNI_ERR;
 127         }
 128         if (NSK_TRUE == nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_METHOD_EXIT, NULL)) {
 129             nsk_printf(" Agent :: NOTIFICATIONS ARE ENABLED \n");
 130         } else {
 131             nsk_printf(" Agent :: Error Enabling Notifications..");
 132         }
 133     }
 134     return JNI_OK;
 135 }
 136 
 137 JNIEXPORT jboolean JNICALL
 138 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_popThreadFrame(JNIEnv * jni,
 139                                                                           jclass clas,
 140                                                                           jthread thread) {
 141     jvmtiError err = JVMTI_ERROR_NONE;
 142     jboolean retvalue = JNI_FALSE;
 143     jint state;
 144     nsk_printf("Agent:: POPPING THE FRAME..\n");
 145     jvmti->GetThreadState(thread, &state);
 146     if ( state & JVMTI_THREAD_STATE_SUSPENDED) {
 147         err = jvmti->PopFrame(thread);
 148         if (err == JVMTI_ERROR_NONE) {
 149             nsk_printf("Agent:: PopFrame succeeded..\n");
 150             return JNI_TRUE;
 151         } else  {
 152             nsk_printf(" ## Error occured %s \n",TranslateError(err));
 153         }
 154     } else {
 155         nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature ");
 156     }
 157     return retvalue;
 158 }
 159 
 160 JNIEXPORT jboolean JNICALL
 161 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_resumeThread(JNIEnv * jni,
 162                                                                         jclass clas,
 163                                                                         jthread thread) {
 164     jvmtiError err = JVMTI_ERROR_NONE;
 165     jboolean retvalue = JNI_FALSE;
 166 




  40 #define DIR_NAME "newclass"
  41 #define METHOD_NAME "display"
  42 
  43 static jint redefineNumber = 0;
  44 static jvmtiEnv * jvmti = NULL;
  45 
  46 typedef enum {
  47   suspend_error = -1,
  48   not_suspended,
  49   suspended
  50 } thread_suspend_status_t;
  51 
  52 static volatile thread_suspend_status_t thread_suspend_status = not_suspended;
  53 
  54 void JNICALL callbackMethodExit(jvmtiEnv *jvmti_env,
  55                                 JNIEnv* jni_env,
  56                                 jthread thread,
  57                                 jmethodID method,
  58                                 jboolean was_popped_by_exception,
  59                                 jvalue return_value) {
  60     if (was_popped_by_exception) {
  61         char * name;
  62         char * signature;
  63         char * generic ;
  64         jvmtiError err;
  65         err= JVMTI_ERROR_NONE;
  66         jvmti_env->GetMethodName(method, &name, &signature, &generic);
  67         if (strcmp(name,METHOD_NAME) == 0) {
  68             jclass cls;
  69             char fileName[512];
  70             nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName,
  71                                   sizeof(fileName)/sizeof(char));
  72             jvmti_env->GetMethodDeclaringClass(method, &cls);
  73             if (nsk_jvmti_redefineClass(jvmti_env, cls,fileName) == NSK_TRUE) {
  74                 nsk_printf(" Agent:: redefine class success ..\n");
  75                 nsk_printf("Agent::SUSPENDING>> \n");
  76                 err=jvmti_env->SuspendThread(thread);
  77                 if (err ==  JVMTI_ERROR_NONE) {
  78                     thread_suspend_status = suspended;
  79                     nsk_printf("Agent:: Thread successfully suspended..\n");
  80                 } else if (err == JVMTI_ERROR_THREAD_SUSPENDED) {
  81                     thread_suspend_status = suspend_error;
  82                     nsk_printf(" ## Error occured %s \n",TranslateError(err));
  83                 }
  84             }
  85         }
  86     }
  87 }
  88 
  89 #ifdef STATIC_BUILD
  90 JNIEXPORT jint JNICALL Agent_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) {
  91     return Agent_Initialize(jvm, options, reserved);
  92 }
  93 JNIEXPORT jint JNICALL Agent_OnAttach_hs202t002(JavaVM *jvm, char *options, void *reserved) {
  94     return Agent_Initialize(jvm, options, reserved);
  95 }
  96 JNIEXPORT jint JNI_OnLoad_hs202t002(JavaVM *jvm, char *options, void *reserved) {
  97     return JNI_VERSION_1_8;
  98 }
  99 #endif
 100 jint  Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
 101     jint rc ;
 102     nsk_printf("Agent:: VM.. Started..\n");
 103     redefineNumber=0;
 104     rc=vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1);
 105     if (rc!= JNI_OK) {
 106         nsk_printf("Agent:: Could not load JVMTI interface \n");
 107         return JNI_ERR;
 108     } else {
 109         jvmtiCapabilities caps;
 110         jvmtiEventCallbacks eventCallbacks;
 111         memset(&caps, 0, sizeof(caps));
 112         if (nsk_jvmti_parseOptions(options) == NSK_FALSE) {
 113             nsk_printf("# error agent Failed to parse options \n");
 114             return JNI_ERR;
 115         }
 116         caps.can_redefine_classes = 1;
 117         caps.can_suspend = 1;
 118         caps.can_pop_frame = 1;
 119         caps.can_generate_method_exit_events = 1;
 120         jvmti->AddCapabilities(&caps);
 121         memset(&eventCallbacks, 0, sizeof(eventCallbacks));
 122         eventCallbacks.MethodExit = callbackMethodExit;
 123         rc=jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks));
 124         if (rc != JVMTI_ERROR_NONE) {
 125             nsk_printf(" Agent:: Error occured while setting event callbacks \n");
 126             return JNI_ERR;
 127         }
 128         if (NSK_TRUE == nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_METHOD_EXIT, NULL)) {
 129             nsk_printf(" Agent :: NOTIFICATIONS ARE ENABLED \n");
 130         } else {
 131             nsk_printf(" Agent :: Error Enabling Notifications..");
 132         }
 133     }
 134     return JNI_OK;
 135 }
 136 
 137 JNIEXPORT jboolean JNICALL
 138 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_popThreadFrame(JNIEnv * jni,
 139                                                                           jclass clas,
 140                                                                           jthread thread) {
 141     jvmtiError err = JVMTI_ERROR_NONE;
 142     jboolean retvalue = JNI_FALSE;
 143     jint state;
 144     nsk_printf("Agent:: POPPING THE FRAME..\n");
 145     jvmti->GetThreadState(thread, &state);
 146     if (state & JVMTI_THREAD_STATE_SUSPENDED) {
 147         err = jvmti->PopFrame(thread);
 148         if (err == JVMTI_ERROR_NONE) {
 149             nsk_printf("Agent:: PopFrame succeeded..\n");
 150             return JNI_TRUE;
 151         } else  {
 152             nsk_printf(" ## Error occured %s \n",TranslateError(err));
 153         }
 154     } else {
 155         nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature ");
 156     }
 157     return retvalue;
 158 }
 159 
 160 JNIEXPORT jboolean JNICALL
 161 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t002_hs202t002_resumeThread(JNIEnv * jni,
 162                                                                         jclass clas,
 163                                                                         jthread thread) {
 164     jvmtiError err = JVMTI_ERROR_NONE;
 165     jboolean retvalue = JNI_FALSE;
 166 


< prev index next >