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/Flag.c
38829 views
1
/*
2
* Copyright (c) 2003, 2014, 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 <stdio.h>
28
#include <string.h>
29
#include <jni.h>
30
#include "management.h"
31
#include "sun_management_Flag.h"
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;
39
static jobject other_origin = NULL;
40
41
JNIEXPORT jint JNICALL
42
Java_sun_management_Flag_getInternalFlagCount
43
(JNIEnv *env, jclass cls)
44
{
45
jlong count = jmm_interface->GetLongAttribute(env, NULL,
46
JMM_VM_GLOBAL_COUNT);
47
return (jint) count;
48
}
49
50
JNIEXPORT jobjectArray JNICALL
51
Java_sun_management_Flag_getAllFlagNames
52
(JNIEnv *env, jclass cls)
53
{
54
return jmm_interface->GetVMGlobalNames(env);
55
}
56
57
static jobject find_origin_constant(JNIEnv* env, const char* enum_name) {
58
jvalue field;
59
field = JNU_GetStaticFieldByName(env,
60
NULL,
61
"com/sun/management/VMOption$Origin",
62
enum_name,
63
"Lcom/sun/management/VMOption$Origin;");
64
return (*env)->NewGlobalRef(env, field.l);
65
}
66
67
JNIEXPORT void JNICALL
68
Java_sun_management_Flag_initialize
69
(JNIEnv *env, jclass cls)
70
{
71
default_origin = find_origin_constant(env, "DEFAULT");
72
vm_creation_origin = find_origin_constant(env, "VM_CREATION");
73
mgmt_origin = find_origin_constant(env, "MANAGEMENT");
74
envvar_origin = find_origin_constant(env, "ENVIRON_VAR");
75
config_file_origin = find_origin_constant(env, "CONFIG_FILE");
76
ergo_origin = find_origin_constant(env, "ERGONOMIC");
77
other_origin = find_origin_constant(env, "OTHER");
78
}
79
80
JNIEXPORT jint JNICALL
81
Java_sun_management_Flag_getFlags
82
(JNIEnv *env, jclass cls, jobjectArray names, jobjectArray flags, jint count)
83
{
84
jint num_flags, i, index;
85
jmmVMGlobal* globals;
86
size_t gsize;
87
const char* class_name = "sun/management/Flag";
88
const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V";
89
jobject origin;
90
jobject valueObj;
91
jobject flag;
92
93
if (flags == NULL) {
94
JNU_ThrowNullPointerException(env, 0);
95
return 0;
96
}
97
98
if (count <= 0) {
99
JNU_ThrowIllegalArgumentException(env, 0);
100
return 0;
101
}
102
103
gsize = (size_t)count * sizeof(jmmVMGlobal);
104
globals = (jmmVMGlobal*) malloc(gsize);
105
if (globals == NULL) {
106
JNU_ThrowOutOfMemoryError(env, 0);
107
return 0;
108
}
109
110
memset(globals, 0, gsize);
111
num_flags = jmm_interface->GetVMGlobals(env, names, globals, count);
112
if (num_flags == 0) {
113
free(globals);
114
return 0;
115
}
116
117
index = 0;
118
for (i = 0; i < count; i++) {
119
if (globals[i].name == NULL) {
120
continue;
121
}
122
switch (globals[i].type) {
123
case JMM_VMGLOBAL_TYPE_JBOOLEAN:
124
valueObj = JNU_NewObjectByName(env, "java/lang/Boolean", "(Z)V",
125
globals[i].value.z);
126
break;
127
case JMM_VMGLOBAL_TYPE_JSTRING:
128
valueObj = globals[i].value.l;
129
break;
130
case JMM_VMGLOBAL_TYPE_JLONG:
131
valueObj = JNU_NewObjectByName(env, "java/lang/Long", "(J)V",
132
globals[i].value.j);
133
break;
134
case JMM_VMGLOBAL_TYPE_JDOUBLE:
135
valueObj = JNU_NewObjectByName(env, "java/lang/Double", "(D)V",
136
globals[i].value.d);
137
break;
138
default:
139
// ignore unsupported type
140
continue;
141
}
142
switch (globals[i].origin) {
143
case JMM_VMGLOBAL_ORIGIN_DEFAULT:
144
origin = default_origin;
145
break;
146
case JMM_VMGLOBAL_ORIGIN_COMMAND_LINE:
147
origin = vm_creation_origin;
148
break;
149
case JMM_VMGLOBAL_ORIGIN_MANAGEMENT:
150
origin = mgmt_origin;
151
break;
152
case JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR:
153
origin = envvar_origin;
154
break;
155
case JMM_VMGLOBAL_ORIGIN_CONFIG_FILE:
156
origin = config_file_origin;
157
break;
158
case JMM_VMGLOBAL_ORIGIN_ERGONOMIC:
159
origin = ergo_origin;
160
break;
161
case JMM_VMGLOBAL_ORIGIN_OTHER:
162
origin = other_origin;
163
break;
164
default:
165
// unknown origin
166
origin = other_origin;
167
break;
168
}
169
flag = JNU_NewObjectByName(env, class_name, signature, globals[i].name,
170
valueObj, globals[i].writeable,
171
globals[i].external, origin);
172
if (flag == NULL) {
173
free(globals);
174
JNU_ThrowOutOfMemoryError(env, 0);
175
return 0;
176
}
177
(*env)->SetObjectArrayElement(env, flags, index, flag);
178
index++;
179
}
180
181
if (index != num_flags) {
182
JNU_ThrowInternalError(env, "Number of Flag objects created unmatched");
183
free(globals);
184
return 0;
185
}
186
187
free(globals);
188
189
/* return the number of Flag objects created */
190
return num_flags;
191
}
192
193
JNIEXPORT void JNICALL
194
Java_sun_management_Flag_setLongValue
195
(JNIEnv *env, jclass cls, jstring name, jlong value)
196
{
197
jvalue v;
198
v.j = value;
199
200
jmm_interface->SetVMGlobal(env, name, v);
201
}
202
203
JNIEXPORT void JNICALL
204
Java_sun_management_Flag_setDoubleValue
205
(JNIEnv *env, jclass cls, jstring name, jdouble value)
206
{
207
jvalue v;
208
v.d = value;
209
210
jmm_interface->SetVMGlobal(env, name, v);
211
}
212
213
JNIEXPORT void JNICALL
214
Java_sun_management_Flag_setBooleanValue
215
(JNIEnv *env, jclass cls, jstring name, jboolean value)
216
{
217
jvalue v;
218
v.z = value;
219
220
jmm_interface->SetVMGlobal(env, name, v);
221
}
222
223
JNIEXPORT void JNICALL
224
Java_sun_management_Flag_setStringValue
225
(JNIEnv *env, jclass cls, jstring name, jstring value)
226
{
227
jvalue v;
228
v.l = value;
229
230
jmm_interface->SetVMGlobal(env, name, v);
231
}
232
233