Package org.jruby.runtime
Class ThreadContext
java.lang.Object
org.jruby.runtime.ThreadContext
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intintintbooleanfinal RubyBooleanfinal IRubyObjectfinal Rubyfinal RuntimeCacheDeprecated.final JavaSitesfinal TraceEventManagerfinal RubyBooleanstatic final com.headius.backport9.stack.StackWalkerstatic final com.headius.backport9.stack.StackWalker -
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.voidDeprecated.use the trivially-inlinable static versionstatic voidclearCallInfo(ThreadContext context) Clear call info state (set to 0).voidvoidSet 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.voideachCallerLocation(Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream, Consumer<RubyThread.Location> consumer) LikecreateCallerLocations(int, Integer, Stream)but accepts a lambda to yield each location and yields all stack elements until the loop ends or is broken early.org.jcodings.Encoding[]voidvoidprotected 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) The name under which the current method was called, if called via an alias.A string representing the name of the current method and the name under which it was called.getConstant(String internedName) Deprecated.intgetFiber()getFile()The currently-running method's original name, used for stack traces, super calls, and __method__, and trace hooks.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.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.getSingleBacktraceExact(int level) Return the trace of level or null.booleanstatic booleanhasKeywords(int callInfo) booleanbooleanbooleanIs 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) voidstatic voidpopBacktrace(ThreadContext context) voidpopCatch()voidpopFrame()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) static voidpushBacktrace(ThreadContext context, String method, String file, int line) voidpushCatch(CatchThrow catchTarget) voidpushCatch(RubyContinuation.Continuation catchTarget) Deprecated.voidpushEvalSimpleFrame(IRubyObject executeObject) voidpushNewScope(StaticScope staticScope) voidpushScope(DynamicScope scope) voidRender the current backtrace as a string to the given StringBuilder.intDeprecated.use the trivially-inlinable static versionstatic intresetCallInfo(ThreadContext context) Reset call info state and return the value of call info right before it is reset.<T> IRubyObjectsafeRecurse(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, String name, boolean outer) 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
-
runtime
-
nil
-
tru
-
fals
-
runtimeCache
-
traceEvents
-
CALL_SPLATS
public static final int CALL_SPLATS- See Also:
-
CALL_KEYWORD
public static final int CALL_KEYWORD- See Also:
-
CALL_KEYWORD_REST
public static final int CALL_KEYWORD_REST- See Also:
-
CALL_KEYWORD_EMPTY
public static final int CALL_KEYWORD_EMPTY- See Also:
-
callInfo
public int callInfo -
secureRandom
Deprecated.UsegetSecureRandom()instead.This fields is no longer initialized, is null by default! -
sites
-
callNumber
public int callNumber -
WALKER
public static final com.headius.backport9.stack.StackWalker WALKER -
WALKER8
public static final com.headius.backport9.stack.StackWalker WALKER8 -
exceptionRequiresBacktrace
public boolean exceptionRequiresBacktrace
-
-
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
-
clearErrorInfo
public void clearErrorInfo() -
getSavedExceptionInLambda
-
setSavedExceptionInLambda
-
getLastCallType
-
getLastVisibility
-
setLastCallStatusAndVisibility
-
getLastExitStatus
-
setLastExitStatus
-
printScope
public void printScope() -
getCurrentScope
-
getCurrentStaticScope
-
pushScope
-
pushNewScope
-
popScope
public void popScope() -
getThread
-
getFiberCurrentThread
-
getRubyDateFormatter
-
setThread
-
getFiber
-
setFiber
-
useRecursionGuardsFrom
Fibers must use the same recursion guards as their parent thread. -
setRootFiber
-
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
-
pushEvalSimpleFrame
-
pushFrame
public void pushFrame() -
popFrame
public void popFrame() -
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 $_
-
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.
-
getCompositeName
A string representing the name of the current method and the name under which it was called. If not called via an alias, this will be a single string. If called via an alias, it will be encoded as "\0alias\0original" and must be unpacked for its components.- Returns:
- a representation of the current method's name and the name it was called under
- See Also:
-
getFrameName
The currently-running method's original name, used for stack traces, super calls, and __method__, and trace hooks.- Returns:
- the current method's name
-
getCalleeName
The name under which the current method was called, if called via an alias. Used for __callee__.- Returns:
- the name under which the current method was called
-
getFrameSelf
-
getFrameKlazz
-
getFrameBlock
-
getFile
-
getLine
public int getLine() -
setLine
public void setLine(int line) -
setFileAndLine
-
getFileAndLine
-
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
-
eachCallerLocation
public void eachCallerLocation(Stream<com.headius.backport9.stack.StackWalker.StackFrame> stackStream, Consumer<RubyThread.Location> consumer) LikecreateCallerLocations(int, Integer, Stream)but accepts a lambda to yield each location and yields all stack elements until the loop ends or is broken early.- Parameters:
stackStream- the stream of StackFrame objects from JVMconsumer- the consumer of RubyThread.Location objects
-
getSingleBacktrace
Return a single RubyStackTraceElement representing the nearest Ruby stack trace element. Used for warnings and Kernel#__dir__.- Returns:
- the nearest stack trace element
-
getSingleBacktraceExact
Return the trace of level or null. -
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
-
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) -
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:
-
resetCallInfo
Deprecated.use the trivially-inlinable static versionReset call info state and return the value of call info right before it is reset.- Returns:
- the old call info
-
resetCallInfo
Reset call info state and return the value of call info right before it is reset. This method is static to make it trivially inlinable on most JVM JITs- Returns:
- the old call info
-
clearCallInfo
Deprecated.use the trivially-inlinable static versionClear call info state (set to 0). -
clearCallInfo
Clear call info state (set to 0). This method is static to make it trivially inlinable on most JVM JITs -
hasKeywords
public static boolean hasKeywords(int callInfo) -
setBackRef
Deprecated.
-
getSecureRandom()instead.