<div dir="ltr">Thank you.<div><br></div><div>P.S. <font color="#222222" style="font-size:medium;font-family:"Times New Roman",serif">I have worked with code generators since the 1960s and experienced several times staring at the code without seeing the error. </font><font color="#222222" style="font-size:medium;font-family:"Times New Roman",serif">It was the method type descriptor that was wrong.</font></div><div><font color="#222222" style="font-size:medium;font-family:"Times New Roman",serif"><br></font></div><div><font color="#222222" style="font-size:medium;font-family:"Times New Roman",serif">- Øystein</font></div>
        
        


<pre lang="en" class="gmail-western"><a name="tw-target-text6"></a></pre></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 17, 2024 at 3:01 PM Adam Sotona <<a href="mailto:adam.sotona@oracle.com">adam.sotona@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-1904800186368741952">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-1904800186368741952WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">objectref and two arguments are three object to consume.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<div id="m_-1904800186368741952mail-editor-reference-message-container">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="color:black">From:
</span></b><span style="color:black">Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com" target="_blank">o.myhre@gmail.com</a>><br>
<b>Date: </b>Monday, 17 June 2024 at 14:58<br>
<b>To: </b>Adam Sotona <<a href="mailto:adam.sotona@oracle.com" target="_blank">adam.sotona@oracle.com</a>><br>
<b>Cc: </b>classfile-api-dev <<a href="mailto:classfile-api-dev@openjdk.org" target="_blank">classfile-api-dev@openjdk.org</a>><br>
<b>Subject: </b>[External] : Re: Wrong error reported<u></u><u></u></span></p>
</div>
<div>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">You say “</span><span style="font-family:Arial,sans-serif;color:rgb(34,34,34)">15: INVOKESPECIAL" consumes 3 objects from stack</span><span style="color:black"> </span><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">”.</span><u></u><u></u></pre>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><a name="m_-1904800186368741952_tw-target-text1"></a><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">I don't see how that could be the case. The jvm spec says:</span><u></u><u></u></pre>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">               </span><span lang="EN" style="font-size:11pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">..., <i>objectref</i>, [<i>arg1</i>, [<i>arg2 </i>...]] →</span><u></u><u></u></pre>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><u></u> <u></u></pre>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><a name="m_-1904800186368741952_tw-target-text2"></a><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">In my case I have one argument and </span><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(34,34,34)">INVOKESPECIAL</span><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)"> should consume TWO objects.</span><u></u><u></u></pre>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><u></u> <u></u></pre>
<pre style="line-height:26.95pt;background:rgb(248,249,250)"><a name="m_-1904800186368741952_tw-target-text3"></a><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(32,33,36)">In detail</span><u></u><u></u></pre>
<h2 style="margin-bottom:5.95pt"><span style="font-size:12pt;font-family:"Times New Roman",serif;font-weight:normal">Just before the
<span style="color:rgb(34,34,34)">INVOKESPECIAL</span> the operand stack looks like this:</span><span style="font-weight:normal"><u></u><u></u></span></h2>
<p style="margin-bottom:12pt"><u></u> <u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:Arial,sans-serif;color:rgb(34,34,34)">                      this.SL, P_TXT2, P_TXT2, this.P_T</span><span style="font-family:"Times New Roman",serif">
</span><u></u><u></u></p>
<p style="margin-bottom:12pt"><u></u> <u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:"Times New Roman",serif">where</span><u></u><u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:"Times New Roman",serif">    - this.SL is a pointer to the argument to the constructor.</span><u></u><u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:"Times New Roman",serif">    - P_TXT2 is the implicit object reference to the class being constructed.</span><u></u><u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:"Times New Roman",serif">   - After that, the rest of the operand stack which should not be touched</span><u></u><u></u></p>
<p style="margin-bottom:12pt"><u></u> <u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:"Times New Roman",serif">The
<span style="color:rgb(34,34,34)">INVOKESPECIAL should in this case consume TWO objects from the operand stack.</span></span><u></u><u></u></p>
<p style="margin-bottom:5.95pt"><span style="font-family:"Times New Roman",serif;color:rgb(34,34,34)">See the
</span><span style="font-family:Arial,sans-serif;color:rgb(34,34,34)">method type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}</span><u></u><u></u></p>
<pre><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(34,34,34)">As I mentioned earlier, the javac compiler produces the same code.</span><span lang="EN"><u></u><u></u></span></pre>
<pre><span lang="EN"><u></u> <u></u></span></pre>
<pre><span lang="EN" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(34,34,34)">- Øystein Myhre Andersen</span><span lang="EN"><u></u><u></u></span></pre>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Jun 17, 2024 at 1:09<span style="font-family:Arial,sans-serif"> </span>PM Adam Sotona <<a href="mailto:adam.sotona@oracle.com" target="_blank">adam.sotona@oracle.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">15: INVOKESPECIAL consumes 3 objects from stack</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11pt"> </span><u></u><u></u></p>
<div id="m_-1904800186368741952m_8980700410496493579mail-editor-reference-message-container">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="color:black">From:
</span></b><span style="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 Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com" target="_blank">o.myhre@gmail.com</a>><br>
<b>Date: </b>Monday, 10 June 2024 at 10:07<br>
<b>To: </b>classfile-api-dev <<a href="mailto:classfile-api-dev@openjdk.org" target="_blank">classfile-api-dev@openjdk.org</a>><br>
<b>Subject: </b>Wrong error reported</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I got:<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<div>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">Exception in thread "main"
</span><span style="font-size:10pt;font-family:Consolas;color:rgb(0,102,204)">java.lang.IllegalArgumentException</span><span style="font-size:10pt;font-family:Consolas;color:red">: Operand stack underflow at bytecode offset 26 of method _STM()</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">- max stack: 65535</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">max locals: 65535</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">attributes: []</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">//stack map frame @0: {locals: [simulaTestPrograms/adHoc01_P_TXT2], stack: []}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">0: {opcode: ALOAD_0, slot: 0}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">1: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: P_T, field type: Lsimula/runtime/RTS_TXT;}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">4: {opcode: NEW, type: simulaTestPrograms/adHoc01_P_TXT2}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">7: {opcode: DUP}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">8: {opcode: ALOAD_0, slot: 0}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">9: {opcode: GETFIELD, owner: simula/runtime/RTS_RTObject, field name: _SL, field type: Lsimula/runtime/RTS_RTObject;}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">12: {opcode: CHECKCAST, type: simulaTestPrograms/adHoc01}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">15: {opcode: INVOKESPECIAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: <init>, method type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">18: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: _RESULT, field type: Lsimula/runtime/RTS_TXT;}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">21: {opcode: LDC, constant value: Abra}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">23: {opcode: INVOKESTATIC, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: _ASGSTR, method type: (Lsimula/runtime/RTS_TXT;Ljava/lang/String;)Lsimula/runtime/RTS_TXT;}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">26: {opcode: INVOKESTATIC, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: _ASGTXT, method type: (Lsimula/runtime/RTS_TXT;Lsimula/runtime/RTS_TXT;)Lsimula/runtime/RTS_TXT;}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">29: {opcode: POP}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">30: {opcode: ALOAD_0, slot: 0}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">31: {opcode: INVOKEVIRTUAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: EBLK, method type: ()V}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">34: {opcode: ALOAD_0, slot: 0}</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">35: {opcode: ARETURN}</span><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Then I monitor the operand stack as follows:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">    0: {opcode: ALOAD_0, slot: 0}<br>
    1: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: P_T, field type: Lsimula/runtime/RTS_TXT;}<br>
==> STACK: this.P_T<br>
<br>
    4: {opcode: NEW, type: simulaTestPrograms/adHoc01_P_TXT2}<br>
==> STACK: P_TXT2, this.P_T<br>
<br>
    7: {opcode: DUP}<br>
==> STACK: P_TXT2, P_TXT2, this.P_T<br>
<br>
    8: {opcode: ALOAD_0, slot: 0}<br>
    9: {opcode: GETFIELD, owner: simula/runtime/RTS_RTObject, field name: _SL, field type: Lsimula/runtime/RTS_RTObject;}<br>
    12: {opcode: CHECKCAST, type: simulaTestPrograms/adHoc01}<br>
==> STACK: this.SL, P_TXT2, P_TXT2, this.P_T<br>
<br>
    15: {opcode: INVOKESPECIAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: <init>, method type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}<br>
==> STACK: P_TXT2, this.P_T<br>
<br>
    18: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: _RESULT, field type: Lsimula/runtime/RTS_TXT;}<br>
==> STACK: P_TXT2.RESULT, this.P_T<br>
<br>
    21: {opcode: LDC, constant value: Abra}<br>
==> STACK: "Abra", P_TXT2.RESULT, this.P_T<br>
<br>
    23: {opcode: INVOKESTATIC, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: _ASGSTR, method type: (Lsimula/runtime/RTS_TXT;Ljava/lang/String;)Lsimula/runtime/RTS_TXT;}<br>
==> STACK: Return-value-1, this.P_T<br>
<br>
    26: {opcode: INVOKESTATIC, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: _ASGTXT, method type: (Lsimula/runtime/RTS_TXT;Lsimula/runtime/RTS_TXT;)Lsimula/runtime/RTS_TXT;}<br>
==> STACK: Return-value-2<br>
<br>
    29: {opcode: POP}<br>
==> STACK: <br>
<br>
    30: {opcode: ALOAD_0, slot: 0}<br>
    31: {opcode: INVOKEVIRTUAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: EBLK, method type: ()V}<br>
    34: {opcode: ALOAD_0, slot: 0}<br>
    35: {opcode: ARETURN}<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">This shows that the error 'Operand stack underflow at bytecode offset 26 of method _STM()' is wrong.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I have also compiled it fram java source:<u></u><u></u></p>
</div>
<div>
<div>
<div>
<p style="margin:0in"><b><span style="font-size:10pt;font-family:Consolas;color:rgb(127,0,85)">public</span></b><span style="font-size:10pt;font-family:Consolas;color:black"> adHoc01_P_TXT2 _STM() {</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:rgb(63,127,95)">// JavaLine 45 <== SourceLine 6</span><u></u><u></u></p>
<p style="margin:0in"><i><span style="font-size:10pt;font-family:Consolas;color:black">_ASGTXT</span></i><span style="font-size:10pt;font-family:Consolas;color:black">(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(0,0,192)">P_T</span><span style="font-size:10pt;font-family:Consolas;color:black">,
<i>_ASGSTR</i>(</span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(127,0,85)">new</span></b><span style="font-size:10pt;font-family:Consolas;color:black"> adHoc01_P_TXT2((</span><i><span style="font-size:10pt;font-family:Consolas;color:rgb(0,0,192)">_CUR</span></i><span style="font-size:10pt;font-family:Consolas;color:black">.</span><span style="font-size:10pt;font-family:Consolas;color:rgb(0,0,192)">_SL</span><span style="font-size:10pt;font-family:Consolas;color:black">)).</span><span style="font-size:10pt;font-family:Consolas;color:rgb(0,0,192)">_RESULT</span><span style="font-size:10pt;font-family:Consolas;color:black">,
</span><span style="font-size:10pt;font-family:Consolas;color:rgb(42,0,255)">"Abra"</span><span style="font-size:10pt;font-family:Consolas;color:black">) );</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:black">EBLK();</span><u></u><u></u></p>
<p style="margin:0in"><b><span style="font-size:10pt;font-family:Consolas;color:rgb(127,0,85)">return</span></b><span style="font-size:10pt;font-family:Consolas;color:black"> (</span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(127,0,85)">this</span></b><span style="font-size:10pt;font-family:Consolas;color:black">);</span><u></u><u></u></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:black">}
</span><span style="font-size:10pt;font-family:Consolas;color:rgb(63,127,95)">// End of Procedure BODY</span><u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">Which compiles to the same byte-code. AND it executes correctly.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Is there something I'm not  seeing here ?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">- Regards, Øystein Myhre Andersen<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>

</div></blockquote></div>