<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>Hello,<br data-mce-bogus="1"></div><div>ASM defines an order when reading/streaming, there is no order when writing to a ClassWriter.<br></div><div>So the constraint is if you create an intermediary ClassVisitor, you need to keep the order.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>see section 2.2.6 of the ASM guide (https://asm.ow2.io/asm4-guide.pdf)<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>regards,<br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Chen Liang" <chen.l.liang@oracle.com><br><b>To: </b>"Mark Roberts" <markro@cs.washington.edu>, "Adam Sotona" <adam.sotona@oracle.com>, "classfile-api-dev" <classfile-api-dev@openjdk.org><br><b>Sent: </b>Friday, November 22, 2024 7:50:17 PM<br><b>Subject: </b>Re: java.lang.classfile model enumeration order<br></blockquote></div><div><style style="display:none;"> P {margin-top:0;margin-bottom:0;} </style></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">


<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I think the interest in the order is more among the same kind of elements instead of among different kinds of elements.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Chen Liang</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Brian Goetz <brian.goetz@oracle.com><br>
<b>Sent:</b> Friday, November 22, 2024 12:09 PM<br>
<b>To:</b> Mark Roberts <markro@cs.washington.edu>; Adam Sotona <adam.sotona@oracle.com>; Chen Liang <chen.l.liang@oracle.com>; classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Subject:</b> Re: java.lang.classfile model enumeration order</font>
<div> </div>
</div>
<div><font size="4" face="monospace">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.</font><br>
<br>
<br>
<div class="x_moz-cite-prefix">On 11/22/2024 1:07 PM, Mark Roberts wrote:<br>
</div>
<blockquote>

<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Aptos}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:blue;
        text-decoration:underline}
span.x_EmailStyle19
        {font-family:"Calibri",sans-serif;
        color:windowtext}
.x_MsoChpDefault
        {font-size:10.0pt}
div.x_WordSection1
        {}
-->
</style>
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:11.0pt">So to summarize: it’s true today, but don’t rely on it.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Mark</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<div>
<div style="border:none; border-top:solid #e1e1e1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b><span style="font-size:11.0pt">From:</span></b><span style="font-size:11.0pt"> Brian Goetz <<a href="mailto:brian.goetz@oracle.com" class="x_moz-txt-link-freetext" target="_blank">brian.goetz@oracle.com</a>>
<br>
<b>Sent:</b> Friday, November 22, 2024 8:02 AM<br>
<b>To:</b> Adam Sotona <<a href="mailto:adam.sotona@oracle.com" class="x_moz-txt-link-freetext" target="_blank">adam.sotona@oracle.com</a>>; Mark Roberts <<a href="mailto:markro@cs.washington.edu" class="x_moz-txt-link-freetext" target="_blank">markro@cs.washington.edu</a>>; Chen Liang <<a href="mailto:chen.l.liang@oracle.com" class="x_moz-txt-link-freetext" target="_blank">chen.l.liang@oracle.com</a>>;
<a href="mailto:classfile-api-dev@openjdk.org" class="x_moz-txt-link-freetext" target="_blank">classfile-api-dev@openjdk.org</a><br>
<b>Subject:</b> Re: java.lang.classfile model enumeration order</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:13.5pt; font-family:"Courier New"">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.)<br>
<br>
<br>
<br>
</span><span style="font-size:11.0pt"></span></p>
<div>
<p class="x_MsoNormal">On 11/22/2024 5:42 AM, Adam Sotona wrote:</p>
</div>
<blockquote style="margin-top:5.0pt; margin-bottom:5.0pt">
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:Aptos">Hi Mark,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:Aptos">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.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:Aptos">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.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:Aptos"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:Aptos">Adam</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:Aptos"> </span></p>
<div id="x_mail-editor-reference-message-container">
<div>
<div>
<div style="border:none; border-top:solid #b5c4df 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt; font-family:Aptos; color:black">From:
</span></b><span style="font-size:12.0pt; font-family:Aptos; color:black">classfile-api-dev
<a href="mailto:classfile-api-dev-retn@openjdk.org" target="_blank"><classfile-api-dev-retn@openjdk.org></a> on behalf of Mark Roberts
<a href="mailto:markro@cs.washington.edu" target="_blank"><markro@cs.washington.edu></a><br>
<b>Date: </b>Friday, 22 November 2024 at 1:12<br>
<b>To: </b>Chen Liang <a href="mailto:chen.l.liang@oracle.com" target="_blank"><chen.l.liang@oracle.com></a>,
<a href="mailto:classfile-api-dev@openjdk.org" class="x_moz-txt-link-freetext" target="_blank">classfile-api-dev@openjdk.org</a>
<a href="mailto:classfile-api-dev@openjdk.org" target="_blank"><classfile-api-dev@openjdk.org></a><br>
<b>Subject: </b>java.lang.classfile model enumeration order</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:11.0pt">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?</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt">Thank you, Mark</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
</div>
</div>
</div>
</div>
</blockquote>
<p class="x_MsoNormal"><span style="font-size:11.0pt"> </span></p>
</div>
</blockquote>
<br>
</div><br></blockquote></div></div></body></html>