RFR: 8298432: Investigate the benefits of usage of GetPrimitiveArrayCritical in the cmm code [v2]

Sergey Bylokhov serb at openjdk.org
Wed Nov 26 19:42:18 UTC 2025


> The LCMS JNI code currently uses GetByteArrayElements, GetShortArrayElements, GetIntArrayElements. These can be replaced by GetPrimitiveArrayCritical, which avoids unnecessary copying of array data and provides measurable performance improvements.
> 
> This optimization was postponed earlier due to several reasons:
> 
>  - At that time, G1 did not support pinning, so critical sections could interfere with GC (see [JEP 423](https://openjdk.org/jeps/423)). Also note that this API is already used safely in many parts of java2d/awt.
>  - There was a plan to migrate to panama, but cold-startup issues ([JDK-8313344](https://bugs.openjdk.org/browse/JDK-8313344)) remain unresolved.
>  - GetPrimitiveArrayCritical forbids many JNI operations inside the critical region, including allocations and java callbacks, which could be unsafe for LCMS error handlers. However, LCMS color conversions do not trigger such callbacks (see [LittleCMS #516](https://github.com/mm2/Little-CMS/issues/516)).
> 
> Performance data of various [combinations](https://bugs.openjdk.org/secure/attachment/114273/OnePixelConvert-1.java) for ColorSpace.toXX/fromXX in single-threaded and multi-threaded (64 threads) modes:
> https://jmh.morethan.io/?gists=b1440355577dc48f2b19b976b67f1120,d31c6a585330c9167b462e377445ad2f
> Example:
> <img width="1448" height="158" alt="image" src="https://github.com/user-attachments/assets/57c98739-8007-43cc-8d87-b50a8bf2aec1" />

Sergey Bylokhov has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'openjdk:master' into JDK-8298432-v3
 - Merge branch 'openjdk:master' into JDK-8298432-v3
 - 8298432: Investigate the benefits of usage of GetPrimitiveArrayCritical in the cmm code

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/27841/files
  - new: https://git.openjdk.org/jdk/pull/27841/files/e372a430..4871f883

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27841&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27841&range=00-01

  Stats: 333176 lines in 3097 files changed: 215179 ins; 72640 del; 45357 mod
  Patch: https://git.openjdk.org/jdk/pull/27841.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27841/head:pull/27841

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


More information about the client-libs-dev mailing list