Exercise 6        Name __________________        Score __/20

  1. public class Q1 {
  2.     public static void main(String [] args) {
  3.        Q2 qa = new Q2();
  4.        qa.f1( 5 );
  5.        Q2 qb = new Q2();
  6.        qa.f2( qb, 4);
  7.     }
  8. }
  1. class Q2 {
  2.    int a;
  3.    public int f1( int n ) {  
  4.        int i;
  5.        int j;
  6.        i = n;
  7.        j = i + 1;
  8.        this.a = n;
  9.        return this.a;
  10.    }
  11. }
  1.    public void f2( Q2 q, int m ) {  
  2.        int i;
  3.        i = q.f1(m);
  4.    }
  5. }

 

  1. (4) Diagram the JVM frame contents (show both formal and actual parameters) for the method call: qa.f1( 5 );
    qa.f1( 5 )
    0 this=qa
    1 n=5
    2 i
    3 j
  2. (2) Diagram the stack (show TOS) for the method call:  qa.f1( 5 );
    qa.f1( 5 )
    0 qa
    1 TOS 5
  3. (6) Diagram the JVM frame contents (show both formal and actual parameters) for the two method calls starting with: qa.f2( qb, 4 );
     
     
    qa.f2( qb, 4)
    0 this=qa
    1 q=qb
    2 m=4
    3 i
     
    q.f1( m )
    0 this=qb
    1 n=4
    2 i
    3 j
  4. (2) Diagram the stack (show TOS) for the method call at line 20:  qa.f2( qb, 4 );
    qa.f2( qb, 4 )
    0 qa
    1 qb
    2 TOS 4
  5. (2) Diagram the stack (show TOS) for the method call:  q.f1( m );
    q.f1( m )
    0 qb
    1 TOS 4

     

  6. (1) In which visitor method should the frame (argument and local variable) offsets be calculated?

    AMethodDecl

  7. (3) Frame offset computation occurs after building the symbol table. Give three class and method names needed for assigning offsets that are from the SymbolTable package .
    1. Method sizeParams
    2. Method sizeVars
    3. Variable setOffset