<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,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.</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">[1] <a href="https://bugs.openjdk.org/browse/JDK-8352536">https://bugs.openjdk.org/browse/JDK-8352536</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">[2] <a href="https://github.com/openjdk/jdk/pull/24139">https://github.com/openjdk/jdk/pull/24139</a></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Mar 10, 2025 at 12:38 PM David Lloyd <<a href="mailto:david.lloyd@redhat.com">david.lloyd@redhat.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 dir="ltr"><div><div class="gmail_default" style="font-family:arial,helvetica,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.</div></div><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,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.</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">After transformation, it doesn't really matter if you have a byte[] or ByteBuffer because either way, the class can be defined directly.</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">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.</div></div><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">Is this something that might be considered?</div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">- DML • he/him<br></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>