test/hotspot/jtreg/vmTestbase/nsk/jvmti/RawMonitorEnter/rawmonenter004/rawmonenter004.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
       
    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 PASSED 0
    33 #define PASSED 0
    47 #define STATUS_FAILED 2
    34 #define STATUS_FAILED 2
    48 #define WAIT_STEP 100
    35 #define WAIT_STEP 100
    49 #define INCREMENT_LIMIT 1000
    36 #define INCREMENT_LIMIT 1000
    72 
    59 
    73     if (options != NULL && strcmp(options, "printdump") == 0) {
    60     if (options != NULL && strcmp(options, "printdump") == 0) {
    74         printdump = JNI_TRUE;
    61         printdump = JNI_TRUE;
    75     }
    62     }
    76 
    63 
    77     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
    64     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
    78         JVMTI_VERSION_1_1);
       
    79     if (res != JNI_OK || jvmti == NULL) {
    65     if (res != JNI_OK || jvmti == NULL) {
    80         printf("Wrong result of a valid call to GetEnv!\n");
    66         printf("Wrong result of a valid call to GetEnv!\n");
    81         return JNI_ERR;
    67         return JNI_ERR;
    82     }
    68     }
    83 
    69 
   135         printf("(CreateRawMonitor#wait) unexpected error: %s (%d)\n",
   121         printf("(CreateRawMonitor#wait) unexpected error: %s (%d)\n",
   136                TranslateError(err), err);
   122                TranslateError(err), err);
   137         return STATUS_FAILED;
   123         return STATUS_FAILED;
   138     }
   124     }
   139 
   125 
   140     threads_limit = JNI_ENV_PTR(env)->GetArrayLength(JNI_ENV_ARG(env, threads));
   126     threads_limit = env->GetArrayLength(threads);
   141 
   127 
   142     if (printdump == JNI_TRUE) {
   128     if (printdump == JNI_TRUE) {
   143         printf(">>> starting %d threads ...\n", threads_limit);
   129         printf(">>> starting %d threads ...\n", threads_limit);
   144     }
   130     }
   145 
   131 
   146     for (i = 0; i < threads_limit; i++) {
   132     for (i = 0; i < threads_limit; i++) {
   147         thr = JNI_ENV_PTR(env)->GetObjectArrayElement(JNI_ENV_ARG(env,
   133         thr = env->GetObjectArrayElement(threads, i);
   148             threads), i);
       
   149         err = jvmti->RunAgentThread(thr, increment_thread, NULL,
   134         err = jvmti->RunAgentThread(thr, increment_thread, NULL,
   150                                     JVMTI_THREAD_NORM_PRIORITY);
   135                                     JVMTI_THREAD_NORM_PRIORITY);
   151         if (err != JVMTI_ERROR_NONE) {
   136         if (err != JVMTI_ERROR_NONE) {
   152             printf("(RunDebugThread) unexpected error: %s (%d)\n",
   137             printf("(RunDebugThread) unexpected error: %s (%d)\n",
   153                    TranslateError(err), err);
   138                    TranslateError(err), err);
   190     }
   175     }
   191 
   176 
   192     return result;
   177     return result;
   193 }
   178 }
   194 
   179 
   195 #ifdef __cplusplus
       
   196 }
   180 }
   197 #endif