The LCMS JNI code currently uses GetByteArrayElements, GetShortArrayElements, GetIntArrayElements, and GetDoubleArrayElements. 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" /> ------------- Commit messages: - Merge branch 'openjdk:master' into JDK-8298432-v3 - 8298432: Investigate the benefits of usage of GetPrimitiveArrayCritical in the cmm code Changes: https://git.openjdk.org/jdk/pull/27841/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27841&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8298432 Stats: 79 lines in 4 files changed: 4 ins; 60 del; 15 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
