declare the native array type with GC enabled

This commit is contained in:
Volker Berlin 2020-12-27 17:39:35 +01:00
parent 6b6e6843cb
commit c96b27a12e
3 changed files with 60 additions and 18 deletions

View File

@ -345,7 +345,11 @@ public class TypeManager {
componentClassIndex = ((StructType)arrayType).classIndex; componentClassIndex = ((StructType)arrayType).classIndex;
} }
type = new ArrayType( arrayType, this, componentClassIndex ); type = new ArrayType( arrayType, this, componentClassIndex, options );
if( options.useGC() ) {
StructType nativeArrayType = (StructType)type.getNativeArrayType();
structTypes.put( nativeArrayType.getName(), nativeArrayType );
}
structTypes.put( arrayType, type ); structTypes.put( arrayType, type );
} }
return type; return type;
@ -584,17 +588,24 @@ public class TypeManager {
instanceOFs = new LinkedHashSet<>(); // remembers the order from bottom to top class. instanceOFs = new LinkedHashSet<>(); // remembers the order from bottom to top class.
instanceOFs.add( this ); instanceOFs.add( this );
interfaceMethods = new LinkedHashMap<>(); interfaceMethods = new LinkedHashMap<>();
if( classIndex < PRIMITIVE_CLASSES.length ) { switch( kind ) {
// nothing case primitive:
} else if( this instanceof ArrayType ) { // nothing
HashSet<String> allNeededFields = new HashSet<>(); break;
listStructFields( "java/lang/Object", functions, types, classFileLoader, allNeededFields ); case array:
} else { HashSet<String> allNeededFields = new HashSet<>();
// add all interfaces to the instanceof set listStructFields( "java/lang/Object", functions, types, classFileLoader, allNeededFields );
listInterfaces( functions, types, classFileLoader ); fields.add( new NamedStorageType( ((ArrayType)this).getNativeArrayType(), null, FIELD_VALUE ) );
break;
case array_native:
fields.add( new NamedStorageType( ((ArrayType)this).getArrayType(), null, null ) );
break;
default:
// add all interfaces to the instanceof set
listInterfaces( functions, types, classFileLoader );
HashSet<String> allNeededFields = new HashSet<>(); allNeededFields = new HashSet<>();
listStructFields( name, functions, types, classFileLoader, allNeededFields ); listStructFields( name, functions, types, classFileLoader, allNeededFields );
} }
} }
@ -661,9 +672,6 @@ public class TypeManager {
} else { } else {
fields.add( new NamedStorageType( ValueType.i32, className, FIELD_VTABLE ) ); fields.add( new NamedStorageType( ValueType.i32, className, FIELD_VTABLE ) );
fields.add( new NamedStorageType( ValueType.i32, className, FIELD_HASHCODE ) ); fields.add( new NamedStorageType( ValueType.i32, className, FIELD_HASHCODE ) );
if( getComponentClassIndex() >= 0 ) {
fields.add( new NamedStorageType( this, className, FIELD_VALUE ) );
}
} }
// list all fields // list all fields

View File

@ -207,7 +207,8 @@ public class TextModuleWriter extends ModuleWriter {
inset = 1; inset = 1;
newline( output ); newline( output );
String typeName = normalizeName( type.getName() ); String typeName = normalizeName( type.getName() );
output.append( "(type $" ).append( typeName ).append( " (struct" ); String kind = type.getKind() == StructTypeKind.array_native ? "array" : "struct";
output.append( "(type $" ).append( typeName ).append( " (" ).append( kind );
inset++; inset++;
for( NamedStorageType field : type.getFields() ) { for( NamedStorageType field : type.getFields() ) {
newline( output ); newline( output );

View File

@ -19,6 +19,7 @@ import javax.annotation.Nonnull;
import de.inetsoftware.jwebassembly.WasmException; import de.inetsoftware.jwebassembly.WasmException;
import de.inetsoftware.jwebassembly.module.TypeManager; import de.inetsoftware.jwebassembly.module.TypeManager;
import de.inetsoftware.jwebassembly.module.WasmOptions;
import de.inetsoftware.jwebassembly.module.TypeManager.StructType; import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind; import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind;
@ -32,6 +33,8 @@ public class ArrayType extends StructType {
private AnyType arrayType; private AnyType arrayType;
private AnyType nativeArrayType;
private int componentClassIndex; private int componentClassIndex;
/** /**
@ -43,11 +46,36 @@ public class ArrayType extends StructType {
* the manager which hold all StructTypes * the manager which hold all StructTypes
* @param componentClassIndex * @param componentClassIndex
* the running index of the component/array class/type * the running index of the component/array class/type
* @param options
* compiler properties
*/ */
public ArrayType( AnyType arrayType, @Nonnull TypeManager manager, int componentClassIndex ) { public ArrayType( AnyType arrayType, @Nonnull TypeManager manager, int componentClassIndex, WasmOptions options ) {
super( getJavaClassName( arrayType ), StructTypeKind.array, manager ); this( getJavaClassName( arrayType ), StructTypeKind.array, manager, arrayType );
this.arrayType = arrayType;
this.componentClassIndex = componentClassIndex; this.componentClassIndex = componentClassIndex;
if( options.useGC() ) {
String nativeName = '_' + getName();
this.nativeArrayType = new ArrayType( nativeName, StructTypeKind.array_native, manager, arrayType );
//structTypes.put( name, nativeArrayType );
} else {
this.nativeArrayType = arrayType;
}
}
/**
* Create a new instance
*
* @param name
* the type name
* @param kind
* the kind, array or array_native
* @param manager
* the manager which hold all StructTypes
* @param arrayType
* the type of the array
*/
private ArrayType( @Nonnull String name, @Nonnull StructTypeKind kind, @Nonnull TypeManager manager, AnyType arrayType ) {
super( name, kind, manager );
this.arrayType = arrayType;
} }
/** /**
@ -57,6 +85,7 @@ public class ArrayType extends StructType {
* the type of the array * the type of the array
* @return the name * @return the name
*/ */
@Nonnull
private static String getJavaClassName( AnyType arrayType ) { private static String getJavaClassName( AnyType arrayType ) {
if( !arrayType.isRefType() ) { if( !arrayType.isRefType() ) {
switch( (ValueType)arrayType ) { switch( (ValueType)arrayType ) {
@ -97,6 +126,10 @@ public class ArrayType extends StructType {
return arrayType; return arrayType;
} }
public AnyType getNativeArrayType() {
return nativeArrayType;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */