test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/JvmtiTest/JvmtiTest.cpp
changeset 51775 dfed97156841
parent 51551 e409244ce72e
child 52229 d8843761f478
equal deleted inserted replaced
51774:79dc492c00ab 51775:dfed97156841
    24 #include <stdio.h>
    24 #include <stdio.h>
    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 
    28 
    29 #ifdef __cplusplus
       
    30 extern "C" {
    29 extern "C" {
    31 #endif
       
    32 
    30 
    33 #ifndef JNI_ENV_ARG
       
    34 
       
    35 #ifdef __cplusplus
       
    36 #define JNI_ENV_ARG(x, y) y
       
    37 #define JNI_ENV_ARG1(x)
       
    38 #define JNI_ENV_PTR(x) x
       
    39 #else
       
    40 #define JNI_ENV_ARG(x,y) x, y
       
    41 #define JNI_ENV_ARG1(x) x
       
    42 #define JNI_ENV_PTR(x) (*x)
       
    43 #endif
       
    44 
       
    45 #endif
       
    46 
       
    47 #define JVMTI_ENV_ARG JNI_ENV_ARG
       
    48 #define JVMTI_ENV_ARG1 JNI_ENV_ARG1
       
    49 #define JVMTI_ENV_PTR JNI_ENV_PTR
       
    50 
    31 
    51 #define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;}
    32 #define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;}
    52 #define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;}
    33 #define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;}
    53 
    34 
    54 #define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; }
    35 #define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; }
    97         if (strstr(options, "printdump")) {
    78         if (strstr(options, "printdump")) {
    98             printdump = 1;
    79             printdump = 1;
    99         }
    80         }
   100     }
    81     }
   101 
    82 
   102     res = JNI_ENV_PTR(jvm)->
    83     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
   103         GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1);
       
   104     if (res < 0) {
    84     if (res < 0) {
   105         debug_printf("Wrong result of a valid call to GetEnv!\n");
    85         debug_printf("Wrong result of a valid call to GetEnv!\n");
   106         return JNI_ERR;
    86         return JNI_ERR;
   107     }
    87     }
   108 
    88 
   109 
    89 
   110     /* Add capabilities */
    90     /* Add capabilities */
   111     res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
    91     res = jvmti->GetPotentialCapabilities(&jvmti_caps);
   112     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
    92     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
   113 
    93 
   114     res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
    94     res = jvmti->AddCapabilities(&jvmti_caps);
   115     JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res);
    95     JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res);
   116 
    96 
   117 
    97 
   118     res = JVMTI_ENV_PTR(jvmti)->GetSystemProperties(JVMTI_ENV_ARG(jvmti, &count), &properties);
    98     res = jvmti->GetSystemProperties(&count, &properties);
   119 
    99 
   120     JVMTI_ERROR_CHECK("GetSystemProperties returned error", res);
   100     JVMTI_ERROR_CHECK("GetSystemProperties returned error", res);
   121 
   101 
   122     for (i=0; i< count; i++) {
   102     for (i=0; i< count; i++) {
   123         char *value;
   103         char *value;
   124 
   104 
   125         res = JVMTI_ENV_PTR(jvmti)->GetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), &value);
   105         res = jvmti->GetSystemProperty((const char *) properties[i], &value);
   126         JVMTI_ERROR_CHECK("GetSystemProperty returned error", res);
   106         JVMTI_ERROR_CHECK("GetSystemProperty returned error", res);
   127         debug_printf(" %s    %s \n", properties[i], value);
   107         debug_printf(" %s    %s \n", properties[i], value);
   128 
   108 
   129         /* Only writeable properties returns JVMTI_ERROR_NONE. */
   109         /* Only writeable properties returns JVMTI_ERROR_NONE. */
   130         res = JVMTI_ENV_PTR(jvmti)->SetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), value);
   110         res = jvmti->SetSystemProperty((const char *) properties[i], value);
   131         debug_printf("SetSystemProperty returned error %d\n", res);
   111         debug_printf("SetSystemProperty returned error %d\n", res);
   132 
   112 
   133      }
   113      }
   134 
   114 
   135     return JNI_OK;
   115     return JNI_OK;
   140 Java_nsk_jvmti_unit_functions_environment_JvmtiTest_GetResult(JNIEnv * env, jclass cls) {
   120 Java_nsk_jvmti_unit_functions_environment_JvmtiTest_GetResult(JNIEnv * env, jclass cls) {
   141     return iGlobalStatus;
   121     return iGlobalStatus;
   142 }
   122 }
   143 
   123 
   144 
   124 
   145 #ifdef __cplusplus
       
   146 }
   125 }
   147 #endif