java.lang.classfile model enumeration order

Mark Roberts markro at cs.washington.edu
Fri Nov 22 18:07:24 UTC 2024


So to summarize: it’s true today, but don’t rely on it.



Mark



*From:* Brian Goetz <brian.goetz at oracle.com>
*Sent:* Friday, November 22, 2024 8:02 AM
*To:* Adam Sotona <adam.sotona at oracle.com>; Mark Roberts <
markro at cs.washington.edu>; Chen Liang <chen.l.liang at oracle.com>;
classfile-api-dev at openjdk.org
*Subject:* Re: java.lang.classfile model enumeration order



This is a property of the implementation, but not something that the spec
guarantees, though.  Also, in the middle of a transformation pipeline,
there is no longer a "classfile order" to fall back on.  So it is best to
not assume anything about ordering, unless the ordering is part of the
semantics (like the bytecodes in a method body.)



On 11/22/2024 5:42 AM, Adam Sotona wrote:

Hi Mark,

Fields and methods are included in the ClassElement stream or iterator in
the same order, and this order corresponds to their order in the class file.

This principle is common for the whole API, except for some
PseudoInstructions identifying their start and stop positions  in the
stream by Labels. These PseudoInstructions are always streamed before
respective LabelTargets.



Adam



*From: *classfile-api-dev <classfile-api-dev-retn at openjdk.org>
<classfile-api-dev-retn at openjdk.org> on behalf of Mark Roberts
<markro at cs.washington.edu> <markro at cs.washington.edu>
*Date: *Friday, 22 November 2024 at 1:12
*To: *Chen Liang <chen.l.liang at oracle.com> <chen.l.liang at oracle.com>,
classfile-api-dev at openjdk.org <classfile-api-dev at openjdk.org>
<classfile-api-dev at openjdk.org>
*Subject: *java.lang.classfile model enumeration order

Are there any rules/guarantees that the order of items in
ClassModel::methods() will match the order in ‘for (ClassElement ce : cm)’
 for the ce elements that are MethodModel?  And also for similar items down
the class hierarchy?



Thank you, Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20241122/7454c279/attachment-0001.htm>


More information about the classfile-api-dev mailing list