File: | jdk/src/jdk.management/share/native/libmanagement_ext/DiagnosticCommandImpl.c |
Warning: | line 154, column 8 Value stored to 'ret' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (c) 2013, 2021, 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_ext.h" |
29 | #include "com_sun_management_internal_DiagnosticCommandImpl.h" |
30 | |
31 | JNIEXPORT__attribute__((visibility("default"))) void JNICALL Java_com_sun_management_internal_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__attribute__((visibility("default"))) jobjectArray JNICALL |
42 | Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommands |
43 | (JNIEnv *env, jobject dummy) |
44 | { |
45 | return jmm_interface->GetDiagnosticCommands(env); |
46 | } |
47 | |
48 | // |
49 | // Checks for an exception and if one occurred, |
50 | // pops 'pops' local frames and frees 'x' before |
51 | // returning NULL |
52 | // |
53 | #define POP_EXCEPTION_CHECK_AND_FREE(pops, x)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < pops; i++) { (*env)->PopLocalFrame(env, ((void*)0) ); } free(x); return ((void*)0); } } while(0) do { \ |
54 | if ((*env)->ExceptionCheck(env)) { \ |
55 | int i; \ |
56 | for (i = 0; i < pops; i++) { \ |
57 | (*env)->PopLocalFrame(env, NULL((void*)0)); \ |
58 | } \ |
59 | free(x); \ |
60 | return NULL((void*)0); \ |
61 | } \ |
62 | } while(0) |
63 | |
64 | jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command, |
65 | int num_arg) { |
66 | int i; |
67 | jobject obj; |
68 | jobjectArray result; |
69 | dcmdArgInfo* dcmd_arg_info_array; |
70 | jclass dcmdArgInfoCls; |
71 | jclass arraysCls; |
72 | jmethodID mid; |
73 | jobject resultList; |
74 | |
75 | dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo)); |
76 | /* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */ |
77 | if (dcmd_arg_info_array == NULL((void*)0) && num_arg != 0) { |
78 | JNU_ThrowOutOfMemoryError(env, 0); |
79 | return NULL((void*)0); |
80 | } |
81 | jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command, |
82 | dcmd_arg_info_array, num_arg); |
83 | dcmdArgInfoCls = (*env)->FindClass(env, |
84 | "com/sun/management/internal/DiagnosticCommandArgumentInfo"); |
85 | POP_EXCEPTION_CHECK_AND_FREE(0, dcmd_arg_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 0; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_arg_info_array); return ((void*)0); } } while(0); |
86 | |
87 | result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL((void*)0)); |
88 | if (result == NULL((void*)0)) { |
89 | free(dcmd_arg_info_array); |
90 | return NULL((void*)0); |
91 | } |
92 | for (i=0; i<num_arg; i++) { |
93 | // Capacity for 5 local refs: jname, jdesc, jtype, jdefStr and obj |
94 | (*env)->PushLocalFrame(env, 5); |
95 | jstring jname, jdesc, jtype, jdefStr; |
96 | |
97 | jname = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].name); |
98 | POP_EXCEPTION_CHECK_AND_FREE(1, dcmd_arg_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 1; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_arg_info_array); return ((void*)0); } } while(0); |
99 | |
100 | jdesc = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].description); |
101 | POP_EXCEPTION_CHECK_AND_FREE(1, dcmd_arg_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 1; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_arg_info_array); return ((void*)0); } } while(0); |
102 | |
103 | jtype = (*env)->NewStringUTF(env,dcmd_arg_info_array[i].type); |
104 | POP_EXCEPTION_CHECK_AND_FREE(1, dcmd_arg_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 1; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_arg_info_array); return ((void*)0); } } while(0); |
105 | |
106 | jdefStr = (*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string); |
107 | POP_EXCEPTION_CHECK_AND_FREE(1, dcmd_arg_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 1; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_arg_info_array); return ((void*)0); } } while(0); |
108 | obj = JNU_NewObjectByName(env, |
109 | "com/sun/management/internal/DiagnosticCommandArgumentInfo", |
110 | "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZI)V", |
111 | jname, jdesc, jtype, |
112 | dcmd_arg_info_array[i].default_string == NULL((void*)0) ? NULL((void*)0): jdefStr, |
113 | dcmd_arg_info_array[i].mandatory, |
114 | dcmd_arg_info_array[i].option, |
115 | dcmd_arg_info_array[i].multiple, |
116 | dcmd_arg_info_array[i].position); |
117 | if (obj == NULL((void*)0)) { |
118 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
119 | free(dcmd_arg_info_array); |
120 | return NULL((void*)0); |
121 | } |
122 | obj = (*env)->PopLocalFrame(env, obj); |
123 | (*env)->SetObjectArrayElement(env, result, i, obj); |
124 | POP_EXCEPTION_CHECK_AND_FREE(0, dcmd_arg_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 0; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_arg_info_array); return ((void*)0); } } while(0); |
125 | } |
126 | free(dcmd_arg_info_array); |
127 | arraysCls = (*env)->FindClass(env, "java/util/Arrays"); |
128 | if ((*env)->ExceptionCheck(env)) { |
129 | return NULL((void*)0); |
130 | } |
131 | mid = (*env)->GetStaticMethodID(env, arraysCls, |
132 | "asList", "([Ljava/lang/Object;)Ljava/util/List;"); |
133 | resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result); |
134 | if ((*env)->ExceptionCheck(env)) { |
135 | // Make sure we return NULL in case of OOM inside Java |
136 | return NULL((void*)0); |
137 | } |
138 | return resultList; |
139 | } |
140 | |
141 | /* Throws IllegalArgumentException if at least one of the diagnostic command |
142 | * passed in argument is not supported by the JVM |
143 | */ |
144 | JNIEXPORT__attribute__((visibility("default"))) jobjectArray JNICALL |
145 | Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo |
146 | (JNIEnv *env, jobject dummy, jobjectArray commands) |
147 | { |
148 | int i; |
149 | jclass dcmdInfoCls; |
150 | jobject result; |
151 | jobjectArray args; |
152 | jobject obj; |
153 | jmmOptionalSupport mos; |
154 | jint ret = jmm_interface->GetOptionalSupport(env, &mos); |
Value stored to 'ret' during its initialization is never read | |
155 | jsize num_commands; |
156 | dcmdInfo* dcmd_info_array; |
157 | jstring jname, jdesc, jimpact, cmd; |
158 | |
159 | if (commands == NULL((void*)0)) { |
160 | JNU_ThrowNullPointerException(env, "Invalid String Array"); |
161 | return NULL((void*)0); |
162 | } |
163 | num_commands = (*env)->GetArrayLength(env, commands); |
164 | // Ensure capacity for 2 + num_commands local refs: |
165 | // 2 => dcmdInfoCls, result |
166 | // num_commmands => one obj per command |
167 | (*env)->PushLocalFrame(env, 2 + num_commands); |
168 | dcmdInfoCls = (*env)->FindClass(env, |
169 | "com/sun/management/internal/DiagnosticCommandInfo"); |
170 | if ((*env)->ExceptionCheck(env)) { |
171 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
172 | return NULL((void*)0); |
173 | } |
174 | |
175 | result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL((void*)0)); |
176 | if (result == NULL((void*)0)) { |
177 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
178 | return NULL((void*)0); |
179 | } |
180 | if (num_commands == 0) { |
181 | result = (*env)->PopLocalFrame(env, result); |
182 | /* Handle the 'zero commands' case specially to avoid calling 'malloc()' */ |
183 | /* with a zero argument because that may legally return a NULL pointer. */ |
184 | return result; |
185 | } |
186 | dcmd_info_array = (dcmdInfo*) malloc(num_commands * sizeof(dcmdInfo)); |
187 | if (dcmd_info_array == NULL((void*)0)) { |
188 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
189 | JNU_ThrowOutOfMemoryError(env, NULL((void*)0)); |
190 | return NULL((void*)0); |
191 | } |
192 | jmm_interface->GetDiagnosticCommandInfo(env, commands, dcmd_info_array); |
193 | for (i=0; i<num_commands; i++) { |
194 | // Ensure capacity for 6 + 3 local refs: |
195 | // 6 => jname, jdesc, jimpact, cmd, args, obj |
196 | // 3 => permission class, name, action |
197 | (*env)->PushLocalFrame(env, 6 + 3); |
198 | |
199 | cmd = (*env)->GetObjectArrayElement(env, commands, i); |
200 | args = getDiagnosticCommandArgumentInfoArray(env, |
201 | cmd, |
202 | dcmd_info_array[i].num_arguments); |
203 | if (args == NULL((void*)0)) { |
204 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
205 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
206 | free(dcmd_info_array); |
207 | return NULL((void*)0); |
208 | } |
209 | |
210 | jname = (*env)->NewStringUTF(env,dcmd_info_array[i].name); |
211 | POP_EXCEPTION_CHECK_AND_FREE(2, dcmd_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 2; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_info_array); return ((void*)0); } } while(0); |
212 | |
213 | jdesc = (*env)->NewStringUTF(env,dcmd_info_array[i].description); |
214 | POP_EXCEPTION_CHECK_AND_FREE(2, dcmd_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 2; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_info_array); return ((void*)0); } } while(0); |
215 | |
216 | jimpact = (*env)->NewStringUTF(env,dcmd_info_array[i].impact); |
217 | POP_EXCEPTION_CHECK_AND_FREE(2, dcmd_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 2; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_info_array); return ((void*)0); } } while(0); |
218 | |
219 | obj = JNU_NewObjectByName(env, |
220 | "com/sun/management/internal/DiagnosticCommandInfo", |
221 | "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V", |
222 | jname, jdesc, jimpact, |
223 | dcmd_info_array[i].permission_class==NULL((void*)0)?NULL((void*)0):(*env)->NewStringUTF(env,dcmd_info_array[i].permission_class), |
224 | dcmd_info_array[i].permission_name==NULL((void*)0)?NULL((void*)0):(*env)->NewStringUTF(env,dcmd_info_array[i].permission_name), |
225 | dcmd_info_array[i].permission_action==NULL((void*)0)?NULL((void*)0):(*env)->NewStringUTF(env,dcmd_info_array[i].permission_action), |
226 | dcmd_info_array[i].enabled, |
227 | args); |
228 | if (obj == NULL((void*)0)) { |
229 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
230 | (*env)->PopLocalFrame(env, NULL((void*)0)); |
231 | free(dcmd_info_array); |
232 | return NULL((void*)0); |
233 | } |
234 | obj = (*env)->PopLocalFrame(env, obj); |
235 | |
236 | (*env)->SetObjectArrayElement(env, result, i, obj); |
237 | POP_EXCEPTION_CHECK_AND_FREE(1, dcmd_info_array)do { if ((*env)->ExceptionCheck(env)) { int i; for (i = 0; i < 1; i++) { (*env)->PopLocalFrame(env, ((void*)0)); } free(dcmd_info_array); return ((void*)0); } } while(0); |
238 | } |
239 | result = (*env)->PopLocalFrame(env, result); |
240 | free(dcmd_info_array); |
241 | return result; |
242 | } |
243 | |
244 | /* Throws IllegalArgumentException if the diagnostic command |
245 | * passed in argument is not supported by the JVM |
246 | */ |
247 | JNIEXPORT__attribute__((visibility("default"))) jstring JNICALL |
248 | Java_com_sun_management_internal_DiagnosticCommandImpl_executeDiagnosticCommand |
249 | (JNIEnv *env, jobject dummy, jstring command) { |
250 | return jmm_interface->ExecuteDiagnosticCommand(env, command); |
251 | } |