<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Please have a look at the PR. If you feel the API surface has grown too much, maybe removing the `ByteBuffer` variants is a logical step, since users can always wrap a `ByteBuffer` with a `MemorySegment`? If you could comment on the PR if you feel that to be the case, I would appreciate it.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Mar 20, 2025 at 4:09 PM Adam Sotona <<a href="mailto:adam.sotona@oracle.com">adam.sotona@oracle.com</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="msg1102407431525991501">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_1102407431525991501WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">I’m sorry to join the discussion a bit late.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Here are the points to consider:<u></u><u></u></span></p>
<ul style="margin-top:0in" type="disc">
<li class="m_1102407431525991501MsoListParagraph" style="margin-left:0in"><span style="font-size:11pt">Class-File API is implementation is after many rounds of performance optimizations purely based on byte arrays.<u></u><u></u></span></li><li class="m_1102407431525991501MsoListParagraph" style="margin-left:0in"><span style="font-size:11pt">Internal use of ByteBuffer has been removed from the implementation, as it caused significant JDK bootstrap performance regression.<u></u><u></u></span></li><li class="m_1102407431525991501MsoListParagraph" style="margin-left:0in"><span style="font-size:11pt">Enormous amount of work has been spent on the API surface reduction and removal of all unnecessary “conveniences”.<u></u><u></u></span></li></ul>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Adam<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<div id="m_1102407431525991501mail-editor-reference-message-container">
<div>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From:
</span></b><span style="font-size:12pt;color:black">classfile-api-dev <<a href="mailto:classfile-api-dev-retn@openjdk.org" target="_blank">classfile-api-dev-retn@openjdk.org</a>> on behalf of David Lloyd <<a href="mailto:david.lloyd@redhat.com" target="_blank">david.lloyd@redhat.com</a>><br>
<b>Date: </b>Thursday, 20 March 2025 at 21:11<br>
<b>To: </b><a href="mailto:classfile-api-dev@openjdk.org" target="_blank">classfile-api-dev@openjdk.org</a> <<a href="mailto:classfile-api-dev@openjdk.org" target="_blank">classfile-api-dev@openjdk.org</a>><br>
<b>Subject: </b>Re: Class files in ByteBuffer<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">I've opened a bug [1] and pull request [2] incorporating this discussion (more or less). I've implemented support for both `MemorySegment` and `ByteBuffer`, but this could be
 revisited if it doesn't look OK. The implementation is not terribly invasive for now, only grabbing a few low-hanging optimizations.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">[1] </span><a href="https://bugs.openjdk.org/browse/JDK-8352536" target="_blank"><span style="font-size:12pt;font-family:Arial,sans-serif">https://bugs.openjdk.org/browse/JDK-8352536</span></a><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">[2] </span><a href="https://github.com/openjdk/jdk/pull/24139" target="_blank"><span style="font-size:12pt;font-family:Arial,sans-serif">https://github.com/openjdk/jdk/pull/24139</span></a><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">On Mon, Mar 10, 2025 at 12:38</span><span style="font-size:12pt;font-family:Arial,sans-serif"> </span><span style="font-size:12pt">PM David Lloyd <</span><a href="mailto:david.lloyd@redhat.com" target="_blank"><span style="font-size:12pt">david.lloyd@redhat.com</span></a><span style="font-size:12pt">>
 wrote:<u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">When defining a class in the JDK, one may either use a byte array or a byte buffer to hold the contents of the class. The latter is useful when (for example) a JAR file containing
 uncompressed classes is mapped into memory. Thus, some class loaders depend on this form of the API for class definition.<u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">If I were to supplement such a class loader with a class transformation step based on the class file API, I would have to copy the bytes of each class on to the heap as a byte[]
 before I could begin parsing it. This is potentially expensive, and definitely awkward.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">After transformation, it doesn't really matter if you have a byte[] or ByteBuffer because either way, the class can be defined directly.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">It would be nice if the class file parser could accept either a byte[] or a ByteBuffer. I did a quick bit of exploratory work and it looks like porting the code to read from
 a ByteBuffer instead of a byte[]  (using ByteBuffer.wrap() for the array case) would be largely straightforward *except* for the code which parses UTF-8 constants into strings. Also there could be some small performance differences (maybe positive, maybe negative)
 depending on how the buffer is accessed.<u></u><u></u></span></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Is this something that might be considered?<u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"><u></u> <u></u></span></p>
</div>
<p class="MsoNormal"><span class="m_1102407431525991501gmailsignatureprefix"><span style="font-size:12pt">--
</span></span><span style="font-size:12pt"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">- DML • he/him<u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><br clear="all">
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<p class="MsoNormal"><span class="m_1102407431525991501gmailsignatureprefix"><span style="font-size:12pt">--
</span></span><span style="font-size:12pt"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">- DML • he/him<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div></blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">- DML • he/him<br></div></div>