On Tue, 3 Sep 2024 12:23:50 GMT, Shaojin Wen <s...@openjdk.org> wrote:
>> A small optimization, optimize the BufferWriter implementation and use of >> ClassFile, provide faster patchInt and skip > > Shaojin Wen has updated the pull request incrementally with one additional > commit since the last revision: > > Update > src/java.base/share/classes/jdk/internal/classfile/impl/BufWriterImpl.java > > Co-authored-by: Claes Redestad <claes.redes...@oracle.com> This migration of write 0 to skip reveals that they are different. Good RFE. (Maybe we can make the BufWriterImpl buffer growth to allocate non-initialized array after the write 0 fixes) src/java.base/share/classes/jdk/internal/classfile/impl/BufWriterImpl.java line 192: > 190: } > 191: > 192: public void skip(int skipSize) { Conceptually I would prefer to make such an API return an int for skipped index so we can more easily patch later. But that is really optional. src/java.base/share/classes/jdk/internal/classfile/impl/BufWriterImpl.java line 240: > 238: public void writeIndexOrZero(PoolEntry entry) { > 239: if (entry == null || entry.index() == 0) > 240: skip(2); Writing `0` CP index for `null` is mandated by the attributes that do so. https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-4.html#jvms-4.7.24-300-D-A.1 src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java line 598: > 596: bytecodesBufWriter.writeIndex(ref); > 597: bytecodesBufWriter.writeU1(count); > 598: bytecodesBufWriter.skip(1); `0` is mandated: https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-6.html#jvms-6.5.invokeinterface src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java line 604: > 602: writeBytecode(INVOKEDYNAMIC); > 603: bytecodesBufWriter.writeIndex(ref); > 604: bytecodesBufWriter.skip(2); `0` is mandated: https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-6.html#jvms-6.5.invokedynamic ------------- Changes requested by liach (Reviewer). PR Review: https://git.openjdk.org/jdk/pull/20780#pullrequestreview-2277504778 PR Review Comment: https://git.openjdk.org/jdk/pull/20780#discussion_r1742099316 PR Review Comment: https://git.openjdk.org/jdk/pull/20780#discussion_r1742100573 PR Review Comment: https://git.openjdk.org/jdk/pull/20780#discussion_r1742102738 PR Review Comment: https://git.openjdk.org/jdk/pull/20780#discussion_r1742102983