Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassSignature/getclsig005/getclsig005.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 234#define CLASS_SIGNATURE "Lnsk/jvmti/GetClassSignature/getclsig005;"3536static jvmtiEnv *jvmti = NULL;37static jint result = PASSED;38static jboolean printdump = JNI_FALSE;3940#ifdef STATIC_BUILD41JNIEXPORT jint JNICALL Agent_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) {42return Agent_Initialize(jvm, options, reserved);43}44JNIEXPORT jint JNICALL Agent_OnAttach_getclsig005(JavaVM *jvm, char *options, void *reserved) {45return Agent_Initialize(jvm, options, reserved);46}47JNIEXPORT jint JNI_OnLoad_getclsig005(JavaVM *jvm, char *options, void *reserved) {48return JNI_VERSION_1_8;49}50#endif51jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {52jint res;5354if (options != NULL && strcmp(options, "printdump") == 0) {55printdump = JNI_TRUE;56}5758res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);59if (res != JNI_OK || jvmti == NULL) {60printf("Wrong result of a valid call to GetEnv!\n");61return JNI_ERR;62}6364return JNI_OK;65}6667JNIEXPORT jint JNICALL68Java_nsk_jvmti_GetClassSignature_getclsig005_check(JNIEnv *env, jclass cls) {69jvmtiError err;70char *sig, *generic;7172if (jvmti == NULL) {73printf("JVMTI client was not properly loaded!\n");74return STATUS_FAILED;75}7677if (printdump == JNI_TRUE) {78printf(">>> invalid class check ...\n");79}80err = jvmti->GetClassSignature(NULL, &sig, &generic);81if (err != JVMTI_ERROR_INVALID_CLASS) {82printf("Error expected: JVMTI_ERROR_INVALID_CLASS,\n");83printf("\tactual: %s (%d)\n", TranslateError(err), err);84result = STATUS_FAILED;85}8687if (printdump == JNI_TRUE) {88printf(">>> (signature_ptr) null pointer check ...\n");89}90err = jvmti->GetClassSignature(cls, NULL, &generic);91if (err != JVMTI_ERROR_NONE) {92printf("(signature_ptr) unexpected error: %s (%d)\n",93TranslateError(err), err);94result = STATUS_FAILED;95} else {96if (printdump == JNI_TRUE) {97printf(">>> generic = \"%s\"\n", generic);98}99}100101if (printdump == JNI_TRUE) {102printf(">>> (generic_ptr) null pointer check ...\n");103}104err = jvmti->GetClassSignature(cls, &sig, NULL);105if (err != JVMTI_ERROR_NONE) {106printf("(generic_ptr) unexpected error: %s (%d)\n",107TranslateError(err), err);108result = STATUS_FAILED;109} else {110if (printdump == JNI_TRUE) {111printf(">>> sig = \"%s\"\n", sig);112}113if (sig == NULL || strcmp(sig, CLASS_SIGNATURE) != 0) {114printf("Wrong class sig: \"%s\", expected: \"%s\"\n",115CLASS_SIGNATURE, sig);116result = STATUS_FAILED;117}118}119120if (printdump == JNI_TRUE) {121printf(">>> ... done\n");122}123124return result;125}126127}128129130