RFR: 8299576: Reimplement java.io.Bits using VarHandle access [v2]
Andriy Plokhotnyuk
duke at openjdk.org
Wed Jan 4 13:18:49 UTC 2023
On Wed, 4 Jan 2023 12:40:43 GMT, Per Minborg <pminborg at openjdk.org> wrote:
> > @minborg Amazing piece!
> > Will `java.lang.invoke.VarHandle` instances be shared in JDK to reuse in other places?
> > The [jsoniter-scala-coreJVM](https://github.com/plokhotnyuk/jsoniter-scala/tree/master/jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core) module of the [jsoniter-scala](https://github.com/plokhotnyuk/jsoniter-scala) project has a lot of SWAR tricks that use `java.lang.invoke.VarHandle` to speed up parsing/serialization of primitives, `java.math.BigDecimal`, and `java.time.*` classes from/to textual representation.
> > Are you interested to port some of them to JDK as it was done for `java.util.UUID` parsing [here](https://github.com/openjdk/jdk/commit/ebadfaeb2e1cc7b5ce5f101cd8a539bc5478cf5b)?
>
> Thanks. I think instances will be private to this class and other have to be created elsewhere if needed.
>
> Do you see any concrete examples of classes in the JDK that could benefit from a "VarHandlization"?
Basically, places for improvements are `parse(String s)` and `toString` methods of classes mentioned above.
When parsing from `String` we can access the internal array of bytes, and for serialization we can create `String` instances from byte arrays without copying using some a kind of `Unsafe` access for both.
Please open [`JsonReader`](https://github.com/plokhotnyuk/jsoniter-scala/blob/master/jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala) and [`JsonWriter`](https://github.com/plokhotnyuk/jsoniter-scala/blob/master/jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonWriter.scala) sources and skim through `ByteArrayAccess` usages there.
-------------
PR: https://git.openjdk.org/jdk/pull/11840
More information about the core-libs-dev
mailing list