Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/jclglob.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 1998, 2016 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
24
25
#include <string.h>
26
#include "jcl.h"
27
28
#include "jclglob.h"
29
#include "jcltrace.h"
30
#if defined(J9VM_PORT_OMRSIG_SUPPORT)
31
#include "omrsig.h"
32
#endif /* defined(J9VM_PORT_OMRSIG_SUPPORT) */
33
34
static UDATA keyInitCount = 0;
35
36
void * JCL_ID_CACHE = NULL;
37
38
39
40
jint handleOnLoadEvent(JavaVM * vm);
41
void *jclCachePointer( JNIEnv *env );
42
void freeHack(JNIEnv * env);
43
44
/**
45
* @internal
46
*/
47
void freeHack(JNIEnv * env)
48
{
49
jclass classRef;
50
51
/* clean up class references */
52
/* PR 116213 - remove jnicheck warnings */
53
54
classRef = JCL_CACHE_GET(env, CLS_java_lang_String);
55
if (classRef) (*env)->DeleteGlobalRef(env, (jweak) classRef);
56
57
classRef = JCL_CACHE_GET(env, CLS_java_lang_reflect_Parameter);
58
if (classRef) (*env)->DeleteGlobalRef(env, (jweak) classRef);
59
60
}
61
62
63
/**
64
* This DLL is being loaded, do any initialization required.
65
* This may be called more than once.
66
*/
67
jint JNICALL JCL_OnLoad(JavaVM * vm, void *reserved)
68
{
69
return handleOnLoadEvent(vm);
70
}
71
72
73
/**
74
* This DLL is being unloaded, do any clean up required.
75
* This may be called more than once!!
76
*/
77
void JNICALL
78
JNI_OnUnload(JavaVM * vm, void *reserved)
79
{
80
JNIEnv *env;
81
void *keyInitCountPtr = GLOBAL_DATA( keyInitCount );
82
void **jclIdCache = GLOBAL_DATA( JCL_ID_CACHE);
83
84
if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK) {
85
JniIDCache *idCache = (JniIDCache *) J9VMLS_GET(env, *jclIdCache);
86
87
if (idCache) {
88
PORT_ACCESS_FROM_ENV(env);
89
90
/* Had to move some of the code out of this function to get the IBM C compiler to generate a valid DLL */
91
freeHack(env);
92
93
/* Free VMLS keys */
94
idCache = (JniIDCache *) J9VMLS_GET(env, *jclIdCache);
95
terminateTrace(env);
96
97
J9VMLS_FNTBL(env)->J9VMLSFreeKeys(env, keyInitCountPtr, jclIdCache, NULL);
98
j9mem_free_memory(idCache);
99
}
100
}
101
}
102
103
104
/**
105
* @internal
106
* This DLL is being loaded, do any initialization required.
107
* This may be called more than once.
108
*/
109
jint handleOnLoadEvent(JavaVM * vm)
110
{
111
JniIDCache *idCache;
112
JNIEnv *env;
113
void *keyInitCountPtr = GLOBAL_DATA( keyInitCount );
114
void **jclIdCache = GLOBAL_DATA( JCL_ID_CACHE );
115
116
if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK) {
117
PORT_ACCESS_FROM_ENV(env);
118
119
if (J9VMLS_FNTBL(env)->J9VMLSAllocKeys(env, keyInitCountPtr, jclIdCache, NULL)) {
120
goto fail;
121
}
122
123
idCache = (JniIDCache *) j9mem_allocate_memory(sizeof(JniIDCache), J9MEM_CATEGORY_VM_JCL);
124
if (!idCache)
125
goto fail2;
126
127
memset(idCache, 0, sizeof(JniIDCache));
128
J9VMLS_SET(env, *jclIdCache, idCache);
129
130
return JNI_VERSION_1_2;
131
}
132
133
fail2:
134
J9VMLS_FNTBL(env)->J9VMLSFreeKeys(env, keyInitCountPtr, jclIdCache, NULL);
135
fail:
136
return 0;
137
}
138
139