Skip to content

Commit 5da965e

Browse files
committed
Fix for WFCORE-7235, evolve platform MBeans with JDK11 com.sun.management content and JDK11 java.lang new content
1 parent f68c877 commit 5da965e

31 files changed

+1464
-53
lines changed

core-feature-pack/common/src/main/resources/modules/system/layers/base/org/jboss/as/platform-mbean/main/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
<module name="org.wildfly.security.elytron-private"/>
2626
<module name="org.jboss.msc"/>
2727
<module name="org.jboss.logging"/>
28+
<module name="org.jboss.as.version"/>
2829
</dependencies>
2930
</module>

core-model-test/framework/src/main/java/org/jboss/as/core/model/test/KnownIssuesValidationConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private static ValidationConfiguration createForStandalone() {
4747
config.allowNullValueTypeForOperationReplyProperties(createStandlonePlatformMBeanAddress(PlatformMBeanConstants.OPERATING_SYSTEM), READ_RESOURCE_OPERATION);
4848
config.allowNullValueTypeForOperationReplyProperties(createStandlonePlatformMBeanAddress(PlatformMBeanConstants.MEMORY_POOL), READ_RESOURCE_OPERATION);
4949
config.allowNullValueTypeForOperationReplyProperties(createStandlonePlatformMBeanAddress(PlatformMBeanConstants.RUNTIME), READ_RESOURCE_OPERATION);
50+
config.allowNullValueTypeForOperationReplyProperties(createStandlonePlatformMBeanAddress(PlatformMBeanConstants.PLATFORM_LOGGING), READ_RESOURCE_OPERATION);
5051
final ModelNode MEMORY_POOL_CHILDREN_ADDR = createStandlonePlatformMBeanAddress(PlatformMBeanConstants.MEMORY_POOL);
5152
MEMORY_POOL_CHILDREN_ADDR.add(NAME, "*");
5253
config.allowNullValueTypeForOperationReplyProperties(MEMORY_POOL_CHILDREN_ADDR, READ_RESOURCE_OPERATION);
@@ -73,6 +74,7 @@ private static ValidationConfiguration createForHost() {
7374
config.allowNullValueTypeForOperationReplyProperties(createHostPlatformMBeanAddress(PlatformMBeanConstants.OPERATING_SYSTEM), READ_RESOURCE_OPERATION);
7475
config.allowNullValueTypeForOperationReplyProperties(createHostPlatformMBeanAddress(PlatformMBeanConstants.MEMORY_POOL), READ_RESOURCE_OPERATION);
7576
config.allowNullValueTypeForOperationReplyProperties(createHostPlatformMBeanAddress(PlatformMBeanConstants.RUNTIME), READ_RESOURCE_OPERATION);
77+
config.allowNullValueTypeForOperationReplyProperties(createHostPlatformMBeanAddress(PlatformMBeanConstants.PLATFORM_LOGGING), READ_RESOURCE_OPERATION);
7678
final ModelNode MEMORY_POOL_CHILDREN_ADDR = createHostPlatformMBeanAddress(PlatformMBeanConstants.MEMORY_POOL);
7779
MEMORY_POOL_CHILDREN_ADDR.add(NAME, "*");
7880
config.allowNullValueTypeForOperationReplyProperties(MEMORY_POOL_CHILDREN_ADDR, READ_RESOURCE_OPERATION);
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright The WildFly Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package org.jboss.as.platform.mbean;
6+
7+
import java.lang.management.ManagementFactory;
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
import java.util.Objects;
12+
import javax.management.Attribute;
13+
import javax.management.AttributeNotFoundException;
14+
import javax.management.InstanceNotFoundException;
15+
import javax.management.IntrospectionException;
16+
import javax.management.InvalidAttributeValueException;
17+
import javax.management.MBeanAttributeInfo;
18+
import javax.management.MBeanException;
19+
import javax.management.MBeanOperationInfo;
20+
import javax.management.MBeanParameterInfo;
21+
import javax.management.MalformedObjectNameException;
22+
import javax.management.ObjectName;
23+
import javax.management.ReflectionException;
24+
25+
/**
26+
* Utility to access to the com.sun.management MBeans
27+
*
28+
* @author jdenise
29+
*/
30+
class AbstractExtendedMBean {
31+
32+
private final ObjectName name;
33+
34+
AbstractExtendedMBean(String name) {
35+
try {
36+
this.name = new ObjectName(name);
37+
} catch (MalformedObjectNameException ex) {
38+
throw new IllegalStateException(ex);
39+
}
40+
}
41+
42+
boolean isAttributeDefined(String attributeName) {
43+
Objects.requireNonNull(attributeName);
44+
try {
45+
for (MBeanAttributeInfo attribute
46+
: ManagementFactory.getPlatformMBeanServer().getMBeanInfo(name).getAttributes()) {
47+
if (attributeName.equals(attribute.getName())) {
48+
return true;
49+
}
50+
}
51+
} catch (InstanceNotFoundException | IntrospectionException | ReflectionException ex) {
52+
// XXX OK, attribute not available.
53+
}
54+
return false;
55+
}
56+
57+
// Operation
58+
boolean isOperationDefined(String operationName, String[] types) {
59+
Objects.requireNonNull(operationName);
60+
Objects.requireNonNull(types);
61+
try {
62+
for (MBeanOperationInfo op
63+
: ManagementFactory.getPlatformMBeanServer().getMBeanInfo(name).getOperations()) {
64+
if (operationName.equals(op.getName())) {
65+
List<String> signature = new ArrayList<>();
66+
for(MBeanParameterInfo p : op.getSignature()) {
67+
signature.add(p.getType());
68+
}
69+
List<String> receivedTypes = Arrays.asList(types);
70+
if(receivedTypes.equals(signature)) {
71+
return true;
72+
}
73+
}
74+
}
75+
} catch (InstanceNotFoundException | IntrospectionException | ReflectionException ex) {
76+
// XXX OK, operation not available.
77+
}
78+
return false;
79+
}
80+
81+
Object getAttribute(String attributeName) {
82+
try {
83+
return ManagementFactory.getPlatformMBeanServer().
84+
getAttribute(name, attributeName);
85+
} catch (AttributeNotFoundException
86+
| InstanceNotFoundException
87+
| MBeanException
88+
| ReflectionException ex) {
89+
throw new IllegalStateException(ex);
90+
}
91+
}
92+
93+
void setAttribute(String attributeName, Object value) {
94+
try {
95+
Attribute attribute = new Attribute(attributeName, value);
96+
ManagementFactory.getPlatformMBeanServer().
97+
setAttribute(name, attribute);
98+
} catch (AttributeNotFoundException
99+
| InstanceNotFoundException
100+
| InvalidAttributeValueException
101+
| MBeanException
102+
| ReflectionException ex) {
103+
throw new IllegalStateException(ex);
104+
}
105+
}
106+
107+
Object invokeOperation(String opName, Object[] values, String[] signature) {
108+
try {
109+
return ManagementFactory.getPlatformMBeanServer().
110+
invoke(name, opName, values, signature);
111+
} catch (InstanceNotFoundException | MBeanException | ReflectionException ex) {
112+
throw new IllegalStateException(ex);
113+
}
114+
}
115+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright The WildFly Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package org.jboss.as.platform.mbean;
6+
7+
import java.lang.management.ManagementFactory;
8+
import java.lang.management.MemoryUsage;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import javax.management.openmbean.CompositeData;
12+
import javax.management.openmbean.TabularData;
13+
14+
/**
15+
* Implements the access to the com.sun.management.GarbageCollectorMXBean
16+
*
17+
* @author jdenise
18+
*/
19+
class ExtendedGarbageCollectorMBean extends AbstractExtendedMBean {
20+
21+
static class GcInfo {
22+
23+
private final long duration;
24+
private final long endTime;
25+
private final long id;
26+
private final Map<String, MemoryUsage> memoryUsageAfterGc;
27+
private final Map<String, MemoryUsage> memoryUsageBeforeGc;
28+
private final long startTime;
29+
30+
GcInfo(long duration,
31+
long endTime,
32+
long id,
33+
Map<String, MemoryUsage> memoryUsageAfterGc,
34+
Map<String, MemoryUsage> memoryUsageBeforeGc,
35+
long startTime) {
36+
this.duration = duration;
37+
this.endTime = endTime;
38+
this.id = id;
39+
this.memoryUsageAfterGc = memoryUsageAfterGc;
40+
this.memoryUsageBeforeGc = memoryUsageBeforeGc;
41+
this.startTime = startTime;
42+
}
43+
44+
long getDuration() {
45+
return duration;
46+
}
47+
48+
long getEndTime() {
49+
return endTime;
50+
}
51+
52+
long getId() {
53+
return id;
54+
}
55+
56+
Map<String, MemoryUsage> getMemoryUsageAfterGc() {
57+
return memoryUsageAfterGc;
58+
}
59+
60+
Map<String, MemoryUsage> getMemoryUsageBeforeGc() {
61+
return memoryUsageBeforeGc;
62+
}
63+
64+
long getStartTime() {
65+
return startTime;
66+
}
67+
}
68+
static final String LAST_GC_INFO_ATTRIBUTE = "LastGcInfo";
69+
private static final String DURATION = "duration";
70+
private static final String END_TIME = "endTime";
71+
private static final String ID = "id";
72+
private static final String MEMORY_USAGE_BEFORE_GC = "memoryUsageBeforeGc";
73+
private static final String MEMORY_USAGE_AFTER_GC = "memoryUsageAfterGc";
74+
private static final String START_TIME = "startTime";
75+
76+
ExtendedGarbageCollectorMBean(String gcName) {
77+
super(PlatformMBeanUtil.getObjectNameStringWithNameKey(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, gcName));
78+
}
79+
80+
GcInfo getLastGcInfo() {
81+
GcInfo gcInfo = null;
82+
CompositeData cd = (CompositeData) getAttribute(LAST_GC_INFO_ATTRIBUTE);
83+
if (cd != null) {
84+
long duration = (long) cd.get(DURATION);
85+
long endTime = (long) cd.get(END_TIME);
86+
long id = (long) cd.get(ID);
87+
TabularData beforeGc = (TabularData) cd.get(MEMORY_USAGE_BEFORE_GC);
88+
Map<String, MemoryUsage> beforeGcMap = new HashMap<>();
89+
for (Object value : beforeGc.values()) {
90+
CompositeData cdValue = (CompositeData) value;
91+
String key = (String)cdValue.get("key");
92+
CompositeData usageCd = (CompositeData)cdValue.get("value");
93+
MemoryUsage usage = MemoryUsage.from(usageCd);
94+
beforeGcMap.put(key, usage);
95+
}
96+
TabularData afterGc = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
97+
Map<String, MemoryUsage> afterGcMap = new HashMap<>();
98+
for (Object value : afterGc.values()) {
99+
CompositeData cdValue = (CompositeData) value;
100+
String key = (String)cdValue.get("key");
101+
CompositeData usageCd = (CompositeData)cdValue.get("value");
102+
MemoryUsage usage = MemoryUsage.from(usageCd);
103+
afterGcMap.put(key, usage);
104+
}
105+
106+
long startTime = (long) cd.get(START_TIME);
107+
gcInfo = new GcInfo(duration,
108+
endTime,
109+
id,
110+
afterGcMap,
111+
beforeGcMap,
112+
startTime);
113+
}
114+
return gcInfo;
115+
}
116+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright The WildFly Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package org.jboss.as.platform.mbean;
6+
7+
import java.lang.management.ManagementFactory;
8+
9+
/**
10+
* Implements the access to the com.sun.management.OperatingSystemMXBean
11+
*
12+
* @author jdenise
13+
*/
14+
class ExtendedOperatingSystemMBean extends AbstractExtendedMBean {
15+
16+
static final String COMMITTED_VIRTUAL_MEMORY_SIZE_ATTRIBUTE = "CommittedVirtualMemorySize";
17+
static final String FREE_MEMORY_SIZE_ATTRIBUTE = "FreeMemorySize";
18+
static final String FREE_SWAP_SPACE_SIZE_ATTRIBUTE = "FreeSwapSpaceSize";
19+
static final String PROCESS_CPU_LOAD_ATTRIBUTE = "ProcessCpuLoad";
20+
static final String PROCESS_CPU_TIME_ATTRIBUTE = "ProcessCpuTime";
21+
static final String CPU_LOAD_ATTRIBUTE = "CpuLoad";
22+
static final String TOTAL_MEMORY_SIZE = "TotalMemorySize";
23+
static final String TOTAL_SWAP_SPACE_SIZE = "TotalSwapSpaceSize";
24+
25+
// Unix specific
26+
static final String MAX_FILE_DESCRIPTOR_COUNT_ATTRIBUTE = "MaxFileDescriptorCount";
27+
static final String OPEN_FILE_DESCRIPTOR_COUNT = "OpenFileDescriptorCount";
28+
29+
ExtendedOperatingSystemMBean() {
30+
super(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
31+
}
32+
33+
long getCommittedVirtualMemorySize() {
34+
return (long) getAttribute(COMMITTED_VIRTUAL_MEMORY_SIZE_ATTRIBUTE);
35+
36+
}
37+
38+
long getFreePhysicalMemorySize() {
39+
return (long) getAttribute(FREE_MEMORY_SIZE_ATTRIBUTE);
40+
}
41+
42+
long getFreeSwapSpaceSize() {
43+
return (long) getAttribute(FREE_SWAP_SPACE_SIZE_ATTRIBUTE);
44+
}
45+
46+
double getProcessCpuLoad() {
47+
return (double) getAttribute(PROCESS_CPU_LOAD_ATTRIBUTE);
48+
}
49+
50+
double getSystemCpuLoad() {
51+
return (double) getAttribute(CPU_LOAD_ATTRIBUTE);
52+
}
53+
54+
long getProcessCpuTime() {
55+
return (long) getAttribute(PROCESS_CPU_TIME_ATTRIBUTE);
56+
}
57+
58+
long getTotalPhysicalMemorySize() {
59+
return (long) getAttribute(TOTAL_MEMORY_SIZE);
60+
}
61+
62+
long getTotalSwapSpaceSize() {
63+
return (long) getAttribute(TOTAL_SWAP_SPACE_SIZE);
64+
}
65+
66+
long getMaxFileDescriptorCount() {
67+
return (long) getAttribute(MAX_FILE_DESCRIPTOR_COUNT_ATTRIBUTE);
68+
}
69+
70+
long getOpenFileDescriptorCount() {
71+
return (long) getAttribute(OPEN_FILE_DESCRIPTOR_COUNT);
72+
}
73+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright The WildFly Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package org.jboss.as.platform.mbean;
6+
7+
import java.lang.management.ManagementFactory;
8+
9+
/**
10+
* Implements the access to the com.sun.management.ThreadMXBean
11+
*
12+
* @author jdenise
13+
*/
14+
class ExtendedThreadMBean extends AbstractExtendedMBean {
15+
16+
static final String THREAD_ALLOCATED_MEMORY_ENABLED_ATTRIBUTE = "ThreadAllocatedMemoryEnabled";
17+
static final String THREAD_ALLOCATED_MEMORY_SUPPORTED_ATTRIBUTE = "ThreadAllocatedMemorySupported";
18+
static final String CURRENT_THREAD_ALLOCATED_BYTES_ATTRIBUTE = "CurrentThreadAllocatedBytes";
19+
20+
static final String GET_THREAD_CPU_TIME = "getThreadCpuTime";
21+
static final String GET_THREAD_ALLOCATED_BYTES = "getThreadAllocatedBytes";
22+
static final String GET_THREAD_USER_TIME = "getThreadUserTime";
23+
24+
ExtendedThreadMBean() {
25+
super(ManagementFactory.THREAD_MXBEAN_NAME);
26+
}
27+
28+
long getCurrentThreadAllocatedBytes() {
29+
return (long) getAttribute(CURRENT_THREAD_ALLOCATED_BYTES_ATTRIBUTE);
30+
}
31+
32+
boolean isThreadAllocatedMemoryEnabled() {
33+
return (boolean) getAttribute(THREAD_ALLOCATED_MEMORY_ENABLED_ATTRIBUTE);
34+
35+
}
36+
37+
boolean isThreadAllocatedMemorySupported() {
38+
return (boolean) getAttribute(THREAD_ALLOCATED_MEMORY_SUPPORTED_ATTRIBUTE);
39+
40+
}
41+
42+
void setThreadAllocatedMemoryEnabled(boolean value) {
43+
setAttribute(THREAD_ALLOCATED_MEMORY_ENABLED_ATTRIBUTE, value);
44+
}
45+
46+
long[] getThreadCpuTime(long[] ids) {
47+
return (long[]) invokeOperation(GET_THREAD_CPU_TIME,
48+
new Object[]{ids}, new String[]{long[].class.getName()});
49+
}
50+
51+
long getThreadAllocatedBytes(long id) {
52+
return (long) invokeOperation(GET_THREAD_ALLOCATED_BYTES,
53+
new Object[]{id}, new String[]{long.class.getName()});
54+
}
55+
56+
long[] getThreadAllocatedBytes(long[] id) {
57+
return (long[]) invokeOperation(GET_THREAD_ALLOCATED_BYTES,
58+
new Object[]{id}, new String[]{long[].class.getName()});
59+
}
60+
61+
long[] getThreadUserTime(long[] ids) {
62+
return (long[]) invokeOperation(GET_THREAD_USER_TIME,
63+
new Object[]{ids}, new String[]{long[].class.getName()});
64+
}
65+
}

0 commit comments

Comments
 (0)