Primitive boolean array packing

Aleksey Shipilev shade at redhat.com
Sun Oct 7 19:54:00 UTC 2018


On 10/07/2018 07:51 PM, Andrew Haley wrote:
> On 10/07/2018 04:13 PM, Aleksey Shipilev wrote:
>> On 10/07/2018 02:38 PM, B. Blaser wrote:
>>> Thanks Aleksey, you're absolutely right but a programmer can still
>>> disable this feature and use regular boolean arrays if necessary.
>>
>> I fully expect the JVM feature/flag what optionally breaks the Java
>> specification will be flat out rejected.
> 
> It doesn't break the Java specification:
> 
>     Notes
> 
>     The baload instruction is used to load values from both byte and
>     boolean arrays. In Oracle's Java Virtual Machine implementation,
>     boolean arrays - that is, arrays of type T_BOOLEAN (§2.2,
>     §newarray) - are implemented as arrays of 8-bit values. Other
>     implementations may implement packed boolean arrays; the baload
>     instruction of such implementations must be used to access those
>     arrays.

You need to specify what do you mean by "it". Current prototype sure does break the provisions of
JLS 17.6 "Word Tearing":
  https://docs.oracle.com/javase/specs/jls/se11/html/jls-17.html#jls-17.6

My comment was about generic thing: we cannot break the Java spec even if we have the JVM flag that
makes it right again. I thought that what B. was suggesting as the escape hatch. Of course, if you
do packed boolean[] with locked/CAS-ed writes or otherwise guarantee the absence of word tearing, it
does not break the spec.

-Aleksey



More information about the hotspot-dev mailing list