Primitive boolean array packing
bsrbnd at gmail.com
Sat Oct 6 22:05:58 UTC 2018
Per JVMS, primitive boolean arrays are currently using 8 bits (one
byte) per boolean value, see  (baload/bastore).
We've see in some threads  that 'BitSet' or 'EnumSet' are
occasionally preferred solutions as they are using boolean vectors
(aka long values) using 8x less memory.
But as the spec  allows primitive boolean array packing, I made a
quick experiment which is available here:
This is a partial draft implementing primitive boolean array packing
(8x smaller) at machine-level (vs BitSet at class-level):
* only x86 interpreter implemented => c1/c2/inlining disabled for
methods using baload/bastore (not much performance regression when
building the jdk and running the tests)
* unsafe access partially implemented
* array copy currently not implemented
* -XX:+/-BooleanPacking to enable/disable the feature currently not implemented
A couple of residual tier1 tests are still failing due to the
I didn't search much if such experiments have already been
accomplished, but I'd like to take the temperature of this feature as
completing the implementation represents a significant amount of work.
Is this something that is worth exploring?
Thanks in advance for any feedback.
More information about the jdk-dev