RFR: 8352536: Add overloads to parse and build class files from/to ByteBuffer and MemorySegment

David M. Lloyd duke at openjdk.org
Fri Mar 21 11:24:15 UTC 2025


On Thu, 20 Mar 2025 21:11:41 GMT, Chen Liang <liach 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 159:
> 
>> 157:     public ClassModel parse(final ByteBuffer bytes) {
>> 158:         // defensive copy
>> 159:         ByteBuffer dup = bytes.duplicate();
> 
> The array version has no defensive copy. Doesn't this defeat the performance goal of the API?

No; duplicating a buffer does not duplicate its contents, only the wrapping object.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24139#discussion_r2007373107


More information about the core-libs-dev mailing list