java.lang.classfile model enumeration order
Remi Forax
forax at univ-mlv.fr
Fri Nov 22 19:20:58 UTC 2024
Hello,
ASM defines an order when reading/streaming, there is no order when writing to a ClassWriter.
So the constraint is if you create an intermediary ClassVisitor, you need to keep the order.
see section 2.2.6 of the ASM guide (https://asm.ow2.io/asm4-guide.pdf)
regards,
Rémi
> From: "Chen Liang" <chen.l.liang at oracle.com>
> To: "Mark Roberts" <markro at cs.washington.edu>, "Adam Sotona"
> <adam.sotona at oracle.com>, "classfile-api-dev" <classfile-api-dev at openjdk.org>
> Sent: Friday, November 22, 2024 7:50:17 PM
> Subject: Re: java.lang.classfile model enumeration order
> I think the interest in the order is more among the same kind of elements
> instead of among different kinds of elements.
> ASM currently allows you to mix-and-match fields and methods in class visiting;
> it just has weird requirements such as visitSource -> visitModule ->
> visitNestHost -> visit other attributes. Such requirements are extremely
> error-prone and make little sense, and do not exist in the ClassFile API.
> However, there might be value for the order for the same kind of element in
> class file streaming. For example, if you stream f1, m1, m2, f2, you might want
> f1 before f2 and m1 before m2. This order is currently a complementary gift
> from the implementation, but nothing guarantees that stay the way in the long
> run. The order of fields and methods are not important in class file
> interpretation, after all.
> Regards,
> Chen Liang
> From: Brian Goetz <brian.goetz at oracle.com>
> Sent: Friday, November 22, 2024 12:09 PM
> To: Mark Roberts <markro at cs.washington.edu>; Adam Sotona
> <adam.sotona at oracle.com>; Chen Liang <chen.l.liang at oracle.com>;
> classfile-api-dev at openjdk.org <classfile-api-dev at openjdk.org>
> Subject: Re: java.lang.classfile model enumeration order
> Correct. ASM does guarantee an order of events, but our experience is that such
> constraints do not help the user very much, are error-prone to rely on, and can
> limit future flexibility for the implementation.
> On 11/22/2024 1:07 PM, Mark Roberts wrote:
>> So to summarize: it’s true today, but don’t rely on it.
>> Mark
>> From: Brian Goetz < [ mailto:brian.goetz at oracle.com | brian.goetz at oracle.com ] >
>> Sent: Friday, November 22, 2024 8:02 AM
>> To: Adam Sotona < [ mailto:adam.sotona at oracle.com | adam.sotona at oracle.com ] >;
>> Mark Roberts < [ mailto:markro at cs.washington.edu | markro at cs.washington.edu ]
>> >; Chen Liang < [ mailto:chen.l.liang at oracle.com | chen.l.liang at oracle.com ] >;
>> [ mailto:classfile-api-dev at openjdk.org | 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 [ mailto:classfile-api-dev-retn at openjdk.org |
>>> <classfile-api-dev-retn at openjdk.org> ] on behalf of Mark Roberts [
>>> mailto:markro at cs.washington.edu | <markro at cs.washington.edu> ]
>>> Date: Friday, 22 November 2024 at 1:12
>>> To: Chen Liang [ mailto:chen.l.liang at oracle.com | <chen.l.liang at oracle.com> ] ,
>>> [ mailto:classfile-api-dev at openjdk.org | classfile-api-dev at openjdk.org ] [
>>> mailto: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/0abb0d0f/attachment-0001.htm>
More information about the classfile-api-dev
mailing list