annotate test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetOwnedMonitorInfo/ownmoninf001/ownmoninf001.cpp @ 53610:9cfc8b0c45fd

8214149: Move out assignments when not using NSK*VERIFY macros Summary: Move out the assignments from ifs Reviewed-by: sspitsyn, cjplummer
author jcbeyler
date Wed, 21 Nov 2018 10:46:45 -0800
parents b613bf6a10b1
children
rev   line source
iignatyev@50844 1 /*
iignatyev@50844 2 * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
iignatyev@50844 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
iignatyev@50844 4 *
iignatyev@50844 5 * This code is free software; you can redistribute it and/or modify it
iignatyev@50844 6 * under the terms of the GNU General Public License version 2 only, as
iignatyev@50844 7 * published by the Free Software Foundation.
iignatyev@50844 8 *
iignatyev@50844 9 * This code is distributed in the hope that it will be useful, but WITHOUT
iignatyev@50844 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iignatyev@50844 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
iignatyev@50844 12 * version 2 for more details (a copy is included in the LICENSE file that
iignatyev@50844 13 * accompanied this code).
iignatyev@50844 14 *
iignatyev@50844 15 * You should have received a copy of the GNU General Public License version
iignatyev@50844 16 * 2 along with this work; if not, write to the Free Software Foundation,
iignatyev@50844 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
iignatyev@50844 18 *
iignatyev@50844 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
iignatyev@50844 20 * or visit www.oracle.com if you need additional information or have any
iignatyev@50844 21 * questions.
iignatyev@50844 22 */
iignatyev@50844 23
iignatyev@50844 24 #include <stdio.h>
iignatyev@50844 25 #include <string.h>
iignatyev@50844 26 #include "jvmti.h"
iignatyev@50844 27 #include "agent_common.h"
iignatyev@50844 28 #include "JVMTITools.h"
iignatyev@50844 29
iignatyev@50844 30 extern "C" {
iignatyev@50844 31
iignatyev@50844 32
iignatyev@50844 33 #define PASSED 0
iignatyev@50844 34 #define STATUS_FAILED 2
iignatyev@50844 35
iignatyev@50844 36 static jvmtiEnv *jvmti = NULL;
iignatyev@50844 37 static jvmtiCapabilities caps;
iignatyev@50844 38 static jint result = PASSED;
iignatyev@50844 39
iignatyev@50844 40 #ifdef STATIC_BUILD
iignatyev@50844 41 JNIEXPORT jint JNICALL Agent_OnLoad_ownmoninf001(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 42 return Agent_Initialize(jvm, options, reserved);
iignatyev@50844 43 }
iignatyev@50844 44 JNIEXPORT jint JNICALL Agent_OnAttach_ownmoninf001(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 45 return Agent_Initialize(jvm, options, reserved);
iignatyev@50844 46 }
iignatyev@50844 47 JNIEXPORT jint JNI_OnLoad_ownmoninf001(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 48 return JNI_VERSION_1_8;
iignatyev@50844 49 }
iignatyev@50844 50 #endif
iignatyev@50844 51 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 52 jint res;
iignatyev@50844 53 jvmtiError err;
iignatyev@50844 54
jcbeyler@52440 55 res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
iignatyev@50844 56 if (res != JNI_OK || jvmti == NULL) {
iignatyev@50844 57 printf("Wrong result of a valid call to GetEnv !\n");
iignatyev@50844 58 return JNI_ERR;
iignatyev@50844 59 }
iignatyev@50844 60
iignatyev@52294 61 err = jvmti->GetPotentialCapabilities(&caps);
iignatyev@50844 62 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 63 printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
iignatyev@50844 64 TranslateError(err), err);
iignatyev@50844 65 return JNI_ERR;
iignatyev@50844 66 }
iignatyev@50844 67
iignatyev@52294 68 err = jvmti->AddCapabilities(&caps);
iignatyev@50844 69 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 70 printf("(AddCapabilities) unexpected error: %s (%d)\n",
iignatyev@50844 71 TranslateError(err), err);
iignatyev@50844 72 return JNI_ERR;
iignatyev@50844 73 }
iignatyev@50844 74
iignatyev@52294 75 err = jvmti->GetCapabilities(&caps);
iignatyev@50844 76 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 77 printf("(GetCapabilities) unexpected error: %s (%d)\n",
iignatyev@50844 78 TranslateError(err), err);
iignatyev@50844 79 return JNI_ERR;
iignatyev@50844 80 }
iignatyev@50844 81
iignatyev@50844 82 if (!caps.can_get_owned_monitor_info) {
iignatyev@50844 83 printf("Warning: GetOwnedMonitorInfo is not implemented\n");
iignatyev@50844 84 }
iignatyev@50844 85
iignatyev@50844 86 return JNI_OK;
iignatyev@50844 87 }
iignatyev@50844 88
iignatyev@50844 89 jobject *getInfo(JNIEnv *env, jint point, jthread thr, int count) {
iignatyev@50844 90 jvmtiError err;
iignatyev@50844 91 jint owned_monitor_count;
iignatyev@50844 92 jobject *owned_monitors = NULL;
iignatyev@50844 93
iignatyev@52294 94 err = jvmti->GetOwnedMonitorInfo(thr,
iignatyev@50844 95 &owned_monitor_count, &owned_monitors);
iignatyev@50844 96 if (err == JVMTI_ERROR_MUST_POSSESS_CAPABILITY &&
iignatyev@50844 97 !caps.can_get_owned_monitor_info) {
iignatyev@50844 98 /* Ok, it's expected */
iignatyev@50844 99 } else if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 100 printf("(GetOwnedMonitorInfo#%d) unexpected error: %s (%d)\n",
iignatyev@50844 101 point, TranslateError(err), err);
iignatyev@50844 102 result = STATUS_FAILED;
iignatyev@50844 103 return NULL;
iignatyev@50844 104 } else {
iignatyev@50844 105 if (owned_monitor_count != count) {
iignatyev@50844 106 result = STATUS_FAILED;
iignatyev@50844 107 printf("Point %d: number of owned monitors expected: %d, got: %d\n",
iignatyev@50844 108 point, count, owned_monitor_count);
iignatyev@50844 109 return NULL;
iignatyev@50844 110 }
iignatyev@50844 111 }
iignatyev@50844 112 return owned_monitors;
iignatyev@50844 113 }
iignatyev@50844 114
iignatyev@50844 115 JNIEXPORT void JNICALL
iignatyev@50844 116 Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon0(JNIEnv *env,
iignatyev@50844 117 jclass cls, jint point, jthread thr) {
iignatyev@50844 118 getInfo(env, point, thr, 0);
iignatyev@50844 119 }
iignatyev@50844 120
iignatyev@50844 121 JNIEXPORT void JNICALL
iignatyev@50844 122 Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon1(JNIEnv *env,
iignatyev@50844 123 jclass cls, jint point, jthread thr, jobject lock) {
iignatyev@50844 124 jobject *monitors;
jcbeyler@53610 125 monitors = getInfo(env, point, thr, 1);
jcbeyler@53610 126 if (monitors == NULL) {
iignatyev@50844 127 return;
iignatyev@50844 128 }
jcbeyler@52440 129 if (!env->IsSameObject(lock, monitors[0])) {
iignatyev@50844 130 result = STATUS_FAILED;
iignatyev@50844 131 printf("Point %d: not expected monitor: 0x%p\n", point, monitors[0]);
iignatyev@50844 132 }
iignatyev@50844 133 }
iignatyev@50844 134
iignatyev@50844 135 JNIEXPORT void JNICALL
iignatyev@50844 136 Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_checkMon2(JNIEnv *env,
iignatyev@50844 137 jclass cls, jint point, jthread thr, jobject lock1, jobject lock2) {
iignatyev@50844 138 jobject *monitors;
jcbeyler@53610 139 monitors = getInfo(env, point, thr, 2);
jcbeyler@53610 140 if (monitors == NULL) {
iignatyev@50844 141 return;
iignatyev@50844 142 }
jcbeyler@52440 143 if (!env->IsSameObject(lock1, monitors[0]) && !env->IsSameObject(lock2, monitors[0])) {
iignatyev@50844 144 result = STATUS_FAILED;
iignatyev@50844 145 printf("Point %d: not expected monitor: 0x%p\n", point, monitors[0]);
iignatyev@50844 146 }
jcbeyler@52440 147 if ((!env->IsSameObject(lock1, monitors[1]) && !env->IsSameObject(lock2, monitors[1]))
jcbeyler@52440 148 || env->IsSameObject(monitors[0], monitors[1])) {
iignatyev@50844 149 result = STATUS_FAILED;
iignatyev@50844 150 printf("Point %d: not expected monitor: 0x%p\n", point, monitors[1]);
iignatyev@50844 151 }
iignatyev@50844 152 }
iignatyev@50844 153
iignatyev@50844 154 JNIEXPORT jint JNICALL
iignatyev@50844 155 Java_nsk_jvmti_GetOwnedMonitorInfo_ownmoninf001_getRes(JNIEnv *env, jclass cls) {
iignatyev@50844 156 return result;
iignatyev@50844 157 }
iignatyev@50844 158
iignatyev@50844 159 }