|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectoscript.util.StackFrame
public abstract class StackFrame
The "chain" of stack frames is used to track execution context of a particular thread and, when debugging is enabled, give the debugger a chance to run breakpoints.
Where possible, the head of the chain of stack frames is passed on the
stack, but in cases where it cannot be, such as when control passes to
java code and back, a hashtable is used to map the current thread to
a StackFrame
. To access the current stack frame, or
create one if needed, use currentStackFrame()
.
While on the interface, the stack frame behaves as a chain of
StackFrame
objects, behind the scenes an array is used
for the stack, and a fly-weight pattern is used for the stack frame
objects. This way we (1) avoid extra memory allocations, and (2)
can have different implementations of setLineNumber(oscript.data.Scope, int)
depending
on whether debugging is enabled or not. (Debugging is automatically
enabled when a breakpoint is set.)
In order to maintain this allusion, calls to NodeEvaluator.evalNode(oscript.util.StackFrame, oscript.data.Scope)
must go through the evalNode(oscript.NodeEvaluator, oscript.data.Scope)
call-gate.
The stack frame object is intentionally not thread safe, since it is only
accessed from a single thread context. Because of the use of the fly-
weight pattern, a stack frame object no longer validly represents a stack
frame that has exited, either by normally or via an exception. Because
of this, any code that wishes to save a reference to a stack frame object
must clone()
it.
Because the StackFrame
is only accessed from a single thread
context, it can provide a lightweight mechanism to allocate storage for
BasicScope
objects. This can be used in cases where the scope
object only exists on the stack, and is not held after the program
enclosed by the scope has finished execution, ie. there is no function
enclosed by the scope. For cases of an enclosed function, the scope
storage must be allocated from the heap so that it can be valid at some
point in the future when the enclosed function is potentially called.
Field Summary | |
---|---|
protected StackFrame |
debugStackFrame
StackFrame to use whe debugging. |
protected short[] |
idx
The current index, boxed in array so it can be shared between the two stack-frame instances (regular & debug) |
protected int[] |
lines
The current line number at each stack frame. |
protected NodeEvaluator[] |
nes
The node evaluator, which has file, and id info needed when filling in stack trace. |
protected StackFrame |
regularStackFrame
StackFrame to use when not debugging. |
protected oscript.util.StackFrame.StackFrameBasicScope[] |
scopeLists
The list of scopes allocated at the current frame, which should be recycled once the stack frame is released. |
protected Scope[] |
scopes
The current scopes at each stack frame. |
Method Summary | |
---|---|
BasicScope |
allocateBasicScope(Scope prev,
SymbolTable smit)
Allocate a scope from the stack. |
FunctionScope |
allocateFunctionScope(Function fxn,
Scope prev,
SymbolTable smit,
MemberTable members)
Allocate a fxn-scope from the stack. |
MemberTable |
allocateMemberTable(short sz)
Allocate from the stack. |
java.lang.Object |
clone()
Clone the stack frame, which is necessary in cases where you need to keep a reference to the stack frame (and it's parents) after the original stack frame has exited, such as to store in an exception. |
static StackFrame |
currentStackFrame()
Get the stack frame for the current thread. |
static void |
dumpStack(java.io.OutputStream out)
For debugging |
static void |
dumpStack(java.io.Writer out)
|
boolean |
equals(java.lang.Object obj)
|
java.lang.Object |
evalNode(NodeEvaluator ne,
Scope scope)
Push a new stack frame onto the stack, and pass it to ne 's
evalNode(oscript.NodeEvaluator, oscript.data.Scope) method, returning the result. |
AbstractFile |
getFile()
The file corresponding to the current stack frame. |
int |
getId()
The function name for the current stack frame, if there is one, otherwise -1 . |
int |
getLineNumber()
The current line number in the current stack frame. |
Value |
getName()
Convenience wrapper for getId() , mainly provided for the benefit
of script code that probably doesn't want to know about ids, and just
wants to think in terms of names. |
StackFrame |
getSafeCopy()
|
Scope |
getScope()
The current scope in the current line number. |
int |
hashCode()
|
java.util.Iterator |
iterator()
Return an iterator of stack frames, starting with the top of the stack, and iterating to root of stack. |
static void |
log(java.lang.String str)
|
void |
setLineNumber(int line)
Called by node evaluator to store line number info, and to give the debugger a chance to see if we've hit a breakpoint. |
void |
setLineNumber(Scope scope,
int line)
Called by node evaluator to store line number info, and to give the debugger a chance to see if we've hit a breakpoint. |
java.lang.String |
toString()
Convert to string, to print out a line in the stack-trace. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected StackFrame regularStackFrame
setLineNumber(oscript.data.Scope, int)
does not have extra checks for breakpoints for better performance. This
should be treated as final.
protected StackFrame debugStackFrame
setLineNumber(oscript.data.Scope, int)
does
have extra checks for breakpoints, so breakpoints can work properly.
This should be treated as final.
protected final short[] idx
protected final NodeEvaluator[] nes
protected final int[] lines
protected final Scope[] scopes
protected final oscript.util.StackFrame.StackFrameBasicScope[] scopeLists
Method Detail |
---|
public static StackFrame currentStackFrame()
public final java.lang.Object evalNode(NodeEvaluator ne, Scope scope)
ne
's
evalNode(oscript.NodeEvaluator, oscript.data.Scope)
method, returning the result.
ne
- the node-evaluator for the node to evaluatescope
- the scope to evalute in
public void setLineNumber(Scope scope, int line)
scope
- the current scopeline
- the current line numberpublic void setLineNumber(int line)
scope
- the current scopeline
- the current line numberpublic final BasicScope allocateBasicScope(Scope prev, SymbolTable smit)
public final FunctionScope allocateFunctionScope(Function fxn, Scope prev, SymbolTable smit, MemberTable members)
public final MemberTable allocateMemberTable(short sz)
public Value getName()
getId()
, mainly provided for the benefit
of script code that probably doesn't want to know about ids, and just
wants to think in terms of names.
public final int getId()
-1
.
public final AbstractFile getFile()
public final int getLineNumber()
public final Scope getScope()
public java.util.Iterator iterator()
public StackFrame getSafeCopy()
public final java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public static final void dumpStack(java.io.OutputStream out)
public static final void dumpStack(java.io.Writer out)
public static final void log(java.lang.String str)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |