Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassModifiers/getclmdf005/getclmdf005.cpp
40955 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 23435#define ACC_PUBLIC 0x000136#define ACC_PRIVATE 0x000237#define ACC_PROTECTED 0x000438#define ACC_FINAL 0x001039#define ACC_INTERFACE 0x02004041static jvmtiEnv *jvmti = NULL;42static jint result = PASSED;43static jboolean printdump = JNI_FALSE;4445#ifdef STATIC_BUILD46JNIEXPORT jint JNICALL Agent_OnLoad_getclmdf005(JavaVM *jvm, char *options, void *reserved) {47return Agent_Initialize(jvm, options, reserved);48}49JNIEXPORT jint JNICALL Agent_OnAttach_getclmdf005(JavaVM *jvm, char *options, void *reserved) {50return Agent_Initialize(jvm, options, reserved);51}52JNIEXPORT jint JNI_OnLoad_getclmdf005(JavaVM *jvm, char *options, void *reserved) {53return JNI_VERSION_1_8;54}55#endif56jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {57jint res;5859if (options != NULL && strcmp(options, "printdump") == 0) {60printdump = JNI_TRUE;61}6263res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);64if (res != JNI_OK || jvmti == NULL) {65printf("Wrong result of a valid call to GetEnv!\n");66return JNI_ERR;67}6869return JNI_OK;70}7172JNIEXPORT void JNICALL73Java_nsk_jvmti_GetClassModifiers_getclmdf005_check(JNIEnv *env, jclass cls, jint i, jclass clazz) {74jvmtiError err;75jint modifiers;7677if (jvmti == NULL) {78printf("JVMTI client was not properly loaded!\n");79result = STATUS_FAILED;80return;81}8283err = jvmti->GetClassModifiers(clazz, &modifiers);84if (err != JVMTI_ERROR_NONE) {85printf("(GetClassModifiers#%d) unexpected error: %s (%d)\n",86i, TranslateError(err), err);87result = STATUS_FAILED;88return;89}9091if (printdump == JNI_TRUE) {92printf(">>> %d: 0x%0x\n", i, modifiers);93}9495if ((modifiers & ACC_PUBLIC) == 0) {96printf("(%d) ACC_PUBLIC bit should be set\n", i);97result = STATUS_FAILED;98}99100if ((modifiers & ACC_FINAL) == 0) {101printf("(%d) ACC_FINAL bit should be set\n", i);102result = STATUS_FAILED;103}104105if ((modifiers & ACC_INTERFACE) != 0) {106printf("(%d) ACC_INTERFACE bit should be clear\n", i);107result = STATUS_FAILED;108}109110if ((modifiers & ACC_PROTECTED) != 0) {111printf("(%d) ACC_PROTECTED bit should be clear\n", i);112result = STATUS_FAILED;113}114115if ((modifiers & ACC_PRIVATE) != 0) {116printf("(%d) ACC_PRIVATE bit should be clear\n", i);117result = STATUS_FAILED;118}119}120121JNIEXPORT int JNICALL Java_nsk_jvmti_GetClassModifiers_getclmdf005_getRes(JNIEnv *env, jclass cls) {122return result;123}124125}126127128