Path: blob/master/test/jdk/java/lang/ClassLoader/nativeLibrary/libnativeLibraryTest.c
41153 views
/*1* Copyright (c) 2017, 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 <stdlib.h>2526#include "jni.h"2728static jint count = 0;29static jclass test_class;30static jint current_jni_version = JNI_VERSION_10;3132JNIEXPORT jint JNICALL33JNI_OnLoad(JavaVM *vm, void *reserved) {34JNIEnv *env;35jclass cl;3637(*vm)->GetEnv(vm, (void **) &env, current_jni_version);3839cl = (*env)->FindClass(env, "NativeLibraryTest");40test_class = (*env)->NewGlobalRef(env, cl);4142// increment the count when JNI_OnLoad is called43count++;4445return current_jni_version;46}4748JNIEXPORT void JNICALL49JNI_OnUnload(JavaVM *vm, void *reserved) {50JNIEnv *env;51jmethodID mid;52jclass cl;5354(*vm)->GetEnv(vm, (void **) &env, current_jni_version);55mid = (*env)->GetStaticMethodID(env, test_class, "nativeLibraryUnloaded", "()V");56(*env)->CallStaticVoidMethod(env, test_class, mid);57if ((*env)->ExceptionCheck(env)) {58(*env)->ExceptionDescribe(env);59(*env)->FatalError(env, "Exception thrown");60}6162cl = (*env)->FindClass(env, "p/Test");63if (cl != NULL) {64(*env)->FatalError(env, "p/Test class should not be found");65}66}6768JNIEXPORT jint JNICALL69Java_p_Test_count70(JNIEnv *env, jclass cls) {71return count;72}737475