Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat007/getclstat007.cpp
40952 views
/*1* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include <stdio.h>24#include <string.h>25#include "jvmti.h"26#include "agent_common.h"27#include "JVMTITools.h"2829extern "C" {303132#define PASSED 033#define STATUS_FAILED 23435static jvmtiEnv *jvmti = NULL;36static jint result = PASSED;37static jboolean printdump = JNI_FALSE;3839#ifdef STATIC_BUILD40JNIEXPORT jint JNICALL Agent_OnLoad_getclstat007(JavaVM *jvm, char *options, void *reserved) {41return Agent_Initialize(jvm, options, reserved);42}43JNIEXPORT jint JNICALL Agent_OnAttach_getclstat007(JavaVM *jvm, char *options, void *reserved) {44return Agent_Initialize(jvm, options, reserved);45}46JNIEXPORT jint JNI_OnLoad_getclstat007(JavaVM *jvm, char *options, void *reserved) {47return JNI_VERSION_1_8;48}49#endif50jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {51jint res;5253if (options != NULL && strcmp(options, "printdump") == 0) {54printdump = JNI_TRUE;55}5657res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);58if (res != JNI_OK || jvmti == NULL) {59printf("Wrong result of a valid call to GetEnv!\n");60return JNI_ERR;61}6263return JNI_OK;64}6566JNIEXPORT void JNICALL67Java_nsk_jvmti_GetClassStatus_getclstat007_check(JNIEnv *env, jclass cls,68jint i, jclass klass, jboolean is_array) {69jvmtiError err;70jint status;7172if (jvmti == NULL) {73printf("JVMTI client was not properly loaded!\n");74result = STATUS_FAILED;75return;76}7778err = jvmti->GetClassStatus(klass, &status);79if (err != JVMTI_ERROR_NONE) {80printf("(GetClassStatus#%d) unexpected error: %s (%d)\n",81i, TranslateError(err), err);82result = STATUS_FAILED;83return;84}8586if (printdump == JNI_TRUE) {87printf(">>> %d: 0x%0x\n", i, status);88}8990if (i == 0) {91if ((status & JVMTI_CLASS_STATUS_VERIFIED) == 0) {92printf("(%d) JVMTI_CLASS_STATUS_VERIFIED bit should be set\n", i);93result = STATUS_FAILED;94}95if ((status & JVMTI_CLASS_STATUS_PREPARED) == 0) {96printf("(%d) JVMTI_CLASS_STATUS_PREPARED bit should be set\n", i);97result = STATUS_FAILED;98}99if ((status & JVMTI_CLASS_STATUS_INITIALIZED) == 0) {100printf("(%d) JVMTI_CLASS_STATUS_INITIALIZED bit should be set\n", i);101result = STATUS_FAILED;102}103if ((status & JVMTI_CLASS_STATUS_ERROR) != 0) {104printf("(%d) JVMTI_CLASS_STATUS_ERROR bit should be clear\n", i);105result = STATUS_FAILED;106}107if ((status & JVMTI_CLASS_STATUS_ARRAY) != 0) {108printf("(%d) JVMTI_CLASS_STATUS_ARRAY bit should be clear\n", i);109result = STATUS_FAILED;110}111if ((status & JVMTI_CLASS_STATUS_PRIMITIVE) != 0) {112printf("(%d) JVMTI_CLASS_STATUS_PRIMITIVEbit should be clear\n", i);113result = STATUS_FAILED;114}115} else if (is_array == JNI_TRUE) {116if ((status & JVMTI_CLASS_STATUS_ARRAY) == 0) {117printf("(%d) JVMTI_CLASS_STATUS_ARRAY bit should be set\n", i);118result = STATUS_FAILED;119}120if ((status & (~JVMTI_CLASS_STATUS_ARRAY)) != 0) {121printf("(%d) not JVMTI_CLASS_STATUS_ARRAY bits should be clear: 0x%0x\n",122i, status);123result = STATUS_FAILED;124}125} else {126if ((status & JVMTI_CLASS_STATUS_PRIMITIVE) == 0) {127printf("(%d) JVMTI_CLASS_STATUS_PRIMITIVE bit should be set\n", i);128result = STATUS_FAILED;129}130if ((status & (~JVMTI_CLASS_STATUS_PRIMITIVE)) != 0) {131printf("(%d) not JVMTI_CLASS_STATUS_PRIMITIVE bits should be clear: 0x%0x\n",132i, status);133result = STATUS_FAILED;134}135}136}137138JNIEXPORT int JNICALL139Java_nsk_jvmti_GetClassStatus_getclstat007_getRes(JNIEnv *env, jclass cls) {140return result;141}142143}144145146