Class replacement need also StringManager.stringsMemoryOffset.

This commit is contained in:
Volker Berlin 2020-03-15 12:00:15 +01:00
parent d3e3c4ff5d
commit 386c5adf28
3 changed files with 18 additions and 2 deletions

View File

@ -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.
*

View File

@ -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 );

View File

@ -83,13 +83,13 @@ public class StringManager extends LinkedHashMap<String, Integer> {
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;