Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetClassLoaderClasses/clsldrclss001/clsldrclss001.cpp
40955 views
/*1* Copyright (c) 2003, 2020, 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;3839#ifdef STATIC_BUILD40JNIEXPORT jint JNICALL Agent_OnLoad_clsldrclss001(JavaVM *jvm, char *options, void *reserved) {41return Agent_Initialize(jvm, options, reserved);42}43JNIEXPORT jint JNICALL Agent_OnAttach_clsldrclss001(JavaVM *jvm, char *options, void *reserved) {44return Agent_Initialize(jvm, options, reserved);45}46JNIEXPORT jint JNI_OnLoad_clsldrclss001(JavaVM *jvm, char *options, void *reserved) {47return JNI_VERSION_1_8;48}49#endif50jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {51jint res;5253if (options != NULL && strcmp(options, "printdump") == 0) {54printdump = JNI_TRUE;55}5657res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);58if (res != JNI_OK || jvmti == NULL) {59printf("Wrong result of a valid call to GetEnv!\n");60return JNI_ERR;61}6263return JNI_OK;64}6566JNIEXPORT jint JNICALL67Java_nsk_jvmti_GetClassLoaderClasses_clsldrclss001_check(JNIEnv *env, jclass cls) {68jvmtiError err;69jobject classloader;70jclass *classes;71jint classCount;7273if (jvmti == NULL) {74printf("JVMTI client was not properly loaded!\n");75return STATUS_FAILED;76}7778err = jvmti->GetClassLoader(cls, &classloader);79if (err != JVMTI_ERROR_NONE) {80printf("(GetClassLoader) unexpected error: %s (%d)\n",81TranslateError(err), err);82result = STATUS_FAILED;83return STATUS_FAILED;84}8586if (printdump == JNI_TRUE) {87printf(">>> (initiatingLoader) null pointer check ...\n");88}89err = jvmti->GetClassLoaderClasses(NULL, &classCount, &classes);90if (err == JVMTI_ERROR_NULL_POINTER) {91printf("Expected: the classes initiated by the bootstrap loader,\n");92printf("\tactual: %s (%d)\n", TranslateError(err), err);93result = STATUS_FAILED;94}9596if (printdump == JNI_TRUE) {97printf(">>> (classCountPtr) null pointer check ...\n");98}99err = jvmti->GetClassLoaderClasses(classloader, NULL, &classes);100if (err != JVMTI_ERROR_NULL_POINTER) {101printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");102printf("\tactual: %s (%d)\n", TranslateError(err), err);103result = STATUS_FAILED;104}105106if (printdump == JNI_TRUE) {107printf(">>> (classesPtr) null pointer check ...\n");108}109err = jvmti->GetClassLoaderClasses(classloader, &classCount, NULL);110if (err != JVMTI_ERROR_NULL_POINTER) {111printf("Error expected: JVMTI_ERROR_NULL_POINTER,\n");112printf("\tactual: %s (%d)\n", TranslateError(err), err);113result = STATUS_FAILED;114}115116if (printdump == JNI_TRUE) {117printf(">>> ... done\n");118}119120return result;121}122123}124125126