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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
This class represents a local variable.final class
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionaget
(VMXState.Local local, Authorization auth) Returns the value of the stack element corresponding tolocal
.static Object
aget
(VMXState vmx, int nesting, int index, Authorization auth) Returns the value of the stack elementindex
of thenesting
-th statically containing frame.agetj
(int index, Authorization auth) Returns the value of the stack elementindex
of the current Java frame.apeek()
Returns the topmost value from the stack without popping if off the stack.apeek
(int index) Returns theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.apop()
Pops the topmost value from the stack.void
Pushs the givenvalue
on top of the stack.Returns an instance ofAbruptCompletion.Return
.void
aset
(VMXState.Local local, Object value, Authorization auth) Sets the stack element corresponding tolocal
tovalue
.static void
aset
(Object value, VMXState vmx, int nesting, int index, Authorization auth) Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
.void
asetj
(int index, Object value, Authorization auth) Sets the stack elementindex
of the current Java frame tovalue
.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 tolocal
.static double
dget
(VMXState vmx, int nesting, int index, Authorization auth) Returns the value of the stack elementindex
of thenesting
-th statically containing frame.double
dgetj
(int index, Authorization auth) Returns the value of the stack elementindex
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.double
dpop()
Pops the topmost value from the stack.void
dpush
(double value) Pushs the givenvalue
on top of the stack.dreturn
(double value) Returns an instance ofAbruptCompletion.Return
.static void
dset
(double value, VMXState vmx, int nesting, int index, Authorization auth) Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
.void
dset
(VMXState.Local local, double value, Authorization auth) Sets the stack element corresponding tolocal
tovalue
.void
dsetj
(int index, double value, Authorization auth) Sets the stack elementindex
of the current Java frame tovalue
.void
enter
(int frameSize, Authorization auth) float
fget
(VMXState.Local local, Authorization auth) Returns the value of the stack element corresponding tolocal
.static float
fget
(VMXState vmx, int nesting, int index, Authorization auth) Returns the value of the stack elementindex
of thenesting
-th statically containing frame.float
fgetj
(int index, Authorization auth) Returns the value of the stack elementindex
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.float
fpop()
Pops the topmost value from the stack.void
fpush
(float value) Pushs the givenvalue
on top of the stack.freturn
(float value) Returns an instance ofAbruptCompletion.Return
.static void
fset
(float value, VMXState vmx, int nesting, int index, Authorization auth) Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
.void
fset
(VMXState.Local local, float value, Authorization auth) Sets the stack element corresponding tolocal
tovalue
.void
fsetj
(int index, float value, Authorization auth) Sets the stack elementindex
of the current Java frame tovalue
.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 tolocal
.static int
iget
(VMXState vmx, int nesting, int index, Authorization auth) Returns the value of the stack elementindex
of thenesting
-th statically containing frame.int
igetj
(int index, Authorization auth) Returns the value of the stack elementindex
of the current Java frame.Invokes the givenmethod
using parameters popped from the stack.invoke
(Routine routine, int nesting, Authorization auth) Creates a new stack frame and invokes the givenroutine
.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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.int
ipop()
Pops the topmost value from the stack.void
ipush
(int value) Pushs the givenvalue
on top of the stack.ireturn
(int value) Returns an instance ofAbruptCompletion.Return
.static void
iset
(int value, VMXState vmx, int nesting, int index, Authorization auth) Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
.void
iset
(VMXState.Local local, int value, Authorization auth) Sets the stack element corresponding tolocal
tovalue
.void
isetj
(int index, int value, Authorization auth) Sets the stack elementindex
of the current Java frame tovalue
.void
leave
(Authorization auth) long
lget
(VMXState.Local local, Authorization auth) Returns the value of the stack element corresponding tolocal
.static long
lget
(VMXState vmx, int nesting, int index, Authorization auth) Returns the value of the stack elementindex
of thenesting
-th statically containing frame.long
lgetj
(int index, Authorization auth) Returns the value of the stack elementindex
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.long
lpop()
Pops the topmost value from the stack.void
lpush
(long value) Pushs the givenvalue
on top of the stack.lreturn
(long value) Returns an instance ofAbruptCompletion.Return
.static void
lset
(long value, VMXState vmx, int nesting, int index, Authorization auth) Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
.void
lset
(VMXState.Local local, long value, Authorization auth) Sets the stack element corresponding tolocal
tovalue
.void
lsetj
(int index, long value, Authorization auth) Sets the stack elementindex
of the current Java frame tovalue
.newBreak
(int label) Returns an instance ofAbruptCompletion.Break
.newNonlocal
(int nesting, AbruptCompletion reason, Authorization auth) Returns an instance ofAbruptCompletion.Nonlocal
.Returns an instance ofAbruptCompletion.Return
.Returns an instance ofAbruptCompletion.Throw
.int[]
peekIntArray
(int length) void
pop
(int size) Pops and discardssize
elements from the stack.int[]
popIntArray
(int length) Popslength
values of typeint
from the stack and returns them as an array.vreturn()
Returns an instance ofAbruptCompletion.Return
.
-
Field Details
-
INT_0
public static final int[] INT_0
-
-
Method Details
-
enter
-
leave
-
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
Returns the VMXState for the current thread.- Returns:
- the current VMXState
-
getFrame
Returns the current stack pointer for the static-link stack.- Returns:
- current static-link stack pointer
-
invoke
Creates a new stack frame and invokes the givenroutine
. This method proceeds as follows:-
It is assumed that
routine.getParameterSize()
stack elements have been pushed on the stack. These are used as the parameters for the routine invocation. -
If
routine.hasJavaParameters()
returnstrue
, 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 ofroutine.getJavaFrameSize()
). The stack pointer is set to point behind the frame (which has a total size ofroutine.getFrameSize()
). Otherwise, ifroutine.hasJavaParameters()
returnsfalse
, the pointers are modified correspondingly, with the roles of the frame and the Java frame exchanged. -
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.
-
0 if the invoking routine and the invoked
-
The method
routine.execute
is invoked. - 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 invokednesting
- the nesting of the invoking routine within the invoked routine- Returns:
- the returned value of
routine.execute
-
It is assumed that
-
isetj
Sets the stack elementindex
of the current Java frame tovalue
. -
igetj
Returns the value of the stack elementindex
of the current Java frame.- Returns:
- stack element at
index
-
iset
Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
. -
iget
Returns the value of the stack elementindex
of thenesting
-th statically containing frame.- Returns:
- stack element at
index
-
iset
Sets the stack element corresponding tolocal
tovalue
. -
iget
Returns the value of the stack element corresponding tolocal
.- Returns:
- stack element for
local
-
ipush
public void ipush(int value) Pushs the givenvalue
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.- Returns:
- the
index
-th value from the top of the stack
-
lsetj
Sets the stack elementindex
of the current Java frame tovalue
. -
lgetj
Returns the value of the stack elementindex
of the current Java frame.- Returns:
- stack element at
index
-
lset
Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
. -
lget
Returns the value of the stack elementindex
of thenesting
-th statically containing frame.- Returns:
- stack element at
index
-
lset
Sets the stack element corresponding tolocal
tovalue
. -
lget
Returns the value of the stack element corresponding tolocal
.- Returns:
- stack element for
local
-
lpush
public void lpush(long value) Pushs the givenvalue
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.- Returns:
- the
index
-th value from the top of the stack
-
fsetj
Sets the stack elementindex
of the current Java frame tovalue
. -
fgetj
Returns the value of the stack elementindex
of the current Java frame.- Returns:
- stack element at
index
-
fset
Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
. -
fget
Returns the value of the stack elementindex
of thenesting
-th statically containing frame.- Returns:
- stack element at
index
-
fset
Sets the stack element corresponding tolocal
tovalue
. -
fget
Returns the value of the stack element corresponding tolocal
.- Returns:
- stack element for
local
-
fpush
public void fpush(float value) Pushs the givenvalue
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.- Returns:
- the
index
-th value from the top of the stack
-
dsetj
Sets the stack elementindex
of the current Java frame tovalue
. -
dgetj
Returns the value of the stack elementindex
of the current Java frame.- Returns:
- stack element at
index
-
dset
Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
. -
dget
Returns the value of the stack elementindex
of thenesting
-th statically containing frame.- Returns:
- stack element at
index
-
dset
Sets the stack element corresponding tolocal
tovalue
. -
dget
Returns the value of the stack element corresponding tolocal
.- Returns:
- stack element for
local
-
dpush
public void dpush(double value) Pushs the givenvalue
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 theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.- Returns:
- the
index
-th value from the top of the stack
-
asetj
Sets the stack elementindex
of the current Java frame tovalue
. -
agetj
Returns the value of the stack elementindex
of the current Java frame.- Returns:
- stack element at
index
-
aset
Sets the stack elementindex
of thenesting
-th statically containing frame tovalue
. -
aget
Returns the value of the stack elementindex
of thenesting
-th statically containing frame.- Returns:
- stack element at
index
-
aset
Sets the stack element corresponding tolocal
tovalue
. -
aget
Returns the value of the stack element corresponding tolocal
.- Returns:
- stack element for
local
-
apush
Pushs the givenvalue
on top of the stack. -
apop
Pops the topmost value from the stack.- Returns:
- the popped stack element
-
apeek
Returns the topmost value from the stack without popping if off the stack.- Returns:
- the topmost stack element
-
apeek
Returns theindex
-th value from the top of the stack, i.e., the value with absolute addresssp - index
.- Returns:
- the
index
-th value from the top of the stack
-
pop
public void pop(int size) Pops and discardssize
elements from the stack.- Parameters:
size
- the number of elements to pop
-
invokeInFrame
-
newReturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use.- Returns:
- an instance of
AbruptCompletion.Return
-
newBreak
Returns an instance ofAbruptCompletion.Break
. This instance can be used until itsdispose
-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
Returns an instance ofAbruptCompletion.Throw
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use.- Parameters:
cause
- the cause- Returns:
- an instance of
AbruptCompletion.Throw
-
ireturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the givenvalue
.- Parameters:
value
- the returned value- Returns:
- an instance of
AbruptCompletion.Return
with the givenvalue
-
lreturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the givenvalue
.- Parameters:
value
- the returned value- Returns:
- an instance of
AbruptCompletion.Return
with the givenvalue
-
freturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the givenvalue
.- Parameters:
value
- the returned value- Returns:
- an instance of
AbruptCompletion.Return
with the givenvalue
-
dreturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the givenvalue
.- Parameters:
value
- the returned value- Returns:
- an instance of
AbruptCompletion.Return
with the givenvalue
-
areturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use. The value of the instance is set to the givenvalue
.- Parameters:
value
- the returned value- Returns:
- an instance of
AbruptCompletion.Return
with the givenvalue
-
newNonlocal
public AbruptCompletion.Nonlocal newNonlocal(int nesting, AbruptCompletion reason, Authorization auth) Returns an instance ofAbruptCompletion.Nonlocal
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use.- Parameters:
nesting
- the nesting of the target routine within the invoked routinereason
- the reason of the nonlocal abrupt completion- Returns:
- an instance of
AbruptCompletion.Nonlocal
-
vreturn
Returns an instance ofAbruptCompletion.Return
. This instance can be used until itsdispose
-method is invoked, which marks the instance as available for later re-use.- Returns:
- an instance of
AbruptCompletion.Return
with avoid
return value
-
popIntArray
public int[] popIntArray(int length) Popslength
values of typeint
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 sameVMXState
.- Parameters:
length
- the number of values to be popped- Returns:
- an array containing the
length
popped values
-
peekIntArray
public int[] peekIntArray(int length) -
invoke
Invokes the givenmethod
using parameters popped from the stack. The returned value is wrapped in an instance ofAbruptCompletion.Return
. Checked exceptions are wrapped in an instance ofAbruptCompletion.Throw
which is then thrown.- Parameters:
method
- the method to invoke- Returns:
- the method's return value
-
createDescriptor
Returns a descriptor for a routine invocation. This method returns a descriptor for the later invocation of the givenroutine
. The parameters have to be set as ininvoke(Routine, int, Authorization)
, however, theroutine
is not invoked immediately, but later on by methods declared inRoutineDescriptor
. This later invocation happens in an equal frame context as for the immediate invocation byinvoke(Routine, int, Authorization)
.- Parameters:
routine
- the routine to be invoked later onnesting
- the nesting of the invoking routine within the invoked routine- Returns:
- a descriptor for the specified routine incarnation
-