Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading a Local Variable of Type Double #36

Open
anfuchs opened this issue Aug 16, 2016 · 1 comment
Open

Loading a Local Variable of Type Double #36

anfuchs opened this issue Aug 16, 2016 · 1 comment
Labels

Comments

@anfuchs
Copy link
Contributor

anfuchs commented Aug 16, 2016

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants