de.grogra.xl.vmx
Class VMXState

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

public final class VMXState
extends java.lang.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 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

Nested Class Summary
static class VMXState.Local
          This class represents a local variable.
 class VMXState.MatchConsumerInFrame
           
 
Field Summary
static int[] INT_0
           
 
Method Summary
 java.lang.Object aget(VMXState.Local local, Authorization auth)
          Returns the value of the stack element corresponding to local.
static java.lang.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.
 java.lang.Object agetj(int index, Authorization auth)
          Returns the value of the stack element index of the current Java frame.
 java.lang.Object apeek()
          Returns the topmost value from the stack without popping if off the stack.
 java.lang.Object apeek(int index)
          Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
 java.lang.Object apop()
          Pops the topmost value from the stack.
 void apush(java.lang.Object value)
          Pushs the given value on top of the stack.
 AbruptCompletion.Return areturn(java.lang.Object value)
          Returns an instance of AbruptCompletion.Return.
static void aset(java.lang.Object value, VMXState vmx, int nesting, int index, Authorization auth)
          Sets the stack element index of the nesting-th statically containing frame to value.
 void aset(VMXState.Local local, java.lang.Object value, Authorization auth)
          Sets the stack element corresponding to local to value.
 void asetj(int index, java.lang.Object value, Authorization auth)
          Sets the stack element index of the current Java frame to value.
 RoutineDescriptor createDescriptor(Routine routine, int nesting, Authorization auth)
          Returns a descriptor for a routine invocation.
static VMXState current()
          Returns the VMXState for the current thread.
 double dget(VMXState.Local local, Authorization auth)
          Returns the value of the stack element corresponding to local.
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.
 double dgetj(int index, Authorization auth)
          Returns the value of the stack element index of the current Java frame.
 double dpeek()
          Returns the topmost value from the stack without popping if off the stack.
 double dpeek(int index)
          Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
 double dpop()
          Pops the topmost value from the stack.
 void dpush(double value)
          Pushs the given value on top of the stack.
 AbruptCompletion.Return dreturn(double value)
          Returns an instance of AbruptCompletion.Return.
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.
 void dset(VMXState.Local local, double value, Authorization auth)
          Sets the stack element corresponding to local to value.
 void dsetj(int index, double value, Authorization auth)
          Sets the stack element index of the current Java frame to value.
 void enter(int frameSize, Authorization auth)
           
 float fget(VMXState.Local local, Authorization auth)
          Returns the value of the stack element corresponding to local.
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.
 float fgetj(int index, Authorization auth)
          Returns the value of the stack element index of the current Java frame.
 float fpeek()
          Returns the topmost value from the stack without popping if off the stack.
 float fpeek(int index)
          Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
 float fpop()
          Pops the topmost value from the stack.
 void fpush(float value)
          Pushs the given value on top of the stack.
 AbruptCompletion.Return freturn(float value)
          Returns an instance of AbruptCompletion.Return.
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.
 void fset(VMXState.Local local, float value, Authorization auth)
          Sets the stack element corresponding to local to value.
 void fsetj(int index, float value, Authorization auth)
          Sets the stack element index of the current Java frame to value.
 Frame getFrame(Authorization auth)
          Returns the current stack pointer for the static-link stack.
 int getId()
          Returns a unique id for this VMXState.
 int iget(VMXState.Local local, Authorization auth)
          Returns the value of the stack element corresponding to local.
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.
 int igetj(int index, Authorization auth)
          Returns the value of the stack element index of the current Java frame.
 AbruptCompletion.Return invoke(Method method)
          Invokes the given method using parameters popped from the stack.
 AbruptCompletion.Return invoke(Routine routine, int nesting, Authorization auth)
          Creates a new stack frame and invokes the given routine.
 VMXState.MatchConsumerInFrame invokeInFrame(MatchConsumer consumer, Frame frame)
           
 int ipeek()
          Returns the topmost value from the stack without popping if off the stack.
 int ipeek(int index)
          Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
 int ipop()
          Pops the topmost value from the stack.
 void ipush(int value)
          Pushs the given value on top of the stack.
 AbruptCompletion.Return ireturn(int value)
          Returns an instance of AbruptCompletion.Return.
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.
 void iset(VMXState.Local local, int value, Authorization auth)
          Sets the stack element corresponding to local to value.
 void isetj(int index, int value, Authorization auth)
          Sets the stack element index of the current Java frame to value.
 void leave(Authorization auth)
           
 long lget(VMXState.Local local, Authorization auth)
          Returns the value of the stack element corresponding to local.
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.
 long lgetj(int index, Authorization auth)
          Returns the value of the stack element index of the current Java frame.
 long lpeek()
          Returns the topmost value from the stack without popping if off the stack.
 long lpeek(int index)
          Returns the index-th value from the top of the stack, i.e., the value with absolute address sp - index.
 long lpop()
          Pops the topmost value from the stack.
 void lpush(long value)
          Pushs the given value on top of the stack.
 AbruptCompletion.Return lreturn(long value)
          Returns an instance of AbruptCompletion.Return.
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.
 void lset(VMXState.Local local, long value, Authorization auth)
          Sets the stack element corresponding to local to value.
 void lsetj(int index, long value, Authorization auth)
          Sets the stack element index of the current Java frame to value.
 AbruptCompletion.Break newBreak(int label)
          Returns an instance of AbruptCompletion.Break.
 AbruptCompletion.Nonlocal newNonlocal(int nesting, AbruptCompletion reason, Authorization auth)
          Returns an instance of AbruptCompletion.Nonlocal.
 AbruptCompletion.Return newReturn()
          Returns an instance of AbruptCompletion.Return.
 AbruptCompletion.Throw newThrow(java.lang.Throwable cause)
          Returns an instance of AbruptCompletion.Throw.
 int[] peekIntArray(int length)
           
 void pop(int size)
          Pops and discards size elements from the stack.
 int[] popIntArray(int length)
          Pops length values of type int from the stack and returns them as an array.
 AbruptCompletion.Return vreturn()
          Returns an instance of AbruptCompletion.Return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT_0

public static final int[] INT_0
Method Detail

aget

public java.lang.Object aget(VMXState.Local local,
                             Authorization auth)
Returns the value of the stack element corresponding to local.

Returns:
stack element for local

aget

public static java.lang.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

agetj

public java.lang.Object agetj(int index,
                              Authorization auth)
Returns the value of the stack element index of the current Java frame.

Returns:
stack element at index

apeek

public java.lang.Object apeek()
Returns the topmost value from the stack without popping if off the stack.

Returns:
the topmost stack element

apeek

public java.lang.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

apop

public java.lang.Object apop()
Pops the topmost value from the stack.

Returns:
the popped stack element

apush

public void apush(java.lang.Object value)
Pushs the given value on top of the stack.


areturn

public AbruptCompletion.Return areturn(java.lang.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

aset

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


aset

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


asetj

public void asetj(int index,
                  java.lang.Object value,
                  Authorization auth)
Sets the stack element index of the current Java frame to 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

current

public static VMXState current()
Returns the VMXState for the current thread.

Returns:
the current VMXState

dget

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

Returns:
stack element for local

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

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

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

dpop

public double dpop()
Pops the topmost value from the stack.

Returns:
the popped stack element

dpush

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


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

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.


dset

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


dsetj

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


enter

public void enter(int frameSize,
                  Authorization auth)

fget

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

Returns:
stack element for local

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

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

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

fpop

public float fpop()
Pops the topmost value from the stack.

Returns:
the popped stack element

fpush

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


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

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.


fset

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


fsetj

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


getFrame

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

Returns:
current static-link stack pointer

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

iget

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

Returns:
stack element for local

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

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

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

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

invokeInFrame

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

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

ipop

public int ipop()
Pops the topmost value from the stack.

Returns:
the popped stack element

ipush

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


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

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.


iset

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


isetj

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


leave

public void leave(Authorization auth)

lget

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

Returns:
stack element for local

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

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

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

lpop

public long lpop()
Pops the topmost value from the stack.

Returns:
the popped stack element

lpush

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


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

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.


lset

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


lsetj

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


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

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

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

newThrow

public AbruptCompletion.Throw newThrow(java.lang.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

peekIntArray

public int[] peekIntArray(int length)

pop

public void pop(int size)
Pops and discards size elements from the stack.

Parameters:
size - the number of elements to pop

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

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