Use @Partial for ReplacementForClass

This commit is contained in:
Volker Berlin 2022-07-17 19:54:05 +02:00
parent 94be918c36
commit 3e5d966548
No known key found for this signature in database
GPG Key ID: 988423EF815BE4CB
4 changed files with 11 additions and 15 deletions

View File

@ -114,6 +114,10 @@ public class ModuleGenerator {
staticCodeBuilder = new StaticCodeBuilder( writer.options, classFileLoader, javaCodeBuilder );
scanLibraries( libraries );
//register some synthetic functions
strings.getStringConstantFunction();
types.getTypeTableMemoryOffsetFunctionName();
}
/**
@ -594,14 +598,6 @@ public class ModuleGenerator {
return null;
} else {
FunctionName name = new FunctionName( method );
if( "java/lang/Class.typeTableMemoryOffset()I".equals( name.signatureName ) ) {
strings.getStringConstantFunction(); // we will need also the string constant function for the Class Name, in the other case a program with only new Object().getClass().getName() will fail to compile
return types.getTypeTableMemoryOffsetFunctionName().getCodeBuilder( watParser );
}
if( "de/inetsoftware/jwebassembly/module/StringManager.stringsMemoryOffset()I".equals( name.signatureName ) ) {
strings.getStringConstantFunction();
return null;
}
if( writer.options.ignoreNative() ) {
JWebAssembly.LOGGER.severe( "Native method will throw an exception at runtime: " + name.signatureName );

View File

@ -1,5 +1,5 @@
/*
Copyright 2019 - 2021 Volker Berlin (i-net software)
Copyright 2019 - 2022 Volker Berlin (i-net software)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -25,7 +25,6 @@ import java.util.LinkedHashMap;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import de.inetsoftware.jwebassembly.api.annotation.WasmTextCode;
import de.inetsoftware.jwebassembly.wasm.ValueType;
/**
@ -83,8 +82,7 @@ public class StringManager extends LinkedHashMap<String, Integer> {
return "i32.const " + stringMemoryOffset;
}
};
functions.markAsNeededAndReplaceIfExists( offsetFunction );
functions.markAsNeeded( stringConstantFunction, false );
functions.addReplacement( offsetFunction, null );
}
return stringConstantFunction;

View File

@ -22,7 +22,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -268,7 +267,7 @@ public class TypeManager {
return "i32.const " + typeTableOffset;
}
};
options.functions.markAsNeeded( offsetFunction, !offsetFunction.istStatic() );
options.functions.addReplacement( offsetFunction, null );
return offsetFunction;
}

View File

@ -36,6 +36,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import de.inetsoftware.jwebassembly.api.annotation.Partial;
import de.inetsoftware.jwebassembly.api.annotation.Replace;
import de.inetsoftware.jwebassembly.api.annotation.WasmTextCode;
import de.inetsoftware.jwebassembly.module.TypeManager;
@ -46,7 +47,7 @@ import de.inetsoftware.jwebassembly.module.TypeManager;
* @param <T> the type of the class modeled by this {@code Class}
* @author Volker Berlin
*/
@Replace( "java/lang/Class" )
@Partial( "java/lang/Class" )
class ReplacementForClass<T> {
/**
@ -56,6 +57,8 @@ class ReplacementForClass<T> {
final int classIdx;
private static void registerNatives() {}
/**
* Create a instance
*