Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/j9vm/vmi.c
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2002, 2019 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
* @brief This file contains implementations of the Sun VM interface (JVM_ functions)
25
* which simply forward to a concrete implementation located either in the JCL library
26
* or proxy forwarder.
27
*/
28
29
#include <stdlib.h>
30
#include "j9.h"
31
#include "sunvmi_api.h"
32
33
#include "../util/ut_module.h"
34
#undef UT_MODULE_LOADED
35
#undef UT_MODULE_UNLOADED
36
#define _UTE_STATIC_
37
#include "ut_j9scar.h"
38
39
extern J9JavaVM *BFUjavaVM;
40
SunVMI* g_VMI;
41
42
/**
43
* Initializes the VM-interface from the supplied JNIEnv.
44
*
45
*/
46
void
47
initializeVMI(void)
48
{
49
PORT_ACCESS_FROM_JAVAVM(BFUjavaVM);
50
jint result;
51
52
/* Register this module with trace */
53
UT_MODULE_LOADED(J9_UTINTERFACE_FROM_VM(BFUjavaVM));
54
Trc_SC_VMInitStages_Event1(BFUjavaVM->mainThread);
55
result = (BFUjavaVM)->internalVMFunctions->GetEnv((JavaVM*)BFUjavaVM, (void**)&g_VMI, SUNVMI_VERSION_1_1);
56
if (result != JNI_OK) {
57
j9tty_printf(PORTLIB, "FATAL ERROR: Could not obtain SUNVMI from VM.\n");
58
exit(-1);
59
}
60
}
61
62
jobject JNICALL
63
JVM_LatestUserDefinedLoader(JNIEnv *env)
64
{
65
ENSURE_VMI();
66
return g_VMI->JVM_LatestUserDefinedLoader(env);
67
}
68
69
70
jobject JNICALL
71
#if JAVA_SPEC_VERSION >= 11
72
JVM_GetCallerClass(JNIEnv *env)
73
#else /* JAVA_SPEC_VERSION >= 11 */
74
JVM_GetCallerClass(JNIEnv *env, jint depth)
75
#endif /* JAVA_SPEC_VERSION >= 11 */
76
{
77
ENSURE_VMI();
78
#if JAVA_SPEC_VERSION >= 11
79
return g_VMI->JVM_GetCallerClass(env);
80
#else /* JAVA_SPEC_VERSION >= 11 */
81
return g_VMI->JVM_GetCallerClass(env, depth);
82
#endif /* JAVA_SPEC_VERSION >= 11 */
83
}
84
85
86
jobject JNICALL
87
JVM_NewInstanceFromConstructor(JNIEnv * env, jobject c, jobjectArray args)
88
{
89
ENSURE_VMI();
90
return g_VMI->JVM_NewInstanceFromConstructor(env, c, args);
91
}
92
93
94
jobject JNICALL
95
JVM_InvokeMethod(JNIEnv * env, jobject method, jobject obj, jobjectArray args)
96
{
97
ENSURE_VMI();
98
return g_VMI->JVM_InvokeMethod(env, method, obj, args);
99
}
100
101
102
jint JNICALL
103
JVM_GetClassAccessFlags(JNIEnv * env, jclass clazzRef)
104
{
105
ENSURE_VMI();
106
return g_VMI->JVM_GetClassAccessFlags(env, clazzRef);
107
}
108
109
110
jobject JNICALL
111
JVM_GetClassContext(JNIEnv *env)
112
{
113
ENSURE_VMI();
114
return g_VMI->JVM_GetClassContext(env);
115
}
116
117
118
void JNICALL
119
JVM_Halt(jint exitCode)
120
{
121
ENSURE_VMI();
122
g_VMI->JVM_Halt(exitCode);
123
}
124
125
126
void JNICALL
127
JVM_GCNoCompact(void)
128
{
129
ENSURE_VMI();
130
g_VMI->JVM_GCNoCompact();
131
}
132
133
134
void JNICALL
135
JVM_GC(void)
136
{
137
ENSURE_VMI();
138
g_VMI->JVM_GC();
139
}
140
141
142
/**
143
* JVM_TotalMemory
144
*/
145
jlong JNICALL
146
JVM_TotalMemory(void)
147
{
148
ENSURE_VMI();
149
return g_VMI->JVM_TotalMemory();
150
}
151
152
153
jlong JNICALL
154
JVM_FreeMemory(void)
155
{
156
ENSURE_VMI();
157
return g_VMI->JVM_FreeMemory();
158
}
159
160
161
jobject JNICALL
162
JVM_GetSystemPackages(JNIEnv* env)
163
{
164
ENSURE_VMI();
165
return g_VMI->JVM_GetSystemPackages(env);
166
}
167
168
169
/**
170
* Returns the package information for the specified package name. Package information is the directory or
171
* jar file name from where the package was loaded (separator is to be '/' and for a directory the return string is
172
* to end with a '/' character). If the package is not loaded then null is to be returned.
173
*
174
* @arg[in] env - JNI environment.
175
* @arg[in] pkgName - A Java string for the name of a package. The package must be separated with '/' and optionally end with a '/' character.
176
*
177
* @return Package information as a string.
178
*
179
* @note In the current implementation, the separator is not guaranteed to be '/', not is a directory guaranteed to be
180
* terminated with a slash. It is also unclear what the expected implementation is for UNC paths.
181
*
182
* @note see CMVC defects 81175 and 92979
183
*/
184
jstring JNICALL
185
JVM_GetSystemPackage(JNIEnv* env, jstring pkgName)
186
{
187
ENSURE_VMI();
188
return g_VMI->JVM_GetSystemPackage(env, pkgName);
189
}
190
191
192
jobject JNICALL
193
JVM_AllocateNewObject(JNIEnv *env, jclass caller, jclass current, jclass init)
194
{
195
ENSURE_VMI();
196
return g_VMI->JVM_AllocateNewObject(env, caller, current, init);
197
}
198
199
200
jobject JNICALL
201
JVM_AllocateNewArray(JNIEnv *env, jclass caller, jclass current, jint length)
202
{
203
ENSURE_VMI();
204
return g_VMI->JVM_AllocateNewArray(env, caller, current, length);
205
}
206
207
208
jobject JNICALL
209
JVM_GetClassLoader(JNIEnv *env, jobject obj)
210
{
211
ENSURE_VMI();
212
return g_VMI->JVM_GetClassLoader(env, obj);
213
}
214
215
216
void* JNICALL
217
JVM_GetThreadInterruptEvent(void)
218
{
219
ENSURE_VMI();
220
return g_VMI->JVM_GetThreadInterruptEvent();
221
}
222
223
224
jlong JNICALL
225
JVM_MaxObjectInspectionAge(void)
226
{
227
ENSURE_VMI();
228
return g_VMI->JVM_MaxObjectInspectionAge();
229
}
230
231
jlong JNICALL
232
JVM_MaxMemory(void) {
233
ENSURE_VMI();
234
return g_VMI->JVM_MaxMemory();
235
}
236
237