RFR: 8321620: Optimize JImage decompressors
Chen Liang
liach at openjdk.org
Fri Dec 8 22:43:43 UTC 2023
On Wed, 8 Nov 2023 11:55:22 GMT, Glavo <duke at openjdk.org> wrote:
> This PR significantly speeds up decompressing resources in Jimage while significantly reducing temporary memory allocations in the process.
>
> This will improve startup speed for runtime images generated using `jlink --compress 1` and `jlink --compress 2` .
>
> I generated a runtime image containing javac using `jlink --compress 1 --add-modules jdk.compiler` and tested the time it took to compile a simple HelloWorld program 20 times using `perf stat -r20 javac /dev/shm/HelloWorld.java`, this PR reduces the total time taken from 17830ms to 13598ms (31.12% faster).
src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java line 111:
> 109: int count = Short.toUnsignedInt(bytesIn.getShort());
> 110: bytesOut[bytesOutOffset++] = (byte) ((count >> 8) & 0xff);
> 111: bytesOut[bytesOutOffset++] = (byte) (count & 0xff);
Probably use `ByteArray.setUnsignedShort`:
Suggestion:
ByteArray.setUnsignedShort(bytesOut, bytesOutOffset, count);
bytesOutOffset += 2;
Same remark elsewhere.
src/java.base/share/classes/jdk/internal/jimage/decompressor/StringSharingDecompressor.java line 113:
> 111: bytesOut[bytesOutOffset++] = (byte) (count & 0xff);
> 112: for (int i = 1; i < count; i++) {
> 113: int tag = bytesIn.get() & 0xff;
Suggestion:
int tag = Byte.toUnsignedInt(bytesIn.get());
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16556#discussion_r1387400142
PR Review Comment: https://git.openjdk.org/jdk/pull/16556#discussion_r1387397234
More information about the core-libs-dev
mailing list