Class RecoveryContext


  • public class RecoveryContext
    extends Object
    Holds shared state during expression recovery.
    • Constructor Detail

      • RecoveryContext

        public RecoveryContext​(IRMethod irMethod,
                               MethodEntry sourceMethod,
                               DefUseChains defUseChains)
        Creates an empty context, deriving the local model from the IR method.
        Parameters:
        irMethod - SSA method being recovered
        sourceMethod - the class file method it came from
        defUseChains - def-use chains over the same IR
    • Method Detail

      • getIrMethod

        public IRMethod getIrMethod()
        Returns:
        the ir method
      • getSourceMethod

        public MethodEntry getSourceMethod()
        Returns:
        the source method
      • getDefUseChains

        public DefUseChains getDefUseChains()
        Returns:
        the def use chains
      • getLocals

        public MethodLocals getLocals()
        Returns:
        the locals
      • getSlotPartition

        public SlotVariablePartition getSlotPartition()
        Returns:
        the reaching-definition partition of local slots into source variables
      • setSlotPartition

        public void setSlotPartition​(SlotVariablePartition slotPartition)
        Parameters:
        slotPartition - partition of local slots into source variables
      • setDebugNameResolver

        public void setDebugNameResolver​(IntFunction<String> resolver)
        Installs the lookup backing debugNameForSlot.
        Parameters:
        resolver - slot to recovered debug name, or null to disable the lookup
      • debugNameForSlot

        public String debugNameForSlot​(int slot)
        The recovered debug name a slot carries.
        Parameters:
        slot - local slot index
        Returns:
        the recovered name, or null when the class carries none for the slot or the active name-recovery strategy declines it
      • setDebugDescriptorResolver

        public void setDebugDescriptorResolver​(BiFunction<Integer,​Integer,​String> resolver)
        Installs the lookup backing debugDescriptorAt.
        Parameters:
        resolver - slot and bytecode offset to LVT descriptor, or null to disable the lookup
      • debugDescriptorAt

        public String debugDescriptorAt​(int slot,
                                        int offset)
        The LocalVariableTable type descriptor a slot carries at a bytecode offset.
        Parameters:
        slot - local slot index
        offset - bytecode offset to read the table at
        Returns:
        the descriptor, or null when no resolver is installed or the table has no entry
      • setDebugStoreDescriptorResolver

        public void setDebugStoreDescriptorResolver​(BiFunction<Integer,​Integer,​String> resolver)
        Installs the lookup backing debugDescriptorAtStore.
        Parameters:
        resolver - slot and store offset to LVT descriptor, or null to disable the lookup
      • debugDescriptorAtStore

        public String debugDescriptorAtStore​(int slot,
                                             int storeOffset)
        The LVT descriptor at the pc where a store takes effect.
        Parameters:
        slot - local slot index
        storeOffset - bytecode offset of the store
        Returns:
        the descriptor, or null when no resolver is installed or the table has no entry
      • getRecoveredExpressions

        public Map<SSAValue,​Expression> getRecoveredExpressions()
        Returns:
        the recovered expression of each recovered SSA value
      • getInlinedValues

        public Set<SSAValue> getInlinedValues()
        Returns:
        values folded into their single use instead of being assigned
      • getVariableNames

        public Map<SSAValue,​String> getVariableNames()
        Returns:
        the name bound to each named SSA value
      • getSyntheticCounter

        public int getSyntheticCounter()
        Returns:
        the counter backing synthetic name generation
      • getPendingNewInstructions

        public Map<SSAValue,​String> getPendingNewInstructions()
        Returns:
        the class name of each allocation still waiting for its <init> call
      • getPendingNewLocalSlots

        public Map<Integer,​String> getPendingNewLocalSlots()
        Returns:
        the class name of the pending new value held in each local slot
      • getDeclaredVariables

        public Set<String> getDeclaredVariables()
        Returns:
        the variable names declared in the current scope
      • getDeclaredVariableTypes

        public Map<String,​SourceType> getDeclaredVariableTypes()
        Returns:
        the declared type of each declared variable name
      • getLocalSlotNames

        public Map<Integer,​String> getLocalSlotNames()
        Returns:
        the current variable name of each local slot index
      • getMaterializedValues

        public Set<SSAValue> getMaterializedValues()
        Returns:
        values assigned to variables, which uses must reference by name instead of inlining
      • getForLoopScopedVariables

        public Deque<Set<String>> getForLoopScopedVariables()
        Returns:
        the stack of variable sets declared in for-loop inits, scoped to the loop body
      • getBranchScopedVariables

        public Deque<Set<String>> getBranchScopedVariables()
        Returns:
        the stack of variable sets declared in if-then-else branches, scoped to the branch
      • getRecordDeconstructionTemps

        public Set<SSAValue> getRecordDeconstructionTemps()
        Returns:
        cast results that are a record deconstruction's synthetic temp (the (T) selector)
      • getSsaValueSlot

        public Map<SSAValue,​Integer> getSsaValueSlot()
        Returns:
        the slot index each SSA value was first stored to
      • cacheExpression

        public void cacheExpression​(SSAValue value,
                                    Expression expr)
        Stores the recovered expression for a value, replacing any earlier one.
        Parameters:
        value - value the expression computes
        expr - recovered expression
      • getCachedExpression

        public Expression getCachedExpression​(SSAValue value)
        Parameters:
        value - value to look up
        Returns:
        the cached expression, or null if the value has not been recovered
      • isRecovered

        public boolean isRecovered​(SSAValue value)
        Parameters:
        value - value to test
        Returns:
        true if an expression has been cached for the value
      • markInlined

        public void markInlined​(SSAValue value)
        Records that a value's expression was folded into its single use rather than assigned.
        Parameters:
        value - value that was inlined
      • isInlined

        public boolean isInlined​(SSAValue value)
        Parameters:
        value - value to test
        Returns:
        true if the value was marked inlined
      • setVariableName

        public void setVariableName​(SSAValue value,
                                    String name)
        Binds a name to a value, refusing to rename a parameter that already has one.
        Parameters:
        value - value to name
        name - name to bind
      • getVariableName

        public String getVariableName​(SSAValue value)
        Parameters:
        value - value to look up
        Returns:
        the name bound to the value, or null if it has none
      • nextSyntheticId

        public int nextSyntheticId()
        Returns:
        the next synthetic name id, advancing the counter
      • registerPendingNew

        public void registerPendingNew​(SSAValue result,
                                       String className)
        Registers an allocation result that awaits its <init> call.
        Parameters:
        result - value produced by the allocation
        className - class being allocated
      • isPendingNew

        public boolean isPendingNew​(SSAValue value)
        Parameters:
        value - value to test
        Returns:
        true if the value is an allocation still waiting for its constructor call
      • consumePendingNew

        public String consumePendingNew​(SSAValue value)
        Removes the pending new record for a value and returns its class name.
        Parameters:
        value - allocation result
        Returns:
        the class name held pending for the value, or null if there is none
      • registerPendingNewLocalSlot

        public void registerPendingNewLocalSlot​(int localIndex,
                                                String className)
        Registers a local slot as containing a pending new value.
        Parameters:
        localIndex - local slot the value was stored to
        className - class being allocated
      • consumePendingNewLocalSlot

        public String consumePendingNewLocalSlot​(int localIndex)
        Removes the pending new record for a local slot and returns its class name.
        Parameters:
        localIndex - local slot index
        Returns:
        the class name held pending for the slot, or null if there is none
      • markDeclared

        public void markDeclared​(String name)
        Marks a variable name as declared.
        Parameters:
        name - variable name being declared
      • markDeclaredWithType

        public void markDeclaredWithType​(String name,
                                         SourceType type)
        Marks a variable name as declared, recording its type when one is given.
        Parameters:
        name - variable name being declared
        type - declared type, or null to record none
      • getDeclaredType

        public SourceType getDeclaredType​(String name)
        Parameters:
        name - variable name to look up
        Returns:
        the declared type recorded for the name, or null if none is tracked
      • isDeclared

        public boolean isDeclared​(String name)
        Parameters:
        name - variable name to test
        Returns:
        true if the name has been declared
      • clearDeclaredVariables

        public void clearDeclaredVariables()
        Clears declared variables (for new scope).
      • baselineDeclaredVariables

        public void baselineDeclaredVariables()
        Snapshots the current declared set as the method's baseline (the pre-declared parameters), so a full re-pass can restore it.
      • resetDeclaredVariablesToBaseline

        public void resetDeclaredVariablesToBaseline()
        Restores the declared set to the method baseline captured by baselineDeclaredVariables().
      • markMaterialized

        public void markMaterialized​(SSAValue value)
        Marks an SSA value as materialized into a variable.
        Parameters:
        value - value that was assigned to a variable
      • isMaterialized

        public boolean isMaterialized​(SSAValue value)
        Parameters:
        value - value to test
        Returns:
        true if the value has been materialized into a variable
      • unmarkMaterialized

        public void unmarkMaterialized​(SSAValue value)
        Unmarks an SSA value as materialized, allowing it to be inlined again.
        Parameters:
        value - value to unmark
      • pinToVariable

        public void pinToVariable​(SSAValue value)
        Pins a value to its variable.
        Parameters:
        value - value to pin
      • isPinnedToVariable

        public boolean isPinnedToVariable​(SSAValue value)
        Parameters:
        value - value to test
        Returns:
        true if the value was pinned and so must never be force-inlined at a use
      • pushForLoopScope

        public void pushForLoopScope()
        Pushes a new scope for for-loop variables.
      • popForLoopScope

        public void popForLoopScope()
        Pops the current for-loop scope and removes its variables from declaredVariables.
      • markDeclaredInForLoopInit

        public void markDeclaredInForLoopInit​(String name)
        Marks a variable as declared in a for-loop init expression.
        Parameters:
        name - variable name being declared
      • pushBranchScope

        public void pushBranchScope()
        Pushes a new scope for if-then-else branch variables.
      • popBranchScope

        public void popBranchScope()
        Pops the current branch scope and removes its variables from declaredVariables.
      • markDeclaredInBranch

        public void markDeclaredInBranch​(String name)
        Marks a variable as declared in the current scope.
        Parameters:
        name - variable name being declared
      • isInBranchScope

        public boolean isInBranchScope()
        Returns:
        true while a branch scope is open
      • setLocalSlotName

        public void setLocalSlotName​(int slotIndex,
                                     String name)
        Binds a variable name to a local slot so later loads from the slot recover the same name.
        Parameters:
        slotIndex - local slot index
        name - name to bind
      • getLocalSlotName

        public String getLocalSlotName​(int slotIndex)
        Parameters:
        slotIndex - local slot index
        Returns:
        the name bound to the slot, or null when none has been set
      • setSSAValueSlot

        public void setSSAValueSlot​(SSAValue value,
                                    int slotIndex)
        Records the slot an SSA value was stored to, keeping the first one recorded.
        Parameters:
        value - value that was stored
        slotIndex - local slot it was stored to
      • getSSAValueSlot

        public int getSSAValueSlot​(SSAValue value)
        Parameters:
        value - value to look up
        Returns:
        the slot the value was first stored to, or -1 when it is not tracked
      • parameterSlot

        public int parameterSlot​(SSAValue value)
        Parameters:
        value - value to look up
        Returns:
        the local slot a parameter or receiver value occupies, or -1 when the value is neither
      • isParameterOrThisSlot

        public boolean isParameterOrThisSlot​(int slot)
        Parameters:
        slot - local slot index
        Returns:
        true when the slot holds the receiver or a parameter rather than a body local
      • parameterIndexForSlot

        public int parameterIndexForSlot​(int slot)
        The zero-based parameter index of a parameter slot, with the receiver excluded from the numbering.
        Parameters:
        slot - local slot index
        Returns:
        the parameter index, or -1 when the slot does not hold a parameter