author | psadhukhan |
Tue, 18 Sep 2018 18:12:40 +0530 | |
changeset 51927 | c88fd713b51c |
parent 47216 | 71c04702a3d5 |
child 58766 | 54ffb15c4839 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, 2008, 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 |
package sun.management; |
|
27 |
||
28 |
import java.lang.management.MemoryUsage; |
|
29 |
import javax.management.openmbean.CompositeType; |
|
30 |
import javax.management.openmbean.CompositeData; |
|
31 |
import javax.management.openmbean.CompositeDataSupport; |
|
32 |
import javax.management.openmbean.OpenDataException; |
|
33 |
||
34 |
/** |
|
35 |
* A CompositeData for MemoryUsage for the local management support. |
|
36 |
* This class avoids the performance penalty paid to the |
|
37 |
* construction of a CompositeData use in the local case. |
|
38 |
*/ |
|
39 |
public class MemoryUsageCompositeData extends LazyCompositeData { |
|
40 |
private final MemoryUsage usage; |
|
41 |
||
42 |
private MemoryUsageCompositeData(MemoryUsage u) { |
|
43 |
this.usage = u; |
|
44 |
} |
|
45 |
||
46 |
public MemoryUsage getMemoryUsage() { |
|
47 |
return usage; |
|
48 |
} |
|
49 |
||
50 |
public static CompositeData toCompositeData(MemoryUsage u) { |
|
51 |
MemoryUsageCompositeData mucd = new MemoryUsageCompositeData(u); |
|
52 |
return mucd.getCompositeData(); |
|
53 |
} |
|
54 |
||
55 |
protected CompositeData getCompositeData() { |
|
56 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
|
57 |
// memoryUsageItemNames! |
|
58 |
final Object[] memoryUsageItemValues = { |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
5506
diff
changeset
|
59 |
usage.getInit(), |
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
5506
diff
changeset
|
60 |
usage.getUsed(), |
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
5506
diff
changeset
|
61 |
usage.getCommitted(), |
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
5506
diff
changeset
|
62 |
usage.getMax(), |
2 | 63 |
}; |
64 |
||
65 |
try { |
|
66 |
return new CompositeDataSupport(memoryUsageCompositeType, |
|
67 |
memoryUsageItemNames, |
|
68 |
memoryUsageItemValues); |
|
69 |
} catch (OpenDataException e) { |
|
70 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
71 |
throw new AssertionError(e); |
2 | 72 |
} |
73 |
} |
|
74 |
||
75 |
private static final CompositeType memoryUsageCompositeType; |
|
76 |
static { |
|
77 |
try { |
|
78 |
memoryUsageCompositeType = (CompositeType) |
|
79 |
MappedMXBeanType.toOpenType(MemoryUsage.class); |
|
80 |
} catch (OpenDataException e) { |
|
81 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
82 |
throw new AssertionError(e); |
2 | 83 |
} |
84 |
} |
|
85 |
||
86 |
static CompositeType getMemoryUsageCompositeType() { |
|
87 |
return memoryUsageCompositeType; |
|
88 |
} |
|
89 |
||
90 |
private static final String INIT = "init"; |
|
91 |
private static final String USED = "used"; |
|
92 |
private static final String COMMITTED = "committed"; |
|
93 |
private static final String MAX = "max"; |
|
94 |
||
95 |
private static final String[] memoryUsageItemNames = { |
|
96 |
INIT, |
|
97 |
USED, |
|
98 |
COMMITTED, |
|
99 |
MAX, |
|
100 |
}; |
|
101 |
||
102 |
public static long getInit(CompositeData cd) { |
|
103 |
return getLong(cd, INIT); |
|
104 |
} |
|
105 |
public static long getUsed(CompositeData cd) { |
|
106 |
return getLong(cd, USED); |
|
107 |
} |
|
108 |
public static long getCommitted(CompositeData cd) { |
|
109 |
return getLong(cd, COMMITTED); |
|
110 |
} |
|
111 |
public static long getMax(CompositeData cd) { |
|
112 |
return getLong(cd, MAX); |
|
113 |
} |
|
114 |
||
115 |
/** Validate if the input CompositeData has the expected |
|
116 |
* CompositeType (i.e. contain all attributes with expected |
|
117 |
* names and types). |
|
118 |
*/ |
|
119 |
public static void validateCompositeData(CompositeData cd) { |
|
120 |
if (cd == null) { |
|
121 |
throw new NullPointerException("Null CompositeData"); |
|
122 |
} |
|
123 |
||
124 |
if (!isTypeMatched(memoryUsageCompositeType, cd.getCompositeType())) { |
|
125 |
throw new IllegalArgumentException( |
|
126 |
"Unexpected composite type for MemoryUsage"); |
|
127 |
} |
|
128 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
129 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
130 |
private static final long serialVersionUID = -8504291541083874143L; |
2 | 131 |
} |