diff --git a/src/de/inetsoftware/jwebassembly/module/FunctionManager.java b/src/de/inetsoftware/jwebassembly/module/FunctionManager.java index 8b6306e..5d58408 100644 --- a/src/de/inetsoftware/jwebassembly/module/FunctionManager.java +++ b/src/de/inetsoftware/jwebassembly/module/FunctionManager.java @@ -124,6 +124,21 @@ class FunctionManager { getOrCreate( name ).state = State.Written; } + /** + * Same like markAsNeeded but it will replace the function name if already registered. + * + * @param name + * the function name + */ + void markAsNeededAndReplaceIfExists( SyntheticFunctionName name ) { + FunctionState state = states.get( name ); + if( state != null ) { + states.remove( name ); + states.put( name, state ); + } + markAsNeeded( name ); + } + /** * Mark a function as used/called and return the real name if there is an alias. * diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index fc05c78..fba8c2e 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -474,6 +474,7 @@ public class ModuleGenerator { } 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 ); } throw new WasmException( "Abstract or native method can not be used: " + name.signatureName, -1 ); diff --git a/src/de/inetsoftware/jwebassembly/module/StringManager.java b/src/de/inetsoftware/jwebassembly/module/StringManager.java index 143894b..09b2a7e 100644 --- a/src/de/inetsoftware/jwebassembly/module/StringManager.java +++ b/src/de/inetsoftware/jwebassembly/module/StringManager.java @@ -83,13 +83,13 @@ public class StringManager extends LinkedHashMap { if( stringMemoryOffset < 0 ) { // register the function stringsMemoryOffset() as synthetic function stringMemoryOffset = 0; - FunctionName offsetFunction = + WatCodeSyntheticFunctionName offsetFunction = new WatCodeSyntheticFunctionName( "de/inetsoftware/jwebassembly/module/StringManager", "stringsMemoryOffset", "()I", "", null, ValueType.i32 ) { protected String getCode() { return "i32.const " + stringMemoryOffset; } }; - functions.markAsNeeded( offsetFunction ); + functions.markAsNeededAndReplaceIfExists( offsetFunction ); } return STRING_CONSTANT_FUNCTION;