Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/PerfDataEntry.java
41161 views
1
/*
2
* Copyright (c) 2004, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
package sun.jvm.hotspot.runtime;
26
27
import java.nio.charset.StandardCharsets;
28
import java.util.*;
29
import sun.jvm.hotspot.debugger.*;
30
import sun.jvm.hotspot.oops.*;
31
import sun.jvm.hotspot.types.*;
32
import sun.jvm.hotspot.utilities.*;
33
import sun.jvm.hotspot.utilities.Observable;
34
import sun.jvm.hotspot.utilities.Observer;
35
36
public class PerfDataEntry extends VMObject {
37
private static JIntField entryLengthField;
38
private static JIntField nameOffsetField;
39
private static JIntField vectorLengthField;
40
private static JByteField dataTypeField;
41
private static JByteField flagsField;
42
private static JByteField dataUnitsField;
43
private static JByteField dataVariabilityField;
44
private static JIntField dataOffsetField;
45
46
static {
47
VM.registerVMInitializedObserver(new Observer() {
48
public void update(Observable o, Object data) {
49
initialize(VM.getVM().getTypeDataBase());
50
}
51
});
52
}
53
54
private static synchronized void initialize(TypeDataBase db) {
55
Type type = db.lookupType("PerfDataEntry");
56
entryLengthField = type.getJIntField("entry_length");
57
nameOffsetField = type.getJIntField("name_offset");
58
vectorLengthField = type.getJIntField("vector_length");
59
dataTypeField = type.getJByteField("data_type");
60
flagsField = type.getJByteField("flags");
61
dataUnitsField = type.getJByteField("data_units");
62
dataVariabilityField = type.getJByteField("data_variability");
63
dataOffsetField = type.getJIntField("data_offset");
64
}
65
66
public PerfDataEntry(Address addr) {
67
super(addr);
68
}
69
70
// Accessors
71
72
public int entryLength() {
73
return (int) entryLengthField.getValue(addr);
74
}
75
76
public int nameOffset() {
77
return (int) nameOffsetField.getValue(addr);
78
}
79
80
public int vectorLength() {
81
return (int) vectorLengthField.getValue(addr);
82
}
83
84
// returns one of the constants in BasicType class
85
public int dataType() {
86
char ch = (char) (byte) dataTypeField.getValue(addr);
87
return BasicType.charToType(ch);
88
}
89
90
public byte flags() {
91
return (byte) flagsField.getValue(addr);
92
}
93
94
public boolean supported() {
95
return (flags() & 0x1) != 0;
96
}
97
98
private static class PerfDataUnits {
99
public static int U_None;
100
public static int U_Bytes;
101
public static int U_Ticks;
102
public static int U_Events;
103
public static int U_String;
104
public static int U_Hertz;
105
106
static {
107
VM.registerVMInitializedObserver(new Observer() {
108
public void update(Observable o, Object data) {
109
initialize(VM.getVM().getTypeDataBase());
110
}
111
});
112
}
113
private static synchronized void initialize(TypeDataBase db) {
114
U_None = db.lookupIntConstant("PerfData::U_None");
115
U_Bytes = db.lookupIntConstant("PerfData::U_Bytes");
116
U_Ticks = db.lookupIntConstant("PerfData::U_Ticks");
117
U_Events = db.lookupIntConstant("PerfData::U_Events");
118
U_String = db.lookupIntConstant("PerfData::U_String");
119
U_Hertz = db.lookupIntConstant("PerfData::U_Hertz");
120
}
121
}
122
123
// returns one of the constants in PerfDataUnits
124
public int dataUnits() {
125
return (int) dataUnitsField.getValue(addr);
126
}
127
128
// returns one of the constants in PerfDataVariability
129
public int dataVariability() {
130
return (int) dataVariabilityField.getValue(addr);
131
}
132
133
public int dataOffset() {
134
return (int) dataOffsetField.getValue(addr);
135
}
136
137
public String name() {
138
int off = nameOffset();
139
return CStringUtilities.getString(addr.addOffsetTo(off));
140
}
141
142
public boolean booleanValue() {
143
if (Assert.ASSERTS_ENABLED) {
144
Assert.that(vectorLength() == 0 &&
145
dataType() == BasicType.getTBoolean(), "not a boolean");
146
}
147
return addr.getJBooleanAt(dataOffset());
148
}
149
150
public char charValue() {
151
if (Assert.ASSERTS_ENABLED) {
152
Assert.that(vectorLength() == 0 &&
153
dataType() == BasicType.getTChar(), "not a char");
154
}
155
return addr.getJCharAt(dataOffset());
156
}
157
158
public byte byteValue() {
159
if (Assert.ASSERTS_ENABLED) {
160
Assert.that(vectorLength() == 0 &&
161
dataType() == BasicType.getTByte(), "not a byte");
162
}
163
return addr.getJByteAt(dataOffset());
164
165
}
166
167
public short shortValue() {
168
if (Assert.ASSERTS_ENABLED) {
169
Assert.that(vectorLength() == 0 &&
170
dataType() == BasicType.getTShort(), "not a short");
171
}
172
return addr.getJShortAt(dataOffset());
173
}
174
175
public int intValue() {
176
if (Assert.ASSERTS_ENABLED) {
177
Assert.that(vectorLength() == 0 &&
178
dataType() == BasicType.getTInt(), "not an int");
179
}
180
return addr.getJIntAt(dataOffset());
181
}
182
183
public long longValue() {
184
if (Assert.ASSERTS_ENABLED) {
185
Assert.that(vectorLength() == 0 &&
186
dataType() == BasicType.getTLong(), "not a long");
187
}
188
return addr.getJLongAt(dataOffset());
189
}
190
191
public float floatValue() {
192
if (Assert.ASSERTS_ENABLED) {
193
Assert.that(vectorLength() == 0 &&
194
dataType() == BasicType.getTFloat(), "not a float");
195
}
196
return addr.getJFloatAt(dataOffset());
197
}
198
199
public double doubleValue() {
200
if (Assert.ASSERTS_ENABLED) {
201
Assert.that(vectorLength() == 0 &&
202
dataType() == BasicType.getTDouble(), "not a double");
203
}
204
return addr.getJDoubleAt(dataOffset());
205
}
206
207
public boolean[] booleanArrayValue() {
208
int len = vectorLength();
209
if (Assert.ASSERTS_ENABLED) {
210
Assert.that(len > 0 &&
211
dataType() == BasicType.getTBoolean(), "not a boolean vector");
212
}
213
boolean[] res = new boolean[len];
214
final int off = dataOffset();
215
final long size = getHeap().getBooleanSize();
216
for (int i = 0; i < len; i++) {
217
res[i] = addr.getJBooleanAt(off + i * size);
218
}
219
return res;
220
}
221
222
public char[] charArrayValue() {
223
int len = vectorLength();
224
if (Assert.ASSERTS_ENABLED) {
225
Assert.that(len > 0 &&
226
dataType() == BasicType.getTChar(), "not a char vector");
227
}
228
char[] res = new char[len];
229
final int off = dataOffset();
230
final long size = getHeap().getCharSize();
231
for (int i = 0; i < len; i++) {
232
res[i] = addr.getJCharAt(off + i * size);
233
}
234
return res;
235
}
236
237
public byte[] byteArrayValue() {
238
int len = vectorLength();
239
if (Assert.ASSERTS_ENABLED) {
240
Assert.that(len > 0 &&
241
dataType() == BasicType.getTByte(), "not a byte vector");
242
}
243
byte[] res = new byte[len];
244
final int off = dataOffset();
245
final long size = getHeap().getByteSize();
246
for (int i = 0; i < len; i++) {
247
res[i] = addr.getJByteAt(off + i * size);
248
}
249
return res;
250
}
251
252
public short[] shortArrayValue() {
253
int len = vectorLength();
254
if (Assert.ASSERTS_ENABLED) {
255
Assert.that(len > 0 &&
256
dataType() == BasicType.getTShort(), "not a short vector");
257
}
258
short[] res = new short[len];
259
final int off = dataOffset();
260
final long size = getHeap().getShortSize();
261
for (int i = 0; i < len; i++) {
262
res[i] = addr.getJShortAt(off + i * size);
263
}
264
return res;
265
}
266
267
public int[] intArrayValue() {
268
int len = vectorLength();
269
if (Assert.ASSERTS_ENABLED) {
270
Assert.that(len > 0 &&
271
dataType() == BasicType.getTInt(), "not an int vector");
272
}
273
int[] res = new int[len];
274
final int off = dataOffset();
275
final long size = getHeap().getIntSize();
276
for (int i = 0; i < len; i++) {
277
res[i] = addr.getJIntAt(off + i * size);
278
}
279
return res;
280
}
281
282
public long[] longArrayValue() {
283
int len = vectorLength();
284
if (Assert.ASSERTS_ENABLED) {
285
Assert.that(len > 0 &&
286
dataType() == BasicType.getTLong(), "not a long vector");
287
}
288
long[] res = new long[len];
289
final int off = dataOffset();
290
final long size = getHeap().getLongSize();
291
for (int i = 0; i < len; i++) {
292
res[i] = addr.getJLongAt(off + i * size);
293
}
294
return res;
295
}
296
297
public float[] floatArrayValue() {
298
int len = vectorLength();
299
if (Assert.ASSERTS_ENABLED) {
300
Assert.that(len > 0 &&
301
dataType() == BasicType.getTFloat(), "not a float vector");
302
}
303
float[] res = new float[len];
304
final int off = dataOffset();
305
final long size = getHeap().getFloatSize();
306
for (int i = 0; i < len; i++) {
307
res[i] = addr.getJFloatAt(off + i * size);
308
}
309
return res;
310
}
311
312
public double[] doubleArrayValue() {
313
int len = vectorLength();
314
if (Assert.ASSERTS_ENABLED) {
315
Assert.that(len > 0 &&
316
dataType() == BasicType.getTDouble(), "not a double vector");
317
}
318
double[] res = new double[len];
319
final int off = dataOffset();
320
final long size = getHeap().getDoubleSize();
321
for (int i = 0; i < len; i++) {
322
res[i] = addr.getJDoubleAt(off + i * size);
323
}
324
return res;
325
}
326
327
// value as String
328
public String valueAsString() {
329
int dataType = dataType();
330
int len = vectorLength();
331
String str = null;
332
if (len == 0) { // scalar
333
if (dataType == BasicType.getTBoolean()) {
334
str = Boolean.toString(booleanValue());
335
} else if (dataType == BasicType.getTChar()) {
336
str = "'" + Character.toString(charValue()) + "'";
337
} else if (dataType == BasicType.getTByte()) {
338
str = Byte.toString(byteValue());
339
} else if (dataType == BasicType.getTShort()) {
340
str = Short.toString(shortValue());
341
} else if (dataType == BasicType.getTInt()) {
342
str = Integer.toString(intValue());
343
} else if (dataType == BasicType.getTLong()) {
344
str = Long.toString(longValue());
345
} else if (dataType == BasicType.getTFloat()) {
346
str = Float.toString(floatValue());
347
} else if (dataType == BasicType.getTDouble()) {
348
str = Double.toString(doubleValue());
349
} else {
350
str = "<unknown scalar value>";
351
}
352
} else { // vector
353
if (dataType == BasicType.getTBoolean()) {
354
boolean[] res = booleanArrayValue();
355
StringBuilder buf = new StringBuilder();
356
buf.append('[');
357
for (int i = 0; i < res.length; i++) {
358
buf.append(res[i]);
359
buf.append(", ");
360
}
361
buf.append(']');
362
str = buf.toString();
363
} else if (dataType == BasicType.getTChar()) {
364
// char[] is returned as a String
365
str = new String(charArrayValue());
366
} else if (dataType == BasicType.getTByte()) {
367
// byte[] is returned as a String
368
str = CStringUtilities.getString(addr.addOffsetTo(dataOffset()),
369
StandardCharsets.US_ASCII);
370
} else if (dataType == BasicType.getTShort()) {
371
short[] res = shortArrayValue();
372
StringBuilder buf = new StringBuilder();
373
buf.append('[');
374
for (int i = 0; i < res.length; i++) {
375
buf.append(res[i]);
376
buf.append(", ");
377
}
378
buf.append(']');
379
str = buf.toString();
380
} else if (dataType == BasicType.getTInt()) {
381
int[] res = intArrayValue();
382
StringBuilder buf = new StringBuilder();
383
buf.append('[');
384
for (int i = 0; i < res.length; i++) {
385
buf.append(res[i]);
386
buf.append(", ");
387
}
388
buf.append(']');
389
str = buf.toString();
390
} else if (dataType == BasicType.getTLong()) {
391
long[] res = longArrayValue();
392
StringBuilder buf = new StringBuilder();
393
buf.append('[');
394
for (int i = 0; i < res.length; i++) {
395
buf.append(res[i]);
396
buf.append(", ");
397
}
398
buf.append(']');
399
str = buf.toString();
400
} else if (dataType == BasicType.getTFloat()) {
401
float[] res = floatArrayValue();
402
StringBuilder buf = new StringBuilder();
403
buf.append('[');
404
for (int i = 0; i < res.length; i++) {
405
buf.append(res[i]);
406
buf.append(", ");
407
}
408
buf.append(']');
409
str = buf.toString();
410
} else if (dataType == BasicType.getTDouble()) {
411
double[] res = doubleArrayValue();
412
StringBuilder buf = new StringBuilder();
413
buf.append('[');
414
for (int i = 0; i < res.length; i++) {
415
buf.append(res[i]);
416
buf.append(", ");
417
}
418
buf.append(']');
419
str = buf.toString();
420
} else {
421
str = "<unknown vector value>";
422
}
423
}
424
425
// add units
426
int dataUnitsValue = dataUnits();
427
428
if (dataUnitsValue == PerfDataUnits.U_Bytes) {
429
str += " byte(s)";
430
} else if (dataUnitsValue == PerfDataUnits.U_Ticks) {
431
str += " tick(s)";
432
} else if (dataUnitsValue == PerfDataUnits.U_Events) {
433
str += " event(s)";
434
} else if (dataUnitsValue == PerfDataUnits.U_Hertz) {
435
str += " Hz";
436
}
437
438
return str;
439
}
440
441
// -- Internals only below this point
442
private ObjectHeap getHeap() {
443
return VM.getVM().getObjectHeap();
444
}
445
}
446
447