mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
improve java.lang.Class replacement, WIP
This commit is contained in:
parent
3989070fe0
commit
259a7130f1
@ -473,7 +473,7 @@ public class ModuleGenerator {
|
||||
return javaCodeBuilder;
|
||||
} else {
|
||||
FunctionName name = new FunctionName( method );
|
||||
if( "de/inetsoftware/jwebassembly/module/ReplacementForClass.typeTableMemoryOffset()I".equals( name.signatureName ) ) {
|
||||
if( "java/lang/Class.typeTableMemoryOffset()I".equals( name.signatureName ) ) {
|
||||
return types.getTypeTableMemoryOffsetFunctionName().getCodeBuilder( watParser );
|
||||
}
|
||||
throw new WasmException( "Abstract or native method can not be used: " + name.signatureName, -1 );
|
||||
|
@ -57,7 +57,14 @@ class ReplacementForClass {
|
||||
*/
|
||||
@WasmTextCode( "local.get 0 " // THIS
|
||||
+ "struct.get java/lang/Object .vtable " // vtable is on index 0
|
||||
+ "call $de/inetsoftware/jwebassembly/module/ReplacementForClass.classConstant(I)Lde/inetsoftware/jwebassembly/module/ReplacementForClass; " //
|
||||
+ "local.tee 1 " // save the vtable location
|
||||
+ "i32.const " + TypeManager.TYPE_DESCRIPTION_INSTANCEOF_OFFSET + " " // vtable is on index 0
|
||||
+ "i32.add " //
|
||||
+ "call $java/lang/Class.getIntFromMemory(I)I " //
|
||||
+ "local.get 1 " // get the vtable location
|
||||
+ "i32.add " //
|
||||
+ "call $java/lang/Class.getIntFromMemory(I)I " //
|
||||
+ "call $java/lang/Class.classConstant(I)Lde/inetsoftware/jwebassembly/module/ReplacementForClass; " //
|
||||
+ "return " //
|
||||
)
|
||||
@Replace( "java/lang/Object.getClass()Ljava/lang/Class;" )
|
||||
@ -122,7 +129,7 @@ class ReplacementForClass {
|
||||
*/
|
||||
@WasmTextCode( "local.get 0 " + //
|
||||
"local.get 1 " + //
|
||||
"table.set 2 " + //
|
||||
"table.set 2 " + // table 2 is used for classes
|
||||
"return" )
|
||||
private static native void setClassIntoTable( int strIdx, ReplacementForClass clazz );
|
||||
|
||||
|
@ -127,10 +127,11 @@ public class TypeManager {
|
||||
}
|
||||
|
||||
// write type table
|
||||
ByteArrayOutputStream dataStream = writer.dataStream;
|
||||
typeTableOffset = dataStream.size();
|
||||
@SuppressWarnings( "resource" )
|
||||
LittleEndianOutputStream dataStream = new LittleEndianOutputStream( writer.dataStream );
|
||||
typeTableOffset = writer.dataStream.size();
|
||||
for( StructType type : structTypes.values() ) {
|
||||
dataStream.write( type.vtableOffset );
|
||||
dataStream.writeInt32( type.vtableOffset );
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +142,7 @@ public class TypeManager {
|
||||
*/
|
||||
WatCodeSyntheticFunctionName getTypeTableMemoryOffsetFunctionName() {
|
||||
WatCodeSyntheticFunctionName offsetFunction =
|
||||
new WatCodeSyntheticFunctionName( "de/inetsoftware/jwebassembly/module/ReplacementForClass", "typeTableMemoryOffset", "()I", "", null, ValueType.i32 ) {
|
||||
new WatCodeSyntheticFunctionName( "java/lang/Class", "typeTableMemoryOffset", "()I", "", null, ValueType.i32 ) {
|
||||
protected String getCode() {
|
||||
return "i32.const " + typeTableOffset;
|
||||
}
|
||||
@ -219,7 +220,7 @@ public class TypeManager {
|
||||
"instanceof", "local.get 0 " // THIS
|
||||
+ "struct.get java/lang/Object .vtable " // vtable is on index 0
|
||||
+ "local.tee 2 " // save the vtable location
|
||||
+ "i32.load offset=4 align=4 " // get offset of instanceof inside vtable (int position 1, byte position 4)
|
||||
+ "i32.load offset=" + TYPE_DESCRIPTION_INSTANCEOF_OFFSET + " align=4 " // get offset of instanceof inside vtable (int position 1, byte position 4)
|
||||
+ "local.get 2 " // get the vtable location
|
||||
+ "i32.add " //
|
||||
+ "local.tee 2 " // save the instanceof location
|
||||
|
Loading…
x
Reference in New Issue
Block a user