Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/management/OperatingSystemMXBean/PlatformMXBeanTest.java
38828 views
1
/*
2
* Copyright (c) 2008, 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
* @test
26
* @bug 6610094
27
* @summary Test the OperatingSystemMXBean instance returned by
28
* ManagementFactory.getPlatformMXBeans()
29
* @author Mandy Chung
30
*
31
* @run main PlatformMXBeanTest
32
*/
33
34
import java.lang.management.*;
35
import java.util.List;
36
37
public class PlatformMXBeanTest {
38
public static void main(String[] argv) throws Exception {
39
OperatingSystemMXBean osMBean = getOSPlatformMXBean(OperatingSystemMXBean.class);
40
41
// There should have only one single MXBean for the OS MXBean interfaces:
42
// java.lang.management.OperatingSystemMXBean
43
// com.sun.management.OperatingSystemMXBean
44
// com.sun.management.UnixOperatingSystemMXBean
45
if (osMBean != getOSPlatformMXBean(com.sun.management.OperatingSystemMXBean.class)) {
46
throw new RuntimeException(
47
"Invalid com.sun.management.OperatingSystemMXBean instance");
48
}
49
50
if (!System.getProperty("os.name").startsWith("Windows") &&
51
osMBean != getOSPlatformMXBean(com.sun.management.UnixOperatingSystemMXBean.class)) {
52
throw new RuntimeException(
53
"Invalid com.sun.management.UnixOperatingSystemMXBean instance");
54
}
55
}
56
57
private static <T extends OperatingSystemMXBean>
58
T getOSPlatformMXBean(Class<T> c) {
59
List<T> result = ManagementFactory.getPlatformMXBeans(c);
60
if (result.isEmpty()) {
61
return null;
62
} else if (result.size() == 1) {
63
return result.get(0);
64
} else {
65
throw new RuntimeException(c.getName() + " has " +
66
result.size() + " number of instances");
67
}
68
}
69
}
70
71