| java.lang.Object oscript.util.StackFrame
StackFrame | abstract public class StackFrame (Code) | | 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
StackFrame.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
StackFrame.setLineNumber 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 must go through the
StackFrame.evalNode 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
StackFrame.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.
author: Rob Clark (rob@ti.com) version: 1 |
Field Summary | |
protected StackFrame | debugStackFrame StackFrame to use whe debugging. | final protected short[] | idx | final protected int[] | lines The current line number at each stack frame. | final 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. | final protected StackFrameBasicScope[] | scopeLists The list of scopes allocated at the current frame, which should be
recycled once the stack frame is released. | final protected Scope[] | scopes The current scopes at each stack frame. |
Method Summary | |
final public BasicScope | allocateBasicScope(Scope prev, SymbolTable smit) Allocate a scope from the stack. | final public FunctionScope | allocateFunctionScope(Function fxn, Scope prev, SymbolTable smit, MemberTable members) Allocate a fxn-scope from the stack. | final public MemberTable | allocateMemberTable(short sz) Allocate from the stack. | final public 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. | public static synchronized StackFrame | currentStackFrame() Get the stack frame for the current thread. | final public static void | dumpStack(java.io.OutputStream out) | final public static void | dumpStack(java.io.Writer out) | public boolean | equals(Object obj) | final public Object | evalNode(NodeEvaluator ne, Scope scope) Push a new stack frame onto the stack, and pass it to ne 's
StackFrame.evalNode method, returning the result. | final public AbstractFile | getFile() The file corresponding to the current stack frame. | final public int | getId() The function name for the current stack frame, if there is one, otherwise
-1 . | final public int | getLineNumber() The current line number in the current stack frame. | public oscript.data.Value | getName() Convenience wrapper for
StackFrame.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 StackFrame | getSafeCopy() | final public Scope | getScope() The current scope in the current line number. | public int | hashCode() | public Iterator | iterator() Return an iterator of stack frames, starting with the top of the
stack, and iterating to root of stack. | final public static void | log(String str) | public 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. | public 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. | public String | toString() Convert to string, to print out a line in the stack-trace. |
debugStackFrame | protected StackFrame debugStackFrame(Code) | | StackFrame to use whe debugging. This one's
StackFrame.setLineNumber does
have extra checks for breakpoints, so breakpoints can work properly.
This should be treated as final.
|
idx | final protected short[] idx(Code) | | The current index, boxed in array so it can be shared between the
two stack-frame instances (regular & debug)
|
lines | final protected int[] lines(Code) | | The current line number at each stack frame.
|
nes | final protected NodeEvaluator[] nes(Code) | | The node evaluator, which has file, and id info needed when filling
in stack trace.
|
regularStackFrame | protected StackFrame regularStackFrame(Code) | | StackFrame to use when not debugging. This one's
StackFrame.setLineNumber
does not have extra checks for breakpoints for better performance. This
should be treated as final.
|
scopeLists | final protected StackFrameBasicScope[] scopeLists(Code) | | The list of scopes allocated at the current frame, which should be
recycled once the stack frame is released.
|
scopes | final protected Scope[] scopes(Code) | | The current scopes at each stack frame.
|
allocateBasicScope | final public BasicScope allocateBasicScope(Scope prev, SymbolTable smit)(Code) | | Allocate a scope from the stack. The basic-scope is freed automatically
when the stack-frame is disposed
|
allocateMemberTable | final public MemberTable allocateMemberTable(short sz)(Code) | | Allocate from the stack.
|
clone | final public Object clone()(Code) | | 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.
|
currentStackFrame | public static synchronized StackFrame currentStackFrame()(Code) | | Get the stack frame for the current thread. If one does not already
exist, this will create a new one, otherwise it will return the
current top of the stack.
|
evalNode | final public Object evalNode(NodeEvaluator ne, Scope scope)(Code) | | Push a new stack frame onto the stack, and pass it to ne 's
StackFrame.evalNode method, returning the result.
Parameters: ne - the node-evaluator for the node to evaluate Parameters: scope - the scope to evalute in the result |
getFile | final public AbstractFile getFile()(Code) | | The file corresponding to the current stack frame.
|
getId | final public int getId()(Code) | | The function name for the current stack frame, if there is one, otherwise
-1 .
|
getLineNumber | final public int getLineNumber()(Code) | | The current line number in the current stack frame.
|
getName | public oscript.data.Value getName()(Code) | | Convenience wrapper for
StackFrame.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.
|
getScope | final public Scope getScope()(Code) | | The current scope in the current line number.
|
hashCode | public int hashCode()(Code) | | |
iterator | public Iterator iterator()(Code) | | Return an iterator of stack frames, starting with the top of the
stack, and iterating to root of stack.
|
setLineNumber | public void setLineNumber(Scope scope, int line)(Code) | | Called by node evaluator to store line number info, and to give the
debugger a chance to see if we've hit a breakpoint.
Parameters: scope - the current scope Parameters: line - the current line number |
setLineNumber | public void setLineNumber(int line)(Code) | | Called by node evaluator to store line number info, and to give the
debugger a chance to see if we've hit a breakpoint. This method
is used by the compiler in cases where the scope hasn't changed
sinced last line number, to save a few instructions.
Parameters: scope - the current scope Parameters: line - the current line number |
toString | public String toString()(Code) | | Convert to string, to print out a line in the stack-trace.
|
|
|