Path: blob/master/runtime/jcl/common/jclglob.c
6000 views
/*******************************************************************************1* Copyright (c) 1998, 2016 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21222324#include <string.h>25#include "jcl.h"2627#include "jclglob.h"28#include "jcltrace.h"29#if defined(J9VM_PORT_OMRSIG_SUPPORT)30#include "omrsig.h"31#endif /* defined(J9VM_PORT_OMRSIG_SUPPORT) */3233static UDATA keyInitCount = 0;3435void * JCL_ID_CACHE = NULL;36373839jint handleOnLoadEvent(JavaVM * vm);40void *jclCachePointer( JNIEnv *env );41void freeHack(JNIEnv * env);4243/**44* @internal45*/46void freeHack(JNIEnv * env)47{48jclass classRef;4950/* clean up class references */51/* PR 116213 - remove jnicheck warnings */5253classRef = JCL_CACHE_GET(env, CLS_java_lang_String);54if (classRef) (*env)->DeleteGlobalRef(env, (jweak) classRef);5556classRef = JCL_CACHE_GET(env, CLS_java_lang_reflect_Parameter);57if (classRef) (*env)->DeleteGlobalRef(env, (jweak) classRef);5859}606162/**63* This DLL is being loaded, do any initialization required.64* This may be called more than once.65*/66jint JNICALL JCL_OnLoad(JavaVM * vm, void *reserved)67{68return handleOnLoadEvent(vm);69}707172/**73* This DLL is being unloaded, do any clean up required.74* This may be called more than once!!75*/76void JNICALL77JNI_OnUnload(JavaVM * vm, void *reserved)78{79JNIEnv *env;80void *keyInitCountPtr = GLOBAL_DATA( keyInitCount );81void **jclIdCache = GLOBAL_DATA( JCL_ID_CACHE);8283if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK) {84JniIDCache *idCache = (JniIDCache *) J9VMLS_GET(env, *jclIdCache);8586if (idCache) {87PORT_ACCESS_FROM_ENV(env);8889/* Had to move some of the code out of this function to get the IBM C compiler to generate a valid DLL */90freeHack(env);9192/* Free VMLS keys */93idCache = (JniIDCache *) J9VMLS_GET(env, *jclIdCache);94terminateTrace(env);9596J9VMLS_FNTBL(env)->J9VMLSFreeKeys(env, keyInitCountPtr, jclIdCache, NULL);97j9mem_free_memory(idCache);98}99}100}101102103/**104* @internal105* This DLL is being loaded, do any initialization required.106* This may be called more than once.107*/108jint handleOnLoadEvent(JavaVM * vm)109{110JniIDCache *idCache;111JNIEnv *env;112void *keyInitCountPtr = GLOBAL_DATA( keyInitCount );113void **jclIdCache = GLOBAL_DATA( JCL_ID_CACHE );114115if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK) {116PORT_ACCESS_FROM_ENV(env);117118if (J9VMLS_FNTBL(env)->J9VMLSAllocKeys(env, keyInitCountPtr, jclIdCache, NULL)) {119goto fail;120}121122idCache = (JniIDCache *) j9mem_allocate_memory(sizeof(JniIDCache), J9MEM_CATEGORY_VM_JCL);123if (!idCache)124goto fail2;125126memset(idCache, 0, sizeof(JniIDCache));127J9VMLS_SET(env, *jclIdCache, idCache);128129return JNI_VERSION_1_2;130}131132fail2:133J9VMLS_FNTBL(env)->J9VMLSFreeKeys(env, keyInitCountPtr, jclIdCache, NULL);134fail:135return 0;136}137138139