Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/management/DiagnosticCommandImpl.c
38829 views
1
/*
2
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include <stdlib.h>
27
#include <jni.h>
28
#include "management.h"
29
#include "sun_management_DiagnosticCommandImpl.h"
30
31
JNIEXPORT void JNICALL Java_sun_management_DiagnosticCommandImpl_setNotificationEnabled
32
(JNIEnv *env, jobject dummy, jboolean enabled) {
33
if (jmm_version <= JMM_VERSION_1_2_2) {
34
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
35
"JMX interface to diagnostic framework notifications is not supported by this VM");
36
return;
37
}
38
jmm_interface->SetDiagnosticFrameworkNotificationEnabled(env, enabled);
39
}
40
41
JNIEXPORT jobjectArray JNICALL
42
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommands
43
(JNIEnv *env, jobject dummy)
44
{
45
return jmm_interface->GetDiagnosticCommands(env);
46
}
47
48
jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
49
int num_arg) {
50
int i;
51
jobject obj;
52
jobjectArray result;
53
dcmdArgInfo* dcmd_arg_info_array;
54
jclass dcmdArgInfoCls;
55
jclass arraysCls;
56
jmethodID mid;
57
jobject resultList;
58
59
dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo));
60
/* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */
61
if (dcmd_arg_info_array == NULL && num_arg != 0) {
62
return NULL;
63
}
64
jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command,
65
dcmd_arg_info_array);
66
dcmdArgInfoCls = (*env)->FindClass(env,
67
"sun/management/DiagnosticCommandArgumentInfo");
68
result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL);
69
if (result == NULL) {
70
free(dcmd_arg_info_array);
71
return NULL;
72
}
73
for (i=0; i<num_arg; i++) {
74
obj = JNU_NewObjectByName(env,
75
"sun/management/DiagnosticCommandArgumentInfo",
76
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZI)V",
77
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].name),
78
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].description),
79
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].type),
80
dcmd_arg_info_array[i].default_string == NULL ? NULL:
81
(*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string),
82
dcmd_arg_info_array[i].mandatory,
83
dcmd_arg_info_array[i].option,
84
dcmd_arg_info_array[i].multiple,
85
dcmd_arg_info_array[i].position);
86
if (obj == NULL) {
87
free(dcmd_arg_info_array);
88
return NULL;
89
}
90
(*env)->SetObjectArrayElement(env, result, i, obj);
91
}
92
free(dcmd_arg_info_array);
93
arraysCls = (*env)->FindClass(env, "java/util/Arrays");
94
mid = (*env)->GetStaticMethodID(env, arraysCls,
95
"asList", "([Ljava/lang/Object;)Ljava/util/List;");
96
resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result);
97
return resultList;
98
}
99
100
/* Throws IllegalArgumentException if at least one of the diagnostic command
101
* passed in argument is not supported by the JVM
102
*/
103
JNIEXPORT jobjectArray JNICALL
104
Java_sun_management_DiagnosticCommandImpl_getDiagnosticCommandInfo
105
(JNIEnv *env, jobject dummy, jobjectArray commands)
106
{
107
int i;
108
jclass dcmdInfoCls;
109
jobject result;
110
jobjectArray args;
111
jobject obj;
112
jmmOptionalSupport mos;
113
jint ret = jmm_interface->GetOptionalSupport(env, &mos);
114
jsize num_commands;
115
dcmdInfo* dcmd_info_array;
116
117
if (commands == NULL) {
118
JNU_ThrowNullPointerException(env, "Invalid String Array");
119
return NULL;
120
}
121
num_commands = (*env)->GetArrayLength(env, commands);
122
dcmdInfoCls = (*env)->FindClass(env,
123
"sun/management/DiagnosticCommandInfo");
124
result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL);
125
if (result == NULL) {
126
JNU_ThrowOutOfMemoryError(env, 0);
127
return NULL;
128
}
129
if (num_commands == 0) {
130
/* Handle the 'zero commands' case specially to avoid calling 'malloc()' */
131
/* with a zero argument because that may legally return a NULL pointer. */
132
return result;
133
}
134
dcmd_info_array = (dcmdInfo*) malloc(num_commands * sizeof(dcmdInfo));
135
if (dcmd_info_array == NULL) {
136
JNU_ThrowOutOfMemoryError(env, NULL);
137
return NULL;
138
}
139
jmm_interface->GetDiagnosticCommandInfo(env, commands, dcmd_info_array);
140
for (i=0; i<num_commands; i++) {
141
args = getDiagnosticCommandArgumentInfoArray(env,
142
(*env)->GetObjectArrayElement(env,commands,i),
143
dcmd_info_array[i].num_arguments);
144
if (args == NULL) {
145
free(dcmd_info_array);
146
JNU_ThrowOutOfMemoryError(env, 0);
147
return NULL;
148
}
149
obj = JNU_NewObjectByName(env,
150
"sun/management/DiagnosticCommandInfo",
151
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V",
152
(*env)->NewStringUTF(env,dcmd_info_array[i].name),
153
(*env)->NewStringUTF(env,dcmd_info_array[i].description),
154
(*env)->NewStringUTF(env,dcmd_info_array[i].impact),
155
dcmd_info_array[i].permission_class==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_class),
156
dcmd_info_array[i].permission_name==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_name),
157
dcmd_info_array[i].permission_action==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_action),
158
dcmd_info_array[i].enabled,
159
args);
160
if (obj == NULL) {
161
free(dcmd_info_array);
162
JNU_ThrowOutOfMemoryError(env, 0);
163
return NULL;
164
}
165
(*env)->SetObjectArrayElement(env, result, i, obj);
166
}
167
free(dcmd_info_array);
168
return result;
169
}
170
171
/* Throws IllegalArgumentException if the diagnostic command
172
* passed in argument is not supported by the JVM
173
*/
174
JNIEXPORT jstring JNICALL
175
Java_sun_management_DiagnosticCommandImpl_executeDiagnosticCommand
176
(JNIEnv *env, jobject dummy, jstring command) {
177
return jmm_interface->ExecuteDiagnosticCommand(env, command);
178
}
179
180