1. Consider the following program. Look at the generated bytecode for the method m (using javap -c Test). Can you generate better code by hand?
    public class Test {
      static void m(int x) {
        System.out.print(x+x+x+x+1+2+3+4+5);
      }
      public static void main(String[] args) {
        m(42);
        m(87);
      }
    }
    
    mcode

  2. Try to cheat the Java bytecode verifier in the following manners:
    1. perform address arithmetic
    2. pop something off an empty stack
    3. construct two different types of stack (of the same height) in the branches of an if-else statement

  3. Consider the following program. Does it output 1, 2, or 3? Look at the generated bytecode (using javap -c Test). Discuss the exact semantics of the invokevirtual instruction.
    class A {
      int m(Object x, Object y) {
        return 1;
      }
    }
    class B extends A {
      int m(Object x, String y) {
        return 2;
      }
    }
    class C extends B {
      int m(Object x, Object y) {
        return 3;
      }
    }
    public class Test {
      public static void main(String[] args) {
        A a = new C();
        System.out.println(a.m(null,"abc"));
      }
    }
    
    maincode