Package org.jruby.runtime
Class ThreadContext
java.lang.Object
org.jruby.runtime.ThreadContext
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
int
int
boolean
final RubyBoolean
final IRubyObject
final Ruby
final RuntimeCache
Deprecated.final JavaSites
final TraceEventManager
final RubyBoolean
static final com.headius.backport9.stack.StackWalker
static final com.headius.backport9.stack.StackWalker
-
Method Summary
Modifier and TypeMethodDescriptionaddThreadTraceFunction
(IRubyObject trace_func, boolean useContextHook) void
Poll for thread events that should be fired before a blocking call.void
static void
callThreadPoll
(ThreadContext context) Set the $~ (backref) "global" to nil.void
Deprecated.use the trivially-inlinable static versionstatic void
clearCallInfo
(ThreadContext context) Clear call info state (set to 0).void
void
Set 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 String
createRawBacktraceStringFromThrowable
(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.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.org.jcodings.Encoding[]
void
void
protected void
finalize()
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.int
getFiber()
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".int
getLine()
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 Ruby
Retrieve 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.boolean
static boolean
hasKeywords
(int callInfo) boolean
boolean
boolean
Is this thread actively tracing at this moment.MRI: rb_reg_last_matchMRI: rb_reg_match_lastMRI: rb_reg_match_postMRI: rb_reg_match_prestatic ThreadContext
newContext
(Ruby runtime) void
static void
popBacktrace
(ThreadContext context) void
popCatch()
void
popFrame()
void
popScope()
void
void
void
postEvalWithBinding
(Binding binding, Frame lastFrame) void
void
void
void
void
void
void
void
void
void
void
void
postYieldNoScope
(Frame lastFrame) void
void
void
preEvalScriptlet
(DynamicScope scope) preEvalWithBinding
(Binding binding) void
preExecuteUnder
(IRubyObject executeUnderObj, RubyModule executeUnderClass, Block block) void
preExtensionLoad
(IRubyObject self) void
preMethodBacktraceAndScope
(String name, StaticScope staticScope) void
preMethodBacktraceDummyScope
(String name, StaticScope staticScope) void
preMethodBacktraceOnly
(String name) void
preMethodFrameAndDummyScope
(RubyModule clazz, String name, IRubyObject self, Block block, StaticScope staticScope) void
preMethodFrameAndScope
(RubyModule clazz, String name, IRubyObject self, Block block, StaticScope staticScope) void
preMethodFrameOnly
(RubyModule clazz, String name, IRubyObject self) void
preMethodFrameOnly
(RubyModule clazz, String name, IRubyObject self, Block block) void
preMethodFrameOnly
(RubyModule clazz, String name, IRubyObject self, Visibility visiblity, Block block) void
preMethodNoFrameAndDummyScope
(StaticScope staticScope) void
preMethodScopeOnly
(StaticScope staticScope) void
preNodeEval
(IRubyObject self) void
prepareTopLevel
(RubyClass objectClass, IRubyObject topSelf) void
preScopedBody
(DynamicScope scope) void
preTrace()
preYieldNoScope
(Binding binding) preYieldNoScope
(Block block) preYieldSpecificBlock
(Binding binding, StaticScope scope) void
int
profileEnter
(int nextMethod) int
profileEnter
(String name, DynamicMethod nextMethod) int
profileExit
(int nextMethod, long startTime) static void
pushBacktrace
(ThreadContext context, String method, String file, int line) void
pushCatch
(CatchThrow catchTarget) void
pushCatch
(RubyContinuation.Continuation catchTarget) Deprecated.void
pushEvalSimpleFrame
(IRubyObject executeObject) void
pushNewScope
(StaticScope staticScope) void
pushScope
(DynamicScope scope) void
Render the current backtrace as a string to the given StringBuilder.int
Deprecated.use the trivially-inlinable static versionstatic int
resetCallInfo
(ThreadContext context) Reset call info state and return the value of call info right before it is reset.<T> IRubyObject
safeRecurse
(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, String name, boolean outer) boolean
Check 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.void
setCurrentVisibility
(Visibility visibility) setErrorInfo
(IRubyObject errorInfo) void
setEventHooksEnabled
(boolean flag) void
setExceptionRequiresBacktrace
(boolean exceptionRequiresBacktrace) void
setFiber
(ThreadFiber fiber) void
setFileAndLine
(String file, int line) void
setLastCallStatusAndVisibility
(CallType callType, Visibility visibility) void
setLastExitStatus
(IRubyObject lastExitStatus) setLastLine
(IRubyObject last) Set the $_ (lastlne) "global" to the given value.void
setLine
(int line) void
setLocalMatch
(RubyMatchData localMatch) Set the thread-local MatchData specific to this context.void
setPrivateConstantReference
(RubyModule privateConstantReference) void
setRecursiveSet
(Set<RecursiveComparator.Pair> recursiveSet) void
setRootFiber
(ThreadFiber rootFiber) void
void
setThread
(RubyThread thread) setThreadTraceFunction
(IRubyObject trace_func) void
setWithinTrace
(boolean isWithinTrace) Set whether we are actively tracing or not on this thread.void
void
void
trace
(RubyEvent event, String name, RubyModule implClass) void
trace
(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.void
useRecursionGuardsFrom
(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.