[External] : Re: Wrong error reported
Adam Sotona
adam.sotona at oracle.com
Mon Jun 17 13:01:32 UTC 2024
objectref and two arguments are three object to consume.
From: Øystein Myhre Andersen <o.myhre at gmail.com>
Date: Monday, 17 June 2024 at 14:58
To: Adam Sotona <adam.sotona at oracle.com>
Cc: classfile-api-dev <classfile-api-dev at openjdk.org>
Subject: [External] : Re: Wrong error reported
You say “15: INVOKESPECIAL" consumes 3 objects from stack ”.
I don't see how that could be the case. The jvm spec says:
..., objectref, [arg1, [arg2 ...]] →
In my case I have one argument and INVOKESPECIAL should consume TWO objects.
In detail
Just before the INVOKESPECIAL the operand stack looks like this:
this.SL, P_TXT2, P_TXT2, this.P_T
where
- this.SL is a pointer to the argument to the constructor.
- P_TXT2 is the implicit object reference to the class being constructed.
- After that, the rest of the operand stack which should not be touched
The INVOKESPECIAL should in this case consume TWO objects from the operand stack.
See the method type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}
As I mentioned earlier, the javac compiler produces the same code.
- Øystein Myhre Andersen
On Mon, Jun 17, 2024 at 1:09 PM Adam Sotona <adam.sotona at oracle.com<mailto:adam.sotona at oracle.com>> wrote:
15: INVOKESPECIAL consumes 3 objects from stack
From: classfile-api-dev <classfile-api-dev-retn at openjdk.org<mailto:classfile-api-dev-retn at openjdk.org>> on behalf of Øystein Myhre Andersen <o.myhre at gmail.com<mailto:o.myhre at gmail.com>>
Date: Monday, 10 June 2024 at 10:07
To: classfile-api-dev <classfile-api-dev at openjdk.org<mailto:classfile-api-dev at openjdk.org>>
Subject: Wrong error reported
I got:
Exception in thread "main" java.lang.IllegalArgumentException: Operand stack underflow at bytecode offset 26 of method _STM()
- max stack: 65535
max locals: 65535
attributes: []
//stack map frame @0: {locals: [simulaTestPrograms/adHoc01_P_TXT2], stack: []}
0: {opcode: ALOAD_0, slot: 0}
1: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: P_T, field type: Lsimula/runtime/RTS_TXT;}
4: {opcode: NEW, type: simulaTestPrograms/adHoc01_P_TXT2}
7: {opcode: DUP}
8: {opcode: ALOAD_0, slot: 0}
9: {opcode: GETFIELD, owner: simula/runtime/RTS_RTObject, field name: _SL, field type: Lsimula/runtime/RTS_RTObject;}
12: {opcode: CHECKCAST, type: simulaTestPrograms/adHoc01}
15: {opcode: INVOKESPECIAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: <init>, method type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}
18: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: _RESULT, field type: Lsimula/runtime/RTS_TXT;}
21: {opcode: LDC, constant value: Abra}
23: {opcode: INVOKESTATIC, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: _ASGSTR, method type: (Lsimula/runtime/RTS_TXT;Ljava/lang/String;)Lsimula/runtime/RTS_TXT;}
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;}
29: {opcode: POP}
30: {opcode: ALOAD_0, slot: 0}
31: {opcode: INVOKEVIRTUAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: EBLK, method type: ()V}
34: {opcode: ALOAD_0, slot: 0}
35: {opcode: ARETURN}
Then I monitor the operand stack as follows:
0: {opcode: ALOAD_0, slot: 0}
1: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: P_T, field type: Lsimula/runtime/RTS_TXT;}
==> STACK: this.P_T
4: {opcode: NEW, type: simulaTestPrograms/adHoc01_P_TXT2}
==> STACK: P_TXT2, this.P_T
7: {opcode: DUP}
==> STACK: P_TXT2, P_TXT2, this.P_T
8: {opcode: ALOAD_0, slot: 0}
9: {opcode: GETFIELD, owner: simula/runtime/RTS_RTObject, field name: _SL, field type: Lsimula/runtime/RTS_RTObject;}
12: {opcode: CHECKCAST, type: simulaTestPrograms/adHoc01}
==> STACK: this.SL, P_TXT2, P_TXT2, this.P_T
15: {opcode: INVOKESPECIAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: <init>, method type: (Lsimula/runtime/RTS_RTObject;Lsimula/runtime/RTS_TXT;)V}
==> STACK: P_TXT2, this.P_T
18: {opcode: GETFIELD, owner: simulaTestPrograms/adHoc01_P_TXT2, field name: _RESULT, field type: Lsimula/runtime/RTS_TXT;}
==> STACK: P_TXT2.RESULT, this.P_T
21: {opcode: LDC, constant value: Abra}
==> STACK: "Abra", P_TXT2.RESULT, this.P_T
23: {opcode: INVOKESTATIC, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: _ASGSTR, method type: (Lsimula/runtime/RTS_TXT;Ljava/lang/String;)Lsimula/runtime/RTS_TXT;}
==> STACK: Return-value-1, this.P_T
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;}
==> STACK: Return-value-2
29: {opcode: POP}
==> STACK:
30: {opcode: ALOAD_0, slot: 0}
31: {opcode: INVOKEVIRTUAL, owner: simulaTestPrograms/adHoc01_P_TXT2, method name: EBLK, method type: ()V}
34: {opcode: ALOAD_0, slot: 0}
35: {opcode: ARETURN}
This shows that the error 'Operand stack underflow at bytecode offset 26 of method _STM()' is wrong.
I have also compiled it fram java source:
public adHoc01_P_TXT2 _STM() {
// JavaLine 45 <== SourceLine 6
_ASGTXT(P_T, _ASGSTR(new adHoc01_P_TXT2((_CUR._SL))._RESULT, "Abra") );
EBLK();
return (this);
} // End of Procedure BODY
Which compiles to the same byte-code. AND it executes correctly.
Is there something I'm not seeing here ?
- Regards, Øystein Myhre Andersen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20240617/6083a74a/attachment-0001.htm>
More information about the classfile-api-dev
mailing list