wwu-pi / muggl

A Symbolic ATCG
GNU General Public License v3.0
2 stars 1 forks source link

Loading a Local Variable of Type Double #36

Open anfuchs opened 8 years ago

anfuchs commented 8 years ago

The following method is given with two double parameters as input:

public void doSimple(double d1, double d2) {
  SimpleEntity se = new SimpleEntity(d2, d2);
  entityManager.persist(se);
}

The Java Instructions are:

  0: new           #20
  3: dup
  4: dload_3
  5: dload_3
  6: invokespecial #22
  9: astore        5
 11: aload_0
 12: getfield      #24
 15: aload         5
 17: invokeinterface #26,  2
 22: return

Since a double value takes two slots (on the operand stack, in the local variable table, etc.), the local variable table is as follows:

LocalVariableTable:
  Start  Length  Slot  Name   Signature
      0      23     0  this   Lde/wwu/pi/muggl/services/SimpleService;
      0      23     1    d1   D
      0      23     3    d2   D
     11      12     5    se   Lde/wwu/pi/muggl/services/entities/SimpleEntity;

Notice that d2 is at index 3, not at 2 (even though it is the second method argument...).

However, the Load instruction in Muggl does not consider that fact:

java.lang.ArrayIndexOutOfBoundsException: 3
    at de.wwu.muggl.vm.classfile.structures.Method.setVariable(Method.java:770)
    at de.wwu.muggl.instructions.general.Load.executeSymbolically(Load.java:192)
    at de.wwu.muggl.instructions.general.Load.executeSymbolically(Load.java:111)
    at de.wwu.muggl.vm.impl.symbolic.SymbolicVirtualMachine.executeInstruction(SymbolicVirtualMachine.java:455)
    at de.wwu.muggl.vm.impl.jpa.JPAVirtualMachine.executeInstruction(JPAVirtualMachine.java:38)
    at de.wwu.muggl.vm.VirtualMachine.executeFrame(VirtualMachine.java:503)
    at de.wwu.muggl.vm.impl.symbolic.SymbolicVirtualMachine.executeFrame(SymbolicVirtualMachine.java:377)
    at de.wwu.muggl.vm.impl.jpa.JPAVirtualMachine.executeFrame(JPAVirtualMachine.java:25)
    at de.wwu.muggl.vm.VirtualMachine.runMainLoop(VirtualMachine.java:427)
    at de.wwu.muggl.vm.impl.symbolic.SymbolicVirtualMachine.runMainLoop(SymbolicVirtualMachine.java:272)
    at de.wwu.muggl.vm.VirtualMachine.run(VirtualMachine.java:239)

Last line here throws error:

    public void setVariable(int index, Variable variable) {
        // Initialize the array, if needed.
        if (this.variables == null) {
            if (this.codeAttribute == null) {
                throw new IllegalStateException("The method has no code!");
            }
            this.variables = new Variable[getNumberOfParameters()];
        }

        // Set the new one.
        this.variables[index] = variable;
    }
Dagefoerde commented 8 years ago

Duplicates #18 (although your description is more detailed; will close mine).