Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig004/getclsig004.cpp
40952 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 23435static jvmtiEnv *jvmti = NULL;36static jint result = PASSED;37static jboolean printdump = JNI_FALSE;38static const char *sigs[] = {39"B",40"C",41"D",42"F",43"I",44"J",45"Ljava/lang/Object;",46"S",47"V",48"Z"49};5051#ifdef STATIC_BUILD52JNIEXPORT jint JNICALL Agent_OnLoad_getclsig004(JavaVM *jvm, char *options, void *reserved) {53return Agent_Initialize(jvm, options, reserved);54}55JNIEXPORT jint JNICALL Agent_OnAttach_getclsig004(JavaVM *jvm, char *options, void *reserved) {56return Agent_Initialize(jvm, options, reserved);57}58JNIEXPORT jint JNI_OnLoad_getclsig004(JavaVM *jvm, char *options, void *reserved) {59return JNI_VERSION_1_8;60}61#endif62jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {63jint res;6465if (options != NULL && strcmp(options, "printdump") == 0) {66printdump = JNI_TRUE;67}6869res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);70if (res != JNI_OK || jvmti == NULL) {71printf("Wrong result of a valid call to GetEnv!\n");72return JNI_ERR;73}7475return JNI_OK;76}7778JNIEXPORT void JNICALL79Java_nsk_jvmti_GetClassSignature_getclsig004_check(JNIEnv *env,80jclass cls, jint i, jclass clazz) {81jvmtiError err;82char *sig, *generic;8384if (jvmti == NULL) {85printf("JVMTI client was not properly loaded!\n");86result = STATUS_FAILED;87return;88}8990err = jvmti->GetClassSignature(clazz, &sig, &generic);91if (err != JVMTI_ERROR_NONE) {92printf("(GetClassSignature#%d) unexpected error: %s (%d)\n",93i, TranslateError(err), err);94result = STATUS_FAILED;95return;96}9798if (printdump == JNI_TRUE) {99printf(">>> %d: %s\n", i, sig);100}101102if (strcmp(sig, sigs[i]) != 0) {103printf("(%d) wrong sig: \"%s\", expected: \"%s\"\n", i, sig, sigs[i]);104result = STATUS_FAILED;105}106}107108JNIEXPORT int JNICALL109Java_nsk_jvmti_GetClassSignature_getclsig004_getRes(JNIEnv *env, jclass cls) {110return result;111}112113}114115116