Top Inners Fields Constructors Methods
org.jruby.runtime

public final Class ThreadContext

extends Object
Class Inheritance
Imports
com.headius.backport9.stack.StackWalker, com.headius.backport9.stack.impl.StackWalker8, org.jcodings.Encoding, org.jruby.Ruby, .RubyArray, .RubyBoolean, .RubyClass, .RubyContinuation, .RubyMatchData, .RubyProc, .RubyInstanceConfig, .RubyModule, .RubyRegexp, .RubyThread, org.jruby.exceptions.CatchThrow, .Unrescuable, org.jruby.ast.executable.RuntimeCache, org.jruby.ext.fiber.ThreadFiber, org.jruby.internal.runtime.methods.DynamicMethod, org.jruby.ir.JIT, org.jruby.parser.StaticScope, org.jruby.runtime.backtrace.BacktraceData, .BacktraceElement, .RubyStackTraceElement, .TraceType, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.profile.ProfileCollection, org.jruby.runtime.scope.ManyVarsDynamicScope, org.jruby.util.RecursiveComparator, .RubyDateFormatter, org.jruby.util.cli.Options, org.jruby.util.log.Logger, .LoggerFactory, java.lang.ref.WeakReference, java.security.SecureRandom, java.util.HashMap, .IdentityHashMap, .Map, .Set, java.util.function.Consumer, java.util.stream.IntStream, .Stream

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static interface

Field Summary

Modifier and TypeField and Description
private BacktraceElement[]
private int
public static final int
public static final int
public static final int
private static final int
CALL_POLL_COUNT

The number of calls after which to do a thread event poll

public static final int
public int
public int
private int
private CatchThrow[]
private int
private RubyDateFormatter
private static final CatchThrow[]
private Encoding[]
private boolean
public boolean
public final RubyBoolean
private WeakReference<ThreadFiber>
private int
private Frame[]
private static final int
private static final int
private boolean
private boolean
pack-priv CallType
pack-priv IRubyObject
pack-priv Visibility
private static final Logger
private RubyMatchData
public final IRubyObject
private static final WeakReference<ThreadFiber>
private RubyModule
private ProfileCollection
private Set<RecursiveComparator.Pair>
private ThreadFiber
public final Ruby
public final RuntimeCache
private Throwable
private int
private DynamicScope[]
public transient SecureRandom
secureRandom

Deprecated Use getSecureRandom() instead.
This fields is no longer initialized, is null by default!
public final JavaSites
private Map<String, IdentityHashMap<IRubyObject, IRubyObject>>
private RubyThread
public final TraceEventManager
private TraceEventManager.CallTraceFuncHook
public final RubyBoolean
private static boolean
private static boolean
public static final StackWalker
public static final StackWalker

Constructor Summary

AccessConstructor and Description
private
ThreadContext(Ruby runtime)

Constructor for Context.

Method Summary

Modifier and TypeMethod and Description
public IRubyObject
addThreadTraceFunction(IRubyObject trace_func, boolean useContextHook)

public void
blockingThreadPoll()

Poll for thread events that should be fired before a blocking call.

public void
public static void
public IRubyObject

Returns:

nil
clearBackRef
()

Set the $~ (backref) "global" to nil.

public void
clearCallInfo()
Deprecated use the trivially-inlinable static version

Clear call info state (set to 0).

public static void
clearCallInfo(ThreadContext context)

Clear call info state (set to 0).

public void
public void
clearLocalMatch()

Set the thread-local MatchData specific to this context to null.

public IRubyObject
public IRubyObject

Returns:

an Array with the backtrace
createCallerBacktrace
(int level, int length, Stream<StackWalker.StackFrame> stackStream)

Create an Array with backtrace information for Kernel#caller

public IRubyObject

Returns:

an Array with the backtrace locations
createCallerLocations
(int
the level at which the trace should start
level
,
Integer
the length of the trace
length
,
Stream<StackWalker.StackFrame> stackStream)

Create an array containing Thread::Backtrace::Location objects for the requested caller trace level and length.

public static String
createRawBacktraceStringFromThrowable(final Throwable ex, final boolean color)

public Binding

Returns:

the current binding
currentBinding
()

Return a binding representing the current call's state

public Binding

Returns:

the current binding, using the specified self
currentBinding
(IRubyObject
the self object to use
self
)

Return a binding representing the current call's state but with a specified self

public Binding

Returns:

the current binding using the specified self and visibility
currentBinding
(IRubyObject
the self object to use
self
,
Visibility
the visibility to use
visibility
)

Return a binding representing the current call's state but with the specified visibility and self.

public Binding

Returns:

the current binding using the specified self and scope
currentBinding
(IRubyObject
the self object to use
self
,
DynamicScope
the scope to use
scope
)

Return a binding representing the current call's state but with the specified scope and self.

public Binding

Returns:

the current binding using the specified self, scope, and visibility
currentBinding
(IRubyObject
the self object to use
self
,
Visibility
the visibility to use
visibility
,
DynamicScope
the scope to use
scope
)

Return a binding representing the current call's state but with the specified visibility, scope, and self.

public void
eachCallerLocation(Stream<StackWalker.StackFrame>
the stream of StackFrame objects from JVM
stackStream
,
Consumer<RubyThread.Location>
the consumer of RubyThread.Location objects
consumer
)

Like createCallerLocations(int, Integer, Stream) but accepts a lambda to yield each location and yields all stack elements until the loop ends or is broken early.

private void
public Encoding[]
public void
public void
private static void
private void
private void
private void
private static BacktraceElement[]
fillNewBacktrace(ThreadContext context, BacktraceElement[] newBacktrace, int newSize)

private Frame[]
fillNewFrameStack(Frame[] newFrameStack, int newSize)

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

public CatchThrow

Returns:

The continuation associated with this tag
getActiveCatch
(Object
The interned string to search for
tag
)

Find the active Continuation for the given tag.

public IRubyObject

Returns:

the value of $~
getBackRef
()

Get the value of the $~ (backref) "global".

public Stream<BacktraceElement>

Returns:

the backtrace
getBacktrace
()

Create a snapshot Array with current backtrace information.

public final Stream<BacktraceElement>
getBacktrace(int level)

public String

Returns:

the name under which the current method was called
getCalleeName
()

The name under which the current method was called, if called via an alias.

public String

Returns:

a representation of the current method's name and the name it was called under
getCompositeName
()

A string representing the name of the current method and the name under which it was called.

public IRubyObject
getConstant(String internedName)
Deprecated

Used by the evaluator and the compiler to look up a constant by name

public Frame
public DynamicScope
public StaticScope
public int
public Visibility
public IRubyObject
public ThreadFiber
public RubyThread
public String
public String
public Block
public RubyModule
public String

Returns:

the current method's name
getFrameName
()

The currently-running method's original name, used for stack traces, super calls, and __method__, and trace hooks.

public IRubyObject
public CallType
public IRubyObject
public IRubyObject

Returns:

the value of $_
getLastLine
()

Get the value of the $_ (lastline) "global".

public Visibility
public int
public RubyMatchData

Returns:

the current thread-local MatchData, or null if none
getLocalMatch
()

Get the thread-local MatchData specific to this context.

public IRubyObject

Returns:

the current thread-local MatchData, or nil if none
getLocalMatchOrNil
()

Get the thread-local MatchData specific to this context or nil if none.

public Frame
private RubyStackTraceElement[]
getPartialTrace(int level, Integer length, Stream<StackWalker.StackFrame> stackStream)

public Frame
public RubyModule
public ProfileCollection

Returns:

the thread's profile collection
getProfileCollection
()

Get the profile collection for this thread (ThreadContext).

public Set<RecursiveComparator.Pair>
public RubyDateFormatter
public final Ruby

Returns:

the runtime associated with this context
getRuntime
()

Retrieve the runtime associated with this context.

public Throwable
public SecureRandom
public RubyStackTraceElement

Returns:

the nearest stack trace element
getSingleBacktrace
(int level)

Return a single RubyStackTraceElement representing the nearest Ruby stack trace element.

public RubyStackTraceElement
getSingleBacktrace()

Same as calling getSingleBacktrace(0);

public RubyStackTraceElement
getSingleBacktraceExact(int level)

Return the trace of level or null.

public RubyThread
private RubyStackTraceElement[]
getWarnTrace(int level, Stream<StackWalker.StackFrame> stackStream)

public boolean
public static boolean
hasKeywords(int callInfo)

public boolean
public boolean
public boolean

Returns:

true if so
isWithinTrace
()

Is this thread actively tracing at this moment.

public IRubyObject
last_match()

MRI: rb_reg_last_match

public IRubyObject
match_last()

MRI: rb_reg_match_last

public IRubyObject
match_post()

MRI: rb_reg_match_post

public IRubyObject
match_pre()

MRI: rb_reg_match_pre

public static ThreadContext
newContext(Ruby runtime)

public void
private void
public static void
public void
public void
private void
popFrameReal(Frame oldFrame)

public void
public void
public void
public void
postEvalWithBinding(Binding binding, Frame lastFrame)

public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
postYield(Binding binding, Frame lastFrame)

public void
public void
public void
public void
public Frame
public void
preExecuteUnder(IRubyObject executeUnderObj, RubyModule executeUnderClass, Block block)

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

public void
public void
preMethodFrameOnly(RubyModule clazz, String name, IRubyObject self, Visibility visiblity, Block block)

public void
public void
public void
public void
public void
prepareTopLevel(RubyClass objectClass, IRubyObject topSelf)

public void
public void
public Frame
public Frame
public Frame
public void
public int
profileEnter(int nextMethod)

public int
profileEnter(String name, DynamicMethod nextMethod)

public int
profileExit(int nextMethod, long startTime)

private void
public static void
pushBacktrace(ThreadContext context, String method, String file, int line)

private void
pushCallFrame(RubyModule clazz, String name, IRubyObject self, Block block)

private void
pushCallFrame(RubyModule clazz, String name, IRubyObject self, Visibility visibility, Block block)

public void
pushCatch(RubyContinuation.Continuation catchTarget)
Deprecated

public void
pushCatch(CatchThrow catchTarget)

private void
public void
private Frame
public void
private Frame
public DynamicScope
public void
public void
renderCurrentBacktrace(StringBuilder
the StringBuilder to which to render the backtrace
sb
)

Render the current backtrace as a string to the given StringBuilder.

public int

Returns:

the old call info
resetCallInfo
()
Deprecated use the trivially-inlinable static version

Reset call info state and return the value of call info right before it is reset.

public static int

Returns:

the old call info
resetCallInfo
(ThreadContext context)

Reset call info state and return the value of call info right before it is reset.

private static int
safeLength(int level, Integer length, RubyStackTraceElement[] trace)

public <T> IRubyObject
safeRecurse(ThreadContext.RecursiveFunctionEx<T> func, T state, IRubyObject obj, String name, boolean outer)

private Map<IRubyObject, IRubyObject>
private <T> IRubyObject
private <T> IRubyObject
public boolean

Returns:

true if it exists. otherwise false.
scopeExistsOnCallStack
(DynamicScope
the scope to look for
scope
)

Check if a scope is present on the call stack.

public IRubyObject

Returns:

the value passed in
setBackRef
(RubyMatchData
the value to set
match
)

Set the $~ (backref) "global" to the given RubyMatchData value.

public IRubyObject
setBackRef(IRubyObject match)
Deprecated

public void
public IRubyObject
public void
setEventHooksEnabled(boolean flag)

public void
setExceptionRequiresBacktrace(boolean exceptionRequiresBacktrace)

public void
public void
setFileAndLine(String file, int line)

public void
public void
public IRubyObject

Returns:

the value passed in
setLastLine
(IRubyObject
the value to set
last
)

Set the $_ (lastlne) "global" to the given value.

public void
setLine(int line)

public void
setLocalMatch(RubyMatchData
the new thread-local MatchData or null
localMatch
)

Set the thread-local MatchData specific to this context.

public void
setPrivateConstantReference(RubyModule privateConstantReference)

public void
public void
public void
public void
public IRubyObject
public void
setWithinTrace(boolean
true is so
isWithinTrace
)

Set whether we are actively tracing or not on this thread.

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

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

public IRubyObject

Returns:

The current match, or nil
updateBackref
()

Update the current frame's backref using the current thread-local match, or clear it if that match is null.

public void
useRecursionGuardsFrom(ThreadContext context)

Fibers must use the same recursion guards as their parent thread.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait