From chen.l.liang at oracle.com Thu Jun 6 23:18:55 2024 From: chen.l.liang at oracle.com (Chen Liang) Date: Thu, 6 Jun 2024 23:18:55 +0000 Subject: ClassReader and BufWriter parity - Cleanup BufWriter! Message-ID: Hello Brian and CF list, ClassFile API restricts user access to the raw bytes of a Class File. ClassReader is only there to support reading custom attributes, and we have just removed a few irrelevant methods in ClassReader in last few API changes in Java 23 to further restrict it. Great changes. The same story goes for BufWriter. If you pay attention to how users can obtain it: yes, only in AttributeMapper! It is a parallel of ClassReader. Yet, it has way too many irrelevant methods, and can access too many things, such as WritableElement (why do you even need to write them in attributes!) Basic plan for BufWriter is to remove non-attribute APIs from BufWriter, especially ones without ClassReader equivalents. Remember, we can always add them back if we need to! Detailed actions (Removals to become impl details): - [ ] `ConstantPoolBuilder.writeBootstrapMethods` ? BufWriter attribute only - [ ] `LocalVariable.writeTo` ? BufWriter attribute only - [ ] `LocalVariableType.writeTo` ? BufWriter attribute only - [ ] `WritableElement` ? impl-internal interface like LabelContext - [ ] `BufWriter` - [ ] `writeList` ? No `WritableElement` - [ ] `writeListIndices` ? consider exposing `BoundAttribute.readEntryList` in ClassReader for consistency (rename and ad check type), or hide both - [ ] `writeBytes(BufWriter other)` ? No multiple instances of BufWriter - [ ] `writeTo(BufWriter)` ? No multiple instances of BufWriter - [ ] `copyTo` ? No reading from BufWriter - [ ] `ClassReader.compare` ? No reading from BufWriter P.S. I previously proposed to remove LocalVariable(Type).writeTo alone; now this brainstorm allows us to truly understand the role of BufWriter and take throughout actions. Regards, Chen Liang -------------- next part -------------- An HTML attachment was scrubbed... URL: From o.myhre at gmail.com Mon Jun 10 08:06:52 2024 From: o.myhre at gmail.com (=?UTF-8?Q?=C3=98ystein_Myhre_Andersen?=) Date: Mon, 10 Jun 2024 10:06:52 +0200 Subject: Wrong error reported Message-ID: 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: , 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: , 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: From adam.sotona at oracle.com Mon Jun 17 11:09:29 2024 From: adam.sotona at oracle.com (Adam Sotona) Date: Mon, 17 Jun 2024 11:09:29 +0000 Subject: Wrong error reported In-Reply-To: References: Message-ID: 15: INVOKESPECIAL consumes 3 objects from stack From: classfile-api-dev on behalf of ?ystein Myhre Andersen Date: Monday, 10 June 2024 at 10:07 To: classfile-api-dev 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: , 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: , 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: From o.myhre at gmail.com Mon Jun 17 12:57:36 2024 From: o.myhre at gmail.com (=?UTF-8?Q?=C3=98ystein_Myhre_Andersen?=) Date: Mon, 17 Jun 2024 14:57:36 +0200 Subject: Wrong error reported In-Reply-To: References: Message-ID: 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 wrote: > 15: INVOKESPECIAL consumes 3 objects from stack > > > > > > *From: *classfile-api-dev on behalf > of ?ystein Myhre Andersen > *Date: *Monday, 10 June 2024 at 10:07 > *To: *classfile-api-dev > *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: , 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: , 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: From adam.sotona at oracle.com Mon Jun 17 13:01:32 2024 From: adam.sotona at oracle.com (Adam Sotona) Date: Mon, 17 Jun 2024 13:01:32 +0000 Subject: [External] : Re: Wrong error reported In-Reply-To: References: Message-ID: objectref and two arguments are three object to consume. From: ?ystein Myhre Andersen Date: Monday, 17 June 2024 at 14:58 To: Adam Sotona Cc: classfile-api-dev 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 > wrote: 15: INVOKESPECIAL consumes 3 objects from stack From: classfile-api-dev > on behalf of ?ystein Myhre Andersen > Date: Monday, 10 June 2024 at 10:07 To: classfile-api-dev > 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: , 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: , 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: From o.myhre at gmail.com Mon Jun 17 13:47:23 2024 From: o.myhre at gmail.com (=?UTF-8?Q?=C3=98ystein_Myhre_Andersen?=) Date: Mon, 17 Jun 2024 15:47:23 +0200 Subject: [External] : Re: Wrong error reported In-Reply-To: References: Message-ID: Thank you. P.S. I have worked with code generators since the 1960s and experienced several times staring at the code without seeing the error. It was the method type descriptor that was wrong. - ?ystein On Mon, Jun 17, 2024 at 3:01?PM Adam Sotona wrote: > objectref and two arguments are three object to consume. > > > > *From: *?ystein Myhre Andersen > *Date: *Monday, 17 June 2024 at 14:58 > *To: *Adam Sotona > *Cc: *classfile-api-dev > *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 > wrote: > > 15: INVOKESPECIAL consumes 3 objects from stack > > > > > > *From: *classfile-api-dev on behalf > of ?ystein Myhre Andersen > *Date: *Monday, 10 June 2024 at 10:07 > *To: *classfile-api-dev > *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: , 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: , 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: