RFR: 8339290: Optimize ClassFile Utf8EntryImpl#writeTo [v5]
Chen Liang
liach at openjdk.org
Mon Sep 2 14:47:21 UTC 2024
On Mon, 2 Sep 2024 14:06:42 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> Use fast path for ascii characters 1 to 127 to improve the performance of writing Utf8Entry to BufferWriter.
>
> Shaojin Wen 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 21 additional commits since the last revision:
>
> - Update src/java.base/share/classes/java/lang/StringCoding.java
>
> Co-authored-by: ExE Boss <3889017+ExE-Boss at users.noreply.github.com>
> - vectorized countGreaterThanZero
> - add comments
> - optimization for none-ascii latin1
> - Revert "vectorized countGreaterThanZero"
>
> This reverts commit 88a77722c8f5401ac28572509d6a08b3e88e8e40.
> - vectorized countGreaterThanZero
> - copyright
> - use JLA if length < 256
> - fix utf_len error
> - code style
> - ... and 11 more: https://git.openjdk.org/jdk/compare/e43c4655...2a36b443
test/micro/org/openjdk/bench/java/lang/classfile/Utf8EntryWriteTo.java line 85:
> 83: for (int i = 0; i < constants.length; i++) {
> 84: constants[i] = s.repeat(32);
> 85: }
I think this micro is testing too much irrelevant parts of classfile generation. I would recommend these changes:
1. Compute a `ConstantPoolBuilder` in `setup`, like:
ConstantPoolBuilder poolBuilder;
ClassEntry thisClass;
poolBuilder = ConstantPoolBuilder.of();
thisClass = poolBuilder.classEntry(CLASS_DESC);
for (var s : constants) {
poolBuilder.utf8Entry(s);
}
3. In benchmark, test like:
@Benchmark
public byte[] writeTo() {
return cf.build(thisClass, poolBuilder, clb -> {});
}
This should eradicate the cost around method or instruction generation while still ensuring the constants are written to the class file as part of the constant pool.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20772#discussion_r1741018079
More information about the core-libs-dev
mailing list