< prev index next >

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

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


  46 static jvmtiEnv * jvmti;
  47 
  48 
  49 JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti,
  50                                         JNIEnv* jni,
  51                                         jthread thread,
  52                                         jclass klass) {
  53     char * className;
  54     char * generic;
  55     jvmti->GetClassSignature(klass, &className, &generic);
  56     if (strcmp(className,CLASS_NAME) == 0) {
  57         jmethodID method;
  58         method = jni->GetMethodID(klass, METHOD_NAME, METHOD_SIGN);
  59         if (method == NULL) {
  60             nsk_printf("Agent:: Method is null ");
  61         } else {
  62             jlocation start;
  63             jlocation end;
  64             jvmtiError err ;
  65             err=jvmti->GetMethodLocation(method, &start, &end);
  66             if ( err != JVMTI_ERROR_NONE ) {
  67                 nsk_printf(" ## Error occured %s \n",TranslateError(err));
  68             }else {
  69                 nsk_printf("\n Start = %d and end = %d ", start , end);
  70                 nsk_printf(" setting break points..");
  71                 err= jvmti->SetBreakpoint(method, start);
  72                 if (err != JVMTI_ERROR_NONE) {
  73                     nsk_printf(" ## Error occured %s \n",TranslateError(err));
  74                 } else  {
  75                     nsk_printf(" NO ERRORS ");
  76                     if (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, NULL) == NSK_TRUE ) {
  77                         nsk_printf(" Enabled.. notification event ..\n");
  78                     }
  79                 }
  80             }
  81         }
  82     }
  83 }
  84 
  85 /*
  86  *This event call back will be called when a filed
  87  *threadState is beeing upodated or beeing used in
  88  *the program java flow.
  89  *In this current example the code will be called
  90  */
  91 void JNICALL callbackSingleStep(jvmtiEnv *jvmti_env,
  92         JNIEnv* jni,
  93         jthread thread,
  94         jmethodID method,
  95         jlocation location) {
  96     jvmtiError err;


  99     char * generic ;
 100     err = JVMTI_ERROR_NONE;
 101     jvmti_env->GetMethodName(method, &name, &signature, &generic);
 102     if (strcmp(name,METHOD_NAME) == 0) { /* same method */
 103         jclass cls;
 104         jmethodID mem ;
 105         jvmti_env->GetMethodDeclaringClass(method, &cls);
 106         mem=jni->GetMethodID(cls,METHOD_NOTIFYALL,"()V");
 107         jni->CallVoidMethod(thread,mem);
 108     }
 109 
 110 }
 111 
 112 void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env,
 113         JNIEnv* jni_env,
 114         jthread thread,
 115         jmethodID method,
 116         jlocation location) {
 117     jvmtiError err;
 118     err = JVMTI_ERROR_NONE;
 119     if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP, NULL)
 120             == NSK_TRUE ) {
 121         nsk_printf(" Enabled.. notification event ..");
 122     }
 123     err= jvmti->SetEventNotificationMode(JVMTI_DISABLE,
 124             JVMTI_EVENT_BREAKPOINT, NULL);
 125     if (err == JVMTI_ERROR_NONE) {
 126         nsk_printf(" Disabled notification..");
 127     }
 128 
 129 }
 130 
 131 
 132 #ifdef STATIC_BUILD
 133 JNIEXPORT jint JNICALL Agent_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) {
 134     return Agent_Initialize(jvm, options, reserved);
 135 }
 136 JNIEXPORT jint JNICALL Agent_OnAttach_hs202t001(JavaVM *jvm, char *options, void *reserved) {
 137     return Agent_Initialize(jvm, options, reserved);
 138 }
 139 JNIEXPORT jint JNI_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) {
 140     return JNI_VERSION_1_8;
 141 }
 142 #endif
 143 jint  Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
 144     jvmtiError rc;
 145     jint code;
 146     nsk_printf("Agent:: VM.. Started..\n");
 147     code = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1);
 148     if ( code != JNI_OK ) {
 149         nsk_printf("Agent:: Could not load JVMTI interface \n");
 150         return JNI_ERR;
 151     } else {
 152         jvmtiCapabilities caps;
 153         jvmtiEventCallbacks eventCallbacks;
 154         memset(&caps, 0, sizeof(caps));
 155         if (nsk_jvmti_parseOptions(options) == NSK_FALSE ) {
 156             nsk_printf("# error agent Failed to parse options \n");
 157             return JNI_ERR;
 158         }
 159         caps.can_redefine_classes = 1;
 160         caps.can_suspend = 1;
 161         caps.can_pop_frame = 1;
 162         caps.can_generate_all_class_hook_events = 1;
 163         caps.can_generate_compiled_method_load_events = 1;
 164         caps.can_generate_breakpoint_events=1;
 165         caps.can_generate_single_step_events=1;
 166         jvmti->AddCapabilities(&caps);
 167         memset(&eventCallbacks, 0, sizeof(eventCallbacks));
 168         eventCallbacks.ClassPrepare =callbackClassPrepare;
 169         eventCallbacks.SingleStep =callbackSingleStep;
 170         eventCallbacks.Breakpoint =callbackBreakpoint;
 171         rc = jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks));
 172         if (rc != JVMTI_ERROR_NONE) {
 173             nsk_printf(" ## Error occured %s \n",TranslateError(rc));
 174             return JNI_ERR;
 175         }
 176         if ( nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE ) {
 177             nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n");
 178         } else {
 179             nsk_printf(" Error in Eanableing Notifications..");
 180         }
 181     }
 182     return JNI_OK;
 183 }
 184 
 185 JNIEXPORT jboolean JNICALL
 186 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_popThreadFrame(JNIEnv * jni,
 187         jclass clas,
 188         jthread thread) {
 189     jvmtiError err ;
 190     jboolean retvalue;
 191     jint state;
 192     nsk_printf("Agent:: POPING THE FRAME....\n");
 193     retvalue = JNI_FALSE;
 194     jvmti->GetThreadState(thread, &state);
 195     if ( state & JVMTI_THREAD_STATE_SUSPENDED) {
 196         err = jvmti->PopFrame(thread);
 197         if (err == JVMTI_ERROR_NONE) {
 198             nsk_printf("Agent:: NO Errors poped very well ..\n");
 199             retvalue=JNI_OK;
 200             return retvalue;
 201         } else if (err != JVMTI_ERROR_NONE) {
 202             nsk_printf(" ## Error occured %s \n",TranslateError(err));
 203         }
 204         nsk_printf("Agent:: some other error ..\n");
 205     } else {
 206         nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature ");
 207     }
 208     return retvalue;
 209 }
 210 
 211 JNIEXPORT jboolean JNICALL
 212 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_resumeThread(JNIEnv * jni,
 213                                                                            jclass clas,
 214                                                                            jthread thread) {
 215     jvmtiError err ;


  46 static jvmtiEnv * jvmti;
  47 
  48 
  49 JNIEXPORT void JNICALL callbackClassPrepare(jvmtiEnv *jvmti,
  50                                         JNIEnv* jni,
  51                                         jthread thread,
  52                                         jclass klass) {
  53     char * className;
  54     char * generic;
  55     jvmti->GetClassSignature(klass, &className, &generic);
  56     if (strcmp(className,CLASS_NAME) == 0) {
  57         jmethodID method;
  58         method = jni->GetMethodID(klass, METHOD_NAME, METHOD_SIGN);
  59         if (method == NULL) {
  60             nsk_printf("Agent:: Method is null ");
  61         } else {
  62             jlocation start;
  63             jlocation end;
  64             jvmtiError err ;
  65             err=jvmti->GetMethodLocation(method, &start, &end);
  66             if (err != JVMTI_ERROR_NONE) {
  67                 nsk_printf(" ## Error occured %s \n",TranslateError(err));
  68             }else {
  69                 nsk_printf("\n Start = %d and end = %d ", start , end);
  70                 nsk_printf(" setting break points..");
  71                 err= jvmti->SetBreakpoint(method, start);
  72                 if (err != JVMTI_ERROR_NONE) {
  73                     nsk_printf(" ## Error occured %s \n",TranslateError(err));
  74                 } else  {
  75                     nsk_printf(" NO ERRORS ");
  76                     if (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_BREAKPOINT, NULL) == NSK_TRUE) {
  77                         nsk_printf(" Enabled.. notification event ..\n");
  78                     }
  79                 }
  80             }
  81         }
  82     }
  83 }
  84 
  85 /*
  86  *This event call back will be called when a filed
  87  *threadState is beeing upodated or beeing used in
  88  *the program java flow.
  89  *In this current example the code will be called
  90  */
  91 void JNICALL callbackSingleStep(jvmtiEnv *jvmti_env,
  92         JNIEnv* jni,
  93         jthread thread,
  94         jmethodID method,
  95         jlocation location) {
  96     jvmtiError err;


  99     char * generic ;
 100     err = JVMTI_ERROR_NONE;
 101     jvmti_env->GetMethodName(method, &name, &signature, &generic);
 102     if (strcmp(name,METHOD_NAME) == 0) { /* same method */
 103         jclass cls;
 104         jmethodID mem ;
 105         jvmti_env->GetMethodDeclaringClass(method, &cls);
 106         mem=jni->GetMethodID(cls,METHOD_NOTIFYALL,"()V");
 107         jni->CallVoidMethod(thread,mem);
 108     }
 109 
 110 }
 111 
 112 void JNICALL callbackBreakpoint(jvmtiEnv *jvmti_env,
 113         JNIEnv* jni_env,
 114         jthread thread,
 115         jmethodID method,
 116         jlocation location) {
 117     jvmtiError err;
 118     err = JVMTI_ERROR_NONE;
 119     if (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_SINGLE_STEP, NULL)
 120             == NSK_TRUE) {
 121         nsk_printf(" Enabled.. notification event ..");
 122     }
 123     err= jvmti->SetEventNotificationMode(JVMTI_DISABLE,
 124             JVMTI_EVENT_BREAKPOINT, NULL);
 125     if (err == JVMTI_ERROR_NONE) {
 126         nsk_printf(" Disabled notification..");
 127     }
 128 
 129 }
 130 
 131 
 132 #ifdef STATIC_BUILD
 133 JNIEXPORT jint JNICALL Agent_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) {
 134     return Agent_Initialize(jvm, options, reserved);
 135 }
 136 JNIEXPORT jint JNICALL Agent_OnAttach_hs202t001(JavaVM *jvm, char *options, void *reserved) {
 137     return Agent_Initialize(jvm, options, reserved);
 138 }
 139 JNIEXPORT jint JNI_OnLoad_hs202t001(JavaVM *jvm, char *options, void *reserved) {
 140     return JNI_VERSION_1_8;
 141 }
 142 #endif
 143 jint  Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
 144     jvmtiError rc;
 145     jint code;
 146     nsk_printf("Agent:: VM.. Started..\n");
 147     code = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_1);
 148     if (code != JNI_OK) {
 149         nsk_printf("Agent:: Could not load JVMTI interface \n");
 150         return JNI_ERR;
 151     } else {
 152         jvmtiCapabilities caps;
 153         jvmtiEventCallbacks eventCallbacks;
 154         memset(&caps, 0, sizeof(caps));
 155         if (nsk_jvmti_parseOptions(options) == NSK_FALSE) {
 156             nsk_printf("# error agent Failed to parse options \n");
 157             return JNI_ERR;
 158         }
 159         caps.can_redefine_classes = 1;
 160         caps.can_suspend = 1;
 161         caps.can_pop_frame = 1;
 162         caps.can_generate_all_class_hook_events = 1;
 163         caps.can_generate_compiled_method_load_events = 1;
 164         caps.can_generate_breakpoint_events=1;
 165         caps.can_generate_single_step_events=1;
 166         jvmti->AddCapabilities(&caps);
 167         memset(&eventCallbacks, 0, sizeof(eventCallbacks));
 168         eventCallbacks.ClassPrepare =callbackClassPrepare;
 169         eventCallbacks.SingleStep =callbackSingleStep;
 170         eventCallbacks.Breakpoint =callbackBreakpoint;
 171         rc = jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks));
 172         if (rc != JVMTI_ERROR_NONE) {
 173             nsk_printf(" ## Error occured %s \n",TranslateError(rc));
 174             return JNI_ERR;
 175         }
 176         if (nsk_jvmti_enableNotification(jvmti,JVMTI_EVENT_CLASS_PREPARE, NULL) == NSK_TRUE) {
 177             nsk_printf("Agent :: NOTIFICATIONS ARE ENABLED \n");
 178         } else {
 179             nsk_printf(" Error in Eanableing Notifications..");
 180         }
 181     }
 182     return JNI_OK;
 183 }
 184 
 185 JNIEXPORT jboolean JNICALL
 186 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_popThreadFrame(JNIEnv * jni,
 187         jclass clas,
 188         jthread thread) {
 189     jvmtiError err ;
 190     jboolean retvalue;
 191     jint state;
 192     nsk_printf("Agent:: POPING THE FRAME....\n");
 193     retvalue = JNI_FALSE;
 194     jvmti->GetThreadState(thread, &state);
 195     if (state & JVMTI_THREAD_STATE_SUSPENDED) {
 196         err = jvmti->PopFrame(thread);
 197         if (err == JVMTI_ERROR_NONE) {
 198             nsk_printf("Agent:: NO Errors poped very well ..\n");
 199             retvalue=JNI_OK;
 200             return retvalue;
 201         } else if (err != JVMTI_ERROR_NONE) {
 202             nsk_printf(" ## Error occured %s \n",TranslateError(err));
 203         }
 204         nsk_printf("Agent:: some other error ..\n");
 205     } else {
 206         nsk_printf("Agent:: Thread was not suspened.. check for capabilities, and java method signature ");
 207     }
 208     return retvalue;
 209 }
 210 
 211 JNIEXPORT jboolean JNICALL
 212 Java_nsk_jvmti_scenarios_hotswap_HS202_hs202t001_hs202t001_resumeThread(JNIEnv * jni,
 213                                                                            jclass clas,
 214                                                                            jthread thread) {
 215     jvmtiError err ;
< prev index next >