:: Enseignements :: ESIPE :: E5INFO :: 2019-2020 :: Machine Virtuelle (et bazar autour ...) ::
[LOGO]

Lab 3 - JVM Interpreter


We now want to implement an interpreter based on the JVM.
Here is a video of Charles Nutter, one of the creators of JRuby that explains how the Java bytecode works.
Java Bytecode for Dummies by Charles Nutter

Exercice 1 - JVM interpreter

The aim of this exercise is to write a simple interpreter/compiler that will generate a Java Class with one static method for each function of smalljs.
One goal is to make the interpreter lazy and to only compile a method when needed (i.e. at the first execution) so the interpreter will work mostly like a JIT.
Once a function is translated to bytecode, the interpreter will transfer the execution to the JVM

  1. What is the purpose of the classes
    • Rewriter,
    • FunctionClassLoader,
    • Dictionary and
    • RT ?

    How the method Rewriter.createFunction works in details ?
  2. In the Rewriter visitor, implement the support of Literal.
    Warning: ldc in bytecode only load primitive and String, to load a constant which is an Integer you have use a ldc constant dynamic with the boostrap method bsm_const.
    Verify that the test marked "Q2" pass.
  3. Verify that the string literal are also supported by executing the test marked "Q3".
  4. Add the support of the function call by implementing the visit of FunCall.
    For that, you need to generate an instruction invokedynamic on the bootstrap method bsm_funcall.
    Verify that the test marked "Q4" pass.
    Note: When an identifier is not a local variable, a ldc constant dynamic is emitted. Implement the visit of LocalVarAccess to add that behavior. Note2: in case the local variable exists, throw an exception, we will change that later.
  5. Verify that the test marked "Q5" pass.
  6. Verify that the return value are propagated properly so the test marked "Q6" pass.
  7. Also Verify that the test marked "Q7" pass.
  8. Add the support to rewrite the declaration of a variable and the loading of that variable by implementing respectively the visit of LocalVarAssignment and LocalVarAccess.
    Verify that the tests marked "Q8" pass.
  9. Verify that the test marked "Q9" pass.
  10. We now want to support the declaration of user defined function. The idea is to pass Fun as an argument of a ldc constant dynamic, but arguments can only be constant, so we reuse the dictionary trick.
    Verify that the tests marked "Q10" pass.
  11. In order to implement the if ... else, implement the visit of If ast node and verify that the tests marked "Q11" pass.
  12. Verify that the tests marked "Q12" pass.