Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.management/share/classes/sun/management/MonitorInfoCompositeData.java
41152 views
1
/*
2
* Copyright (c) 2005, 2019, 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;
27
28
import java.lang.management.MonitorInfo;
29
import java.util.HashMap;
30
import java.util.Map;
31
import javax.management.openmbean.CompositeType;
32
import javax.management.openmbean.CompositeData;
33
import javax.management.openmbean.CompositeDataSupport;
34
import javax.management.openmbean.OpenDataException;
35
import javax.management.openmbean.OpenType;
36
37
/**
38
* A CompositeData for MonitorInfo for the local management support.
39
* This class avoids the performance penalty paid to the
40
* construction of a CompositeData use in the local case.
41
*/
42
public class MonitorInfoCompositeData extends LazyCompositeData {
43
@SuppressWarnings("serial") // Not statically typed as Serializable
44
private final MonitorInfo lock;
45
46
private MonitorInfoCompositeData(MonitorInfo mi) {
47
this.lock = mi;
48
}
49
50
public MonitorInfo getMonitorInfo() {
51
return lock;
52
}
53
54
public static CompositeData toCompositeData(MonitorInfo mi) {
55
MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi);
56
return micd.getCompositeData();
57
}
58
59
protected CompositeData getCompositeData() {
60
StackTraceElement ste = lock.getLockedStackFrame();
61
CompositeData steCData = ste != null ? StackTraceElementCompositeData.toCompositeData(ste)
62
: null;
63
// values may be null; can't use Map.of
64
Map<String,Object> items = new HashMap<>();
65
items.put(CLASS_NAME, lock.getClassName());
66
items.put(IDENTITY_HASH_CODE, lock.getIdentityHashCode());
67
items.put(LOCKED_STACK_FRAME, steCData);
68
items.put(LOCKED_STACK_DEPTH, lock.getLockedStackDepth());
69
70
try {
71
return new CompositeDataSupport(MONITOR_INFO_COMPOSITE_TYPE, items);
72
} catch (OpenDataException e) {
73
// Should never reach here
74
throw new AssertionError(e);
75
}
76
}
77
78
private static final String CLASS_NAME = "className";
79
private static final String IDENTITY_HASH_CODE = "identityHashCode";
80
private static final String LOCKED_STACK_FRAME = "lockedStackFrame";
81
private static final String LOCKED_STACK_DEPTH = "lockedStackDepth";
82
83
private static final String[] MONITOR_INFO_ATTRIBUTES = {
84
CLASS_NAME,
85
IDENTITY_HASH_CODE,
86
LOCKED_STACK_FRAME,
87
LOCKED_STACK_DEPTH
88
};
89
90
private static final CompositeType MONITOR_INFO_COMPOSITE_TYPE;
91
private static final CompositeType V6_COMPOSITE_TYPE;
92
static {
93
try {
94
MONITOR_INFO_COMPOSITE_TYPE = (CompositeType)
95
MappedMXBeanType.toOpenType(MonitorInfo.class);
96
97
OpenType<?>[] types = new OpenType<?>[MONITOR_INFO_ATTRIBUTES.length];
98
for (int i = 0; i < MONITOR_INFO_ATTRIBUTES.length; i++) {
99
String name = MONITOR_INFO_ATTRIBUTES[i];
100
types[i] = name.equals(LOCKED_STACK_FRAME)
101
? StackTraceElementCompositeData.v5CompositeType()
102
: MONITOR_INFO_COMPOSITE_TYPE.getType(name);
103
}
104
V6_COMPOSITE_TYPE = new CompositeType("MonitorInfo",
105
"JDK 6 MonitorInfo",
106
MONITOR_INFO_ATTRIBUTES,
107
MONITOR_INFO_ATTRIBUTES,
108
types);
109
} catch (OpenDataException e) {
110
// Should never reach here
111
throw new AssertionError(e);
112
}
113
}
114
115
static CompositeType v6CompositeType() {
116
return V6_COMPOSITE_TYPE;
117
}
118
119
public static String getClassName(CompositeData cd) {
120
return getString(cd, CLASS_NAME);
121
}
122
123
public static int getIdentityHashCode(CompositeData cd) {
124
return getInt(cd, IDENTITY_HASH_CODE);
125
}
126
127
public static StackTraceElement getLockedStackFrame(CompositeData cd) {
128
CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
129
if (ste != null) {
130
return StackTraceElementCompositeData.from(ste);
131
} else {
132
return null;
133
}
134
}
135
136
public static int getLockedStackDepth(CompositeData cd) {
137
return getInt(cd, LOCKED_STACK_DEPTH);
138
}
139
140
/** Validate if the input CompositeData has the expected
141
* CompositeType (i.e. contain all attributes with expected
142
* names and types).
143
*/
144
public static void validateCompositeData(CompositeData cd) {
145
if (cd == null) {
146
throw new NullPointerException("Null CompositeData");
147
}
148
149
if (!isTypeMatched(MONITOR_INFO_COMPOSITE_TYPE, cd.getCompositeType()) &&
150
!isTypeMatched(V6_COMPOSITE_TYPE, cd.getCompositeType())) {
151
throw new IllegalArgumentException(
152
"Unexpected composite type for MonitorInfo");
153
}
154
}
155
156
private static final long serialVersionUID = -5825215591822908529L;
157
}
158
159