<div dir="ltr">Hello Mark,<div>This indeed is a bug; we can change this in 25 to make any entry with LDC that has a pool entry with index over 0xFF throw IllegalArgumentException, and add a new ofLoad and ofArgument factories that do not require the Opcode (ClassFile API can choose a suitable opcode in these cases). We anticipate users to call CodeBuilder.loadConstant(ConstantDesc) or loadConstant(LoadableConstantEntry) so we did not enhance this more complicated API.</div><div><br></div><div>This behavior exists so we allow specifying the Opcode, so that you can use LDC_W for small index constants; before we automatically converted those LDC_W to LDC even if the entry is from the same CP as the CodeBuilder; see <a href="https://github.com/openjdk/jdk/blob/8f6ccde9829ea0e4fe1c087e68bec4d9efb55c64/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java#L1352">https://github.com/openjdk/jdk/blob/8f6ccde9829ea0e4fe1c087e68bec4d9efb55c64/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java#L1352</a></div><div><br></div><div>A similar truncation issue was noted in <a href="https://bugs.openjdk.org/browse/JDK-8341277">https://bugs.openjdk.org/browse/JDK-8341277</a> and fixed; but it didn't handle CP indices, and this indeed is a good bug to fix for 25.</div><div><br></div><div>Regards, Chen</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Feb 9, 2025 at 6:22 PM Mark Roberts <<a href="mailto:markro@cs.washington.edu">markro@cs.washington.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg6733018008617294813"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_6733018008617294813WordSection1"><p class="MsoNormal">I just changed from 24-ea+22-2649 to 24+36-3646 and almost all my test cases worked fine.  However, I ran into a problem with ldc:</p><p class="MsoNormal"> </p><p class="MsoNormal">ConstantInstruction.ofLoad(Opcode.LDC, poolBuilder.stringEntry(binaryClassName))</p><p class="MsoNormal"> </p><p class="MsoNormal">This used to work if the constant pool entry for binaryClassName was >256 – it would automatically generate a ldc_w.</p><p class="MsoNormal"> </p><p class="MsoNormal">Now it generates a ldc and uses just the lower 8 bits of the offset.  This seems like a problem as a user is not expected to know the constant pool offset, are they?</p><p class="MsoNormal"> </p><p class="MsoNormal">Thank you,</p><p class="MsoNormal">Mark</p><p class="MsoNormal"> </p></div></div>
</div></blockquote></div>