RFR: 8299576: Reimplement java.io.Bits using VarHandle access [v7]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jan 9 12:14:52 UTC 2023
On Mon, 9 Jan 2023 11:07:51 GMT, Uwe Schindler <uschindler at openjdk.org> wrote:
>> src/java.base/share/classes/java/io/Bits.java line 77:
>>
>>> 75: // Using Double.longBitsToDouble collapses NaN values to a single
>>> 76: // "canonical" NaN value
>>> 77: return Double.longBitsToDouble((long) LONG.get(b, off));
>>
>> For the records, I believe the template classes for byte array var handle already perform this conversion - e.g.
>>
>>
>> @ForceInline
>> static $type$ get(VarHandle ob, Object oba, int index) {
>> ArrayHandle handle = (ArrayHandle)ob;
>> byte[] ba = (byte[]) oba;
>> #if[floatingPoint]
>> $rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
>> ba,
>> ((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
>> handle.be);
>> return $Type$.$rawType$BitsTo$Type$(rawValue); // <-----------------------------
>> #else[floatingPoint]
>> return UNSAFE.get$Type$Unaligned(
>> ba,
>> ((long) index(ba, index)) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
>> handle.be);
>> #end[floatingPoint]
>> }
>> ````
>
> For the other direction it uses the `floatToRawIntBits`: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template#L148-L153
>
> I think for symmatry we should keep it as is.
I see - thanks for the explanation - the problem is with `floatToIntBits` vs `floatToRawIntBits` in the "put" operation. The get operation is ok, but then having asymmetry where we use a float VH in one case (get) but not in the other (put) is not desirable.
-------------
PR: https://git.openjdk.org/jdk/pull/11840
More information about the core-libs-dev
mailing list