Package org.jruby.runtime
Class ThreadContext
java.lang.Object
org.jruby.runtime.ThreadContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BacktraceElement[]private intprivate static final intThe number of calls after which to do a thread event pollintprivate intprivate CatchThrow[]private intprivate RubyDateFormatterprivate static final CatchThrow[]private org.jcodings.Encoding[]private booleanbooleanfinal RubyBooleanprivate WeakReference<ThreadFiber>private intprivate Frame[]private static final intprivate static final intprivate booleanprivate boolean(package private) CallType(package private) IRubyObject(package private) Visibilityprivate static final Loggerprivate RubyMatchDatafinal IRubyObjectprivate static final WeakReference<ThreadFiber>private RubyModuleprivate ProfileCollectionprivate Set<RecursiveComparator.Pair>private ThreadFiberfinal Rubyfinal RuntimeCacheprivate Throwableprivate intprivate DynamicScope[]Deprecated.final JavaSitesprivate Map<String,Map<IRubyObject, IRubyObject>> private RubyThreadprivate Ruby.CallTraceFuncHookfinal RubyBooleanprivate static booleanprivate static booleanstatic final com.headius.backport9.stack.StackWalkerstatic final com.headius.backport9.stack.StackWalker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddThreadTraceFunction(IRubyObject trace_func, boolean useContextHook) voidPoll for thread events that should be fired before a blocking call.voidstatic voidcallThreadPoll(ThreadContext context) Set the $~ (backref) "global" to nil.voidSet the thread-local MatchData specific to this context to null.createCallerBacktrace(int level, int length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) Create an Array with backtrace information for Kernel#callercreateCallerLocations(int level, Integer length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) Create an array containing Thread::Backtrace::Location objects for the requested caller trace level and length.static StringcreateRawBacktraceStringFromThrowable(Throwable ex, boolean color) Return a binding representing the current call's statecurrentBinding(IRubyObject self) Return a binding representing the current call's state but with a specified selfcurrentBinding(IRubyObject self, DynamicScope scope) Return a binding representing the current call's state but with the specified scope and self.currentBinding(IRubyObject self, Visibility visibility) Return a binding representing the current call's state but with the specified visibility and self.currentBinding(IRubyObject self, Visibility visibility, DynamicScope scope) Return a binding representing the current call's state but with the specified visibility, scope, and self.org.jcodings.Encoding[]voidvoidprivate static voidexpandBacktraceStack(ThreadContext context) private voidprivate voidprivate voidprivate static BacktraceElement[]fillNewBacktrace(ThreadContext context, BacktraceElement[] newBacktrace, int newSize) private Frame[]fillNewFrameStack(Frame[] newFrameStack, int newSize) protected voidfinalize()getActiveCatch(Object tag) Find the active Continuation for the given tag.Get the value of the $~ (backref) "global".Create a snapshot Array with current backtrace information.final Stream<BacktraceElement>getBacktrace(int level) getConstant(String internedName) Deprecated.intgetFiber()getFile()private RubyStackTraceElement[]getFullTrace(Integer length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) Get the value of the $_ (lastline) "global".intgetLine()Get the thread-local MatchData specific to this context.Get the thread-local MatchData specific to this context or nil if none.private RubyStackTraceElement[]getPartialTrace(int level, Integer length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) Get the profile collection for this thread (ThreadContext).final RubyRetrieve the runtime associated with this context.Same as calling getSingleBacktrace(0);getSingleBacktrace(int level) Return a single RubyStackTraceElement representing the nearest Ruby stack trace element.booleanbooleanbooleanbooleanIs this thread actively tracing at this moment.MRI: rb_reg_last_matchMRI: rb_reg_match_lastMRI: rb_reg_match_postMRI: rb_reg_match_prestatic ThreadContextnewContext(Ruby runtime) voidprivate voidstatic voidpopBacktrace(ThreadContext context) voidpopCatch()voidpopFrame()private voidpopFrameReal(Frame oldFrame) voidpopScope()voidvoidvoidpostEvalWithBinding(Binding binding, Frame lastFrame) voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidpostYieldNoScope(Frame lastFrame) voidvoidvoidpreEvalScriptlet(DynamicScope scope) preEvalWithBinding(Binding binding) voidpreExecuteUnder(IRubyObject executeUnderObj, RubyModule executeUnderClass, Block block) voidpreExtensionLoad(IRubyObject self) voidpreMethodBacktraceAndScope(String name, StaticScope staticScope) voidpreMethodBacktraceDummyScope(String name, StaticScope staticScope) voidpreMethodBacktraceOnly(String name) voidpreMethodFrameAndDummyScope(RubyModule clazz, String name, IRubyObject self, Block block, StaticScope staticScope) voidpreMethodFrameAndScope(RubyModule clazz, String name, IRubyObject self, Block block, StaticScope staticScope) voidpreMethodFrameOnly(RubyModule clazz, String name, IRubyObject self) voidpreMethodFrameOnly(RubyModule clazz, String name, IRubyObject self, Block block) voidpreMethodFrameOnly(RubyModule clazz, String name, IRubyObject self, Visibility visiblity, Block block) voidpreMethodNoFrameAndDummyScope(StaticScope staticScope) voidpreMethodScopeOnly(StaticScope staticScope) voidpreNodeEval(IRubyObject self) voidprepareTopLevel(RubyClass objectClass, IRubyObject topSelf) voidpreScopedBody(DynamicScope scope) voidpreTrace()preYieldNoScope(Binding binding) preYieldNoScope(Block block) preYieldSpecificBlock(Binding binding, StaticScope scope) voidintprofileEnter(int nextMethod) intprofileEnter(String name, DynamicMethod nextMethod) intprofileExit(int nextMethod, long startTime) private voidstatic voidpushBacktrace(ThreadContext context, String method, String file, int line) private voidpushCallFrame(RubyModule clazz, String name, IRubyObject self, Block block) private voidpushCallFrame(RubyModule clazz, String name, IRubyObject self, Visibility visibility, Block block) voidpushCatch(CatchThrow catchTarget) voidpushCatch(RubyContinuation.Continuation catchTarget) Deprecated.private voidpushEvalFrame(IRubyObject self) voidpushEvalSimpleFrame(IRubyObject executeObject) voidprivate Frameprivate FramepushFrameForBlock(Binding binding) pushNewScope(StaticScope staticScope) voidpushScope(DynamicScope scope) voidRender the current backtrace as a string to the given StringBuilder.private static intsafeLength(int level, Integer length, RubyStackTraceElement[] trace) <T> IRubyObjectsafeRecurse(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, String name, boolean outer) private Map<IRubyObject,IRubyObject> safeRecurseGetGuards(String name) private <T> IRubyObjectsafeRecurseInner(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, Map<IRubyObject, IRubyObject> guards) private <T> IRubyObjectsafeRecurseOutermost(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, Map<IRubyObject, IRubyObject> guards) booleanCheck if a scope is present on the call stack.setBackRef(RubyMatchData match) Set the $~ (backref) "global" to the given RubyMatchData value.setBackRef(IRubyObject match) Deprecated.voidsetCurrentVisibility(Visibility visibility) setErrorInfo(IRubyObject errorInfo) voidsetEventHooksEnabled(boolean flag) voidsetExceptionRequiresBacktrace(boolean exceptionRequiresBacktrace) voidsetFiber(ThreadFiber fiber) voidsetFileAndLine(String file, int line) voidsetLastCallStatusAndVisibility(CallType callType, Visibility visibility) voidsetLastExitStatus(IRubyObject lastExitStatus) setLastLine(IRubyObject last) Set the $_ (lastlne) "global" to the given value.voidsetLine(int line) voidsetLocalMatch(RubyMatchData localMatch) Set the thread-local MatchData specific to this context.voidsetPrivateConstantReference(RubyModule privateConstantReference) voidsetRecursiveSet(Set<RecursiveComparator.Pair> recursiveSet) voidsetRootFiber(ThreadFiber rootFiber) voidvoidsetThread(RubyThread thread) setThreadTraceFunction(IRubyObject trace_func) voidsetWithinTrace(boolean isWithinTrace) Set whether we are actively tracing or not on this thread.voidvoidvoidtrace(RubyEvent event, String name, RubyModule implClass) voidtrace(RubyEvent event, String name, RubyModule implClass, String file, int line) Update the current frame's backref using the current thread-local match, or clear it if that match is null.voiduseRecursionGuardsFrom(ThreadContext context) Fibers must use the same recursion guards as their parent thread.
-
Field Details
-
LOG
-
INITIAL_SIZE
private static final int INITIAL_SIZE- See Also:
-
INITIAL_FRAMES_SIZE
private static final int INITIAL_FRAMES_SIZE- See Also:
-
CALL_POLL_COUNT
private static final int CALL_POLL_COUNTThe number of calls after which to do a thread event poll- See Also:
-
runtime
-
nil
-
tru
-
fals
-
runtimeCache
-
traceFuncHook
-
isWithinTrace
private boolean isWithinTrace -
thread
-
NULL_FIBER_REF
-
fiber
-
rootFiber
-
dateFormatter
-
frameStack
-
frameIndex
private int frameIndex -
backtrace
-
backtraceIndex
private int backtraceIndex -
scopeStack
-
scopeIndex
private int scopeIndex -
EMPTY_CATCHTARGET_STACK
-
catchStack
-
catchIndex
private int catchIndex -
isProfiling
private boolean isProfiling -
profileCollection
-
eventHooksEnabled
private boolean eventHooksEnabled -
lastCallType
CallType lastCallType -
lastVisibility
Visibility lastVisibility -
lastExitStatus
IRubyObject lastExitStatus -
savedExcInLambda
-
secureRandom
Deprecated.This fields is no longer initialized, is null by default! UsegetSecureRandom()instead. -
tryPreferredPRNG
private static boolean tryPreferredPRNG -
trySHA1PRNG
private static boolean trySHA1PRNG -
privateConstantReference
-
sites
-
matchData
-
encodingHolder
private org.jcodings.Encoding[] encodingHolder -
callNumber
public int callNumber -
WALKER
public static final com.headius.backport9.stack.StackWalker WALKER -
WALKER8
public static final com.headius.backport9.stack.StackWalker WALKER8 -
currentMethodSerial
private int currentMethodSerial -
symToGuards
-
recursiveSet
-
exceptionRequiresBacktrace
public boolean exceptionRequiresBacktrace
-
-
Constructor Details
-
ThreadContext
Constructor for Context.
-
-
Method Details
-
newContext
-
getSecureRandom
-
finalize
-
getRuntime
Retrieve the runtime associated with this context. Note that there's no reason to call this method rather than accessing the runtime field directly.- Returns:
- the runtime associated with this context
- See Also:
-
getErrorInfo
-
setErrorInfo
-
getSavedExceptionInLambda
-
setSavedExceptionInLambda
-
getLastCallType
-
getLastVisibility
-
setLastCallStatusAndVisibility
-
getLastExitStatus
-
setLastExitStatus
-
printScope
public void printScope() -
getCurrentScope
-
getCurrentStaticScope
-
expandFrameStack
private void expandFrameStack() -
fillNewFrameStack
-
pushScope
-
pushNewScope
-
popScope
public void popScope() -
expandScopeStack
private void expandScopeStack() -
getThread
-
getFiberCurrentThread
-
getRubyDateFormatter
-
setThread
-
getFiber
-
setFiber
-
useRecursionGuardsFrom
Fibers must use the same recursion guards as their parent thread. -
setRootFiber
-
expandCatchStack
private void expandCatchStack() -
pushCatch
Deprecated. -
pushCatch
-
popCatch
public void popCatch() -
getActiveCatch
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
-
pushEvalSimpleFrame
-
pushCallFrame
-
pushCallFrame
private void pushCallFrame(RubyModule clazz, String name, IRubyObject self, Visibility visibility, Block block) -
pushBackrefFrame
private void pushBackrefFrame() -
popBackrefFrame
private void popBackrefFrame() -
pushEvalFrame
-
pushFrame
public void pushFrame() -
popFrame
public void popFrame() -
popFrameReal
-
getCurrentFrame
-
getNextFrame
-
getPreviousFrame
-
clearBackRef
Set the $~ (backref) "global" to nil.- Returns:
- nil
-
updateBackref
Update the current frame's backref using the current thread-local match, or clear it if that match is null.- Returns:
- The current match, or nil
-
setBackRef
Set the $~ (backref) "global" to the given RubyMatchData value. The value will be marked as "in use" since it can now be seen across threads that share the current frame.- Parameters:
match- the value to set- Returns:
- the value passed in
-
getBackRef
Get the value of the $~ (backref) "global".- Returns:
- the value of $~
-
last_match
MRI: rb_reg_last_match -
match_pre
MRI: rb_reg_match_pre -
match_post
MRI: rb_reg_match_post -
match_last
MRI: rb_reg_match_last -
setLastLine
Set the $_ (lastlne) "global" to the given value.- Parameters:
last- the value to set- Returns:
- the value passed in
-
getLastLine
Get the value of the $_ (lastline) "global".- Returns:
- the value of $_
-
expandBacktraceStack
-
fillNewBacktrace
private static BacktraceElement[] fillNewBacktrace(ThreadContext context, BacktraceElement[] newBacktrace, int newSize) -
pushBacktrace
-
popBacktrace
-
hasAnyScopes
public boolean hasAnyScopes() -
scopeExistsOnCallStack
Check if a scope is present on the call stack. This is the IR equivalent of isJumpTargetAlive- Parameters:
scope- the scope to look for- Returns:
- true if it exists. otherwise false.
-
getFrameName
-
getFrameSelf
-
getFrameKlazz
-
getFrameBlock
-
getFile
-
getLine
public int getLine() -
setLine
public void setLine(int line) -
setFileAndLine
-
getCurrentVisibility
-
setCurrentVisibility
-
pollThreadEvents
public void pollThreadEvents() -
getCurrentTarget
public int getCurrentTarget() -
callThreadPoll
public void callThreadPoll() -
blockingThreadPoll
public void blockingThreadPoll()Poll for thread events that should be fired before a blocking call. See vm_check_ints_blocking and RUBY_VM_CHECK_INTS_BLOCKING in CRuby. -
callThreadPoll
-
trace
-
trace
-
getConstant
Deprecated.Used by the evaluator and the compiler to look up a constant by name -
renderCurrentBacktrace
Render the current backtrace as a string to the given StringBuilder. This will honor the currently-configured backtrace format and content.- Parameters:
sb- the StringBuilder to which to render the backtrace
-
createCallerBacktrace
public IRubyObject createCallerBacktrace(int level, int length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) Create an Array with backtrace information for Kernel#caller- Parameters:
level-length-- Returns:
- an Array with the backtrace
-
createCallerLocations
public IRubyObject createCallerLocations(int level, Integer length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) Create an array containing Thread::Backtrace::Location objects for the requested caller trace level and length.- Parameters:
level- the level at which the trace should startlength- the length of the trace- Returns:
- an Array with the backtrace locations
-
getFullTrace
private RubyStackTraceElement[] getFullTrace(Integer length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) -
getPartialTrace
private RubyStackTraceElement[] getPartialTrace(int level, Integer length, Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream) -
safeLength
-
getSingleBacktrace
Return a single RubyStackTraceElement representing the nearest Ruby stack trace element. Used for warnings and Kernel#__dir__.- Returns:
- the nearest stack trace element
-
getSingleBacktrace
Same as calling getSingleBacktrace(0);- See Also:
-
isEventHooksEnabled
public boolean isEventHooksEnabled() -
setEventHooksEnabled
public void setEventHooksEnabled(boolean flag) -
getBacktrace
Create a snapshot Array with current backtrace information.- Returns:
- the backtrace
-
getBacktrace
-
createRawBacktraceStringFromThrowable
-
pushFrameForBlock
-
preAdoptThread
public void preAdoptThread() -
preExtensionLoad
-
preMethodFrameAndScope
public void preMethodFrameAndScope(RubyModule clazz, String name, IRubyObject self, Block block, StaticScope staticScope) -
preMethodFrameAndDummyScope
public void preMethodFrameAndDummyScope(RubyModule clazz, String name, IRubyObject self, Block block, StaticScope staticScope) -
preMethodNoFrameAndDummyScope
-
postMethodFrameAndScope
public void postMethodFrameAndScope() -
preMethodFrameOnly
-
preMethodFrameOnly
public void preMethodFrameOnly(RubyModule clazz, String name, IRubyObject self, Visibility visiblity, Block block) -
preMethodFrameOnly
-
preBackrefMethod
public void preBackrefMethod() -
postMethodFrameOnly
public void postMethodFrameOnly() -
postBackrefMethod
public void postBackrefMethod() -
preMethodScopeOnly
-
postMethodScopeOnly
public void postMethodScopeOnly() -
preMethodBacktraceAndScope
-
postMethodBacktraceAndScope
public void postMethodBacktraceAndScope() -
preMethodBacktraceOnly
-
preMethodBacktraceDummyScope
-
postMethodBacktraceOnly
public void postMethodBacktraceOnly() -
postMethodBacktraceDummyScope
public void postMethodBacktraceDummyScope() -
prepareTopLevel
-
preNodeEval
-
postNodeEval
public void postNodeEval() -
preExecuteUnder
-
postExecuteUnder
public void postExecuteUnder() -
preTrace
public void preTrace() -
postTrace
public void postTrace() -
preYieldSpecificBlock
-
preYieldNoScope
-
preYieldNoScope
-
preEvalScriptlet
-
postEvalScriptlet
public void postEvalScriptlet() -
preEvalWithBinding
-
postEvalWithBinding
-
postYield
-
postYieldNoScope
-
preScopedBody
-
postScopedBody
public void postScopedBody() -
isWithinTrace
public boolean isWithinTrace()Is this thread actively tracing at this moment.- Returns:
- true if so
- See Also:
-
setWithinTrace
public void setWithinTrace(boolean isWithinTrace) Set whether we are actively tracing or not on this thread.- Parameters:
isWithinTrace- true is so- See Also:
-
currentBinding
Return a binding representing the current call's state- Returns:
- the current binding
-
currentBinding
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
Return a binding representing the current call's state but with the specified visibility and self.- Parameters:
self- the self object to usevisibility- the visibility to use- Returns:
- the current binding using the specified self and visibility
-
currentBinding
Return a binding representing the current call's state but with the specified scope and self.- Parameters:
self- the self object to usescope- the scope to use- Returns:
- the current binding using the specified self and scope
-
currentBinding
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 usevisibility- the visibility to usescope- the scope to use- Returns:
- the current binding using the specified self, scope, and visibility
-
getProfileCollection
Get the profile collection for this thread (ThreadContext).- Returns:
- the thread's profile collection
-
startProfiling
public void startProfiling() -
stopProfiling
public void stopProfiling() -
isProfiling
public boolean isProfiling() -
profileEnter
public int profileEnter(int nextMethod) -
profileEnter
-
profileExit
public int profileExit(int nextMethod, long startTime) -
getRecursiveSet
-
setRecursiveSet
-
setExceptionRequiresBacktrace
public void setExceptionRequiresBacktrace(boolean exceptionRequiresBacktrace) -
exceptionBacktraceOn
public void exceptionBacktraceOn() -
exceptionBacktraceOff
public void exceptionBacktraceOff() -
clearThreadTraceFunctions
-
addThreadTraceFunction
-
setThreadTraceFunction
-
setPrivateConstantReference
-
getPrivateConstantReference
-
safeRecurse
public <T> IRubyObject safeRecurse(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, String name, boolean outer) -
safeRecurseOutermost
private <T> IRubyObject safeRecurseOutermost(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, Map<IRubyObject, IRubyObject> guards) -
safeRecurseGetGuards
-
safeRecurseInner
private <T> IRubyObject safeRecurseInner(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, Map<IRubyObject, IRubyObject> guards) -
encodingHolder
public org.jcodings.Encoding[] encodingHolder() -
setLocalMatch
Set the thread-local MatchData specific to this context. This is different from the frame backref since frames may be shared by several executing contexts at once (see jruby/jruby#4868).- Parameters:
localMatch- the new thread-local MatchData or null
-
clearLocalMatch
public void clearLocalMatch()Set the thread-local MatchData specific to this context to null.- See Also:
-
getLocalMatch
Get the thread-local MatchData specific to this context. This is different from the frame backref since frames may be shared by several executing contexts at once (see jruby/jruby#4868).- Returns:
- the current thread-local MatchData, or null if none
-
getLocalMatchOrNil
Get the thread-local MatchData specific to this context or nil if none.- Returns:
- the current thread-local MatchData, or nil if none
- See Also:
-
setBackRef
Deprecated.
-