Class ItableAllocator<T>

java.lang.Object
com.google.j2cl.transpiler.backend.wasm.ItableAllocator<T>

public class ItableAllocator<T> extends Object
Assigns a field index in the itable for each interface.

Each interfaces implemented in the same class will have a different field indices, but across different parts of the hierarchy indices can be reused. This algorithm heuristically minimizes the size of the itable by trying to assign indices in order of most implemented interfaces. Each index in the itable instance will have the interface vtable for the class and can be used for both dynamic interface dispatch and interface "instanceof" checks.

This is a baseline implementation of "packed encoding" based on the algorithm described in section 4.3 of "Efficient type inclusion tests" by Vitek et al (OOPSLA 97). Although the ideas presented in the paper are for performing "instanceof" checks, they generalize to interface dispatch.

  • Constructor Details

    • ItableAllocator

      public ItableAllocator(List<T> classes, Function<T,Set<T>> implementedInterfaceByType)
  • Method Details

    • getItableSize

      public int getItableSize()
      Returns the number of fields needed in the itable structures.
    • getItableFieldIndex

      public int getItableFieldIndex(T type)
      Returns the field index for an interface, or -1 if the interface is not implemented by any class.