test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass016/redefclass016.cpp
changeset 51715 13a63d4a3f8d
parent 51551 e409244ce72e
equal deleted inserted replaced
51714:975d3636a2f9 51715:13a63d4a3f8d
    25 #include <string.h>
    25 #include <string.h>
    26 #include "jvmti.h"
    26 #include "jvmti.h"
    27 #include "agent_common.h"
    27 #include "agent_common.h"
    28 #include "JVMTITools.h"
    28 #include "JVMTITools.h"
    29 
    29 
    30 #ifdef __cplusplus
       
    31 extern "C" {
    30 extern "C" {
    32 #endif
    31 
    33 
       
    34 #ifndef JNI_ENV_ARG
       
    35 
       
    36 #ifdef __cplusplus
       
    37 #define JNI_ENV_ARG(x, y) y
       
    38 #define JNI_ENV_PTR(x) x
       
    39 #else
       
    40 #define JNI_ENV_ARG(x,y) x, y
       
    41 #define JNI_ENV_PTR(x) (*x)
       
    42 #endif
       
    43 
       
    44 #endif
       
    45 
    32 
    46 #define PASSED 0
    33 #define PASSED 0
    47 #define STATUS_FAILED 2
    34 #define STATUS_FAILED 2
    48 
    35 
    49 static jvmtiEnv *jvmti = NULL;
    36 static jvmtiEnv *jvmti = NULL;
   155 
   142 
   156     check(jvmti_env, thread, klass, method, bpeakpointsCount);
   143     check(jvmti_env, thread, klass, method, bpeakpointsCount);
   157     bpeakpointsCount++;
   144     bpeakpointsCount++;
   158 
   145 
   159     classDef.klass = klass;
   146     classDef.klass = klass;
   160     classDef.class_byte_count =
   147     classDef.class_byte_count = env->GetArrayLength(classBytes);
   161         JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG((JNIEnv *)env, classBytes));
   148     bytes = (unsigned char *) env->GetByteArrayElements(classBytes, NULL);
   162     bytes = (unsigned char *)
       
   163         JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG((JNIEnv *)env,
       
   164             classBytes), NULL);
       
   165 
   149 
   166     for (i = 0; i < classDef.class_byte_count - 3; i++) {
   150     for (i = 0; i < classDef.class_byte_count - 3; i++) {
   167         if (((jint)bytes[i+3] |
   151         if (((jint)bytes[i+3] |
   168             ((jint)bytes[i+2] << 8) |
   152             ((jint)bytes[i+2] << 8) |
   169             ((jint)bytes[i+1] << 16) |
   153             ((jint)bytes[i+1] << 16) |
   217 
   201 
   218     if (options != NULL && strcmp(options, "printdump") == 0) {
   202     if (options != NULL && strcmp(options, "printdump") == 0) {
   219         printdump = JNI_TRUE;
   203         printdump = JNI_TRUE;
   220     }
   204     }
   221 
   205 
   222     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
   206     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
   223         JVMTI_VERSION_1_1);
       
   224     if (res != JNI_OK || jvmti == NULL) {
   207     if (res != JNI_OK || jvmti == NULL) {
   225         printf("Wrong result of a valid call to GetEnv!\n");
   208         printf("Wrong result of a valid call to GetEnv!\n");
   226         return JNI_ERR;
   209         return JNI_ERR;
   227     }
   210     }
   228 
   211 
   290     if (!caps.can_redefine_classes ||
   273     if (!caps.can_redefine_classes ||
   291         !caps.can_generate_breakpoint_events ||
   274         !caps.can_generate_breakpoint_events ||
   292         !caps.can_get_line_numbers ||
   275         !caps.can_get_line_numbers ||
   293         !caps.can_access_local_variables) return;
   276         !caps.can_access_local_variables) return;
   294 
   277 
   295     mid = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, clazz), "run", "()V");
   278     mid = env->GetMethodID(clazz, "run", "()V");
   296     if (mid == NULL) {
   279     if (mid == NULL) {
   297         printf("Cannot find Method ID for method run\n");
   280         printf("Cannot find Method ID for method run\n");
   298         result = STATUS_FAILED;
   281         result = STATUS_FAILED;
   299         return;
   282         return;
   300     }
   283     }
   301 
   284 
   302     classBytes = (jbyteArray) JNI_ENV_PTR(env)->NewGlobalRef(JNI_ENV_ARG(env, bytes));
   285     classBytes = (jbyteArray) env->NewGlobalRef(bytes);
   303 
   286 
   304     err = jvmti->GetLineNumberTable(mid, &entryCount, &lines);
   287     err = jvmti->GetLineNumberTable(mid, &entryCount, &lines);
   305     if (err != JVMTI_ERROR_NONE) {
   288     if (err != JVMTI_ERROR_NONE) {
   306         printf("(GetLineNumberTable) unexpected error: %s (%d)\n",
   289         printf("(GetLineNumberTable) unexpected error: %s (%d)\n",
   307                TranslateError(err), err);
   290                TranslateError(err), err);
   351         result = STATUS_FAILED;
   334         result = STATUS_FAILED;
   352     }
   335     }
   353     return result;
   336     return result;
   354 }
   337 }
   355 
   338 
   356 #ifdef __cplusplus
   339 }
   357 }
       
   358 #endif