RFR: 8299576: Reimplement java.io.Bits using VarHandle access [v5]

Uwe Schindler uschindler at openjdk.org
Thu Jan 5 11:40:52 UTC 2023


On Wed, 4 Jan 2023 14:37:34 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> Currently, `java.io.Bits` is using explicit logic to read/write various primitive types to/from byte arrays. Switching to the use of `VarHandle` access would provide better performance and less code. 
>> 
>> Also, using a standard API for these conversions means future `VarHandle` improvements will benefit `Bits` too. 
>> 
>> Improvements in `Bits` will propagate to `ObjectInputStream`, `ObjectOutputStream` and `RandomAccessFile`.
>> 
>> Initial benchmarks and performance discussions can be found here: https://github.com/openjdk/panama-foreign/pull/762
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use canonical NaN values

The copypasted snippet above is misleading, you need to read the whole statement, so an IllegalStateException can only happen for unaligned access on access modes other than get/set (so volatile or opaque reads): "If access is misaligned then access for anything **other than the get and set access modes** will result in an IllegalStateException.", the sentence you posted is about if it is atomic or not. It just says that on 32 bits, long/double are not atomic for normal set/get.

P.S.: We definitely know that it works on 32 bit, the whole code of Lucene is full of those VarHandles :-)

-------------

PR: https://git.openjdk.org/jdk/pull/11840


More information about the core-libs-dev mailing list