diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index 2ec7710..b399a87 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -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 ); diff --git a/src/de/inetsoftware/jwebassembly/module/StringManager.java b/src/de/inetsoftware/jwebassembly/module/StringManager.java index 8e98bac..af785a0 100644 --- a/src/de/inetsoftware/jwebassembly/module/StringManager.java +++ b/src/de/inetsoftware/jwebassembly/module/StringManager.java @@ -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 { return "i32.const " + stringMemoryOffset; } }; - functions.markAsNeededAndReplaceIfExists( offsetFunction ); - functions.markAsNeeded( stringConstantFunction, false ); + functions.addReplacement( offsetFunction, null ); } return stringConstantFunction; diff --git a/src/de/inetsoftware/jwebassembly/module/TypeManager.java b/src/de/inetsoftware/jwebassembly/module/TypeManager.java index c49a14b..7d78eff 100644 --- a/src/de/inetsoftware/jwebassembly/module/TypeManager.java +++ b/src/de/inetsoftware/jwebassembly/module/TypeManager.java @@ -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; } diff --git a/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java b/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java index 6213229..7dff105 100644 --- a/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java +++ b/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java @@ -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 the type of the class modeled by this {@code Class} * @author Volker Berlin */ -@Replace( "java/lang/Class" ) +@Partial( "java/lang/Class" ) class ReplacementForClass { /** @@ -56,6 +57,8 @@ class ReplacementForClass { final int classIdx; + private static void registerNatives() {} + /** * Create a instance *