Skip to content

Step2: Recursive

Compare
Choose a tag to compare
@vsanna vsanna released this 19 Sep 23:46
· 19 commits to main since this release

what is attemted

  • Introduced Thread/Frame so that jvm can call other methods(invokeXXX)
  • introduced classparser so that we can manage methods
  • introduced MethodArea so that we can manage classes/methods
  • introduced invokestatic!!
  • make more instructions available
  • add Recursive.java as guest code

output

class Recursive {
    static public void recursiveMain() {
        recursive(10);
    }

    static int recursive(int a) {
        if(a < 1000) {
            return recursive(a + a);
        } else {
            return a;
        }
    }
}
stack#=0, pc = 265, inst = 4, frame=LFrame{locals=[], operandStack=[]}
stack#=0, pc = 266, inst = b8, frame=LFrame{locals=[], operandStack=[Word(0,0,0,1: 1)]}
stack#=1, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[]}
stack#=1, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[Word(0,0,0,1: 1)]}
stack#=1, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,1: 1)]}
stack#=1, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[]}
stack#=1, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[Word(0,0,0,1: 1)]}
stack#=1, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[Word(0,0,0,1: 1), Word(0,0,0,1: 1)]}
stack#=1, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,1: 1)], operandStack=[Word(0,0,0,2: 2)]}
stack#=2, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[]}
stack#=2, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[Word(0,0,0,2: 2)]}
stack#=2, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,2: 2)]}
stack#=2, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[]}
stack#=2, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[Word(0,0,0,2: 2)]}
stack#=2, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[Word(0,0,0,2: 2), Word(0,0,0,2: 2)]}
stack#=2, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,2: 2)], operandStack=[Word(0,0,0,4: 4)]}
stack#=3, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[]}
stack#=3, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[Word(0,0,0,4: 4)]}
stack#=3, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,4: 4)]}
stack#=3, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[]}
stack#=3, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[Word(0,0,0,4: 4)]}
stack#=3, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[Word(0,0,0,4: 4), Word(0,0,0,4: 4)]}
stack#=3, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,4: 4)], operandStack=[Word(0,0,0,8: 8)]}
stack#=4, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[]}
stack#=4, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[Word(0,0,0,8: 8)]}
stack#=4, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,8: 8)]}
stack#=4, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[]}
stack#=4, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[Word(0,0,0,8: 8)]}
stack#=4, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[Word(0,0,0,8: 8), Word(0,0,0,8: 8)]}
stack#=4, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,8: 8)], operandStack=[Word(0,0,0,10: 16)]}
stack#=5, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[]}
stack#=5, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[Word(0,0,0,10: 16)]}
stack#=5, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,10: 16)]}
stack#=5, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[]}
stack#=5, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[Word(0,0,0,10: 16)]}
stack#=5, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[Word(0,0,0,10: 16), Word(0,0,0,10: 16)]}
stack#=5, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,10: 16)], operandStack=[Word(0,0,0,20: 32)]}
stack#=6, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[]}
stack#=6, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[Word(0,0,0,20: 32)]}
stack#=6, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,20: 32)]}
stack#=6, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[]}
stack#=6, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[Word(0,0,0,20: 32)]}
stack#=6, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[Word(0,0,0,20: 32), Word(0,0,0,20: 32)]}
stack#=6, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,20: 32)], operandStack=[Word(0,0,0,40: 64)]}
stack#=7, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[]}
stack#=7, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[Word(0,0,0,40: 64)]}
stack#=7, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,40: 64)]}
stack#=7, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[]}
stack#=7, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[Word(0,0,0,40: 64)]}
stack#=7, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[Word(0,0,0,40: 64), Word(0,0,0,40: 64)]}
stack#=7, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,40: 64)], operandStack=[Word(0,0,0,80: 128)]}
stack#=8, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[]}
stack#=8, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[Word(0,0,0,80: 128)]}
stack#=8, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,0,80: 128)]}
stack#=8, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[]}
stack#=8, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[Word(0,0,0,80: 128)]}
stack#=8, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[Word(0,0,0,80: 128), Word(0,0,0,80: 128)]}
stack#=8, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,0,80: 128)], operandStack=[Word(0,0,1,0: 256)]}
stack#=9, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[]}
stack#=9, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[Word(0,0,1,0: 256)]}
stack#=9, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,1,0: 256)]}
stack#=9, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[]}
stack#=9, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[Word(0,0,1,0: 256)]}
stack#=9, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[Word(0,0,1,0: 256), Word(0,0,1,0: 256)]}
stack#=9, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,1,0: 256)], operandStack=[Word(0,0,2,0: 512)]}
stack#=10, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[]}
stack#=10, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[Word(0,0,2,0: 512)]}
stack#=10, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,2,0: 512)]}
stack#=10, pc = 320, inst = 1a, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[]}
stack#=10, pc = 321, inst = 1a, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[Word(0,0,2,0: 512)]}
stack#=10, pc = 322, inst = 60, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[Word(0,0,2,0: 512), Word(0,0,2,0: 512)]}
stack#=10, pc = 323, inst = b8, frame=LFrame{locals=[Word(0,0,2,0: 512)], operandStack=[Word(0,0,4,0: 1024)]}
stack#=11, pc = 313, inst = 1a, frame=LFrame{locals=[Word(0,0,4,0: 1024)], operandStack=[]}
stack#=11, pc = 314, inst = 11, frame=LFrame{locals=[Word(0,0,4,0: 1024)], operandStack=[Word(0,0,4,0: 1024)]}
stack#=11, pc = 317, inst = a2, frame=LFrame{locals=[Word(0,0,4,0: 1024)], operandStack=[Word(0,0,3,e8: 1000), Word(0,0,4,0: 1024)]}
stack#=11, pc = 327, inst = 1a, frame=LFrame{locals=[Word(0,0,4,0: 1024)], operandStack=[]}
stack#=11, pc = 328, inst = ac, frame=LFrame{locals=[Word(0,0,4,0: 1024)], operandStack=[Word(0,0,4,0: 1024)]}