Class TypeManager
- java.lang.Object
-
- de.inetsoftware.jwebassembly.module.TypeManager
-
public class TypeManager extends java.lang.ObjectManage the written and to write types (classes)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeManager.BlockTypeA type that can use for a block(package private) classTypeManager.LambdaTypeA generated type that represent a lambda expressionstatic classTypeManager.StructTypeA reference to a type.static classTypeManager.StructTypeKindThe kind of type
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<TypeManager.BlockType,TypeManager.BlockType>blockTypesstatic intBOOLEANType id of primitive classstatic intBYTEType id of primitive classstatic intCHARType id of primitive classprivate static FunctionNameCLASS_CONSTANT_FUNCTIONprivate ClassFileLoaderclassFileLoaderstatic intDOUBLEType id of primitive class(package private) static java.lang.StringFIELD_HASHCODEName of field with system hash code, start with a point for an invalid Java identifier.static java.lang.StringFIELD_VALUEName of field with array value.(package private) static java.lang.StringFIELD_VTABLEname of virtual function table, start with a point for an invalid Java identifierstatic intFLOATType id of primitive classstatic intINTType id of primitive classprivate booleanisFinishstatic intLONGType id of primitive class(package private) WasmOptionsoptionsprivate static java.lang.String[]PRIMITIVE_CLASSESthe list of primitive types.static intSHORTType id of primitive classprivate java.util.Map<java.lang.Object,TypeManager.StructType>structTypesstatic intTYPE_DESCRIPTION_ARRAY_TYPEByte position in the type description that contains the type of the array (component type).static intTYPE_DESCRIPTION_INSTANCEOF_OFFSETByte position in the type description that contains the offset to the instanceof list.static intTYPE_DESCRIPTION_INTERFACE_OFFSETByte position in the type description that contains the offset to the interfaces.static intTYPE_DESCRIPTION_TYPE_NAMEByte position in the type description that contains the offset to class name idx in the string constant table.private inttypeIndexCounterprivate inttypeTableOffsetstatic intVOIDType id of primitive classprivate static intVTABLE_FIRST_FUNCTION_INDEXThe reserved position on start of the vtable: offset of interface call table (itable) offset of instanceof list offset of class name idx in the string constant table
-
Constructor Summary
Constructors Constructor Description TypeManager(WasmOptions options)Initialize the type manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArrayTypearrayType(AnyType arrayType)Get the array type for the given component type.(package private) TypeManager.BlockTypeblockType(java.util.List<AnyType> params, java.util.List<AnyType> results)Create block typeprivate voidcheckStructTypesState(java.lang.Object newType)Check the internal state of the manager and create initial classes.(package private) WatCodeSyntheticFunctionNamecreateCallInterface()Create the FunctionName for a interface call.(package private) WatCodeSyntheticFunctionNamecreateCallVirtual()Create the FunctionName for a virtual call.(package private) WatCodeSyntheticFunctionNamecreateCast()Create the FunctionName for the CAST operation and mark it as used.(package private) WatCodeSyntheticFunctionNamecreateInstanceOf()Create the FunctionName for the INSTANCEOF operation and mark it as used.(package private) FunctionNamegetClassConstantFunction()Get the function name to get a constant class.(package private) WatCodeSyntheticFunctionNamegetTypeTableMemoryOffsetFunctionName()Create an accessor for typeTableOffset and mark it.(package private) voidinit(ClassFileLoader classFileLoader)Initialize the type manager(package private) booleanisFinish()If the scan phase is finish(package private) TypeManager.LambdaTypelambdaType(BootstrapMethod method, java.util.ArrayList<AnyType> params, TypeManager.StructType interfaceType, java.lang.String interfaceMethodName)Create a lambda type(package private) voidprepareFinish(ModuleWriter writer)Finish the prepare and write the types.(package private) voidscanTypeHierarchy()Scan the hierarchy of the types.intsize()Count of used typesTypeManager.StructTypevalueOf(java.lang.String name)Get the StructType.
-
-
-
Field Detail
-
FIELD_VTABLE
static final java.lang.String FIELD_VTABLE
name of virtual function table, start with a point for an invalid Java identifier- See Also:
- Constant Field Values
-
FIELD_HASHCODE
static final java.lang.String FIELD_HASHCODE
Name of field with system hash code, start with a point for an invalid Java identifier.- See Also:
- Constant Field Values
-
FIELD_VALUE
public static final java.lang.String FIELD_VALUE
Name of field with array value.- See Also:
- Constant Field Values
-
TYPE_DESCRIPTION_INTERFACE_OFFSET
public static final int TYPE_DESCRIPTION_INTERFACE_OFFSET
Byte position in the type description that contains the offset to the interfaces. Length 4 bytes.- See Also:
- Constant Field Values
-
TYPE_DESCRIPTION_INSTANCEOF_OFFSET
public static final int TYPE_DESCRIPTION_INSTANCEOF_OFFSET
Byte position in the type description that contains the offset to the instanceof list. Length 4 bytes.- See Also:
- Constant Field Values
-
TYPE_DESCRIPTION_TYPE_NAME
public static final int TYPE_DESCRIPTION_TYPE_NAME
Byte position in the type description that contains the offset to class name idx in the string constant table. Length 4 bytes.- See Also:
- Constant Field Values
-
TYPE_DESCRIPTION_ARRAY_TYPE
public static final int TYPE_DESCRIPTION_ARRAY_TYPE
Byte position in the type description that contains the type of the array (component type). Length 4 bytes.- See Also:
- Constant Field Values
-
VTABLE_FIRST_FUNCTION_INDEX
private static final int VTABLE_FIRST_FUNCTION_INDEX
The reserved position on start of the vtable:- offset of interface call table (itable)
- offset of instanceof list
- offset of class name idx in the string constant table
- See Also:
- Constant Field Values
-
CLASS_CONSTANT_FUNCTION
private static final FunctionName CLASS_CONSTANT_FUNCTION
-
BOOLEAN
public static final int BOOLEAN
Type id of primitive class- See Also:
- Constant Field Values
-
BYTE
public static final int BYTE
Type id of primitive class- See Also:
- Constant Field Values
-
CHAR
public static final int CHAR
Type id of primitive class- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
Type id of primitive class- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
Type id of primitive class- See Also:
- Constant Field Values
-
INT
public static final int INT
Type id of primitive class- See Also:
- Constant Field Values
-
LONG
public static final int LONG
Type id of primitive class- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT
Type id of primitive class- See Also:
- Constant Field Values
-
VOID
public static final int VOID
Type id of primitive class- See Also:
- Constant Field Values
-
PRIMITIVE_CLASSES
private static final java.lang.String[] PRIMITIVE_CLASSES
the list of primitive types. The order is important and must correlate with getPrimitiveClass.- See Also:
ReplacementForClass#getPrimitiveClass(String)
-
structTypes
private final java.util.Map<java.lang.Object,TypeManager.StructType> structTypes
-
blockTypes
private final java.util.Map<TypeManager.BlockType,TypeManager.BlockType> blockTypes
-
typeIndexCounter
private int typeIndexCounter
-
isFinish
private boolean isFinish
-
options
final WasmOptions options
-
typeTableOffset
private int typeTableOffset
-
classFileLoader
private ClassFileLoader classFileLoader
-
-
Constructor Detail
-
TypeManager
TypeManager(WasmOptions options)
Initialize the type manager.- Parameters:
options- compiler properties
-
-
Method Detail
-
init
void init(ClassFileLoader classFileLoader)
Initialize the type manager- Parameters:
classFileLoader- for loading the class files
-
size
public int size()
Count of used types- Returns:
- the count
-
isFinish
boolean isFinish()
If the scan phase is finish- Returns:
- true, if scan phase is finish
-
scanTypeHierarchy
void scanTypeHierarchy() throws java.io.IOExceptionScan the hierarchy of the types.- Throws:
java.io.IOException- if any I/O error occur on loading or writing
-
prepareFinish
void prepareFinish(ModuleWriter writer) throws java.io.IOException
Finish the prepare and write the types. Now no new types and functions should be added.- Parameters:
writer- the targets for the types- Throws:
java.io.IOException- if any I/O error occur on loading or writing
-
getTypeTableMemoryOffsetFunctionName
WatCodeSyntheticFunctionName getTypeTableMemoryOffsetFunctionName()
Create an accessor for typeTableOffset and mark it.- Returns:
- the function name
-
getClassConstantFunction
@Nonnull FunctionName getClassConstantFunction()
Get the function name to get a constant class.- Returns:
- the function
-
checkStructTypesState
private void checkStructTypesState(java.lang.Object newType)
Check the internal state of the manager and create initial classes.- Parameters:
newType- the requested type for debug output
-
valueOf
@Nonnull public TypeManager.StructType valueOf(java.lang.String name)
Get the StructType. If needed an instance is created.- Parameters:
name- the type name like java/lang/Object- Returns:
- the struct type
-
arrayType
@Nonnull public ArrayType arrayType(AnyType arrayType)
Get the array type for the given component type.- Parameters:
arrayType- the component type of the array- Returns:
- the array type
-
lambdaType
TypeManager.LambdaType lambdaType(@Nonnull BootstrapMethod method, java.util.ArrayList<AnyType> params, TypeManager.StructType interfaceType, java.lang.String interfaceMethodName)
Create a lambda type- Parameters:
method- the name BootstrapMethod from the parsed class fileparams- the parameters of the constructor and type fieldsinterfaceType- the implemented interfaceinterfaceMethodName- the name of the implemented method in the interface- Returns:
- the type
-
blockType
@Nonnull TypeManager.BlockType blockType(java.util.List<AnyType> params, java.util.List<AnyType> results)
Create block type- Parameters:
params- the parametersresults- the results- Returns:
- the type
-
createCallVirtual
@Nonnull WatCodeSyntheticFunctionName createCallVirtual()
Create the FunctionName for a virtual call. The function has 2 parameters (THIS, virtualfunctionIndex) and returns the index of the function.- Returns:
- the name
-
createCallInterface
@Nonnull WatCodeSyntheticFunctionName createCallInterface()
Create the FunctionName for a interface call. The function has 3 parameters (THIS,classIndex, virtualfunctionIndex) and returns the index of the function.- Returns:
- the name
-
createInstanceOf
WatCodeSyntheticFunctionName createInstanceOf()
Create the FunctionName for the INSTANCEOF operation and mark it as used. The function has 2 parameters (THIS, classIndex) and returns true if there is a match.- Returns:
- the name
-
createCast
WatCodeSyntheticFunctionName createCast()
Create the FunctionName for the CAST operation and mark it as used. The function has 2 parameters (THIS, classIndex) and returns this if the type match else it throw an exception.- Returns:
- the name
-
-