Module xl.vmx

Class VMXState

java.lang.Object
de.grogra.xl.vmx.VMXState

public final class VMXState extends Object
A VMXState is associated with a single Thread. It provides a stack (consisting of frames) and some other features to be used exclusively within the context of this thread.

A VMXState can be seen as an extension of the per-thread state that a Java virtual machine maintains. This per-thread state contains a stack. However, this stack can only be accessed by instructions for the Java virtual machine, not by method invocations, and it is a purely local stack without the possibility to access stack frames of other method invocations than the current one.

Some features of the XL programming language, e.g., invocations of generator methods, require nested routines and a stack with support for access of stack frame of statically containing routine invocations. The stack of a VMXState provides such support; implementations of these features of the XL programming language can make use of the stack of the current thread's VMXState.

A VMXState has a stack pointer sp, a "Java frame pointer" jfp, and a frame for the current routine invocation getFrame(Authorization). Each frame has a VMXState.VMXFrame.staticLink to the frame of statically containing routine invocation. The stack frame of the statically containing routine invocation is the stack frame belonging to the nearest invocation of the containing (i.e., the textually enclosing) routine of the current routine. As for the Java virtual machine, values of the types long and double occupy two consecutive elements of the stack, values of the other types occupy a single element.

Author:
Ole Kniemeyer
  • Field Details

    • INT_0

      public static final int[] INT_0
  • Method Details

    • enter

      public void enter(int frameSize, Authorization auth)
    • leave

      public void leave(Authorization auth)
    • getId

      public int getId()
      Returns a unique id for this VMXState. The id is unique within the scope of the current Java virtual machine.
      Returns:
      a unique id
    • current

      public static VMXState current()
      Returns the VMXState for the current thread.
      Returns:
      the current VMXState
    • getFrame

      public Frame getFrame(Authorization auth)
      Returns the current stack pointer for the static-link stack.
      Returns:
      current static-link stack pointer
    • invoke

      public AbruptCompletion.Return invoke(Routine routine, int nesting, Authorization auth)
      Creates a new stack frame and invokes the given routine. This method proceeds as follows:
      1. It is assumed that routine.getParameterSize() stack elements have been pushed on the stack. These are used as the parameters for the routine invocation.
      2. If routine.hasJavaParameters() returns true, the Java frame pointer is set to point to the stack element of the first parameter. The frame pointer is set to point behind the Java frame (which has a total size of routine.getJavaFrameSize()). The stack pointer is set to point behind the frame (which has a total size of routine.getFrameSize()). Otherwise, if routine.hasJavaParameters() returns false, the pointers are modified correspondingly, with the roles of the frame and the Java frame exchanged.
      3. A new element is pushed on the static-link stack. nesting is used in this step. Its value has to be
        • 0 if the invoking routine and the invoked routine are statically contained in the same routine (i.e., their immediately enclosing routine is the same),
        • n if the invoked routine is the n-th statically containing routine of the invoking routine,
        • -1 otherwise.
      4. The method routine.execute is invoked.
      5. All modifications to the stack pointers are undone, the routine parameters are popped from the stack. This step happens even in the case of an exception.
      Parameters:
      routine - the routine to be invoked
      nesting - the nesting of the invoking routine within the invoked routine
      Returns:
      the returned value of routine.execute
    • isetj

      public void isetj(int index, int value, Authorization auth)
      Sets the stack element index of the current Java frame to value.
    • igetj

      public int igetj(int index, Authorization auth)
      Returns the value of the stack element index of the current Java frame.
      Returns:
      stack element at index
    • iset

      public static void iset(int value, VMXState vmx, int nesting, int index, Authorization auth)
      Sets the stack element index of the nesting-th statically containing frame to value.
    • iget

      public static int iget(VMXState vmx, int nesting, int index, Authorization auth)
      Returns the value of the stack element index of the nesting-th statically containing frame.
      Returns:
      stack element at index
    • iset

      public void iset(VMXState.Local local, int value, Authorization auth)
      Sets the stack element corresponding to local to value.
    • iget

      public int iget(VMXState.Local local, Authorization auth)
      Returns the value of the stack element corresponding to local.
      Returns:
      stack element for local
    • ipush

      public void ipush(int value)
      Pushs the given value on top of the stack.
    • ipop

      public int ipop()
      Pops the topmost value from the stack.
      Returns:
      the popped stack element
    • ipeek

      public int ipeek()
      Returns the topmost value from the stack without popping if off the stack.
      Returns:
      the topmost stack element
    • ipeek

      public int ipeek(int index)
      Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
      Returns:
      the index-th value from the top of the stack
    • lsetj

      public void lsetj(int index, long value, Authorization auth)
      Sets the stack element index of the current Java frame to value.
    • lgetj

      public long lgetj(int index, Authorization auth)
      Returns the value of the stack element index of the current Java frame.
      Returns:
      stack element at index
    • lset

      public static void lset(long value, VMXState vmx, int nesting, int index, Authorization auth)
      Sets the stack element index of the nesting-th statically containing frame to value.
    • lget

      public static long lget(VMXState vmx, int nesting, int index, Authorization auth)
      Returns the value of the stack element index of the nesting-th statically containing frame.
      Returns:
      stack element at index
    • lset

      public void lset(VMXState.Local local, long value, Authorization auth)
      Sets the stack element corresponding to local to value.
    • lget

      public long lget(VMXState.Local local, Authorization auth)
      Returns the value of the stack element corresponding to local.
      Returns:
      stack element for local
    • lpush

      public void lpush(long value)
      Pushs the given value on top of the stack.
    • lpop

      public long lpop()
      Pops the topmost value from the stack.
      Returns:
      the popped stack element
    • lpeek

      public long lpeek()
      Returns the topmost value from the stack without popping if off the stack.
      Returns:
      the topmost stack element
    • lpeek

      public long lpeek(int index)
      Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
      Returns:
      the index-th value from the top of the stack
    • fsetj

      public void fsetj(int index, float value, Authorization auth)
      Sets the stack element index of the current Java frame to value.
    • fgetj

      public float fgetj(int index, Authorization auth)
      Returns the value of the stack element index of the current Java frame.
      Returns:
      stack element at index
    • fset

      public static void fset(float value, VMXState vmx, int nesting, int index, Authorization auth)
      Sets the stack element index of the nesting-th statically containing frame to value.
    • fget

      public static float fget(VMXState vmx, int nesting, int index, Authorization auth)
      Returns the value of the stack element index of the nesting-th statically containing frame.
      Returns:
      stack element at index
    • fset

      public void fset(VMXState.Local local, float value, Authorization auth)
      Sets the stack element corresponding to local to value.
    • fget

      public float fget(VMXState.Local local, Authorization auth)
      Returns the value of the stack element corresponding to local.
      Returns:
      stack element for local
    • fpush

      public void fpush(float value)
      Pushs the given value on top of the stack.
    • fpop

      public float fpop()
      Pops the topmost value from the stack.
      Returns:
      the popped stack element
    • fpeek

      public float fpeek()
      Returns the topmost value from the stack without popping if off the stack.
      Returns:
      the topmost stack element
    • fpeek

      public float fpeek(int index)
      Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
      Returns:
      the index-th value from the top of the stack
    • dsetj

      public void dsetj(int index, double value, Authorization auth)
      Sets the stack element index of the current Java frame to value.
    • dgetj

      public double dgetj(int index, Authorization auth)
      Returns the value of the stack element index of the current Java frame.
      Returns:
      stack element at index
    • dset

      public static void dset(double value, VMXState vmx, int nesting, int index, Authorization auth)
      Sets the stack element index of the nesting-th statically containing frame to value.
    • dget

      public static double dget(VMXState vmx, int nesting, int index, Authorization auth)
      Returns the value of the stack element index of the nesting-th statically containing frame.
      Returns:
      stack element at index
    • dset

      public void dset(VMXState.Local local, double value, Authorization auth)
      Sets the stack element corresponding to local to value.
    • dget

      public double dget(VMXState.Local local, Authorization auth)
      Returns the value of the stack element corresponding to local.
      Returns:
      stack element for local
    • dpush

      public void dpush(double value)
      Pushs the given value on top of the stack.
    • dpop

      public double dpop()
      Pops the topmost value from the stack.
      Returns:
      the popped stack element
    • dpeek

      public double dpeek()
      Returns the topmost value from the stack without popping if off the stack.
      Returns:
      the topmost stack element
    • dpeek

      public double dpeek(int index)
      Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
      Returns:
      the index-th value from the top of the stack
    • asetj

      public void asetj(int index, Object value, Authorization auth)
      Sets the stack element index of the current Java frame to value.
    • agetj

      public Object agetj(int index, Authorization auth)
      Returns the value of the stack element index of the current Java frame.
      Returns:
      stack element at index
    • aset

      public static void aset(Object value, VMXState vmx, int nesting, int index, Authorization auth)
      Sets the stack element index of the nesting-th statically containing frame to value.
    • aget

      public static Object aget(VMXState vmx, int nesting, int index, Authorization auth)
      Returns the value of the stack element index of the nesting-th statically containing frame.
      Returns:
      stack element at index
    • aset

      public void aset(VMXState.Local local, Object value, Authorization auth)
      Sets the stack element corresponding to local to value.
    • aget

      public Object aget(VMXState.Local local, Authorization auth)
      Returns the value of the stack element corresponding to local.
      Returns:
      stack element for local
    • apush

      public void apush(Object value)
      Pushs the given value on top of the stack.
    • apop

      public Object apop()
      Pops the topmost value from the stack.
      Returns:
      the popped stack element
    • apeek

      public Object apeek()
      Returns the topmost value from the stack without popping if off the stack.
      Returns:
      the topmost stack element
    • apeek

      public Object apeek(int index)
      Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
      Returns:
      the index-th value from the top of the stack
    • pop

      public void pop(int size)
      Pops and discards size elements from the stack.
      Parameters:
      size - the number of elements to pop
    • invokeInFrame

      public VMXState.MatchConsumerInFrame invokeInFrame(MatchConsumer consumer, Frame frame)
    • newReturn

      public AbruptCompletion.Return newReturn()
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use.
      Returns:
      an instance of AbruptCompletion.Return
    • newBreak

      public AbruptCompletion.Break newBreak(int label)
      Returns an instance of AbruptCompletion.Break. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use.
      Parameters:
      label - the break label
      Returns:
      an instance of AbruptCompletion.Break
    • newThrow

      public AbruptCompletion.Throw newThrow(Throwable cause)
      Returns an instance of AbruptCompletion.Throw. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use.
      Parameters:
      cause - the cause
      Returns:
      an instance of AbruptCompletion.Throw
    • ireturn

      public AbruptCompletion.Return ireturn(int value)
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the given value.
      Parameters:
      value - the returned value
      Returns:
      an instance of AbruptCompletion.Return with the given value
    • lreturn

      public AbruptCompletion.Return lreturn(long value)
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the given value.
      Parameters:
      value - the returned value
      Returns:
      an instance of AbruptCompletion.Return with the given value
    • freturn

      public AbruptCompletion.Return freturn(float value)
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the given value.
      Parameters:
      value - the returned value
      Returns:
      an instance of AbruptCompletion.Return with the given value
    • dreturn

      public AbruptCompletion.Return dreturn(double value)
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the given value.
      Parameters:
      value - the returned value
      Returns:
      an instance of AbruptCompletion.Return with the given value
    • areturn

      public AbruptCompletion.Return areturn(Object value)
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the given value.
      Parameters:
      value - the returned value
      Returns:
      an instance of AbruptCompletion.Return with the given value
    • newNonlocal

      public AbruptCompletion.Nonlocal newNonlocal(int nesting, AbruptCompletion reason, Authorization auth)
      Returns an instance of AbruptCompletion.Nonlocal. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use.
      Parameters:
      nesting - the nesting of the target routine within the invoked routine
      reason - the reason of the nonlocal abrupt completion
      Returns:
      an instance of AbruptCompletion.Nonlocal
    • vreturn

      public AbruptCompletion.Return vreturn()
      Returns an instance of AbruptCompletion.Return. This instance can be used until its dispose-method is invoked, which marks the instance as available for later re-use.
      Returns:
      an instance of AbruptCompletion.Return with a void return value
    • popIntArray

      public int[] popIntArray(int length)
      Pops length values of type int from the stack and returns them as an array. The first popped element is placed in the last component of the array and so on. The returned array can only be used safely until the next invocation of this method on the same VMXState.
      Parameters:
      length - the number of values to be popped
      Returns:
      an array containing the length popped values
    • peekIntArray

      public int[] peekIntArray(int length)
    • invoke

      public AbruptCompletion.Return invoke(Method method)
      Invokes the given method using parameters popped from the stack. The returned value is wrapped in an instance of AbruptCompletion.Return. Checked exceptions are wrapped in an instance of AbruptCompletion.Throw which is then thrown.
      Parameters:
      method - the method to invoke
      Returns:
      the method's return value
    • createDescriptor

      public RoutineDescriptor createDescriptor(Routine routine, int nesting, Authorization auth)
      Returns a descriptor for a routine invocation. This method returns a descriptor for the later invocation of the given routine. The parameters have to be set as in invoke(Routine, int, Authorization), however, the routine is not invoked immediately, but later on by methods declared in RoutineDescriptor. This later invocation happens in an equal frame context as for the immediate invocation by invoke(Routine, int, Authorization).
      Parameters:
      routine - the routine to be invoked later on
      nesting - the nesting of the invoking routine within the invoked routine
      Returns:
      a descriptor for the specified routine incarnation