RFR: 8352536: Add overloads to parse and build class files from/to ByteBuffer and MemorySegment
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Mar 21 10:20:14 UTC 2025
On Thu, 20 Mar 2025 19:49:33 GMT, David M. Lloyd <duke at openjdk.org> wrote:
> Provide method overloads to the ClassFile interface of the java.lang.classfile API which allow parsing of classes found in byte buffers and memory segments, as well as allowing built class files to be output to these types.
src/java.base/share/classes/jdk/internal/classfile/impl/ClassFileImpl.java line 147:
> 145: public ClassModel parse(final MemorySegment bytes) {
> 146: AbstractMemorySegmentImpl amsi = (AbstractMemorySegmentImpl) bytes;
> 147: if (amsi.unsafeGetBase() instanceof byte[] ba) {
there's also `MemorySegment::heapObject` if you don't want to drop down to unsafe. That method returns an empty optional if the segment is read-only -- but that might be good enough for a fast-path.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24139#discussion_r2007272984
More information about the core-libs-dev
mailing list