test/hotspot/jtreg/vmTestbase/nsk/jvmti/RedefineClasses/redefclass001/redefclass001.cpp
changeset 51715 13a63d4a3f8d
parent 51551 e409244ce72e
child 52642 9cfc8b0c45fd
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
       
    33 
    31 
    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 STATUS_FAILED 2
    33 #define STATUS_FAILED 2
    47 #define PASSED 0
    34 #define PASSED 0
    48 
    35 
    49 static jvmtiEnv *jvmti = NULL;
    36 static jvmtiEnv *jvmti = NULL;
    62 #endif
    49 #endif
    63 jint  Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
    50 jint  Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
    64     jint res;
    51     jint res;
    65     jvmtiError err;
    52     jvmtiError err;
    66 
    53 
    67     if ((res = JNI_ENV_PTR(vm)->GetEnv(JNI_ENV_ARG(vm, (void **) &jvmti),
    54     if ((res = vm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1)) != JNI_OK) {
    68             JVMTI_VERSION_1_1)) != JNI_OK) {
       
    69         printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res);
    55         printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res);
    70         return JNI_ERR;
    56         return JNI_ERR;
    71     }
    57     }
    72 
    58 
    73     err = jvmti->GetPotentialCapabilities(&caps);
    59     err = jvmti->GetPotentialCapabilities(&caps);
   113         return PASSED;
    99         return PASSED;
   114     }
   100     }
   115 
   101 
   116 /* filling the structure jvmtiClassDefinition */
   102 /* filling the structure jvmtiClassDefinition */
   117     classDef.klass = redefCls;
   103     classDef.klass = redefCls;
   118     classDef.class_byte_count =
   104     classDef.class_byte_count = env->GetArrayLength(classBytes);
   119         JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, classBytes));
   105     classDef.class_bytes = (unsigned char *) env->GetByteArrayElements(classBytes, NULL);
   120     classDef.class_bytes = (unsigned char *)
       
   121         JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env, classBytes),
       
   122             NULL);
       
   123 
   106 
   124     if (fl == 2) {
   107     if (fl == 2) {
   125         printf(">>>>>>>> Invoke RedefineClasses():\n");
   108         printf(">>>>>>>> Invoke RedefineClasses():\n");
   126         printf("\tnew class byte count=%d\n", classDef.class_byte_count);
   109         printf("\tnew class byte count=%d\n", classDef.class_byte_count);
   127     }
   110     }
   137         printf("<<<<<<<< RedefineClasses() is successfully done\n");
   120         printf("<<<<<<<< RedefineClasses() is successfully done\n");
   138 
   121 
   139     return PASSED;
   122     return PASSED;
   140 }
   123 }
   141 
   124 
   142 #ifdef __cplusplus
       
   143 }
   125 }
   144 #endif