author | ppunegov |
Tue, 20 Oct 2015 21:12:25 +0300 | |
changeset 33453 | b62df32d4af8 |
parent 30355 | e37c7eba132f |
child 41197 | d98087633032 |
permissions | -rw-r--r-- |
17954 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
17954 | 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 |
||
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
26 |
#include <stdlib.h> |
17954 | 27 |
#include <jni.h> |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
28 |
#include "management_ext.h" |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
29 |
#include "com_sun_management_internal_DiagnosticCommandImpl.h" |
17954 | 30 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
31 |
JNIEXPORT void JNICALL Java_com_sun_management_internal_DiagnosticCommandImpl_setNotificationEnabled |
17954 | 32 |
(JNIEnv *env, jobject dummy, jboolean enabled) { |
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
33 |
if (jmm_version <= JMM_VERSION_1_2_2) { |
17954 | 34 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
35 |
"JMX interface to diagnostic framework notifications is not supported by this VM"); |
|
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
36 |
return; |
17954 | 37 |
} |
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
38 |
jmm_interface->SetDiagnosticFrameworkNotificationEnabled(env, enabled); |
17954 | 39 |
} |
40 |
||
41 |
JNIEXPORT jobjectArray JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
42 |
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommands |
17954 | 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)); |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
60 |
/* According to ISO C it is perfectly legal for malloc to return zero if called with a zero argument */ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
61 |
if (dcmd_arg_info_array == NULL && num_arg != 0) { |
17954 | 62 |
return NULL; |
63 |
} |
|
64 |
jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command, |
|
65 |
dcmd_arg_info_array); |
|
66 |
dcmdArgInfoCls = (*env)->FindClass(env, |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
67 |
"com/sun/management/internal/DiagnosticCommandArgumentInfo"); |
27192
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
68 |
if ((*env)->ExceptionCheck(env)) { |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
69 |
free(dcmd_arg_info_array); |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
70 |
return NULL; |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
71 |
} |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
72 |
|
17954 | 73 |
result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL); |
74 |
if (result == NULL) { |
|
75 |
free(dcmd_arg_info_array); |
|
76 |
return NULL; |
|
77 |
} |
|
78 |
for (i=0; i<num_arg; i++) { |
|
79 |
obj = JNU_NewObjectByName(env, |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
80 |
"com/sun/management/internal/DiagnosticCommandArgumentInfo", |
17954 | 81 |
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZI)V", |
82 |
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].name), |
|
83 |
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].description), |
|
84 |
(*env)->NewStringUTF(env,dcmd_arg_info_array[i].type), |
|
85 |
dcmd_arg_info_array[i].default_string == NULL ? NULL: |
|
86 |
(*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string), |
|
87 |
dcmd_arg_info_array[i].mandatory, |
|
88 |
dcmd_arg_info_array[i].option, |
|
89 |
dcmd_arg_info_array[i].multiple, |
|
90 |
dcmd_arg_info_array[i].position); |
|
91 |
if (obj == NULL) { |
|
92 |
free(dcmd_arg_info_array); |
|
93 |
return NULL; |
|
94 |
} |
|
95 |
(*env)->SetObjectArrayElement(env, result, i, obj); |
|
96 |
} |
|
97 |
free(dcmd_arg_info_array); |
|
98 |
arraysCls = (*env)->FindClass(env, "java/util/Arrays"); |
|
27192
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
99 |
if ((*env)->ExceptionCheck(env)) { |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
100 |
return NULL; |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
101 |
} |
17954 | 102 |
mid = (*env)->GetStaticMethodID(env, arraysCls, |
103 |
"asList", "([Ljava/lang/Object;)Ljava/util/List;"); |
|
104 |
resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result); |
|
27192
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
105 |
if ((*env)->ExceptionCheck(env)) { |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
106 |
// Make sure we return NULL in case of OOM inside Java |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
107 |
return NULL; |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
108 |
} |
17954 | 109 |
return resultList; |
110 |
} |
|
111 |
||
112 |
/* Throws IllegalArgumentException if at least one of the diagnostic command |
|
113 |
* passed in argument is not supported by the JVM |
|
114 |
*/ |
|
115 |
JNIEXPORT jobjectArray JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
116 |
Java_com_sun_management_internal_DiagnosticCommandImpl_getDiagnosticCommandInfo |
17954 | 117 |
(JNIEnv *env, jobject dummy, jobjectArray commands) |
118 |
{ |
|
119 |
int i; |
|
120 |
jclass dcmdInfoCls; |
|
121 |
jobject result; |
|
122 |
jobjectArray args; |
|
123 |
jobject obj; |
|
124 |
jmmOptionalSupport mos; |
|
125 |
jint ret = jmm_interface->GetOptionalSupport(env, &mos); |
|
126 |
jsize num_commands; |
|
127 |
dcmdInfo* dcmd_info_array; |
|
128 |
||
129 |
if (commands == NULL) { |
|
130 |
JNU_ThrowNullPointerException(env, "Invalid String Array"); |
|
131 |
return NULL; |
|
132 |
} |
|
133 |
num_commands = (*env)->GetArrayLength(env, commands); |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
134 |
dcmdInfoCls = (*env)->FindClass(env, |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
135 |
"com/sun/management/internal/DiagnosticCommandInfo"); |
27192
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
136 |
if ((*env)->ExceptionCheck(env)) { |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
137 |
return NULL; |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
138 |
} |
a16236cd61d7
8029465: warnings from b118 for jdk.src.share.native.sun.management: JNI exception pending
dsamersoff
parents:
25859
diff
changeset
|
139 |
|
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
140 |
result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL); |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
141 |
if (result == NULL) { |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
142 |
JNU_ThrowOutOfMemoryError(env, 0); |
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
143 |
return NULL; |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
144 |
} |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
145 |
if (num_commands == 0) { |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
146 |
/* Handle the 'zero commands' case specially to avoid calling 'malloc()' */ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
147 |
/* with a zero argument because that may legally return a NULL pointer. */ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
148 |
return result; |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
149 |
} |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
18299
diff
changeset
|
150 |
dcmd_info_array = (dcmdInfo*) malloc(num_commands * sizeof(dcmdInfo)); |
17954 | 151 |
if (dcmd_info_array == NULL) { |
152 |
JNU_ThrowOutOfMemoryError(env, NULL); |
|
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
153 |
return NULL; |
17954 | 154 |
} |
155 |
jmm_interface->GetDiagnosticCommandInfo(env, commands, dcmd_info_array); |
|
156 |
for (i=0; i<num_commands; i++) { |
|
157 |
args = getDiagnosticCommandArgumentInfoArray(env, |
|
158 |
(*env)->GetObjectArrayElement(env,commands,i), |
|
159 |
dcmd_info_array[i].num_arguments); |
|
160 |
if (args == NULL) { |
|
161 |
free(dcmd_info_array); |
|
162 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
163 |
return NULL; |
17954 | 164 |
} |
165 |
obj = JNU_NewObjectByName(env, |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
166 |
"com/sun/management/internal/DiagnosticCommandInfo", |
17954 | 167 |
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V", |
168 |
(*env)->NewStringUTF(env,dcmd_info_array[i].name), |
|
169 |
(*env)->NewStringUTF(env,dcmd_info_array[i].description), |
|
170 |
(*env)->NewStringUTF(env,dcmd_info_array[i].impact), |
|
171 |
dcmd_info_array[i].permission_class==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_class), |
|
172 |
dcmd_info_array[i].permission_name==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_name), |
|
173 |
dcmd_info_array[i].permission_action==NULL?NULL:(*env)->NewStringUTF(env,dcmd_info_array[i].permission_action), |
|
174 |
dcmd_info_array[i].enabled, |
|
175 |
args); |
|
176 |
if (obj == NULL) { |
|
177 |
free(dcmd_info_array); |
|
178 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
22624
860bde7fa0eb
8032518: fatal error has been detected by the Java Runtime Environment(access violation)
mgronlun
parents:
22605
diff
changeset
|
179 |
return NULL; |
17954 | 180 |
} |
181 |
(*env)->SetObjectArrayElement(env, result, i, obj); |
|
182 |
} |
|
183 |
free(dcmd_info_array); |
|
184 |
return result; |
|
185 |
} |
|
186 |
||
187 |
/* Throws IllegalArgumentException if the diagnostic command |
|
188 |
* passed in argument is not supported by the JVM |
|
189 |
*/ |
|
190 |
JNIEXPORT jstring JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27192
diff
changeset
|
191 |
Java_com_sun_management_internal_DiagnosticCommandImpl_executeDiagnosticCommand |
17954 | 192 |
(JNIEnv *env, jobject dummy, jstring command) { |
193 |
return jmm_interface->ExecuteDiagnosticCommand(env, command); |
|
194 |
} |