Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassStatus/getclstat006/getclstat006.cpp
40951 views
/*1* Copyright (c) 2003, 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 23435typedef struct {36jint value;37const char *name;38} bit_info;3940static jvmtiEnv *jvmti = NULL;41static jint result = PASSED;42static jboolean printdump = JNI_FALSE;43static bit_info bits[] = {44{ JVMTI_CLASS_STATUS_INITIALIZED, "JVMTI_CLASS_STATUS_INITIALIZED" },45{ JVMTI_CLASS_STATUS_ERROR, "JVMTI_CLASS_STATUS_ERROR" }46};4748#ifdef STATIC_BUILD49JNIEXPORT jint JNICALL Agent_OnLoad_getclstat006(JavaVM *jvm, char *options, void *reserved) {50return Agent_Initialize(jvm, options, reserved);51}52JNIEXPORT jint JNICALL Agent_OnAttach_getclstat006(JavaVM *jvm, char *options, void *reserved) {53return Agent_Initialize(jvm, options, reserved);54}55JNIEXPORT jint JNI_OnLoad_getclstat006(JavaVM *jvm, char *options, void *reserved) {56return JNI_VERSION_1_8;57}58#endif59jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {60jint res;6162if (options != NULL && strcmp(options, "printdump") == 0) {63printdump = JNI_TRUE;64}6566res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);67if (res != JNI_OK || jvmti == NULL) {68printf("Wrong result of a valid call to GetEnv!\n");69return JNI_ERR;70}7172return JNI_OK;73}7475JNIEXPORT void JNICALL76Java_nsk_jvmti_GetClassStatus_getclstat006_check(JNIEnv *env, jclass cls, jint i, jclass clazz) {77jvmtiError err;78jint status;7980if (jvmti == NULL) {81printf("JVMTI client was not properly loaded!\n");82result = STATUS_FAILED;83return;84}8586err = jvmti->GetClassStatus(clazz, &status);87if (err != JVMTI_ERROR_NONE) {88printf("(GetClassStatus#%d) unexpected error: %s (%d)\n",89i, TranslateError(err), err);90result = STATUS_FAILED;91return;92}9394if (printdump == JNI_TRUE) {95printf(">>> %d: status = 0x%0x\n", i, status);96}9798if ((status & bits[i].value) == 0) {99printf("(%d) %s bit not set\n", i, bits[i].name);100result = STATUS_FAILED;101}102}103104JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassStatus_getclstat006_getRes(JNIEnv *env, jclass cls) {105return result;106}107108}109110111