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 InterpreterContextStartup interpretation depends on thisstatic final Loggerprotected intprotected FullInterpreterContextSpeculatively 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 TypeMethodDescriptionbooleanprotected voidaddChildScope(IRScope scope) voidaddClosure(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.booleanbooleanbooleanbooleanvoidcaptureParentRefinements(ThreadContext context) Duplicate the parent scope's refinements overlay to get a moment-in-time snapshot.voidWe are done with execution of this scope and we can cleanup some amount of things in this scope which will no longer be used.intcorrectVariableDepthForForLoopsForEncoding(int depth) protected voidbooleanbooleanprotected LocalVariablefindExistingLocalVariable(RubySymbol name, int depth) getAST()intorg.jcodings.EncodinggetFile()Deprecated.getId()Returns the lexical scope that contains this scope definitionintgetLine()intDeprecated.getLocalVariable(RubySymbol name, int scopeDepth) Find or create a local variable.Get the local variables for this scope.getName()intReturns the nearest scope which we can extract a live module from.getNewLabel(String prefix) getNewLocalVariable(RubySymbol name, int scopeDepth) intintReturns the top level scopeintabstract IRScopeTypegetSelf()booleanFor lazy scopes which IRBuild on demand we can ask this method whether it has been built yet...booleanbooleaninthashCode()booleanhasLoops()booleanvoidinlineMethod(IRMethod methodToInline, RubyModule metaclass, long callsiteId, int classToken, boolean cloneHost) voidinlineMethodCompiled(IRMethod methodToInline, RubyModule implClass, long callsiteId, int classToken, boolean cloneHost) voidinlineMethodJIT(IRMethod methodToInline, RubyModule implClass, long callsiteId, int classToken, boolean cloneHost) booleanbooleanDoes this scope represent a module body?booleanisNestedInClosure(IRClosure closure) booleanIs this IRClassBody but not IRMetaClassBody?booleanbooleanisScopeContainedBy(IRScope parentScope) returns whether this scope is contained by the parentScope parameter.booleanIs this an eval script or a regular file script?booleanbooleanbooleanlookupExistingLVar(RubySymbol name) booleanbooleanbooleanvoidvoidRun 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.booleanbooleanvoidremoveClosure(IRClosure closure) voidvoidsetByteName(ByteList name) voidvoidvoidvoidsetCoverageMode(int coverageMode) voidsetFileName(String filename) voidvoidsetHasFlipFlops(boolean hasFlipFlops) voidvoidvoidvoidvoidsetNextLabelIndex(int index) voidvoidvoidvoidvoidvoidtoString()booleanusesEval()booleanboolean
-
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:
getDynamicScopein 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:
getStaticScopein 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:
getEncodingin interfaceParseResult
-
getFileName
Deprecated. -
getFile
- Specified by:
getFilein interfaceParseResult
-
getLineNumber
Deprecated. -
getLine
public int getLine()- Specified by:
getLinein 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:
getCoverageModein 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:
getASTin interfaceParseResult
-