Primitive boolean array packing
B. Blaser
bsrbnd at gmail.com
Sat Oct 6 22:05:58 UTC 2018
Hi,
Per JVMS, primitive boolean arrays are currently using 8 bits (one
byte) per boolean value, see [1] (baload/bastore).
We've see in some threads [2] 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 [1] allows primitive boolean array packing, I made a
quick experiment which is available here:
http://cr.openjdk.java.net/~bsrbnd/boolpack/webrev.00/
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
unfinished implementation.
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.
Regards,
Bernard
[1] https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-6.html#jvms-6.5.baload
[2] http://mail.openjdk.java.net/pipermail/compiler-dev/2018-September/012504.html
More information about the compiler-dev
mailing list