Page 1 of 1

Question about java card method header

Posted: Sat Oct 17, 2015 2:52 am
by lightupdark
How does the java card virtual machine construct the header for the methods?
e.g.

Code: Select all

method_info[1] // @0043= {
    // flags     : 0
    // max_stack : 5
    // nargs     : 3
    // max_locals: 0
    /*0045*/ L0:   new             0x0003
    /*0048*/       dup             
    /*0049*/       aload_0         
    /*004a*/       sload_1         
    /*004b*/       sload_2         
    /*004c*/       invokespecial   0x0004
    /*004f*/       pop             
    /*0050*/       return


How can we obtain max_stack: 5? Thanks for any help.

Re: Question about java card method header

Posted: Wed Oct 21, 2015 1:40 am
by UNKNwYSHSA
The stack information for each opcode described in the JCVM specification.

Here's the stack information of the code you given.

Code: Select all

    /*0045*/ L0:   new             0x0003   // +1 The objectref, a reference to the instance, is pushed onto the operand stack.
    /*0048*/       dup                      // +1 The top word on the operand stack is duplicated and pushed onto the operand stack.
    /*0049*/       aload_0                  // +1 The objectref in the local variable at <n> is pushed onto the operand stack.
    /*004a*/       sload_1                  // +1 The value in the local variable at <n> is pushed onto the operand stack.
    /*004b*/       sload_2                  // +1 Here's the max stack. The value in the local variable at <n> is pushed onto the operand stack.
    /*004c*/       invokespecial   0x0004   // The nargs – 1 words of arguments and objectref are popped from the operand stack.
    /*004f*/       pop                      // -1 The top word is popped from the operand stack.