Class ReplacementForClass<T>

  • Type Parameters:
    T - the type of the class modeled by this Class

    class ReplacementForClass<T>
    extends java.lang.Object
    Replacement for java.lang.Class
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int classIdx  
      (package private) int vtable
      The pointer in the memory for the class/type description.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ReplacementForClass​(int vtable, int classIdx)
      Create a instance
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static ReplacementForClass<?> classConstant​(int classIdx)
      WASM code
      boolean desiredAssertionStatus()
      Replacement of the native Java method Class.desiredAssertionStatus()
      (package private) java.util.Map<java.lang.String,​T> enumConstantDirectory()
      Replacement of the Java method enumConstantDirectory() Returns a map from simple name to enum constant.
      static java.lang.Class<?> forName​(java.lang.String className)
      Replacement of the Java method forName(String)
      java.lang.String getCanonicalName()
      Replacement of the Java method getCanonicalName()
      private static ReplacementForClass<?> getClassFromTable​(int classIdx)
      WASM code
      java.lang.ClassLoader getClassLoader()
      Replacement of the Java method getClassLoader()
      (package private) java.lang.ClassLoader getClassLoader0()
      Replacement of the Java method getClassLoader0()
      private static ReplacementForClass<?> getClassObject​(java.lang.Object obj)
      Replacement for Object.getClass().
      ReplacementForClass<?> getComponentType()
      Replacement of the native Java method getComponentType()
      java.lang.reflect.Constructor<T> getDeclaredConstructor​(java.lang.Class<?>... parameterTypes)
      Replacement of the Java method getDeclaredConstructor()
      java.lang.reflect.Field getDeclaredField​(java.lang.String name)
      Replacement of the Java method getDeclaredField()
      java.lang.reflect.Method getDeclaredMethod​(java.lang.String name, java.lang.Class<?>... parameterTypes)
      Replacement of the Java method getDeclaredMethod()
      java.lang.reflect.Type[] getGenericInterfaces()
      Replacement of the Java method getGenericInterfaces()
      java.lang.Class<?>[] getInterfaces()
      Replacement of the Java method getInterfaces()
      private static int getIntFromMemory​(int pos)
      WASM code
      java.lang.reflect.Method getMethod​(java.lang.String name, java.lang.Class<?>... parameterTypes)
      Replacement of the Java method getMethod()
      java.lang.String getName()
      Replacement for Class.getName()
      java.lang.Package getPackage()
      Replacement of the Java methods getPackage()
      (package private) static ReplacementForClass<?> getPrimitiveClass​(java.lang.String name)
      Replacement of the native Java method Class.getPrimitiveClass(java.lang.String)
      java.io.InputStream getResourceAsStream​(java.lang.String name)
      Replacement of the Java method getResourceAsStream()
      java.lang.String getSimpleName()
      Replacement of the Java method getSimpleName()
      java.lang.Class<? super T> getSuperclass()
      Replacement of the Java methods getSuperclass()
      java.lang.String getTypeName()
      Replacement of the Java method getTypeName()
      boolean isArray()
      Replacement of the Java method isArray()
      boolean isAssignableFrom​(java.lang.Class<?> cls)
      Replacement of the Java method isAssignableFrom()
      boolean isInstance​(java.lang.Object obj)
      Replacement of the Java method isInstance()
      boolean isInterface()
      Replacement of the Java method isInterface()
      boolean isPrimitive()
      Replacement of the Java method Class.isPrimitive()
      T newInstance()
      Replacement of the Java method newInstance()
      private static void setClassIntoTable​(int strIdx, ReplacementForClass<?> clazz)
      WASM code
      private static int typeTableMemoryOffset()
      WASM code
      • Methods inherited from class java.lang.Object

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

      • vtable

        final int vtable
        The pointer in the memory for the class/type description.
      • classIdx

        final int classIdx
    • Constructor Detail

      • ReplacementForClass

        private ReplacementForClass​(int vtable,
                                    int classIdx)
        Create a instance
        Parameters:
        vtable - the pointer in the memory for the class/type description.
        classIdx - the class index, the ID of the class
    • Method Detail

      • getClassObject

        private static ReplacementForClass<?> getClassObject​(java.lang.Object obj)
        Replacement for Object.getClass(). The documentation of the memory of the type description is done in method: TypeManager.StructType#writeToStream(java.io.ByteArrayOutputStream, java.util.function.ToIntFunction)
        Parameters:
        obj - the instance
        Returns:
        the class
      • getClassFromTable

        private static ReplacementForClass<?> getClassFromTable​(int classIdx)
        WASM code

        Get a Class instance from the Class table. Should be inlined from the optimizer.

        Parameters:
        classIdx - the id/index of the Class.
        Returns:
        the string or null if not already set.
      • setClassIntoTable

        private static void setClassIntoTable​(int strIdx,
                                              ReplacementForClass<?> clazz)
        WASM code

        Set a Class instance in the Class table. Should be inlined from the optimizer.

        Parameters:
        strIdx - the id/index of the string.
        clazz - the Class instance
      • typeTableMemoryOffset

        private static int typeTableMemoryOffset()
        WASM code

        Placeholder for a synthetic function. Should be inlined from the optimizer.

        Returns:
        the memory offset of the string data in the element section
      • getIntFromMemory

        private static int getIntFromMemory​(int pos)
        WASM code

        Load an i32 from memory. The offset must be aligned. Should be inlined from the optimizer.

        Parameters:
        pos - the memory position
        Returns:
        the value from the memory
      • forName

        public static java.lang.Class<?> forName​(java.lang.String className)
                                          throws java.lang.ClassNotFoundException
        Replacement of the Java method forName(String)
        Parameters:
        className - the fully qualified name of the desired class.
        Returns:
        the Class object for the class with the specified name.
        Throws:
        java.lang.ClassNotFoundException
      • newInstance

        public T newInstance()
                      throws java.lang.InstantiationException,
                             java.lang.IllegalAccessException
        Replacement of the Java method newInstance()
        Returns:
        a newly allocated instance of the class represented by this object.
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • isInstance

        public boolean isInstance​(java.lang.Object obj)
        Replacement of the Java method isInstance()
        Parameters:
        obj - the object to check
        Returns:
        true if obj is an instance of this class
      • isAssignableFrom

        public boolean isAssignableFrom​(java.lang.Class<?> cls)
        Replacement of the Java method isAssignableFrom()
        Parameters:
        cls - the class to check
        Returns:
        true, if type cls can be assigned to objects of this class
      • isInterface

        public boolean isInterface()
        Replacement of the Java method isInterface()
        Returns:
        true if this object represents an interface;
      • isArray

        public boolean isArray()
        Replacement of the Java method isArray()
        Returns:
        true if this object represents an array class;
      • isPrimitive

        public boolean isPrimitive()
        Replacement of the Java method Class.isPrimitive()
        Returns:
        true if and only if this class represents a primitive type
      • getName

        public java.lang.String getName()
        Replacement for Class.getName()
        Returns:
        the name
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Replacement of the Java method getClassLoader()
      • getClassLoader0

        java.lang.ClassLoader getClassLoader0()
        Replacement of the Java method getClassLoader0()
      • getSuperclass

        public java.lang.Class<? super T> getSuperclass()
        Replacement of the Java methods getSuperclass()
      • getPackage

        public java.lang.Package getPackage()
        Replacement of the Java methods getPackage()
      • getInterfaces

        public java.lang.Class<?>[] getInterfaces()
        Replacement of the Java method getInterfaces()
        Returns:
        an array of interfaces implemented by this class.
      • getGenericInterfaces

        public java.lang.reflect.Type[] getGenericInterfaces()
        Replacement of the Java method getGenericInterfaces()
        Returns:
        an array of interfaces implemented by this class
      • getComponentType

        public ReplacementForClass<?> getComponentType()
        Replacement of the native Java method getComponentType()
      • getSimpleName

        public java.lang.String getSimpleName()
        Replacement of the Java method getSimpleName()
        Returns:
        the simple name of the underlying class
      • getTypeName

        public java.lang.String getTypeName()
        Replacement of the Java method getTypeName()
        Returns:
        an informative string for the name of this type
      • getCanonicalName

        public java.lang.String getCanonicalName()
        Replacement of the Java method getCanonicalName()
        Returns:
        the canonical name of the underlying class
      • getMethod

        public java.lang.reflect.Method getMethod​(java.lang.String name,
                                                  java.lang.Class<?>... parameterTypes)
        Replacement of the Java method getMethod()
      • getDeclaredField

        public java.lang.reflect.Field getDeclaredField​(java.lang.String name)
        Replacement of the Java method getDeclaredField()
      • getDeclaredMethod

        public java.lang.reflect.Method getDeclaredMethod​(java.lang.String name,
                                                          java.lang.Class<?>... parameterTypes)
        Replacement of the Java method getDeclaredMethod()
      • getDeclaredConstructor

        public java.lang.reflect.Constructor<T> getDeclaredConstructor​(java.lang.Class<?>... parameterTypes)
        Replacement of the Java method getDeclaredConstructor()
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String name)
        Replacement of the Java method getResourceAsStream()
      • getPrimitiveClass

        static ReplacementForClass<?> getPrimitiveClass​(java.lang.String name)
        Replacement of the native Java method Class.getPrimitiveClass(java.lang.String)
        Parameters:
        name - the class name
        Returns:
        the class
        See Also:
        TypeManager.PRIMITIVE_CLASSES
      • desiredAssertionStatus

        public boolean desiredAssertionStatus()
        Replacement of the native Java method Class.desiredAssertionStatus()
        Returns:
        the desired assertion status of the specified class.
      • enumConstantDirectory

        java.util.Map<java.lang.String,​T> enumConstantDirectory()
        Replacement of the Java method enumConstantDirectory() Returns a map from simple name to enum constant. This package-private method is used internally by Enum to implement