RFR: 8339317: Optimize ClassFile writeBuffer

Claes Redestad redestad at openjdk.org
Fri Aug 30 12:20:32 UTC 2024


On Thu, 29 Aug 2024 21:49:58 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> A small optimization, optimize the BufferWriter implementation and use of ClassFile, provide faster patchInt and skip

src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java line 68:

> 66:         BufWriterImpl buf = (BufWriterImpl) writer;
> 67:         buf.writeIndex(buf.constantPool().utf8Entry(name));
> 68:         buf.writeInt(0);

Since this is the int we're patching later it might be reasonable to have a buf.skip(int) method which just increases buf.offset. Applicable at least here and in `UnboundAttribute::writeTo`

src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java line 476:

> 474:                     bytecodesBufWriter.patchU2(dl.labelPc, branchOffset);
> 475:                 } else {
> 476:                     bytecodesBufWriter.patchInt(dl.labelPc, branchOffset);

Should assert or test that `dl.size == 4` here.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20780#discussion_r1737537176
PR Review Comment: https://git.openjdk.org/jdk/pull/20780#discussion_r1737532837


More information about the core-libs-dev mailing list