test/hotspot/jtreg/vmTestbase/nsk/jvmti/CreateRawMonitor/crrawmon002/crrawmon002.cpp
changeset 51551 e409244ce72e
parent 50260 46c67f5e27c2
child 51699 543a3fb81c4c
equal deleted inserted replaced
51550:a2f1923b3e16 51551:e409244ce72e
       
     1 /*
       
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 #include <stdio.h>
       
    25 #include <string.h>
       
    26 #include "jvmti.h"
       
    27 #include "agent_common.h"
       
    28 #include "JVMTITools.h"
       
    29 
       
    30 #ifdef __cplusplus
       
    31 extern "C" {
       
    32 #endif
       
    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 
       
    46 #define PASSED  0
       
    47 #define STATUS_FAILED  2
       
    48 
       
    49 static jvmtiEnv *jvmti = NULL;
       
    50 static jint result = PASSED;
       
    51 static jboolean printdump = JNI_FALSE;
       
    52 
       
    53 #ifdef STATIC_BUILD
       
    54 JNIEXPORT jint JNICALL Agent_OnLoad_crrawmon002(JavaVM *jvm, char *options, void *reserved) {
       
    55     return Agent_Initialize(jvm, options, reserved);
       
    56 }
       
    57 JNIEXPORT jint JNICALL Agent_OnAttach_crrawmon002(JavaVM *jvm, char *options, void *reserved) {
       
    58     return Agent_Initialize(jvm, options, reserved);
       
    59 }
       
    60 JNIEXPORT jint JNI_OnLoad_crrawmon002(JavaVM *jvm, char *options, void *reserved) {
       
    61     return JNI_VERSION_1_8;
       
    62 }
       
    63 #endif
       
    64 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
       
    65     jint res;
       
    66 
       
    67     if (options != NULL && strcmp(options, "printdump") == 0) {
       
    68         printdump = JNI_TRUE;
       
    69     }
       
    70 
       
    71     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
       
    72         JVMTI_VERSION_1_1);
       
    73     if (res != JNI_OK || jvmti == NULL) {
       
    74         printf("Wrong result of a valid call to GetEnv!\n");
       
    75         return JNI_ERR;
       
    76     }
       
    77 
       
    78     return JNI_OK;
       
    79 }
       
    80 
       
    81 JNIEXPORT jint JNICALL
       
    82 Java_nsk_jvmti_CreateRawMonitor_crrawmon002_check(JNIEnv *env, jclass cls) {
       
    83     jvmtiError err;
       
    84     jrawMonitorID monitor;
       
    85 
       
    86     if (jvmti == NULL) {
       
    87         printf("JVMTI client was not properly loaded!\n");
       
    88         return STATUS_FAILED;
       
    89     }
       
    90 
       
    91     if (printdump == JNI_TRUE) {
       
    92         printf(">>> name null pointer check ...\n");
       
    93     }
       
    94     err = jvmti->CreateRawMonitor(NULL, &monitor);
       
    95     if (err != JVMTI_ERROR_NULL_POINTER) {
       
    96         printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n",
       
    97                TranslateError(err));
       
    98         result = STATUS_FAILED;
       
    99     }
       
   100 
       
   101     if (printdump == JNI_TRUE) {
       
   102         printf(">>> monitorPtr null pointer check ...\n");
       
   103     }
       
   104     err = jvmti->CreateRawMonitor("dummy", NULL);
       
   105     if (err != JVMTI_ERROR_NULL_POINTER) {
       
   106         printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n",
       
   107                TranslateError(err));
       
   108         result = STATUS_FAILED;
       
   109     }
       
   110 
       
   111     return result;
       
   112 }
       
   113 
       
   114 #ifdef __cplusplus
       
   115 }
       
   116 #endif