org.jruby.runtime
Class ThreadContext

java.lang.Object
  extended by org.jruby.runtime.ThreadContext

public final class ThreadContext
extends java.lang.Object


Field Summary
 int callNumber
           
 IRubyObject nil
           
 Ruby runtime
           
 RuntimeCache runtimeCache
           
 
Method Summary
 void callThreadPoll()
           
static void callThreadPoll(ThreadContext context)
           
 Frame[] createBacktrace(int level, boolean nativeException)
          Create an Array with backtrace information.
 BacktraceElement[] createBacktrace2(int level, boolean nativeException)
          Create an Array with backtrace information.
 IRubyObject createCallerBacktrace(Ruby runtime, int level)
          Create an Array with backtrace information.
static java.lang.String createRawBacktraceStringFromThrowable(java.lang.Throwable t)
           
 Binding currentBinding()
          Return a binding representing the current call's state
 Binding currentBinding(IRubyObject self)
          Return a binding representing the current call's state but with a specified self
 Binding currentBinding(IRubyObject self, DynamicScope scope)
          Return a binding representing the current call's state but with the specified scope and self.
 Binding currentBinding(IRubyObject self, Visibility visibility)
          Return a binding representing the current call's state but with the specified visibility and self.
 Binding currentBinding(IRubyObject self, Visibility visibility, DynamicScope scope)
          Return a binding representing the current call's state but with the specified visibility, scope, and self.
protected  void finalize()
           
 RubyStackTraceElement[] gatherCallerBacktrace(int level)
           
static RubyStackTraceElement[] gatherRawBacktrace(Ruby runtime, java.lang.StackTraceElement[] stackTrace)
           
 RubyContinuation.Continuation getActiveCatch(java.lang.Object tag)
          Find the active Continuation for the given tag.
 IRubyObject getConstant(java.lang.String internedName)
          Used by the evaluator and the compiler to look up a constant by name
 boolean getConstantDefined(java.lang.String internedName)
           
 Frame getCurrentFrame()
           
 Frame getCurrentRubyFrame()
           
 DynamicScope getCurrentScope()
           
 int getCurrentTarget()
           
 Visibility getCurrentVisibility()
           
 IRubyObject getErrorInfo()
           
 FiberLibrary.Fiber getFiber()
           
 java.lang.String getFile()
           
 Block getFrameBlock()
           
 int getFrameCount()
           
 int getFrameJumpTarget()
           
 RubyModule getFrameKlazz()
           
 java.lang.String getFrameName()
           
 Frame[] getFrames(int delta)
           
 IRubyObject getFrameSelf()
           
 CallType getLastCallType()
           
 IRubyObject getLastExitStatus()
           
 Visibility getLastVisibility()
           
 int getLine()
           
 Frame getNextFrame()
           
 Frame getPreviousFrame()
           
 RubyModule getPreviousRubyClass()
           
 DynamicScope getPreviousScope()
           
 Visibility getPreviousVisibility()
           
 IProfileData getProfileData()
          Get the profile data for this thread (ThreadContext).
 RubyModule getRubyClass()
           
 int getRubyFrameDelta()
           
 Ruby getRuntime()
           
 RubyThread getThread()
           
 boolean isEventHooksEnabled()
           
 boolean isJumpTargetAlive(int target, int skipFrames)
          Search the frame stack for the given JumpTarget.
 boolean isProfiling()
           
 boolean isWithinDefined()
          Is this thread actively in defined? at the moment.
 boolean isWithinTrace()
          Is this thread actively tracing at this moment.
static ThreadContext newContext(Ruby runtime)
           
 void pollThreadEvents()
           
static void popBacktrace(ThreadContext context)
           
 void popCatch()
           
 void popFrame()
           
 RubyModule popRubyClass()
           
 void popScope()
           
 void postBsfApply()
           
 void postClassEval()
           
 void postCompiledClass()
           
 void postEvalScriptlet()
           
 void postEvalWithBinding(Binding binding, Frame lastFrame)
           
 void postExecuteUnder()
           
 void postExtensionLoad()
           
 void postMethodBacktraceAndScope()
           
 void postMethodBacktraceDummyScope()
           
 void postMethodBacktraceOnly()
           
 void postMethodFrameAndScope()
           
 void postMethodFrameOnly()
           
 void postMethodScopeOnly()
           
 void postMproc()
           
 void postNodeEval()
           
 void postScopedBody()
           
 void postScopeNode()
           
 void postTrace()
           
 void postYield(Binding binding, Frame lastFrame)
           
 void postYieldLight(Binding binding, Frame lastFrame)
           
 void postYieldNoScope(Frame lastFrame)
           
 void preAdoptThread()
           
 void preBsfApply(java.lang.String[] names)
           
 void preClassEval(StaticScope staticScope, RubyModule type)
           
 void preCompiledClass(RubyModule type, StaticScope staticScope)
           
 void preCompiledClassDummyScope(RubyModule type, StaticScope staticScope)
           
 void preEvalScriptlet(DynamicScope scope)
           
 Frame preEvalWithBinding(Binding binding)
           
 void preExecuteUnder(RubyModule executeUnderClass, Block block)
           
 void preExtensionLoad(IRubyObject self)
           
 Frame preForBlock(Binding binding, RubyModule klass)
           
 void preMethodBacktraceAndScope(java.lang.String name, RubyModule clazz, StaticScope staticScope)
           
 void preMethodBacktraceDummyScope(RubyModule clazz, java.lang.String name, StaticScope staticScope)
           
 void preMethodBacktraceOnly(java.lang.String name)
           
 void preMethodFrameAndDummyScope(RubyModule clazz, java.lang.String name, IRubyObject self, Block block, StaticScope staticScope)
           
 void preMethodFrameAndScope(RubyModule clazz, java.lang.String name, IRubyObject self, Block block, StaticScope staticScope)
           
 void preMethodFrameOnly(RubyModule clazz, java.lang.String name, IRubyObject self, Block block)
           
 void preMethodNoFrameAndDummyScope(RubyModule clazz, StaticScope staticScope)
           
 void preMethodScopeOnly(RubyModule clazz, StaticScope staticScope)
           
 void preMproc()
           
 void preNodeEval(RubyModule rubyClass, IRubyObject self)
           
 void preNodeEval(RubyModule rubyClass, IRubyObject self, java.lang.String name)
           
 void prepareTopLevel(RubyClass objectClass, IRubyObject topSelf)
           
 void preRunThread(Frame[] currentFrames)
           
 void preScopedBody(DynamicScope scope)
           
 void preScopeNode(StaticScope staticScope)
           
 void preTrace()
           
 Binding previousBinding()
          Return a binding representing the previous call's state
 Binding previousBinding(IRubyObject self)
          Return a binding representing the previous call's state but with a specified self
 Frame preYieldLightBlock(Binding binding, DynamicScope emptyScope, RubyModule klass)
           
 Frame preYieldNoScope(Binding binding, RubyModule klass)
           
 Frame preYieldSpecificBlock(Binding binding, StaticScope scope, RubyModule klass)
           
 void printScope()
           
 int profileEnter(int nextMethod)
           
 int profileExit(int nextMethod, long startTime)
           
static void pushBacktrace(ThreadContext context, java.lang.String klass, java.lang.String method, ISourcePosition position)
           
static void pushBacktrace(ThreadContext context, java.lang.String klass, java.lang.String method, java.lang.String file, int line)
           
 void pushCatch(RubyContinuation.Continuation catchTarget)
           
 void pushFrame()
           
 void pushRubyClass(RubyModule currentModule)
           
 void pushScope(DynamicScope scope)
           
 JumpException.ReturnJump returnJump(IRubyObject value)
           
 IRubyObject setConstantInCurrent(java.lang.String internedName, IRubyObject result)
          Used by the evaluator and the compiler to set a constant by name This is for a null const decl
 IRubyObject setConstantInModule(java.lang.String internedName, IRubyObject target, IRubyObject result)
          Used by the evaluator and the compiler to set a constant by name.
 IRubyObject setConstantInObject(java.lang.String internedName, IRubyObject result)
          Used by the evaluator and the compiler to set a constant by name This is for a Colon2 const decl
 void setCurrentVisibility(Visibility visibility)
           
 IRubyObject setErrorInfo(IRubyObject errorInfo)
           
 void setEventHooksEnabled(boolean flag)
           
 void setFiber(FiberLibrary.Fiber fiber)
           
 void setFile(java.lang.String file)
           
 void setFileAndLine(ISourcePosition position)
           
 void setFileAndLine(java.lang.String file, int line)
           
 void setLastCallStatus(CallType callType)
          Returns the lastCallStatus.
 void setLastCallStatusAndVisibility(CallType callType, Visibility visibility)
           
 void setLastExitStatus(IRubyObject lastExitStatus)
           
 void setLastVisibility(Visibility visibility)
           
 void setLine(int line)
           
 void setRubyFrameDelta(int newDelta)
           
 void setThread(RubyThread thread)
           
 void setWithinDefined(boolean isWithinDefined)
          Set whether we are actively within defined? or not.
 void setWithinTrace(boolean isWithinTrace)
          Set whether we are actively tracing or not on this thread.
 void startProfiling()
           
 void stopProfiling()
           
 void trace(RubyEvent event, java.lang.String name, RubyModule implClass)
           
 void trace(RubyEvent event, java.lang.String name, RubyModule implClass, java.lang.String file, int line)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

runtime

public final Ruby runtime

nil

public final IRubyObject nil

runtimeCache

public final RuntimeCache runtimeCache

callNumber

public int callNumber
Method Detail

newContext

public static ThreadContext newContext(Ruby runtime)

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getRuntime

public final Ruby getRuntime()

getErrorInfo

public IRubyObject getErrorInfo()

setErrorInfo

public IRubyObject setErrorInfo(IRubyObject errorInfo)

returnJump

public JumpException.ReturnJump returnJump(IRubyObject value)

setLastCallStatus

public void setLastCallStatus(CallType callType)
Returns the lastCallStatus.


getLastCallType

public CallType getLastCallType()

setLastVisibility

public void setLastVisibility(Visibility visibility)

getLastVisibility

public Visibility getLastVisibility()

setLastCallStatusAndVisibility

public void setLastCallStatusAndVisibility(CallType callType,
                                           Visibility visibility)

getLastExitStatus

public IRubyObject getLastExitStatus()

setLastExitStatus

public void setLastExitStatus(IRubyObject lastExitStatus)

printScope

public void printScope()

getCurrentScope

public DynamicScope getCurrentScope()

getPreviousScope

public DynamicScope getPreviousScope()

pushScope

public void pushScope(DynamicScope scope)

popScope

public void popScope()

getThread

public RubyThread getThread()

setThread

public void setThread(RubyThread thread)

getFiber

public FiberLibrary.Fiber getFiber()

setFiber

public void setFiber(FiberLibrary.Fiber fiber)

pushCatch

public void pushCatch(RubyContinuation.Continuation catchTarget)

popCatch

public void popCatch()

getActiveCatch

public RubyContinuation.Continuation getActiveCatch(java.lang.Object tag)
Find the active Continuation for the given tag. Must be called with an interned string.

Parameters:
tag - The interned string to search for
Returns:
The continuation associated with this tag

pushFrame

public void pushFrame()

popFrame

public void popFrame()

getCurrentFrame

public Frame getCurrentFrame()

getRubyFrameDelta

public int getRubyFrameDelta()

setRubyFrameDelta

public void setRubyFrameDelta(int newDelta)

getCurrentRubyFrame

public Frame getCurrentRubyFrame()

getNextFrame

public Frame getNextFrame()

getPreviousFrame

public Frame getPreviousFrame()

getFrameCount

public int getFrameCount()

getFrames

public Frame[] getFrames(int delta)

pushBacktrace

public static void pushBacktrace(ThreadContext context,
                                 java.lang.String klass,
                                 java.lang.String method,
                                 ISourcePosition position)

pushBacktrace

public static void pushBacktrace(ThreadContext context,
                                 java.lang.String klass,
                                 java.lang.String method,
                                 java.lang.String file,
                                 int line)

popBacktrace

public static void popBacktrace(ThreadContext context)

isJumpTargetAlive

public boolean isJumpTargetAlive(int target,
                                 int skipFrames)
Search the frame stack for the given JumpTarget. Return true if it is found and false otherwise. Skip the given number of frames before beginning the search.

Parameters:
target - The JumpTarget to search for
skipFrames - The number of frames to skip before searching
Returns:

getFrameName

public java.lang.String getFrameName()

getFrameSelf

public IRubyObject getFrameSelf()

getFrameJumpTarget

public int getFrameJumpTarget()

getFrameKlazz

public RubyModule getFrameKlazz()

getFrameBlock

public Block getFrameBlock()

getFile

public java.lang.String getFile()

getLine

public int getLine()

setFile

public void setFile(java.lang.String file)

setLine

public void setLine(int line)

setFileAndLine

public void setFileAndLine(java.lang.String file,
                           int line)

setFileAndLine

public void setFileAndLine(ISourcePosition position)

getCurrentVisibility

public Visibility getCurrentVisibility()

getPreviousVisibility

public Visibility getPreviousVisibility()

setCurrentVisibility

public void setCurrentVisibility(Visibility visibility)

pollThreadEvents

public void pollThreadEvents()

getCurrentTarget

public int getCurrentTarget()

callThreadPoll

public void callThreadPoll()

callThreadPoll

public static void callThreadPoll(ThreadContext context)

trace

public void trace(RubyEvent event,
                  java.lang.String name,
                  RubyModule implClass)

trace

public void trace(RubyEvent event,
                  java.lang.String name,
                  RubyModule implClass,
                  java.lang.String file,
                  int line)

pushRubyClass

public void pushRubyClass(RubyModule currentModule)

popRubyClass

public RubyModule popRubyClass()

getRubyClass

public RubyModule getRubyClass()

getPreviousRubyClass

public RubyModule getPreviousRubyClass()

getConstantDefined

public boolean getConstantDefined(java.lang.String internedName)

getConstant

public IRubyObject getConstant(java.lang.String internedName)
Used by the evaluator and the compiler to look up a constant by name


setConstantInCurrent

public IRubyObject setConstantInCurrent(java.lang.String internedName,
                                        IRubyObject result)
Used by the evaluator and the compiler to set a constant by name This is for a null const decl


setConstantInModule

public IRubyObject setConstantInModule(java.lang.String internedName,
                                       IRubyObject target,
                                       IRubyObject result)
Used by the evaluator and the compiler to set a constant by name. This is for a Colon2 const decl


setConstantInObject

public IRubyObject setConstantInObject(java.lang.String internedName,
                                       IRubyObject result)
Used by the evaluator and the compiler to set a constant by name This is for a Colon2 const decl


createCallerBacktrace

public IRubyObject createCallerBacktrace(Ruby runtime,
                                         int level)
Create an Array with backtrace information.

Parameters:
runtime -
level -
nativeException -
Returns:
an Array with the backtrace

gatherCallerBacktrace

public RubyStackTraceElement[] gatherCallerBacktrace(int level)

createBacktrace

public Frame[] createBacktrace(int level,
                               boolean nativeException)
Create an Array with backtrace information.

Parameters:
runtime -
level -
nativeException -
Returns:
an Array with the backtrace

isEventHooksEnabled

public boolean isEventHooksEnabled()

setEventHooksEnabled

public void setEventHooksEnabled(boolean flag)

createBacktrace2

public BacktraceElement[] createBacktrace2(int level,
                                           boolean nativeException)
Create an Array with backtrace information.

Parameters:
runtime -
level -
nativeException -
Returns:
an Array with the backtrace

createRawBacktraceStringFromThrowable

public static java.lang.String createRawBacktraceStringFromThrowable(java.lang.Throwable t)

gatherRawBacktrace

public static RubyStackTraceElement[] gatherRawBacktrace(Ruby runtime,
                                                         java.lang.StackTraceElement[] stackTrace)

preAdoptThread

public void preAdoptThread()

preExtensionLoad

public void preExtensionLoad(IRubyObject self)

postExtensionLoad

public void postExtensionLoad()

preCompiledClass

public void preCompiledClass(RubyModule type,
                             StaticScope staticScope)

preCompiledClassDummyScope

public void preCompiledClassDummyScope(RubyModule type,
                                       StaticScope staticScope)

postCompiledClass

public void postCompiledClass()

preScopeNode

public void preScopeNode(StaticScope staticScope)

postScopeNode

public void postScopeNode()

preClassEval

public void preClassEval(StaticScope staticScope,
                         RubyModule type)

postClassEval

public void postClassEval()

preBsfApply

public void preBsfApply(java.lang.String[] names)

postBsfApply

public void postBsfApply()

preMethodFrameAndScope

public void preMethodFrameAndScope(RubyModule clazz,
                                   java.lang.String name,
                                   IRubyObject self,
                                   Block block,
                                   StaticScope staticScope)

preMethodFrameAndDummyScope

public void preMethodFrameAndDummyScope(RubyModule clazz,
                                        java.lang.String name,
                                        IRubyObject self,
                                        Block block,
                                        StaticScope staticScope)

preMethodNoFrameAndDummyScope

public void preMethodNoFrameAndDummyScope(RubyModule clazz,
                                          StaticScope staticScope)

postMethodFrameAndScope

public void postMethodFrameAndScope()

preMethodFrameOnly

public void preMethodFrameOnly(RubyModule clazz,
                               java.lang.String name,
                               IRubyObject self,
                               Block block)

postMethodFrameOnly

public void postMethodFrameOnly()

preMethodScopeOnly

public void preMethodScopeOnly(RubyModule clazz,
                               StaticScope staticScope)

postMethodScopeOnly

public void postMethodScopeOnly()

preMethodBacktraceAndScope

public void preMethodBacktraceAndScope(java.lang.String name,
                                       RubyModule clazz,
                                       StaticScope staticScope)

postMethodBacktraceAndScope

public void postMethodBacktraceAndScope()

preMethodBacktraceOnly

public void preMethodBacktraceOnly(java.lang.String name)

preMethodBacktraceDummyScope

public void preMethodBacktraceDummyScope(RubyModule clazz,
                                         java.lang.String name,
                                         StaticScope staticScope)

postMethodBacktraceOnly

public void postMethodBacktraceOnly()

postMethodBacktraceDummyScope

public void postMethodBacktraceDummyScope()

prepareTopLevel

public void prepareTopLevel(RubyClass objectClass,
                            IRubyObject topSelf)

preNodeEval

public void preNodeEval(RubyModule rubyClass,
                        IRubyObject self,
                        java.lang.String name)

preNodeEval

public void preNodeEval(RubyModule rubyClass,
                        IRubyObject self)

postNodeEval

public void postNodeEval()

preExecuteUnder

public void preExecuteUnder(RubyModule executeUnderClass,
                            Block block)

postExecuteUnder

public void postExecuteUnder()

preMproc

public void preMproc()

postMproc

public void postMproc()

preRunThread

public void preRunThread(Frame[] currentFrames)

preTrace

public void preTrace()

postTrace

public void postTrace()

preForBlock

public Frame preForBlock(Binding binding,
                         RubyModule klass)

preYieldSpecificBlock

public Frame preYieldSpecificBlock(Binding binding,
                                   StaticScope scope,
                                   RubyModule klass)

preYieldLightBlock

public Frame preYieldLightBlock(Binding binding,
                                DynamicScope emptyScope,
                                RubyModule klass)

preYieldNoScope

public Frame preYieldNoScope(Binding binding,
                             RubyModule klass)

preEvalScriptlet

public void preEvalScriptlet(DynamicScope scope)

postEvalScriptlet

public void postEvalScriptlet()

preEvalWithBinding

public Frame preEvalWithBinding(Binding binding)

postEvalWithBinding

public void postEvalWithBinding(Binding binding,
                                Frame lastFrame)

postYield

public void postYield(Binding binding,
                      Frame lastFrame)

postYieldLight

public void postYieldLight(Binding binding,
                           Frame lastFrame)

postYieldNoScope

public void postYieldNoScope(Frame lastFrame)

preScopedBody

public void preScopedBody(DynamicScope scope)

postScopedBody

public void postScopedBody()

isWithinTrace

public boolean isWithinTrace()
Is this thread actively tracing at this moment.

Returns:
true if so
See Also:
org.jruby.Ruby#callTraceFunction(String, ISourcePosition, IRubyObject, String, IRubyObject)

setWithinTrace

public void setWithinTrace(boolean isWithinTrace)
Set whether we are actively tracing or not on this thread.

Parameters:
isWithinTrace - true is so
See Also:
org.jruby.Ruby#callTraceFunction(String, ISourcePosition, IRubyObject, String, IRubyObject)

isWithinDefined

public boolean isWithinDefined()
Is this thread actively in defined? at the moment.

Returns:
true if within defined?

setWithinDefined

public void setWithinDefined(boolean isWithinDefined)
Set whether we are actively within defined? or not.

Parameters:
isWithinDefined - true if so

currentBinding

public Binding currentBinding()
Return a binding representing the current call's state

Returns:
the current binding

currentBinding

public Binding currentBinding(IRubyObject self)
Return a binding representing the current call's state but with a specified self

Parameters:
self - the self object to use
Returns:
the current binding, using the specified self

currentBinding

public Binding currentBinding(IRubyObject self,
                              Visibility visibility)
Return a binding representing the current call's state but with the specified visibility and self.

Parameters:
self - the self object to use
visibility - the visibility to use
Returns:
the current binding using the specified self and visibility

currentBinding

public Binding currentBinding(IRubyObject self,
                              DynamicScope scope)
Return a binding representing the current call's state but with the specified scope and self.

Parameters:
self - the self object to use
visibility - the scope to use
Returns:
the current binding using the specified self and scope

currentBinding

public Binding currentBinding(IRubyObject self,
                              Visibility visibility,
                              DynamicScope scope)
Return a binding representing the current call's state but with the specified visibility, scope, and self. For shared-scope binding consumers like for loops.

Parameters:
self - the self object to use
visibility - the visibility to use
scope - the scope to use
Returns:
the current binding using the specified self, scope, and visibility

previousBinding

public Binding previousBinding()
Return a binding representing the previous call's state

Returns:
the current binding

previousBinding

public Binding previousBinding(IRubyObject self)
Return a binding representing the previous call's state but with a specified self

Parameters:
self - the self object to use
Returns:
the current binding, using the specified self

getProfileData

public IProfileData getProfileData()
Get the profile data for this thread (ThreadContext).

Returns:
the thread's profile data

profileEnter

public int profileEnter(int nextMethod)

profileExit

public int profileExit(int nextMethod,
                       long startTime)

startProfiling

public void startProfiling()

stopProfiling

public void stopProfiling()

isProfiling

public boolean isProfiling()


Copyright © 2002-2009 JRuby Team. All Rights Reserved.