OpendJDK has a Java Object Layout (JOL) tool which allows to estimate instance real memory size of specified object. It can show an object layout for HotSpot but will it be the same in OpenJ9?
OpenJ9 VM Object Layout
359 Views Asked by Sergey Ponomarev At
2
There are 2 best solutions below
1
On
If you have a system core (e.g. via -Xdump:system:events=vmstop) you can look at the sizes of live objects, including the padding and alignment using jdmpview's !objectsizeinfo command, e.g.:
> !objectsizeinfo java/lang/String
Object field size summary
=========================
Class Total size Data size Space used Instances char byte short int long float double boolean object hidden
---------------- ---------- --------- ---------- --------- ---- ---- ----- --- ---- ----- ------ ------- ------ ------
java/lang/String 16 10* 66752 4172 0 2 0 0 0 0 0 0 1 0
Class Total size Data size Space used Instances char byte short int long float double boolean object hidden
Heap summary 66752 41720 66752 4172 0 8344 0 0 0 0 0 0 4172 0
Well, IMHO, the answer is no, for at least the fact that if you count references sizes too, there is
UseCompressedOopsthat is HotSpot specific. May be J9 has it too, but may be not.There is the issue of padding too, in HotSpot objects are
8 bytesaligned (there are more complicated things about inheritance), but I don't know ifJ9does that...