Package org.jruby.ir
Class IRScope
java.lang.Object
org.jruby.ir.IRScope
- All Implemented Interfaces:
ParseResult
- Direct Known Subclasses:
IRClosure
,IRMethod
,IRModuleBody
,IRScriptBody
Right now, this class abstracts the following execution scopes:
Method, Closure, Module, Class, MetaClass
Top-level Script, and Eval Script
In the compiler-land, IR versions of these scopes encapsulate only as much
information as is required to convert Ruby code into equivalent Java code.
But, in the non-compiler land, there will be a corresponding java object for
some of these scopes which encapsulates the runtime semantics and data needed
for implementing them. In the case of Module, Class, MetaClass, and Method,
they also happen to be instances of the corresponding Ruby classes -- so,
in addition to providing code that help with this specific ruby implementation,
they also have code that let them behave as ruby instances of their corresponding
classes.
Examples:
- the runtime class object might have refs. to the runtime method objects.
- the runtime method object might have a slot for a heap frame (for when it
has closures that need access to the method's local variables), it might
have version information, it might have references to other methods that
were optimized with the current version number, etc.
- the runtime closure object will have a slot for a heap frame (for when it
has closures within) and might get reified as a method in the java land
(but inaccessible in ruby land). So, passing closures in Java land might
be equivalent to passing around the method handles.
and so on ...
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FullInterpreterContext
-X-C full interpretation OR JIT depends on thisprotected InterpreterContext
Startup interpretation depends on thisstatic final Logger
protected int
protected FullInterpreterContext
Speculatively optimized code -
Constructor Summary
ConstructorsModifierConstructorDescriptionIRScope
(IRManager manager, IRScope lexicalParent, ByteList name, int lineNumber, StaticScope staticScope) IRScope
(IRManager manager, IRScope lexicalParent, ByteList name, int lineNumber, StaticScope staticScope, int coverageMode) protected
-
Method Summary
Modifier and TypeMethodDescriptionboolean
protected void
addChildScope
(IRScope scope) void
addClosure
(IRClosure closure) allocateInitialFlags
(IRScope scope) allocateInterpreterContext
(Supplier<List<Instr>> instructions, int tempVariableCount, EnumSet<IRFlags> flags) Make version specific to scope which needs it (e.g.allocateInterpreterContext
(List<Instr> instructions, int tempVariableCount, EnumSet<IRFlags> flags) Make version specific to scope which needs it (e.g.boolean
boolean
boolean
boolean
void
captureParentRefinements
(ThreadContext context) Duplicate the parent scope's refinements overlay to get a moment-in-time snapshot.void
We are done with execution of this scope and we can cleanup some amount of things in this scope which will no longer be used.int
correctVariableDepthForForLoopsForEncoding
(int depth) protected void
boolean
boolean
protected LocalVariable
findExistingLocalVariable
(RubySymbol name, int depth) getAST()
int
org.jcodings.Encoding
getFile()
Deprecated.getId()
Returns the lexical scope that contains this scope definitionint
getLine()
int
Deprecated.getLocalVariable
(RubySymbol name, int scopeDepth) Find or create a local variable.Get the local variables for this scope.getName()
int
Returns the nearest scope which we can extract a live module from.getNewLabel
(String prefix) getNewLocalVariable
(RubySymbol name, int scopeDepth) int
int
Returns the top level scopeint
abstract IRScopeType
getSelf()
boolean
For lazy scopes which IRBuild on demand we can ask this method whether it has been built yet...boolean
boolean
int
hashCode()
boolean
hasLoops()
boolean
void
inlineMethod
(IRMethod methodToInline, RubyModule metaclass, long callsiteId, int classToken, boolean cloneHost) void
inlineMethodCompiled
(IRMethod methodToInline, RubyModule implClass, long callsiteId, int classToken, boolean cloneHost) void
inlineMethodJIT
(IRMethod methodToInline, RubyModule implClass, long callsiteId, int classToken, boolean cloneHost) boolean
boolean
Does this scope represent a module body?boolean
isNestedInClosure
(IRClosure closure) boolean
Is this IRClassBody but not IRMetaClassBody?boolean
boolean
isScopeContainedBy
(IRScope parentScope) returns whether this scope is contained by the parentScope parameter.boolean
Is this an eval script or a regular file script?boolean
boolean
boolean
lookupExistingLVar
(RubySymbol name) boolean
boolean
boolean
void
void
Run any necessary passes to get the IR ready for compilation (AOT and/or JIT)This initializes a more complete(full) InterpreterContext which if used in mixed mode will be used by the JIT and if used in pure-interpreted mode it will be used by an interpreter engine.boolean
boolean
void
removeClosure
(IRClosure closure) void
void
setByteName
(ByteList name) void
void
void
void
setCoverageMode
(int coverageMode) void
setFileName
(String filename) void
void
setHasFlipFlops
(boolean hasFlipFlops) void
void
void
void
void
setNextLabelIndex
(int index) void
void
void
void
void
void
toString()
boolean
usesEval()
boolean
boolean
-
Field Details
-
LOG
-
nextClosureIndex
protected int nextClosureIndex -
interpreterContext
Startup interpretation depends on this -
fullInterpreterContext
-X-C full interpretation OR JIT depends on this -
optimizedInterpreterContext
Speculatively optimized code -
compilable
-
-
Constructor Details
-
IRScope
-
IRScope
public IRScope(IRManager manager, IRScope lexicalParent, ByteList name, int lineNumber, StaticScope staticScope) -
IRScope
public IRScope(IRManager manager, IRScope lexicalParent, ByteList name, int lineNumber, StaticScope staticScope, int coverageMode)
-
-
Method Details
-
getDynamicScope
- Specified by:
getDynamicScope
in interfaceParseResult
-
getScopeId
public int getScopeId() -
hashCode
public int hashCode() -
equals
-
addChildScope
-
getLexicalScopes
-
addClosure
-
removeClosure
-
getNewLabel
-
getNewLabel
-
getClosures
-
getManager
-
setIsMaybeUsingRefinements
public void setIsMaybeUsingRefinements() -
parentMaybeUsingRefinements
public boolean parentMaybeUsingRefinements() -
maybeUsingRefinements
public boolean maybeUsingRefinements() -
getLexicalParent
Returns the lexical scope that contains this scope definition -
getStaticScope
- Specified by:
getStaticScope
in interfaceParseResult
-
isWithinEND
public boolean isWithinEND() -
getNearestNonClosurelikeScope
-
getNearestMethod
-
getNearestTopLocalVariableScope
-
isScopeContainedBy
returns whether this scope is contained by the parentScope parameter. For simplicity a scope is considered to contain itself.- Parameters:
parentScope
- we want to see if it contains this scope- Returns:
- true if this scope is contained by parentScope.
-
getNearestModuleReferencingScopeDepth
public int getNearestModuleReferencingScopeDepth()Returns the nearest scope which we can extract a live module from. If this returns null (like for evals), then it means it cannot be statically determined. -
getId
-
getName
-
getByteName
-
setByteName
-
setFileName
-
getEncoding
public org.jcodings.Encoding getEncoding()- Specified by:
getEncoding
in interfaceParseResult
-
getFileName
Deprecated. -
getFile
- Specified by:
getFile
in interfaceParseResult
-
getLineNumber
Deprecated. -
getLine
public int getLine()- Specified by:
getLine
in interfaceParseResult
-
correctVariableDepthForForLoopsForEncoding
public int correctVariableDepthForForLoopsForEncoding(int depth) -
getRootLexicalScope
Returns the top level scope -
isNestedInClosure
-
setHasBreakInstructions
public void setHasBreakInstructions() -
hasBreakInstructions
public boolean hasBreakInstructions() -
setReceivesKeywordArgs
public void setReceivesKeywordArgs() -
receivesKeywordArgs
public boolean receivesKeywordArgs() -
setRuby2Keywords
public void setRuby2Keywords() -
isRuby2Keywords
public boolean isRuby2Keywords() -
setReceivesClosureArg
public void setReceivesClosureArg() -
receivesClosureArg
public boolean receivesClosureArg() -
setAccessesParentsLocalVariables
public void setAccessesParentsLocalVariables() -
accessesParentsLocalVariables
public boolean accessesParentsLocalVariables() -
hasFlipFlops
public boolean hasFlipFlops() -
setHasFlipFlops
public void setHasFlipFlops(boolean hasFlipFlops) -
setHasLoops
public void setHasLoops() -
hasLoops
public boolean hasLoops() -
setCoverageMode
public void setCoverageMode(int coverageMode) -
getCoverageMode
public int getCoverageMode()- Specified by:
getCoverageMode
in interfaceParseResult
-
setHasNonLocalReturns
public void setHasNonLocalReturns() -
hasNonLocalReturns
public boolean hasNonLocalReturns() -
setCanCaptureCallersBinding
public void setCanCaptureCallersBinding() -
canCaptureCallersBinding
public boolean canCaptureCallersBinding() -
setCanReceiveBreaks
public void setCanReceiveBreaks() -
canReceiveBreaks
public boolean canReceiveBreaks() -
setCanReceiveNonlocalReturns
public void setCanReceiveNonlocalReturns() -
canReceiveNonlocalReturns
public boolean canReceiveNonlocalReturns() -
setUsesEval
public void setUsesEval() -
usesEval
public boolean usesEval() -
anyUsesEval
public boolean anyUsesEval() -
setUsesZSuper
public void setUsesZSuper() -
setUsesSuper
public void setUsesSuper() -
usesSuper
public boolean usesSuper() -
usesZSuper
public boolean usesZSuper() -
setNeedsCodeCoverage
public void setNeedsCodeCoverage() -
needsCodeCoverage
public boolean needsCodeCoverage() -
getExecutedPasses
-
allocateInterpreterContext
public InterpreterContext allocateInterpreterContext(List<Instr> instructions, int tempVariableCount, EnumSet<IRFlags> flags) Make version specific to scope which needs it (e.g. Closure vs non-closure). -
allocateInterpreterContext
public InterpreterContext allocateInterpreterContext(Supplier<List<Instr>> instructions, int tempVariableCount, EnumSet<IRFlags> flags) Make version specific to scope which needs it (e.g. Closure vs non-closure). -
prepareFullBuild
This initializes a more complete(full) InterpreterContext which if used in mixed mode will be used by the JIT and if used in pure-interpreted mode it will be used by an interpreter engine. -
getFullyQualifiedName
-
dumpToIGV
-
prepareForCompilation
Run any necessary passes to get the IR ready for compilation (AOT and/or JIT) -
buildJVMExceptionTable
-
getScopeType
-
toString
-
toStringCompileForm
-
debugOutput
-
toStringInstrs
-
getSelf
-
getLocalVariables
Get the local variables for this scope. This should only be used by persistence layer. -
setNextLabelIndex
public void setNextLabelIndex(int index) -
getNextLabelIndex
public int getNextLabelIndex() -
lookupExistingLVar
-
findExistingLocalVariable
-
getLocalVariable
Find or create a local variable. By default, scopes are assumed to only check current depth. Blocks/Closures override this because they have special nesting rules. -
getNewLocalVariable
-
hasBeenBuilt
public boolean hasBeenBuilt()For lazy scopes which IRBuild on demand we can ask this method whether it has been built yet... -
getExecutionContext
-
getInterpreterContext
-
getFullInterpreterContext
-
getOptimizedInterpreterContext
-
builtInterpreterContext
-
depends
-
inlineMethod
public void inlineMethod(IRMethod methodToInline, RubyModule metaclass, long callsiteId, int classToken, boolean cloneHost) -
inlineMethodJIT
public void inlineMethodJIT(IRMethod methodToInline, RubyModule implClass, long callsiteId, int classToken, boolean cloneHost) -
inlineMethodCompiled
public void inlineMethodCompiled(IRMethod methodToInline, RubyModule implClass, long callsiteId, int classToken, boolean cloneHost) -
getNextClosureId
public int getNextClosureId() -
isModuleBody
public boolean isModuleBody()Does this scope represent a module body? -
isWhereFlipFlopStateVariableIs
public boolean isWhereFlipFlopStateVariableIs() -
isNonSingletonClassBody
public boolean isNonSingletonClassBody()Is this IRClassBody but not IRMetaClassBody? -
isTopLocalVariableScope
public boolean isTopLocalVariableScope() -
isScriptScope
public boolean isScriptScope()Is this an eval script or a regular file script? -
inliningAllowed
public boolean inliningAllowed() -
captureParentRefinements
Duplicate the parent scope's refinements overlay to get a moment-in-time snapshot.- Parameters:
context
-
-
cleanupAfterExecution
public void cleanupAfterExecution()We are done with execution of this scope and we can cleanup some amount of things in this scope which will no longer be used. Sub-classes will be the deciders of what is no longer needed. An example, to illustrate the complexity of cleanup: A class with no nested closures can remove any ICs created and can remove some other infomrational data structures like allocated variables unless closures do exist and then the ICs must stay for when closures JIT. -
executesOnce
public boolean executesOnce() -
persistScopeHeader
-
persistScopeFlags
-
allocateInitialFlags
-
getAST
- Specified by:
getAST
in interfaceParseResult
-