RFR: 8340710: Optimize DirectClassBuilder::build

Chen Liang liach at openjdk.org
Tue Sep 24 01:15:16 UTC 2024


On Sun, 22 Sep 2024 17:04:24 GMT, ExE Boss <duke at openjdk.org> wrote:

>> Do some refactoring so that the code can be inlined by the C1/C2 optimizer.
>> 
>> 1. DirectClassBuilder::build codeSize 361 -> 315
>> 2. DirectCodeBuilder::writeExceptionHandlers codeSize 183 -> 31
>> 3. BufWriterImpl::writeIndex codeSize 62 -> 37 (forceinline)
>> 4. BufWriterImpl::writeU2 (forceinline)
>> 5. Util::writeAttributes codSize 45 -> 40 (forceinline)
>> 6. Util::writeList codSize 47 -> 42 (forceinline)
>
> src/java.base/share/classes/jdk/internal/classfile/impl/DirectClassBuilder.java line 207:
> 
>> 205: 
>> 206:         // Now we can make the head
>> 207:         head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | minorVersion << 16 | majorVersion);
> 
> `minorVersion` needs to be cast to a `long` first, as otherwise when the MSB is set after the shift, then it’ll overwrite the magic number with all 1s.
> 
> Suggestion:
> 
>         head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | ((long) minorVersion) << 16 | majorVersion);

For clarity, I think using Integer.toUnsignedLong on the shift result is better

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21118#discussion_r1770632933


More information about the core-libs-dev mailing list