[foreign-memaccess+abi] RFR: Avoid using StandardCharset in Java code

Per Minborg pminborg at openjdk.org
Tue Aug 15 08:04:32 UTC 2023


On Mon, 14 Aug 2023 11:29:54 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> According to a comment in `java.nio.charset.StandardCharsets`, the use of this class should be avoided from elsewhere in the `jdk.base` module. This PR proposes removing all such direct use of said class in Java code (but not in JavaDocs).
> 
> 
> public final class StandardCharsets {
> 
>     // To avoid accidental eager initialization of often unused Charsets
>     // from happening while the VM is booting up, which may delay
>     // initialization of VM components, we should generally avoid depending
>     // on this class from elsewhere in java.base.

I've ran some benchmarks:


Benchmark                       Mode  Cnt  Score   Error  Units
SwitchBench.ifOnInstancesUtf32  avgt   30  0.654 ? 0.038  ns/op
SwitchBench.ifOnInstancesUtf8   avgt   30  0.576 ? 0.018  ns/op
SwitchBench.ifOnStringsUtf32    avgt   30  3.923 ? 0.015  ns/op
SwitchBench.ifOnStringsUtf8     avgt   30  0.597 ? 0.018  ns/op
SwitchBench.optimizedUtf32      avgt   30  0.618 ? 0.040  ns/op
SwitchBench.optimizedUtf8       avgt   30  0.576 ? 0.016  ns/op
SwitchBench.switchOnNamesUtf32  avgt   30  1.059 ? 0.005  ns/op
SwitchBench.switchOnNamesUtf8   avgt   30  1.058 ? 0.004  ns/op


And the string switch is a bit slow so I will change to another "optimized" solution.

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

PR Comment: https://git.openjdk.org/panama-foreign/pull/864#issuecomment-1678559246


More information about the panama-dev mailing list