Package org.jruby.ir

Class IRScope

java.lang.Object
org.jruby.ir.IRScope
All Implemented Interfaces:
ParseResult
Direct Known Subclasses:
IRClosure, IRMethod, IRModuleBody, IRScriptBody

public abstract class IRScope extends Object implements ParseResult
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 Details

    • LOG

      public static final Logger LOG
    • nextClosureIndex

      protected int nextClosureIndex
    • interpreterContext

      protected InterpreterContext interpreterContext
      Startup interpretation depends on this
    • fullInterpreterContext

      protected FullInterpreterContext fullInterpreterContext
      -X-C full interpretation OR JIT depends on this
    • optimizedInterpreterContext

      protected FullInterpreterContext optimizedInterpreterContext
      Speculatively optimized code
    • compilable

      public Compilable compilable
  • Constructor Details

  • Method Details

    • getDynamicScope

      public DynamicScope getDynamicScope()
      Specified by:
      getDynamicScope in interface ParseResult
    • getScopeId

      public int getScopeId()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • addChildScope

      protected void addChildScope(IRScope scope)
    • getLexicalScopes

      public List<IRScope> getLexicalScopes()
    • addClosure

      public void addClosure(IRClosure closure)
    • removeClosure

      public void removeClosure(IRClosure closure)
    • getNewLabel

      public Label getNewLabel(String prefix)
    • getNewLabel

      public Label getNewLabel()
    • getClosures

      public Collection<IRClosure> getClosures()
    • getManager

      public IRManager getManager()
    • setIsMaybeUsingRefinements

      public void setIsMaybeUsingRefinements()
    • parentMaybeUsingRefinements

      public boolean parentMaybeUsingRefinements()
    • maybeUsingRefinements

      public boolean maybeUsingRefinements()
    • getLexicalParent

      public IRScope getLexicalParent()
      Returns the lexical scope that contains this scope definition
    • getStaticScope

      public StaticScope getStaticScope()
      Specified by:
      getStaticScope in interface ParseResult
    • isWithinEND

      public boolean isWithinEND()
    • getNearestNonClosurelikeScope

      public IRScope getNearestNonClosurelikeScope()
    • getNearestMethod

      public IRMethod getNearestMethod()
    • getNearestTopLocalVariableScope

      public IRScope getNearestTopLocalVariableScope()
    • isScopeContainedBy

      public boolean isScopeContainedBy(IRScope parentScope)
      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

      public String getId()
    • getName

      public RubySymbol getName()
    • getByteName

      public ByteList getByteName()
    • setByteName

      public void setByteName(ByteList name)
    • setFileName

      public void setFileName(String filename)
    • getEncoding

      public org.jcodings.Encoding getEncoding()
      Specified by:
      getEncoding in interface ParseResult
    • getFileName

      @Deprecated public String getFileName()
      Deprecated.
    • getFile

      public String getFile()
      Specified by:
      getFile in interface ParseResult
    • getLineNumber

      @Deprecated public int getLineNumber()
      Deprecated.
    • getLine

      public int getLine()
      Specified by:
      getLine in interface ParseResult
    • correctVariableDepthForForLoopsForEncoding

      public int correctVariableDepthForForLoopsForEncoding(int depth)
    • getRootLexicalScope

      public IRScope getRootLexicalScope()
      Returns the top level scope
    • isNestedInClosure

      public boolean isNestedInClosure(IRClosure closure)
    • 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 interface ParseResult
    • 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

      public List<CompilerPass> 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

      public FullInterpreterContext 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

      public String getFullyQualifiedName()
    • dumpToIGV

      public IGVDumper dumpToIGV()
    • prepareForCompilation

      public BasicBlock[] prepareForCompilation()
      Run any necessary passes to get the IR ready for compilation (AOT and/or JIT)
    • buildJVMExceptionTable

      public Map<BasicBlock,Label> buildJVMExceptionTable(FullInterpreterContext fic)
    • getScopeType

      public abstract IRScopeType getScopeType()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringCompileForm

      public String toStringCompileForm()
    • debugOutput

      public String debugOutput()
    • toStringInstrs

      public String toStringInstrs()
    • getSelf

      public Variable getSelf()
    • getLocalVariables

      public Map<RubySymbol,LocalVariable> 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

      public LocalVariable lookupExistingLVar(RubySymbol name)
    • findExistingLocalVariable

      protected LocalVariable findExistingLocalVariable(RubySymbol name, int depth)
    • getLocalVariable

      public LocalVariable getLocalVariable(RubySymbol name, int scopeDepth)
      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

      public LocalVariable getNewLocalVariable(RubySymbol name, int scopeDepth)
    • hasBeenBuilt

      public boolean hasBeenBuilt()
      For lazy scopes which IRBuild on demand we can ask this method whether it has been built yet...
    • getExecutionContext

      public FullInterpreterContext getExecutionContext()
    • getInterpreterContext

      public InterpreterContext getInterpreterContext()
    • getFullInterpreterContext

      public FullInterpreterContext getFullInterpreterContext()
    • getOptimizedInterpreterContext

      public FullInterpreterContext getOptimizedInterpreterContext()
    • builtInterpreterContext

      public InterpreterContext builtInterpreterContext()
    • depends

      protected void depends(Object obj)
    • 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

      public void captureParentRefinements(ThreadContext context)
      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

      public void persistScopeHeader(IRWriterEncoder file)
    • persistScopeFlags

      public void persistScopeFlags(IRWriterEncoder file)
    • allocateInitialFlags

      public static EnumSet<IRFlags> allocateInitialFlags(IRScope scope)
    • getAST

      public Object getAST()
      Specified by:
      getAST in interface ParseResult