Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf006/getclmdf006.cpp
40955 views
/*1* Copyright (c) 2003, 2021, 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 23435#define ACC_PUBLIC 0x000136#define ACC_PRIVATE 0x000237#define ACC_PROTECTED 0x000438#define ACC_STATIC 0x000839#define ACC_FINAL 0x001040#define ACC_SUPER 0x002041#define ACC_INTERFACE 0x020042#define ACC_ABSTRACT 0x04004344static jvmtiEnv *jvmti = NULL;45static jint result = PASSED;46static jboolean printdump = JNI_FALSE;4748#ifdef STATIC_BUILD49JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf006(JavaVM *jvm, char *options, void *reserved) {50return Agent_Initialize(jvm, options, reserved);51}52JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf006(JavaVM *jvm, char *options, void *reserved) {53return Agent_Initialize(jvm, options, reserved);54}55JNIEXPORT jint JNI_OnLoad_getclmdf006(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}7475void printModifiers(jint mod) {76if (mod & ACC_PUBLIC) printf(" PUBLIC");77if (mod & ACC_PRIVATE) printf(" PRIVATE");78if (mod & ACC_PROTECTED) printf(" PROTECTED");79if (mod & ACC_STATIC) printf(" STATIC");80if (mod & ACC_FINAL) printf(" FINAL");81if (mod & ACC_SUPER) printf(" SUPER");82if (mod & ACC_INTERFACE) printf(" INTERFACE");83if (mod & ACC_ABSTRACT) printf(" ABSTRACT");84printf(" (0x%0x)\n", mod);85}8687JNIEXPORT void JNICALL88Java_nsk_jvmti_GetClassModifiers_getclmdf006_check(JNIEnv *env, jclass cls, jclass clazz, jint mod) {89jvmtiError err;90jint modifiers;9192if (jvmti == NULL) {93printf("JVMTI client was not properly loaded!\n");94result = STATUS_FAILED;95return;96}9798err = jvmti->GetClassModifiers(clazz, &modifiers);99if (err != JVMTI_ERROR_NONE) {100printf("(GetClassModifiers:0x%x) unexpected error: %s (%d)\n",101mod, TranslateError(err), err);102result = STATUS_FAILED;103return;104}105106if (printdump == JNI_TRUE) {107printf(">>>");108printModifiers(modifiers);109}110111if ((modifiers & (~ACC_SUPER)) != mod) {112printf("Access flags expected:");113printModifiers(mod);114printf("\t actual:");115printModifiers(modifiers);116result = STATUS_FAILED;117}118}119120JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf006_getRes(JNIEnv *env, jclass cls) {121return result;122}123124}125126127