<div dir="ltr">
<pre class="gmail-western" style="background:rgb(248,249,250);border:none;padding:0cm;line-height:0.95cm"><font color="#202124"><font face="Times New Roman, serif"><font size="3"><span lang="en">You say “</span></font></font></font><font color="#222222"><font face="Arial, Helvetica, sans-serif"><font style="font-size:10pt">15: INVOKESPECIAL" consumes 3 objects from stack</font></font></font> <font color="#202124"><font face="Times New Roman, serif"><font size="3"><span lang="en">â€.</span></font></font></font>
<a name="tw-target-text1"></a><font color="#202124"><font face="inherit"><font style="font-size:21pt"><span lang="en"><font face="Times New Roman, serif"><font size="3">I don't see how that could be the case. The jvm spec says:</font></font></span></font></font></font>
<font color="#202124"><font face="Times New Roman, serif"><font size="3"><span lang="en"> </span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en">..., </span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en"><i>objectref</i></span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en">, [</span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en"><i>arg1</i></span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en">, [</span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en"><i>arg2 </i></span></font></font></font><font color="#202124"><font face="Times New Roman, serif"><font style="font-size:11pt"><span lang="en">...]] </span></font></font></font><font color="#202124"><font face="Symbol"><font style="font-size:11pt"><span lang="en">→</span></font></font></font>
<a name="tw-target-text2"></a><font color="#202124"><font face="inherit"><font style="font-size:21pt"><span lang="en"><font face="Times New Roman, serif"><font size="3">In my case I have one argument and </font></font><font color="#222222"><font face="Times New Roman, serif"><font size="3">INVOKESPECIAL</font></font></font><font face="Times New Roman, serif"><font size="3"> should consume TWO objects.</font></font></span></font></font></font>
<a name="tw-target-text3"></a><font color="#202124"><font face="Times New Roman, serif"><font size="3"><span lang="en">In detail</span></font></font></font></pre><h2 class="gmail-western" style="font-weight:normal;margin-bottom:0.21cm">
<font face="Times New Roman, serif"><font size="3">Just before the
<font color="#222222">INVOKESPECIAL</font>
the operand stack looks like this:</font></font></h2>
<p style="margin-bottom:0.21cm"><br><br>
</p>
<p style="margin-bottom:0.21cm"><font face="Times New Roman, serif"><font size="3"><font color="#222222"><font face="Arial, Helvetica, sans-serif">Â Â Â Â Â Â Â Â Â Â Â this.SL,
P_TXT2, P_TXT2, this.P_T</font></font> </font></font>
</p>
<p style="margin-bottom:0.21cm"><br><br>
</p>
<p style="margin-bottom:0.21cm"><font face="Times New Roman, serif"><font size="3">where</font></font></p>
<p style="margin-bottom:0.21cm"><font face="Times New Roman, serif"><font size="3">Â Â - this.SL is a pointer to the argument to the constructor.</font></font></p>
<p style="margin-bottom:0.21cm"><font face="Times New Roman, serif"><font size="3">Â Â - P_TXT2 is the implicit object reference to the class being
constructed.</font></font></p>
<p style="margin-bottom:0.21cm"><font face="Times New Roman, serif"><font size="3">Â Â - After that, the rest of the operand stack which should not be touched</font></font></p>
<p style="margin-bottom:0.21cm"><br><br>
</p>
<p style="margin-bottom:0.21cm"><font face="Times New Roman, serif"><font size="3">The
<font color="#222222">INVOKESPECIAL
should in this case consume TWO objects from the operand stack.</font></font></font></p>
<p style="margin-bottom:0.21cm"><font color="#222222"><font face="Times New Roman, serif"><font size="3">See
the </font></font></font><font color="#222222"><font face="Arial, Helvetica, sans-serif"><font size="3">method
type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}</font></font></font></p><p style="margin-bottom:0.21cm">
</p><pre lang="en" class="gmail-western"><font color="#202124"><font face="Times New Roman, serif"><font size="3"><font color="#222222">As I mentioned earlier, the javac compiler produces the same code.</font></font></font></font></pre><pre lang="en" class="gmail-western"><font color="#202124"><font face="Times New Roman, serif"><font size="3"><font color="#222222"><br></font></font></font></font></pre><pre lang="en" class="gmail-western"><font color="#202124"><font face="Times New Roman, serif"><font size="3"><font color="#222222">- Øystein Myhre Andersen</font></font></font></font></pre></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 17, 2024 at 1:09 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-5385707232535783162">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_8980700410496493579WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">15: INVOKESPECIAL consumes 3 objects from stack<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u>Â <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u>Â <u></u></span></p>
<div id="m_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<u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">- max stack: 65535</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">max locals: 65535</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">attributes: []</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">0: {opcode: ALOAD_0, slot: 0}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">4: {opcode: NEW, type: simulaTestPrograms/adHoc01_P_TXT2}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">7: {opcode: DUP}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">8: {opcode: ALOAD_0, slot: 0}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">12: {opcode: CHECKCAST, type: simulaTestPrograms/adHoc01}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">21: {opcode: LDC, constant value: Abra}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">29: {opcode: POP}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">30: {opcode: ALOAD_0, slot: 0}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">34: {opcode: ALOAD_0, slot: 0}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:red">35: {opcode: ARETURN}</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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() {<u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:rgb(63,127,95)">// JavaLine 45 <== SourceLine 6</span><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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">) );<u></u><u></u></span></p>
<p style="margin:0in"><span style="font-size:10pt;font-family:Consolas;color:black">EBLK();<u></u><u></u></span></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">);<u></u><u></u></span></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><span style="font-size:10pt;font-family:Consolas;color:black"><u></u><u></u></span></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>