Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.management/share/classes/sun/management/counter/perf/Prologue.java
41161 views
1
/*
2
* Copyright (c) 2003, 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
package sun.management.counter.perf;
27
28
import sun.management.counter.*;
29
import java.nio.*;
30
31
class Prologue {
32
// these constants should match their #define counterparts in vmdata.hpp
33
private static final byte PERFDATA_BIG_ENDIAN = 0;
34
private static final byte PERFDATA_LITTLE_ENDIAN = 1;
35
private static final int PERFDATA_MAGIC = 0xcafec0c0;
36
37
private class PrologueFieldOffset {
38
private static final int SIZEOF_BYTE = 1;
39
private static final int SIZEOF_INT = 4;
40
private static final int SIZEOF_LONG = 8;
41
42
private static final int MAGIC_SIZE = SIZEOF_INT;
43
private static final int BYTE_ORDER_SIZE = SIZEOF_BYTE;
44
private static final int MAJOR_SIZE = SIZEOF_BYTE;
45
private static final int MINOR_SIZE = SIZEOF_BYTE;
46
private static final int ACCESSIBLE_SIZE = SIZEOF_BYTE;
47
private static final int USED_SIZE = SIZEOF_INT;
48
private static final int OVERFLOW_SIZE = SIZEOF_INT;
49
private static final int MOD_TIMESTAMP_SIZE = SIZEOF_LONG;
50
private static final int ENTRY_OFFSET_SIZE = SIZEOF_INT;
51
private static final int NUM_ENTRIES_SIZE = SIZEOF_INT;
52
53
// these constants must match the field offsets and sizes
54
// in the PerfDataPrologue structure in perfMemory.hpp
55
static final int MAGIC = 0;
56
static final int BYTE_ORDER = MAGIC + MAGIC_SIZE;
57
static final int MAJOR_VERSION = BYTE_ORDER + BYTE_ORDER_SIZE;
58
static final int MINOR_VERSION = MAJOR_VERSION + MAJOR_SIZE;
59
static final int ACCESSIBLE = MINOR_VERSION + MINOR_SIZE;
60
static final int USED = ACCESSIBLE + ACCESSIBLE_SIZE;
61
static final int OVERFLOW = USED + USED_SIZE;
62
static final int MOD_TIMESTAMP = OVERFLOW + OVERFLOW_SIZE;
63
static final int ENTRY_OFFSET = MOD_TIMESTAMP + MOD_TIMESTAMP_SIZE;
64
static final int NUM_ENTRIES = ENTRY_OFFSET + ENTRY_OFFSET_SIZE;
65
static final int PROLOGUE_2_0_SIZE = NUM_ENTRIES + NUM_ENTRIES_SIZE;
66
}
67
68
69
private ByteBuffer header;
70
private int magic;
71
72
Prologue(ByteBuffer b) {
73
this.header = b.duplicate();
74
75
// the magic number is always stored in big-endian format
76
// save and restore the buffer's initial byte order around
77
// the fetch of the data.
78
header.order(ByteOrder.BIG_ENDIAN);
79
header.position(PrologueFieldOffset.MAGIC);
80
magic = header.getInt();
81
82
// the magic number is always stored in big-endian format
83
if (magic != PERFDATA_MAGIC) {
84
throw new InstrumentationException("Bad Magic: " +
85
Integer.toHexString(getMagic()));
86
}
87
88
89
// set the buffer's byte order according to the value of its
90
// byte order field.
91
header.order(getByteOrder());
92
93
// Check version
94
int major = getMajorVersion();
95
int minor = getMinorVersion();
96
97
if (major < 2) {
98
throw new InstrumentationException("Unsupported version: " +
99
major + "." + minor);
100
}
101
102
// Currently, only support 2.0 version.
103
header.limit(PrologueFieldOffset.PROLOGUE_2_0_SIZE);
104
}
105
106
public int getMagic() {
107
return magic;
108
}
109
110
public int getMajorVersion() {
111
header.position(PrologueFieldOffset.MAJOR_VERSION);
112
return (int)header.get();
113
}
114
115
public int getMinorVersion() {
116
header.position(PrologueFieldOffset.MINOR_VERSION);
117
return (int)header.get();
118
}
119
120
public ByteOrder getByteOrder() {
121
header.position(PrologueFieldOffset.BYTE_ORDER);
122
123
byte byte_order = header.get();
124
if (byte_order == PERFDATA_BIG_ENDIAN) {
125
return ByteOrder.BIG_ENDIAN;
126
}
127
else {
128
return ByteOrder.LITTLE_ENDIAN;
129
}
130
}
131
132
public int getEntryOffset() {
133
header.position(PrologueFieldOffset.ENTRY_OFFSET);
134
return header.getInt();
135
}
136
137
// The following fields are updated asynchronously
138
// while they are accessed by these methods.
139
public int getUsed() {
140
header.position(PrologueFieldOffset.USED);
141
return header.getInt();
142
}
143
144
public int getOverflow() {
145
header.position(PrologueFieldOffset.OVERFLOW);
146
return header.getInt();
147
}
148
149
public long getModificationTimeStamp() {
150
header.position(PrologueFieldOffset.MOD_TIMESTAMP);
151
return header.getLong();
152
}
153
154
public int getNumEntries() {
155
header.position(PrologueFieldOffset.NUM_ENTRIES);
156
return header.getInt();
157
}
158
159
public boolean isAccessible() {
160
header.position(PrologueFieldOffset.ACCESSIBLE);
161
byte b = header.get();
162
return (b == 0 ? false : true);
163
}
164
}
165
166