public final class ManagementSupport extends Object
ManagementFactory
. There are two mostly independent
parts: The beans (implementations of PlatformManagedObject
) themselves; and the singleton
MBean server
.
Support for PlatformManagedObject
: All MXBean that provide VM introspection are allocated
eagerly at image build time, and stored in ManagementSupport.platformManagedObjectsMap
as well as
ManagementSupport.platformManagedObjectsSet
. The registration is decentralized: while some general beans
are registered in this class, the OS specific and GC specific beans are registered in the
respective OS or GC code. To find all registrations, look for the usages of
ManagementSupport.addPlatformManagedObjectSingleton(java.lang.Class<T>, T)
and ManagementSupport.addPlatformManagedObjectList(java.lang.Class<T>, java.util.List<T>)
. Eager
allocation of all the beans avoids the complicated registry that the JDK maintains for lazy
loading (the code in PlatformComponent - note that this code and even the package of the class is
significantly different between JDK 8 and JDK 11).
Support for ManagementFactory.getPlatformMBeanServer()
: The MBeanServer
that
makes all MXBean available too is allocated lazily at run time. This has advantages and
disadvantages. The MBeanServer
and all the bean registrations is a quite heavyweight data
structure. All the attributes and operations of the beans are stored in several nested hash maps.
Putting all of that in the image heap would increase the image heap size, but also avoid the
allocation at run time on first access. Unfortunately, there are also many additional global
caches for bean and attribute lookup, for example in MXBeanLookup
, MXBeanIntrospector,
and MBeanServerFactory
. Beans from the hosting VM that runs the image build must not be
made available at runtime using these caches, i.e., a complicated re-build of the caches would be
necessary at image build time. Therefore we opted to inialize the MBeanServer
at run
time.
This has two important consequences: 1) There must not be any MBeanServer
in the image
heap, neither the singleton platform server nor a custom server created by the application.
Classes that cache a MBeanServer
in a static final field must be initialized at run time.
2) All the attribute lookup of the platform beans happens at run time during initialization.
Attributes are found using reflection (enumerating all methods of the bean interface). So the
attributes of the platform beans are only available via the MBeanServer
if the methods
are manually registered for reflection by the application. There is no automatic registration of
all methods because that would lead to a significant number of unnecessary method registrations.
It is cumbersome to access attributes of platform beans via the MBeanServer
, getting the
platform objects and directly calling methods on them is much easier and therefore the common use
case. We therefore believe that the automatic reflection registration is indeed unnecessary.Modifier and Type | Method and Description |
---|---|
<T extends PlatformManagedObject> |
addPlatformManagedObjectList(Class<T> clazz,
List<T> objects)
Adds the provided list of
PlatformManagedObject for the provided interface and all
its superinterfaces. |
<T extends PlatformManagedObject> |
addPlatformManagedObjectSingleton(Class<T> clazz,
T object)
Registers a new singleton
PlatformManagedObject for the provided interface and all
its superinterfaces. |
static ManagementSupport |
getSingleton() |
boolean |
isAllowedPlatformManagedObject(PlatformManagedObject object) |
void |
noteThreadFinish(Thread thread) |
void |
noteThreadStart(Thread thread) |
public static ManagementSupport getSingleton()
public <T extends PlatformManagedObject> void addPlatformManagedObjectSingleton(Class<T> clazz, T object)
PlatformManagedObject
for the provided interface and all
its superinterfaces.public <T extends PlatformManagedObject> void addPlatformManagedObjectList(Class<T> clazz, List<T> objects)
PlatformManagedObject
for the provided interface and all
its superinterfaces.public boolean isAllowedPlatformManagedObject(PlatformManagedObject object)
public void noteThreadStart(Thread thread)
public void noteThreadFinish(Thread thread)