author | ppunegov |
Tue, 20 Oct 2015 21:12:25 +0300 | |
changeset 33453 | b62df32d4af8 |
parent 30355 | e37c7eba132f |
child 40199 | 1795251e7dec |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <stdlib.h> |
|
27 |
#include <stdio.h> |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
28 |
#include <string.h> |
2 | 29 |
#include <jni.h> |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
30 |
#include "management_ext.h" |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
31 |
#include "com_sun_management_internal_Flag.h" |
2 | 32 |
|
33 |
static jobject default_origin = NULL; |
|
34 |
static jobject vm_creation_origin = NULL; |
|
35 |
static jobject mgmt_origin = NULL; |
|
36 |
static jobject envvar_origin = NULL; |
|
37 |
static jobject config_file_origin = NULL; |
|
38 |
static jobject ergo_origin = NULL; |
|
22299
ee71d2eaa085
8028994: com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents:
7668
diff
changeset
|
39 |
static jobject attach_origin = NULL; |
2 | 40 |
static jobject other_origin = NULL; |
41 |
||
42 |
JNIEXPORT jint JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
43 |
Java_com_sun_management_internal_Flag_getInternalFlagCount |
2 | 44 |
(JNIEnv *env, jclass cls) |
45 |
{ |
|
46 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
47 |
JMM_VM_GLOBAL_COUNT); |
|
48 |
return (jint) count; |
|
49 |
} |
|
50 |
||
51 |
JNIEXPORT jobjectArray JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
52 |
Java_com_sun_management_internal_Flag_getAllFlagNames |
2 | 53 |
(JNIEnv *env, jclass cls) |
54 |
{ |
|
55 |
return jmm_interface->GetVMGlobalNames(env); |
|
56 |
} |
|
57 |
||
58 |
static jobject find_origin_constant(JNIEnv* env, const char* enum_name) { |
|
59 |
jvalue field; |
|
60 |
field = JNU_GetStaticFieldByName(env, |
|
61 |
NULL, |
|
62 |
"com/sun/management/VMOption$Origin", |
|
63 |
enum_name, |
|
64 |
"Lcom/sun/management/VMOption$Origin;"); |
|
65 |
return (*env)->NewGlobalRef(env, field.l); |
|
66 |
} |
|
67 |
||
68 |
JNIEXPORT void JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
69 |
Java_com_sun_management_internal_Flag_initialize |
2 | 70 |
(JNIEnv *env, jclass cls) |
71 |
{ |
|
72 |
default_origin = find_origin_constant(env, "DEFAULT"); |
|
73 |
vm_creation_origin = find_origin_constant(env, "VM_CREATION"); |
|
74 |
mgmt_origin = find_origin_constant(env, "MANAGEMENT"); |
|
75 |
envvar_origin = find_origin_constant(env, "ENVIRON_VAR"); |
|
76 |
config_file_origin = find_origin_constant(env, "CONFIG_FILE"); |
|
77 |
ergo_origin = find_origin_constant(env, "ERGONOMIC"); |
|
22299
ee71d2eaa085
8028994: com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents:
7668
diff
changeset
|
78 |
attach_origin = find_origin_constant(env, "ATTACH_ON_DEMAND"); |
2 | 79 |
other_origin = find_origin_constant(env, "OTHER"); |
80 |
} |
|
81 |
||
82 |
JNIEXPORT jint JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
83 |
Java_com_sun_management_internal_Flag_getFlags |
2 | 84 |
(JNIEnv *env, jclass cls, jobjectArray names, jobjectArray flags, jint count) |
85 |
{ |
|
86 |
jint num_flags, i, index; |
|
87 |
jmmVMGlobal* globals; |
|
4915
fe435c741ec8
6924497: HotSpotDiagnosticsMXBean.getDiagnosticOptions throws NPE
mchung
parents:
2
diff
changeset
|
88 |
size_t gsize; |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
89 |
const char* class_name = "com/sun/management/internal/Flag"; |
2 | 90 |
const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V"; |
91 |
jobject origin; |
|
92 |
jobject valueObj; |
|
93 |
jobject flag; |
|
94 |
||
95 |
if (flags == NULL) { |
|
96 |
JNU_ThrowNullPointerException(env, 0); |
|
97 |
return 0; |
|
98 |
} |
|
99 |
||
23890 | 100 |
if (count <= 0) { |
2 | 101 |
JNU_ThrowIllegalArgumentException(env, 0); |
102 |
return 0; |
|
103 |
} |
|
104 |
||
23890 | 105 |
gsize = (size_t)count * sizeof(jmmVMGlobal); |
4915
fe435c741ec8
6924497: HotSpotDiagnosticsMXBean.getDiagnosticOptions throws NPE
mchung
parents:
2
diff
changeset
|
106 |
globals = (jmmVMGlobal*) malloc(gsize); |
2 | 107 |
if (globals == NULL) { |
108 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
109 |
return 0; |
|
110 |
} |
|
111 |
||
4915
fe435c741ec8
6924497: HotSpotDiagnosticsMXBean.getDiagnosticOptions throws NPE
mchung
parents:
2
diff
changeset
|
112 |
memset(globals, 0, gsize); |
2 | 113 |
num_flags = jmm_interface->GetVMGlobals(env, names, globals, count); |
114 |
if (num_flags == 0) { |
|
115 |
free(globals); |
|
116 |
return 0; |
|
117 |
} |
|
118 |
||
119 |
index = 0; |
|
120 |
for (i = 0; i < count; i++) { |
|
121 |
if (globals[i].name == NULL) { |
|
122 |
continue; |
|
123 |
} |
|
124 |
switch (globals[i].type) { |
|
125 |
case JMM_VMGLOBAL_TYPE_JBOOLEAN: |
|
126 |
valueObj = JNU_NewObjectByName(env, "java/lang/Boolean", "(Z)V", |
|
127 |
globals[i].value.z); |
|
128 |
break; |
|
129 |
case JMM_VMGLOBAL_TYPE_JSTRING: |
|
130 |
valueObj = globals[i].value.l; |
|
131 |
break; |
|
132 |
case JMM_VMGLOBAL_TYPE_JLONG: |
|
133 |
valueObj = JNU_NewObjectByName(env, "java/lang/Long", "(J)V", |
|
134 |
globals[i].value.j); |
|
135 |
break; |
|
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
136 |
case JMM_VMGLOBAL_TYPE_JDOUBLE: |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
137 |
valueObj = JNU_NewObjectByName(env, "java/lang/Double", "(D)V", |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
138 |
globals[i].value.d); |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
139 |
break; |
2 | 140 |
default: |
5163
e13f471e8dd5
6915365: 3/4 assert(false,"Unsupported VMGlobal Type") at management.cpp:1540
dcubed
parents:
4915
diff
changeset
|
141 |
// ignore unsupported type |
e13f471e8dd5
6915365: 3/4 assert(false,"Unsupported VMGlobal Type") at management.cpp:1540
dcubed
parents:
4915
diff
changeset
|
142 |
continue; |
2 | 143 |
} |
144 |
switch (globals[i].origin) { |
|
145 |
case JMM_VMGLOBAL_ORIGIN_DEFAULT: |
|
146 |
origin = default_origin; |
|
147 |
break; |
|
148 |
case JMM_VMGLOBAL_ORIGIN_COMMAND_LINE: |
|
149 |
origin = vm_creation_origin; |
|
150 |
break; |
|
151 |
case JMM_VMGLOBAL_ORIGIN_MANAGEMENT: |
|
152 |
origin = mgmt_origin; |
|
153 |
break; |
|
154 |
case JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR: |
|
155 |
origin = envvar_origin; |
|
156 |
break; |
|
157 |
case JMM_VMGLOBAL_ORIGIN_CONFIG_FILE: |
|
158 |
origin = config_file_origin; |
|
159 |
break; |
|
160 |
case JMM_VMGLOBAL_ORIGIN_ERGONOMIC: |
|
161 |
origin = ergo_origin; |
|
162 |
break; |
|
22299
ee71d2eaa085
8028994: com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents:
7668
diff
changeset
|
163 |
case JMM_VMGLOBAL_ORIGIN_ATTACH_ON_DEMAND: |
ee71d2eaa085
8028994: com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents:
7668
diff
changeset
|
164 |
origin = attach_origin; |
ee71d2eaa085
8028994: com.sun.management.VMOption is missing the ATTACH_ON_DEMAND origin
sla
parents:
7668
diff
changeset
|
165 |
break; |
2 | 166 |
case JMM_VMGLOBAL_ORIGIN_OTHER: |
167 |
origin = other_origin; |
|
168 |
break; |
|
169 |
default: |
|
170 |
// unknown origin |
|
171 |
origin = other_origin; |
|
172 |
break; |
|
173 |
} |
|
174 |
flag = JNU_NewObjectByName(env, class_name, signature, globals[i].name, |
|
175 |
valueObj, globals[i].writeable, |
|
176 |
globals[i].external, origin); |
|
177 |
if (flag == NULL) { |
|
178 |
free(globals); |
|
179 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
180 |
return 0; |
|
181 |
} |
|
182 |
(*env)->SetObjectArrayElement(env, flags, index, flag); |
|
183 |
index++; |
|
184 |
} |
|
185 |
||
186 |
if (index != num_flags) { |
|
187 |
JNU_ThrowInternalError(env, "Number of Flag objects created unmatched"); |
|
188 |
free(globals); |
|
189 |
return 0; |
|
190 |
} |
|
191 |
||
192 |
free(globals); |
|
193 |
||
194 |
/* return the number of Flag objects created */ |
|
195 |
return num_flags; |
|
196 |
} |
|
197 |
||
198 |
JNIEXPORT void JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
199 |
Java_com_sun_management_internal_Flag_setLongValue |
2 | 200 |
(JNIEnv *env, jclass cls, jstring name, jlong value) |
201 |
{ |
|
202 |
jvalue v; |
|
203 |
v.j = value; |
|
204 |
||
205 |
jmm_interface->SetVMGlobal(env, name, v); |
|
206 |
} |
|
207 |
||
208 |
JNIEXPORT void JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
209 |
Java_com_sun_management_internal_Flag_setDoubleValue |
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
210 |
(JNIEnv *env, jclass cls, jstring name, jdouble value) |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
211 |
{ |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
212 |
jvalue v; |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
213 |
v.d = value; |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
214 |
|
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
215 |
jmm_interface->SetVMGlobal(env, name, v); |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
216 |
} |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
217 |
|
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
218 |
JNIEXPORT void JNICALL |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
219 |
Java_com_sun_management_internal_Flag_setBooleanValue |
2 | 220 |
(JNIEnv *env, jclass cls, jstring name, jboolean value) |
221 |
{ |
|
222 |
jvalue v; |
|
223 |
v.z = value; |
|
224 |
||
225 |
jmm_interface->SetVMGlobal(env, name, v); |
|
226 |
} |
|
227 |
||
228 |
JNIEXPORT void JNICALL |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
27493
diff
changeset
|
229 |
Java_com_sun_management_internal_Flag_setStringValue |
2 | 230 |
(JNIEnv *env, jclass cls, jstring name, jstring value) |
231 |
{ |
|
232 |
jvalue v; |
|
233 |
v.l = value; |
|
234 |
||
235 |
jmm_interface->SetVMGlobal(env, name, v); |
|
236 |
} |