Class LocaleVariableManager


  • class LocaleVariableManager
    extends java.lang.Object
    This manager monitor the locale variables of a method to create a translation from the slot based index in Java to the variable based index in WebAssembly. An 8-byte variable of type long and double consumes in Java 2 slots, but only one index in WebAssmenbly.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  LocaleVariableManager.Variable
      The state of a single local variable slot.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void calculate()
      Calculate the WebAssembly index position on the consumed data.
      private void ensureCapacity​(int slot)
      Ensure that there is enough capacity.
      (package private) void expandUse​(int slot, int javaCodePos)
      Expand code range for which the variable is valid
      private java.lang.String findUniqueVarName​(java.lang.String name)
      Find a unique variable name.
      (package private) int get​(int slot, int javaCodePos)
      Get the WebAssembly variable index of the given Java Slot.
      (package private) LocaleVariableManager.Variable[] getCopy()
      Create a copy of the internal state
      (package private) java.lang.String getLocalName​(int idx)
      Get the name of the variable or null if no name available
      (package private) java.util.List<AnyType> getLocalTypes​(int paramCount)
      Get the data types of the local variables.
      (package private) int getTempVariable​(AnyType valueType, int startCodePosition, int endCodePosition)
      Get the slot of the temporary variable.
      (package private) AnyType getValueType​(int idx)
      Get the ValueType of the variable.
      (package private) void init​(TypeManager types)
      Initialize the variable manager;
      (package private) void reset​(LocalVariableTable variableTable, MethodInfo method, java.util.Iterator<AnyType> signature)
      Reset the manager to an initial state.
      private void resetAddVar​(AnyType type, int slot)
      Add a variable in the reset with range.
      (package private) void setCopy​(LocaleVariableManager.Variable[] copy)
      Set a previous copy
      (package private) void use​(AnyType valueType, int slot, int javaCodePos)
      Mark a variable slot as used with its type.
      private void useImpl​(AnyType valueType, int idx, int javaCodePos)  
      (package private) void useIndex​(AnyType valueType, int wasmIdx)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocaleVariableManager

        LocaleVariableManager()
        Create a new instance.
    • Method Detail

      • init

        void init​(TypeManager types)
        Initialize the variable manager;
        Parameters:
        types - the type manager
      • reset

        void reset​(LocalVariableTable variableTable,
                   MethodInfo method,
                   java.util.Iterator<AnyType> signature)
        Reset the manager to an initial state.
        Parameters:
        variableTable - variable table of the Java method.
        method - the method with signature as fallback for a missing variable table. If null signature is used and the method must be static.
        signature - alternative for method signature, can be null if method is set
      • resetAddVar

        private void resetAddVar​(AnyType type,
                                 int slot)
        Add a variable in the reset with range.
        Parameters:
        type - the type of the variable
        slot - the slot of the variable
      • findUniqueVarName

        private java.lang.String findUniqueVarName​(java.lang.String name)
        Find a unique variable name.
        Parameters:
        name - the suggested name
        Returns:
        a name that not was used before
      • use

        void use​(AnyType valueType,
                 int slot,
                 int javaCodePos)
        Mark a variable slot as used with its type.
        Parameters:
        valueType - the type of the local variable
        slot - the memory/slot index of the local variable
        javaCodePos - the code position/offset in the Java method
      • useImpl

        private void useImpl​(AnyType valueType,
                             int idx,
                             int javaCodePos)
      • useIndex

        void useIndex​(AnyType valueType,
                      int wasmIdx)
      • calculate

        void calculate()
        Calculate the WebAssembly index position on the consumed data.
      • getLocalTypes

        java.util.List<AnyType> getLocalTypes​(int paramCount)
        Get the data types of the local variables. The value is only valid until the next call.
        Parameters:
        paramCount - the count of method parameter which should be exclude
        Returns:
        the reused list with fresh values
      • getLocalName

        @Nullable
        java.lang.String getLocalName​(int idx)
        Get the name of the variable or null if no name available
        Parameters:
        idx - the wasm variable index
        Returns:
        the name
      • getTempVariable

        int getTempVariable​(AnyType valueType,
                            int startCodePosition,
                            int endCodePosition)
        Get the slot of the temporary variable.
        Parameters:
        valueType - the valueType for the variable
        startCodePosition - the start of the Java code position
        endCodePosition - the end of the Java code position
        Returns:
        the slot
      • expandUse

        void expandUse​(int slot,
                       int javaCodePos)
        Expand code range for which the variable is valid
        Parameters:
        slot - the memory/slot index of the local variable
        javaCodePos - the new end code position in the Java method
      • get

        int get​(int slot,
                int javaCodePos)
        Get the WebAssembly variable index of the given Java Slot.
        Parameters:
        slot - the memory/slot index of the local variable in Java
        javaCodePos - the current code position in the Java method
        Returns:
        the variable index in WebAssembly
      • getValueType

        AnyType getValueType​(int idx)
        Get the ValueType of the variable.
        Parameters:
        idx - the index of the local variable in WASM
        Returns:
        the ValueType
      • ensureCapacity

        private void ensureCapacity​(int slot)
        Ensure that there is enough capacity.
        Parameters:
        slot - the needed slot