Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/log.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 1998, 2018 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
#include "jni.h"
24
#include "j9.h"
25
#include "j9port.h"
26
#include "jvmti.h"
27
#include "jvmtinls.h"
28
#include "jclprots.h"
29
30
#define LOG_OPTION_DATA_SIZE 256
31
32
static void raiseException(JNIEnv *env, const char *type, U_32 moduleNumber, U_32 messageNumber, const char *message);
33
34
/*
35
* QueryImpl
36
*
37
* Returns a string representation of the log flags.
38
*/
39
jstring JNICALL
40
Java_com_ibm_jvm_Log_QueryOptionsImpl(JNIEnv *env, jclass clazz)
41
{
42
J9VMThread *thr = (J9VMThread *)env;
43
J9JavaVM *vm = thr->javaVM;
44
I_32 bufferSize = 0;
45
jstring options = NULL;
46
char *nativeOptions = NULL;
47
UDATA rc = 0;
48
PORT_ACCESS_FROM_JAVAVM(vm);
49
50
/* allocate enough memory for the options string */
51
nativeOptions = j9mem_allocate_memory(LOG_OPTION_DATA_SIZE, J9MEM_CATEGORY_VM_JCL);
52
if (NULL == nativeOptions) {
53
vm->internalVMFunctions->throwNativeOOMError(env, 0, 0);
54
return NULL;
55
}
56
57
/* retrieve options string */
58
rc = vm->internalVMFunctions->queryLogOptions(vm, LOG_OPTION_DATA_SIZE, (void *)nativeOptions, &bufferSize);
59
if (JVMTI_ERROR_NONE != rc) {
60
raiseException(env, "java/lang/RuntimeException", J9NLS_JVMTI_COM_IBM_LOG_QUERY_OPT_ERROR,
61
"Could not query JVM log options");
62
j9mem_free_memory(nativeOptions);
63
return NULL;
64
}
65
66
/* convert native string to Unicode jstring */
67
options = (*env)->NewStringUTF(env, nativeOptions);
68
69
/* free now, as we always need to independent of return value of previous call */
70
j9mem_free_memory(nativeOptions);
71
72
if (NULL == options) {
73
raiseException(env, "java/lang/RuntimeException", J9NLS_JVMTI_COM_IBM_LOG_NATIVE_STRING_ERROR,
74
"Could not convert JVM log options native string");
75
}
76
77
return options;
78
}
79
80
/*
81
* SetImpl
82
*
83
* Sets the log flags.
84
*/
85
jint JNICALL
86
Java_com_ibm_jvm_Log_SetOptionsImpl(JNIEnv *env, jclass clazz, jstring options)
87
{
88
J9VMThread *thr = (J9VMThread *)env;
89
J9JavaVM *vm = thr->javaVM;
90
const char *nativeOptions = NULL;
91
UDATA rc = 0;
92
93
/* convert options into a char * */
94
nativeOptions = (*env)->GetStringUTFChars(env, options, 0);
95
if (NULL == nativeOptions) {
96
return JNI_ERR;
97
}
98
99
rc = vm->internalVMFunctions->setLogOptions(vm, (char *)nativeOptions);
100
(*env)->ReleaseStringUTFChars(env, options, nativeOptions);
101
102
if (JVMTI_ERROR_NONE != rc) {
103
raiseException(env, "java/lang/RuntimeException", J9NLS_JVMTI_COM_IBM_LOG_SET_OPT_ERROR,
104
"Could not set JVM log options");
105
return JNI_ERR;
106
}
107
108
return JNI_OK;
109
}
110
111
/* Wrapper for throwing an error */
112
static void
113
raiseException(JNIEnv *env, const char *type, U_32 moduleNumber, U_32 messageNumber, const char *message)
114
{
115
const char *nlsMessage = NULL;
116
jclass exceptionClass = (*env)->FindClass(env, type);
117
PORT_ACCESS_FROM_ENV(env);
118
119
nlsMessage = OMRPORT_FROM_J9PORT(PORTLIB)->nls_lookup_message(OMRPORT_FROM_J9PORT(PORTLIB), J9NLS_ERROR, moduleNumber, messageNumber, message);
120
if (NULL == exceptionClass) {
121
/* Did what we could */
122
return;
123
}
124
(*env)->ThrowNew(env, exceptionClass, nlsMessage);
125
}
126
127