RFR 8041565: JMX ObjectName could be refactored to save memory
Jaroslav Bachorik
jaroslav.bachorik at oracle.com
Mon Apr 13 09:43:34 UTC 2015
Please, review the following change
Issue : https://bugs.openjdk.java.net/browse/JDK-8041565
Webrev: http://cr.openjdk.java.net/~jbachorik/8041565/webrev.00
In situations when there are 10s of thousands ObjectNname instances
around (enterprise setups etc.) the 3 separate internal boolean fields
can lead to a noticeable memory waste. Adding insult to the injury, with
the current field layout it is necessary to align the instances by 4 bytes.
When using JOL (http://openjdk.java.net/projects/code-tools/jol/) to
inspect the object layout we can see this:
Before optimization (JDK8u40):
---
javax.management.ObjectName object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header)| N/A
12 4 int ObjectName._domain_length N/A
16 1 boolean ObjectName._domain_pattern N/A
17 1 boolean ObjectName._property_list_pattern N/A
18 1 boolean ObjectName._property_value_pattern N/A
19 1 (alignment/padding gap) N/A
20 4 String ObjectName._canonicalName N/A
24 4 Property[] ObjectName._kp_array N/A
28 4 Property[] ObjectName._ca_array N/A
32 4 Map ObjectName._propertyList N/A
36 4 (loss due to the next object alignment)
Instance size: 40 bytes (estimated, the sample instance is not available)
Space losses: 1 bytes internal + 4 bytes external = 5 bytes total
{noformat}
After optimization (JDK9 internal build):
---
javax.management.ObjectName object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header) N/A
12 2 short ObjectName._domain_length N/A
14 1 byte ObjectName._pattern_flag N/A
15 1 (alignment/padding gap) N/A
16 4 String ObjectName._canonicalName N/A
20 4 Property[] ObjectName._kp_array N/A
24 4 Property[] ObjectName._ca_array N/A
28 4 Map ObjectName._propertyList N/A
Instance size: 32 bytes (estimated, the sample instance is not available)
Space losses: 1 bytes internal + 0 bytes external = 1 bytes total
After optimization we can save 8 bytes per instance which can translate
to very interesting numbers on large installations.
To achieve this the domain name length is set to be *short* instead of
*int* and the three booleans kept for the performance purposes are
encoded into one byte value (as proposed by the reporter, Jean-Francois
Denise).
All the regression and JCK tests are passing after this change.
Thanks,
-JB-
More information about the serviceability-dev
mailing list