<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4" face="monospace">So, it sounds easy to do that when
      you are reading from the classfile, since all the field_info
      structures are colocated.  But as soon as you start transforming,
      you may inject methods between the fields, or vice versa.  So in
      practice the utility of such guarantees is low, because it will
      come with caveats like "as long as you are the first guy in the
      transform pipeline."  So better to just tell people "you'll get
      all the elements, but with no ordering guarantee" -- they'll write
      better code as a result.  </font><br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 11/22/2024 1:50 PM, Chen Liang
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:SJ2PR10MB766917ACA09B2EC2162013D4A2232@SJ2PR10MB7669.namprd10.prod.outlook.com">
      
      <style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
      <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>
      <hr style="display:inline-block;width:98%" tabindex="-1">
      <div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Brian
          Goetz <a class="moz-txt-link-rfc2396E" href="mailto:brian.goetz@oracle.com"><brian.goetz@oracle.com></a><br>
          <b>Sent:</b> Friday, November 22, 2024 12:09 PM<br>
          <b>To:</b> Mark Roberts <a class="moz-txt-link-rfc2396E" href="mailto:markro@cs.washington.edu"><markro@cs.washington.edu></a>; Adam
          Sotona <a class="moz-txt-link-rfc2396E" href="mailto:adam.sotona@oracle.com"><adam.sotona@oracle.com></a>; Chen Liang
          <a class="moz-txt-link-rfc2396E" href="mailto:chen.l.liang@oracle.com"><chen.l.liang@oracle.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a>
          <a class="moz-txt-link-rfc2396E" href="mailto:classfile-api-dev@openjdk.org"><classfile-api-dev@openjdk.org></a><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 type="cite">
          <meta name="Generator" content="Microsoft Word 15 (filtered medium)">
          <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 moz-txt-link-freetext" moz-do-not-send="true">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 moz-txt-link-freetext" moz-do-not-send="true">adam.sotona@oracle.com</a>>;
                    Mark Roberts <<a href="mailto:markro@cs.washington.edu" class="x_moz-txt-link-freetext moz-txt-link-freetext" moz-do-not-send="true">markro@cs.washington.edu</a>>;
                    Chen Liang <<a href="mailto:chen.l.liang@oracle.com" class="x_moz-txt-link-freetext moz-txt-link-freetext" moz-do-not-send="true">chen.l.liang@oracle.com</a>>;
                    <a href="mailto:classfile-api-dev@openjdk.org" class="x_moz-txt-link-freetext moz-txt-link-freetext" moz-do-not-send="true">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" moz-do-not-send="true"><classfile-api-dev-retn@openjdk.org></a>
                          on behalf of Mark Roberts
                          <a href="mailto:markro@cs.washington.edu" moz-do-not-send="true"><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" moz-do-not-send="true"><chen.l.liang@oracle.com></a>,
                          <a href="mailto:classfile-api-dev@openjdk.org" class="x_moz-txt-link-freetext moz-txt-link-freetext" moz-do-not-send="true">classfile-api-dev@openjdk.org</a>
                          <a href="mailto:classfile-api-dev@openjdk.org" moz-do-not-send="true"><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>
    </blockquote>
    <br>
  </body>
</html>