author | chegar |
Fri, 09 Mar 2018 17:59:11 +0000 | |
branch | http-client-branch |
changeset 56272 | 7394452786ba |
parent 47216 | 71c04702a3d5 |
child 49878 | 2422d4e027b0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, 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.*; |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
29 |
import java.lang.reflect.InvocationTargetException; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
30 |
import java.lang.reflect.Method; |
2 | 31 |
import javax.management.InstanceAlreadyExistsException; |
32 |
import javax.management.InstanceNotFoundException; |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
33 |
import javax.management.MBeanServer; |
2 | 34 |
import javax.management.MBeanRegistrationException; |
35 |
import javax.management.NotCompliantMBeanException; |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
36 |
import javax.management.ObjectName; |
2 | 37 |
import javax.management.RuntimeOperationsException; |
38 |
import java.security.AccessController; |
|
39 |
import java.security.PrivilegedActionException; |
|
40 |
import java.security.PrivilegedExceptionAction; |
|
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30355
diff
changeset
|
41 |
|
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30355
diff
changeset
|
42 |
import jdk.internal.misc.JavaNioAccess; |
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30355
diff
changeset
|
43 |
import jdk.internal.misc.SharedSecrets; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
44 |
|
2 | 45 |
import java.util.ArrayList; |
46 |
import java.util.List; |
|
47 |
||
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
48 |
import java.lang.reflect.UndeclaredThrowableException; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
49 |
import java.security.PrivilegedAction; |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
50 |
import java.util.Collections; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
51 |
import java.util.HashMap; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
52 |
import java.util.Map; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
53 |
import java.util.Optional; |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
54 |
|
2 | 55 |
/** |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
56 |
* ManagementFactoryHelper provides static factory methods to create |
2 | 57 |
* instances of the management interface. |
58 |
*/ |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
59 |
public class ManagementFactoryHelper { |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
60 |
static { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
61 |
// make sure that the management lib is loaded within |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
62 |
// java.lang.management.ManagementFactory |
33674
566777f73c32
8140606: Update library code to use internal Unsafe
chegar
parents:
32834
diff
changeset
|
63 |
jdk.internal.misc.Unsafe.getUnsafe().ensureClassInitialized(ManagementFactory.class); |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
64 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
65 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
66 |
private static final VMManagement jvm = new VMManagementImpl(); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
67 |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
68 |
private ManagementFactoryHelper() {}; |
2 | 69 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
70 |
public static VMManagement getVMManagement() { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
71 |
return jvm; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
72 |
} |
2 | 73 |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
74 |
static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; |
2 | 75 |
private static ClassLoadingImpl classMBean = null; |
76 |
private static MemoryImpl memoryMBean = null; |
|
77 |
private static ThreadImpl threadMBean = null; |
|
78 |
private static RuntimeImpl runtimeMBean = null; |
|
79 |
private static CompilationImpl compileMBean = null; |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
80 |
private static BaseOperatingSystemImpl osMBean = null; |
2 | 81 |
|
82 |
public static synchronized ClassLoadingMXBean getClassLoadingMXBean() { |
|
83 |
if (classMBean == null) { |
|
84 |
classMBean = new ClassLoadingImpl(jvm); |
|
85 |
} |
|
86 |
return classMBean; |
|
87 |
} |
|
88 |
||
89 |
public static synchronized MemoryMXBean getMemoryMXBean() { |
|
90 |
if (memoryMBean == null) { |
|
91 |
memoryMBean = new MemoryImpl(jvm); |
|
92 |
} |
|
93 |
return memoryMBean; |
|
94 |
} |
|
95 |
||
96 |
public static synchronized ThreadMXBean getThreadMXBean() { |
|
97 |
if (threadMBean == null) { |
|
98 |
threadMBean = new ThreadImpl(jvm); |
|
99 |
} |
|
100 |
return threadMBean; |
|
101 |
} |
|
102 |
||
103 |
public static synchronized RuntimeMXBean getRuntimeMXBean() { |
|
104 |
if (runtimeMBean == null) { |
|
105 |
runtimeMBean = new RuntimeImpl(jvm); |
|
106 |
} |
|
107 |
return runtimeMBean; |
|
108 |
} |
|
109 |
||
110 |
public static synchronized CompilationMXBean getCompilationMXBean() { |
|
111 |
if (compileMBean == null && jvm.getCompilerName() != null) { |
|
112 |
compileMBean = new CompilationImpl(jvm); |
|
113 |
} |
|
114 |
return compileMBean; |
|
115 |
} |
|
116 |
||
117 |
public static synchronized OperatingSystemMXBean getOperatingSystemMXBean() { |
|
118 |
if (osMBean == null) { |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
119 |
osMBean = new BaseOperatingSystemImpl(jvm); |
2 | 120 |
} |
121 |
return osMBean; |
|
122 |
} |
|
123 |
||
124 |
public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() { |
|
125 |
MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools(); |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
10359
diff
changeset
|
126 |
List<MemoryPoolMXBean> list = new ArrayList<>(pools.length); |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
127 |
for (MemoryPoolMXBean p : pools) { |
2 | 128 |
list.add(p); |
129 |
} |
|
130 |
return list; |
|
131 |
} |
|
132 |
||
133 |
public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() { |
|
134 |
MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
10359
diff
changeset
|
135 |
List<MemoryManagerMXBean> result = new ArrayList<>(mgrs.length); |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
136 |
for (MemoryManagerMXBean m : mgrs) { |
2 | 137 |
result.add(m); |
138 |
} |
|
139 |
return result; |
|
140 |
} |
|
141 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
142 |
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() { |
2 | 143 |
MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers(); |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
10359
diff
changeset
|
144 |
List<GarbageCollectorMXBean> result = new ArrayList<>(mgrs.length); |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
145 |
for (MemoryManagerMXBean m : mgrs) { |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
146 |
if (GarbageCollectorMXBean.class.isInstance(m)) { |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
147 |
result.add(GarbageCollectorMXBean.class.cast(m)); |
2 | 148 |
} |
149 |
} |
|
150 |
return result; |
|
151 |
} |
|
152 |
||
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
153 |
public static PlatformLoggingMXBean getPlatformLoggingMXBean() { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
154 |
if (LoggingMXBeanAccess.isAvailable()) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
155 |
return PlatformLoggingImpl.MBEAN; |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
156 |
} else { |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
157 |
return null; |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
158 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
159 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
160 |
|
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
161 |
public static boolean isPlatformLoggingMXBeanAvailable() { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
162 |
return LoggingMXBeanAccess.isAvailable(); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
163 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
164 |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
165 |
// The LoggingMXBeanAccess class uses reflection to determine |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
166 |
// whether java.util.logging is present, and load the actual LoggingMXBean |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
167 |
// implementation. |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
168 |
// |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
169 |
static final class LoggingMXBeanAccess { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
170 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
171 |
final static String LOG_MANAGER_CLASS_NAME = "java.util.logging.LogManager"; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
172 |
final static String LOGGING_MXBEAN_CLASS_NAME = "java.util.logging.LoggingMXBean"; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
173 |
final static Class<?> LOG_MANAGER_CLASS = loadLoggingClass(LOG_MANAGER_CLASS_NAME); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
174 |
|
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
175 |
static boolean isAvailable() { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
176 |
return LOG_MANAGER_CLASS != null; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
177 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
178 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
179 |
private static Class<?> loadLoggingClass(String className) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
180 |
return AccessController.doPrivileged(new PrivilegedAction<>() { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
181 |
@Override |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
182 |
public Class<?> run() { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
38370
diff
changeset
|
183 |
Optional<Module> logging = ModuleLayer.boot().findModule("java.logging"); |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
184 |
if (logging.isPresent()) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
185 |
return Class.forName(logging.get(), className); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
186 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
187 |
return null; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
188 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
189 |
}); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
190 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
191 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
192 |
private Map<String, Method> initMethodMap(Object impl) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
193 |
if (impl == null) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
194 |
return Collections.emptyMap(); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
195 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
196 |
Class<?> intfClass = loadLoggingClass(LOGGING_MXBEAN_CLASS_NAME); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
197 |
final Map<String, Method> methodsMap = new HashMap<>(); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
198 |
for (Method m : intfClass.getMethods()) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
199 |
try { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
200 |
// Sanity checking: all public methods present in |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
201 |
// java.util.logging.LoggingMXBean should |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
202 |
// also be in PlatformLoggingMXBean |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
203 |
Method specMethod = PlatformLoggingMXBean.class |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
204 |
.getMethod(m.getName(), m.getParameterTypes()); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
205 |
if (specMethod.getReturnType().isAssignableFrom(m.getReturnType())) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
206 |
if (methodsMap.putIfAbsent(m.getName(), m) != null) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
207 |
throw new RuntimeException("unexpected polymorphic method: " |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
208 |
+ m.getName()); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
209 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
210 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
211 |
} catch (NoSuchMethodException x) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
212 |
// All methods in java.util.logging.LoggingMXBean should |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
213 |
// also be in PlatformLoggingMXBean |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
214 |
throw new InternalError(x); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
215 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
216 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
217 |
return Collections.unmodifiableMap(methodsMap); |
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
218 |
} |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
219 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
220 |
private static Object getMXBeanImplementation() { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
221 |
if (!isAvailable()) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
222 |
// should not happen |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
223 |
throw new NoClassDefFoundError(LOG_MANAGER_CLASS_NAME); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
224 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
225 |
try { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
226 |
final Method m = LOG_MANAGER_CLASS.getMethod("getLoggingMXBean"); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
227 |
return m.invoke(null); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
228 |
} catch (NoSuchMethodException |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
229 |
| IllegalAccessException |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
230 |
| InvocationTargetException x) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
231 |
throw new ExceptionInInitializerError(x); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
232 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
233 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
234 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
235 |
// The implementation object, which will be invoked through |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
236 |
// reflection. The implementation does not need to implement |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
237 |
// PlatformLoggingMXBean, but must declare the same methods |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
238 |
// with same signatures, and they must be public, with one |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
239 |
// exception: |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
240 |
// getObjectName will not be called on the implementation object, |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
241 |
// so the implementation object does not need to declare such |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
242 |
// a method. |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
243 |
final Object impl = getMXBeanImplementation(); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
244 |
final Map<String, Method> methods = initMethodMap(impl); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
245 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
246 |
LoggingMXBeanAccess() { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
247 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
248 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
249 |
<T> T invoke(String methodName, Object... args) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
250 |
Method m = methods.get(methodName); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
251 |
if (m == null) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
252 |
throw new UnsupportedOperationException(methodName); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
253 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
254 |
try { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
255 |
@SuppressWarnings("unchecked") |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
256 |
T result = (T) m.invoke(impl, args); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
257 |
return result; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
258 |
} catch (IllegalAccessException ex) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
259 |
throw new UnsupportedOperationException(ex); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
260 |
} catch (InvocationTargetException ex) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
261 |
throw unwrap(ex); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
262 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
263 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
264 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
265 |
private static RuntimeException unwrap(InvocationTargetException x) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
266 |
Throwable t = x.getCause(); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
267 |
if (t instanceof RuntimeException) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
268 |
return (RuntimeException)t; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
269 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
270 |
if (t instanceof Error) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
271 |
throw (Error)t; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
272 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
273 |
return new UndeclaredThrowableException(t == null ? x : t); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
274 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
275 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
276 |
|
33875
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
277 |
} |
c1c71107d45f
8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
33674
diff
changeset
|
278 |
|
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
279 |
static final class PlatformLoggingImpl implements PlatformLoggingMXBean { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
280 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
281 |
private final LoggingMXBeanAccess loggingAccess; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
282 |
private PlatformLoggingImpl(LoggingMXBeanAccess loggingAccess) { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
283 |
this.loggingAccess = loggingAccess; |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
284 |
} |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
285 |
|
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
286 |
private volatile ObjectName objname; // created lazily |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
287 |
@Override |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
288 |
public ObjectName getObjectName() { |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
289 |
ObjectName result = objname; |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
290 |
if (result == null) { |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
291 |
synchronized (this) { |
10359
2eff81585f6b
7068328: BufferPoolMXBean and PlatformLoggingMXBean getObjectName may return null
mchung
parents:
9013
diff
changeset
|
292 |
result = objname; |
2eff81585f6b
7068328: BufferPoolMXBean and PlatformLoggingMXBean getObjectName may return null
mchung
parents:
9013
diff
changeset
|
293 |
if (result == null) { |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
294 |
result = Util.newObjectName(LOGGING_MXBEAN_NAME); |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
295 |
objname = result; |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
296 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
297 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
298 |
} |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
299 |
return result; |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
300 |
} |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
301 |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
302 |
@Override |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
303 |
public java.util.List<String> getLoggerNames() { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
304 |
return loggingAccess.invoke("getLoggerNames"); |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
305 |
} |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
306 |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
307 |
@Override |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
308 |
public String getLoggerLevel(String loggerName) { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
309 |
return loggingAccess.invoke("getLoggerLevel", loggerName); |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
310 |
} |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
311 |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
312 |
@Override |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
313 |
public void setLoggerLevel(String loggerName, String levelName) { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
314 |
loggingAccess.invoke("setLoggerLevel", loggerName, levelName); |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
315 |
} |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
316 |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
317 |
@Override |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
318 |
public String getParentLoggerName(String loggerName) { |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
319 |
return loggingAccess.invoke("getParentLoggerName", loggerName); |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
320 |
} |
38370
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
321 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
322 |
private static PlatformLoggingImpl getInstance() { |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
323 |
return new PlatformLoggingImpl(new LoggingMXBeanAccess()); |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
324 |
} |
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
325 |
|
61f46e1e7aee
8139982: Re-examine java.management dependency on java.util.logging.LoggingMXBean
dfuchs
parents:
34882
diff
changeset
|
326 |
static final PlatformLoggingMXBean MBEAN = getInstance(); |
4172
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
327 |
} |
bceea7bc12b7
6876135: Add PlatformLoggingMXBean to eliminate the dependency on JMX from logging
mchung
parents:
4156
diff
changeset
|
328 |
|
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
329 |
private static List<BufferPoolMXBean> bufferPools = null; |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
330 |
public static synchronized List<BufferPoolMXBean> getBufferPoolMXBeans() { |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
331 |
if (bufferPools == null) { |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
332 |
bufferPools = new ArrayList<>(2); |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30355
diff
changeset
|
333 |
bufferPools.add(createBufferPoolMXBean(SharedSecrets.getJavaNioAccess() |
9013
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
334 |
.getDirectBufferPool())); |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
335 |
bufferPools.add(createBufferPoolMXBean(sun.nio.ch.FileChannelImpl |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
336 |
.getMappedBufferPool())); |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
337 |
} |
eedac0b9f552
7024172: Move BufferPoolMXBean and PlatformLoggingMXBean java.lang.management
mchung
parents:
5506
diff
changeset
|
338 |
return bufferPools; |
3066
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
339 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
340 |
|
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
341 |
private final static String BUFFER_POOL_MXBEAN_NAME = "java.nio:type=BufferPool"; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
342 |
|
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
343 |
/** |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
344 |
* Creates management interface for the given buffer pool. |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
345 |
*/ |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
346 |
private static BufferPoolMXBean |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30355
diff
changeset
|
347 |
createBufferPoolMXBean(final JavaNioAccess.BufferPool pool) |
3066
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
348 |
{ |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
349 |
return new BufferPoolMXBean() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
350 |
private volatile ObjectName objname; // created lazily |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
351 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
352 |
public ObjectName getObjectName() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
353 |
ObjectName result = objname; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
354 |
if (result == null) { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
355 |
synchronized (this) { |
10359
2eff81585f6b
7068328: BufferPoolMXBean and PlatformLoggingMXBean getObjectName may return null
mchung
parents:
9013
diff
changeset
|
356 |
result = objname; |
2eff81585f6b
7068328: BufferPoolMXBean and PlatformLoggingMXBean getObjectName may return null
mchung
parents:
9013
diff
changeset
|
357 |
if (result == null) { |
4156 | 358 |
result = Util.newObjectName(BUFFER_POOL_MXBEAN_NAME + |
3066
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
359 |
",name=" + pool.getName()); |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
360 |
objname = result; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
361 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
362 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
363 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
364 |
return result; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
365 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
366 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
367 |
public String getName() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
368 |
return pool.getName(); |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
369 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
370 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
371 |
public long getCount() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
372 |
return pool.getCount(); |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
373 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
374 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
375 |
public long getTotalCapacity() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
376 |
return pool.getTotalCapacity(); |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
377 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
378 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
379 |
public long getMemoryUsed() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
380 |
return pool.getMemoryUsed(); |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
381 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
382 |
}; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
383 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
1226
diff
changeset
|
384 |
|
2 | 385 |
private static HotspotRuntime hsRuntimeMBean = null; |
386 |
private static HotspotClassLoading hsClassMBean = null; |
|
387 |
private static HotspotThread hsThreadMBean = null; |
|
388 |
private static HotspotCompilation hsCompileMBean = null; |
|
389 |
private static HotspotMemory hsMemoryMBean = null; |
|
390 |
||
391 |
/** |
|
392 |
* This method is for testing only. |
|
393 |
*/ |
|
394 |
public static synchronized HotspotRuntimeMBean getHotspotRuntimeMBean() { |
|
395 |
if (hsRuntimeMBean == null) { |
|
396 |
hsRuntimeMBean = new HotspotRuntime(jvm); |
|
397 |
} |
|
398 |
return hsRuntimeMBean; |
|
399 |
} |
|
400 |
||
401 |
/** |
|
402 |
* This method is for testing only. |
|
403 |
*/ |
|
404 |
public static synchronized HotspotClassLoadingMBean getHotspotClassLoadingMBean() { |
|
405 |
if (hsClassMBean == null) { |
|
406 |
hsClassMBean = new HotspotClassLoading(jvm); |
|
407 |
} |
|
408 |
return hsClassMBean; |
|
409 |
} |
|
410 |
||
411 |
/** |
|
412 |
* This method is for testing only. |
|
413 |
*/ |
|
414 |
public static synchronized HotspotThreadMBean getHotspotThreadMBean() { |
|
415 |
if (hsThreadMBean == null) { |
|
416 |
hsThreadMBean = new HotspotThread(jvm); |
|
417 |
} |
|
418 |
return hsThreadMBean; |
|
419 |
} |
|
420 |
||
421 |
/** |
|
422 |
* This method is for testing only. |
|
423 |
*/ |
|
424 |
public static synchronized HotspotMemoryMBean getHotspotMemoryMBean() { |
|
425 |
if (hsMemoryMBean == null) { |
|
426 |
hsMemoryMBean = new HotspotMemory(jvm); |
|
427 |
} |
|
428 |
return hsMemoryMBean; |
|
429 |
} |
|
430 |
||
431 |
/** |
|
432 |
* This method is for testing only. |
|
433 |
*/ |
|
434 |
public static synchronized HotspotCompilationMBean getHotspotCompilationMBean() { |
|
435 |
if (hsCompileMBean == null) { |
|
436 |
hsCompileMBean = new HotspotCompilation(jvm); |
|
437 |
} |
|
438 |
return hsCompileMBean; |
|
439 |
} |
|
440 |
||
441 |
/** |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
442 |
* Registers a given MBean if not registered in the MBeanServer; |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
443 |
* otherwise, just return. |
2 | 444 |
*/ |
445 |
private static void addMBean(MBeanServer mbs, Object mbean, String mbeanName) { |
|
446 |
try { |
|
4156 | 447 |
final ObjectName objName = Util.newObjectName(mbeanName); |
2 | 448 |
|
449 |
// inner class requires these fields to be final |
|
450 |
final MBeanServer mbs0 = mbs; |
|
451 |
final Object mbean0 = mbean; |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
452 |
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
453 |
public Void run() throws MBeanRegistrationException, |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
454 |
NotCompliantMBeanException { |
2 | 455 |
try { |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
456 |
mbs0.registerMBean(mbean0, objName); |
2 | 457 |
return null; |
458 |
} catch (InstanceAlreadyExistsException e) { |
|
459 |
// if an instance with the object name exists in |
|
460 |
// the MBeanServer ignore the exception |
|
461 |
} |
|
462 |
return null; |
|
463 |
} |
|
464 |
}); |
|
465 |
} catch (PrivilegedActionException e) { |
|
466 |
throw Util.newException(e.getException()); |
|
467 |
} |
|
468 |
} |
|
469 |
||
470 |
private final static String HOTSPOT_CLASS_LOADING_MBEAN_NAME = |
|
471 |
"sun.management:type=HotspotClassLoading"; |
|
472 |
||
473 |
private final static String HOTSPOT_COMPILATION_MBEAN_NAME = |
|
474 |
"sun.management:type=HotspotCompilation"; |
|
475 |
||
476 |
private final static String HOTSPOT_MEMORY_MBEAN_NAME = |
|
477 |
"sun.management:type=HotspotMemory"; |
|
478 |
||
479 |
private static final String HOTSPOT_RUNTIME_MBEAN_NAME = |
|
480 |
"sun.management:type=HotspotRuntime"; |
|
481 |
||
482 |
private final static String HOTSPOT_THREAD_MBEAN_NAME = |
|
483 |
"sun.management:type=HotspotThreading"; |
|
484 |
||
485 |
static void registerInternalMBeans(MBeanServer mbs) { |
|
486 |
// register all internal MBeans if not registered |
|
487 |
// No exception is thrown if a MBean with that object name |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
488 |
// already registered |
2 | 489 |
addMBean(mbs, getHotspotClassLoadingMBean(), |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
490 |
HOTSPOT_CLASS_LOADING_MBEAN_NAME); |
2 | 491 |
addMBean(mbs, getHotspotMemoryMBean(), |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
492 |
HOTSPOT_MEMORY_MBEAN_NAME); |
2 | 493 |
addMBean(mbs, getHotspotRuntimeMBean(), |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
494 |
HOTSPOT_RUNTIME_MBEAN_NAME); |
2 | 495 |
addMBean(mbs, getHotspotThreadMBean(), |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
496 |
HOTSPOT_THREAD_MBEAN_NAME); |
2 | 497 |
|
498 |
// CompilationMBean may not exist |
|
499 |
if (getCompilationMXBean() != null) { |
|
500 |
addMBean(mbs, getHotspotCompilationMBean(), |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
501 |
HOTSPOT_COMPILATION_MBEAN_NAME); |
2 | 502 |
} |
503 |
} |
|
504 |
||
505 |
private static void unregisterMBean(MBeanServer mbs, String mbeanName) { |
|
506 |
try { |
|
4156 | 507 |
final ObjectName objName = Util.newObjectName(mbeanName); |
2 | 508 |
|
509 |
// inner class requires these fields to be final |
|
510 |
final MBeanServer mbs0 = mbs; |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
511 |
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
512 |
public Void run() throws MBeanRegistrationException, |
2 | 513 |
RuntimeOperationsException { |
514 |
try { |
|
515 |
mbs0.unregisterMBean(objName); |
|
516 |
} catch (InstanceNotFoundException e) { |
|
517 |
// ignore exception if not found |
|
518 |
} |
|
519 |
return null; |
|
520 |
} |
|
521 |
}); |
|
522 |
} catch (PrivilegedActionException e) { |
|
523 |
throw Util.newException(e.getException()); |
|
524 |
} |
|
525 |
} |
|
526 |
||
527 |
static void unregisterInternalMBeans(MBeanServer mbs) { |
|
528 |
// unregister all internal MBeans |
|
529 |
unregisterMBean(mbs, HOTSPOT_CLASS_LOADING_MBEAN_NAME); |
|
530 |
unregisterMBean(mbs, HOTSPOT_MEMORY_MBEAN_NAME); |
|
531 |
unregisterMBean(mbs, HOTSPOT_RUNTIME_MBEAN_NAME); |
|
532 |
unregisterMBean(mbs, HOTSPOT_THREAD_MBEAN_NAME); |
|
533 |
||
534 |
// CompilationMBean may not exist |
|
535 |
if (getCompilationMXBean() != null) { |
|
536 |
unregisterMBean(mbs, HOTSPOT_COMPILATION_MBEAN_NAME); |
|
537 |
} |
|
538 |
} |
|
539 |
||
540 |
public static boolean isThreadSuspended(int state) { |
|
541 |
return ((state & JMM_THREAD_STATE_FLAG_SUSPENDED) != 0); |
|
542 |
} |
|
543 |
||
544 |
public static boolean isThreadRunningNative(int state) { |
|
545 |
return ((state & JMM_THREAD_STATE_FLAG_NATIVE) != 0); |
|
546 |
} |
|
547 |
||
548 |
public static Thread.State toThreadState(int state) { |
|
549 |
// suspended and native bits may be set in state |
|
550 |
int threadStatus = state & ~JMM_THREAD_STATE_FLAG_MASK; |
|
34882 | 551 |
return jdk.internal.misc.VM.toThreadState(threadStatus); |
2 | 552 |
} |
553 |
||
554 |
// These values are defined in jmm.h |
|
555 |
private static final int JMM_THREAD_STATE_FLAG_MASK = 0xFFF00000; |
|
556 |
private static final int JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000; |
|
557 |
private static final int JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000; |
|
558 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
559 |
// Invoked by the VM |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
560 |
private static MemoryPoolMXBean createMemoryPool |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
561 |
(String name, boolean isHeap, long uThreshold, long gcThreshold) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
562 |
return new MemoryPoolImpl(name, isHeap, uThreshold, gcThreshold); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
563 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
564 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
565 |
private static MemoryManagerMXBean createMemoryManager(String name) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
566 |
return new MemoryManagerImpl(name); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
567 |
} |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
568 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
569 |
private static GarbageCollectorMXBean |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
570 |
createGarbageCollector(String name, String type) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
571 |
|
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
572 |
// ignore type parameter which is for future extension |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
573 |
return new GarbageCollectorImpl(name); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
28775
diff
changeset
|
574 |
} |
2 | 575 |
} |