Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/j9vm/javanextvmi.c
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2018, 2022 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
#include <assert.h>
23
#include <jni.h>
24
25
#include "bcverify_api.h"
26
#include "j9.h"
27
#include "j9cfg.h"
28
#include "rommeth.h"
29
#include "ut_j9scar.h"
30
31
/* Define for debug
32
#define DEBUG_BCV
33
*/
34
35
#if JAVA_SPEC_VERSION >= 16
36
JNIEXPORT void JNICALL
37
JVM_DefineArchivedModules(JNIEnv *env, jobject obj1, jobject obj2)
38
{
39
assert(!"JVM_DefineArchivedModules unimplemented");
40
}
41
42
JNIEXPORT void JNICALL
43
JVM_LogLambdaFormInvoker(JNIEnv *env, jstring str)
44
{
45
assert(!"JVM_LogLambdaFormInvoker unimplemented");
46
}
47
48
JNIEXPORT jboolean JNICALL
49
JVM_IsDumpingClassList(JNIEnv *env)
50
{
51
return JNI_FALSE;
52
}
53
#endif /* JAVA_SPEC_VERSION >= 16 */
54
55
#if JAVA_SPEC_VERSION >= 11
56
JNIEXPORT void JNICALL
57
JVM_InitializeFromArchive(JNIEnv *env, jclass clz)
58
{
59
/* A no-op implementation is ok. */
60
}
61
#endif /* JAVA_SPEC_VERSION >= 11 */
62
63
#if JAVA_SPEC_VERSION >= 14
64
typedef struct GetStackTraceElementUserData {
65
J9ROMClass *romClass;
66
J9ROMMethod *romMethod;
67
UDATA bytecodeOffset;
68
} GetStackTraceElementUserData;
69
70
static UDATA
71
getStackTraceElementIterator(J9VMThread *vmThread, void *voidUserData, UDATA bytecodeOffset, J9ROMClass *romClass, J9ROMMethod *romMethod, J9UTF8 *fileName, UDATA lineNumber, J9ClassLoader *classLoader, J9Class* ramClass)
72
{
73
UDATA result = J9_STACKWALK_STOP_ITERATING;
74
75
if ((NULL != romMethod)
76
&& J9_ARE_ALL_BITS_SET(romMethod->modifiers, J9AccMethodFrameIteratorSkip)
77
) {
78
/* Skip methods with java.lang.invoke.FrameIteratorSkip / jdk.internal.vm.annotation.Hidden / java.lang.invoke.LambdaForm$Hidden annotation */
79
result = J9_STACKWALK_KEEP_ITERATING;
80
} else {
81
GetStackTraceElementUserData *userData = voidUserData;
82
83
/* We are done, first non-hidden stack frame is found. */
84
userData->romClass = romClass;
85
userData->romMethod = romMethod;
86
userData->bytecodeOffset = bytecodeOffset;
87
}
88
return result;
89
}
90
91
#if defined(DEBUG_BCV)
92
static void cfdumpBytecodePrintFunction(void *userData, char *format, ...)
93
{
94
PORT_ACCESS_FROM_PORT((J9PortLibrary*)userData);
95
va_list args;
96
char outputBuffer[512] = {0};
97
98
va_start(args, format);
99
j9str_vprintf(outputBuffer, 512, format, args);
100
va_end(args);
101
j9tty_printf(PORTLIB, "%s", outputBuffer);
102
}
103
#endif /* defined(DEBUG_BCV) */
104
105
JNIEXPORT jstring JNICALL
106
JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwableObj)
107
{
108
J9VMThread *vmThread = (J9VMThread *)env;
109
J9JavaVM *vm = vmThread->javaVM;
110
jobject msgObjectRef = NULL;
111
112
Trc_SC_GetExtendedNPEMessage_Entry(vmThread, throwableObj);
113
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_SHOW_EXTENDED_NPEMSG)) {
114
J9InternalVMFunctions const * const vmFuncs = vm->internalVMFunctions;
115
char *npeMsg = NULL;
116
GetStackTraceElementUserData userData = {0};
117
118
Trc_SC_GetExtendedNPEMessage_Entry2(vmThread, throwableObj);
119
vmFuncs->internalEnterVMFromJNI(vmThread);
120
userData.bytecodeOffset = UDATA_MAX;
121
vmFuncs->iterateStackTrace(vmThread, (j9object_t*)throwableObj, getStackTraceElementIterator, &userData, TRUE);
122
if ((NULL != userData.romClass)
123
&& (NULL != userData.romMethod)
124
&& (UDATA_MAX != userData.bytecodeOffset)
125
) {
126
PORT_ACCESS_FROM_VMC(vmThread);
127
J9NPEMessageData npeMsgData = {0};
128
#if defined(DEBUG_BCV)
129
{
130
U_8 *bytecodes = J9_BYTECODE_START_FROM_ROM_METHOD(userData.romMethod);
131
U_32 flags = 0;
132
133
#if defined(J9VM_ENV_LITTLE_ENDIAN)
134
flags |= BCT_LittleEndianOutput;
135
#else /* defined(J9VM_ENV_LITTLE_ENDIAN) */
136
flags |= BCT_BigEndianOutput;
137
#endif /* defined(J9VM_ENV_LITTLE_ENDIAN) */
138
j9bcutil_dumpBytecodes(PORTLIB, userData.romClass, bytecodes, 0, userData.bytecodeOffset, flags, (void *)cfdumpBytecodePrintFunction, PORTLIB, "");
139
}
140
#endif /* defined(DEBUG_BCV) */
141
npeMsgData.npePC = userData.bytecodeOffset;
142
npeMsgData.vmThread = vmThread;
143
npeMsgData.romClass = userData.romClass;
144
npeMsgData.romMethod = userData.romMethod;
145
npeMsg = vmFuncs->getNPEMessage(&npeMsgData);
146
if (NULL != npeMsg) {
147
j9object_t msgObject = vm->memoryManagerFunctions->j9gc_createJavaLangString(vmThread, (U_8 *)npeMsg, strlen(npeMsg), 0);
148
if (NULL != msgObject) {
149
msgObjectRef = vmFuncs->j9jni_createLocalRef(env, msgObject);
150
}
151
j9mem_free_memory(npeMsg);
152
}
153
} else {
154
Trc_SC_GetExtendedNPEMessage_Null_NPE_MSG(vmThread, userData.romClass, userData.romMethod, userData.bytecodeOffset);
155
}
156
vmFuncs->internalExitVMToJNI(vmThread);
157
}
158
Trc_SC_GetExtendedNPEMessage_Exit(vmThread, msgObjectRef);
159
160
return msgObjectRef;
161
}
162
#endif /* JAVA_SPEC_VERSION >= 14 */
163
164
#if JAVA_SPEC_VERSION >= 17
165
JNIEXPORT void JNICALL
166
JVM_DumpClassListToFile(JNIEnv *env, jstring str)
167
{
168
assert(!"JVM_DumpClassListToFile unimplemented");
169
}
170
171
JNIEXPORT void JNICALL
172
JVM_DumpDynamicArchive(JNIEnv *env, jstring str)
173
{
174
assert(!"JVM_DumpDynamicArchive unimplemented");
175
}
176
#endif /* JAVA_SPEC_VERSION >= 17 */
177
178
#if JAVA_SPEC_VERSION >= 18
179
JNIEXPORT jboolean JNICALL
180
JVM_IsFinalizationEnabled(JNIEnv *env)
181
{
182
jboolean isFinalizationEnabled = JNI_TRUE;
183
J9VMThread *currentThread = (J9VMThread*)env;
184
if (J9_ARE_ANY_BITS_SET(currentThread->javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_DISABLE_FINALIZATION)) {
185
isFinalizationEnabled = JNI_FALSE;
186
}
187
return isFinalizationEnabled;
188
}
189
190
JNIEXPORT void JNICALL
191
JVM_ReportFinalizationComplete(JNIEnv *env, jobject obj)
192
{
193
assert(!"JVM_ReportFinalizationComplete unimplemented");
194
}
195
#endif /* JAVA_SPEC_VERSION >= 18 */
196
197
#if JAVA_SPEC_VERSION >= 19
198
JNIEXPORT void JNICALL
199
JVM_LoadZipLibrary(void)
200
{
201
assert(!"JVM_LoadZipLibrary unimplemented");
202
}
203
#endif /* JAVA_SPEC_VERSION >= 18 */
204
205