mirror of
https://github.com/konsoletyper/teavm.git
synced 2025-02-11 11:09:44 +08:00
Fix bugs in register allocator
This commit is contained in:
parent
fae2963900
commit
e92ad161ef
@ -47,6 +47,7 @@ import org.teavm.model.classes.VirtualTable;
|
||||
import org.teavm.model.classes.VirtualTableEntry;
|
||||
import org.teavm.model.classes.VirtualTableProvider;
|
||||
import org.teavm.runtime.RuntimeClass;
|
||||
import org.teavm.runtime.RuntimeObject;
|
||||
|
||||
public class WasmClassGenerator {
|
||||
private ClassReaderSource classSource;
|
||||
@ -425,7 +426,7 @@ public class WasmClassGenerator {
|
||||
public void postProcess() {
|
||||
ClassBinaryData classClassData = binaryDataMap.get(ValueType.object("java.lang.Class"));
|
||||
if (classClassData != null) {
|
||||
int tag = classClassData.start >> 3;
|
||||
int tag = (classClassData.start >> 3) | RuntimeObject.GC_MARKED;
|
||||
for (ClassBinaryData classData : binaryDataMap.values()) {
|
||||
if (classData.data != null) {
|
||||
classData.data.getValue(0).setInt(0, tag);
|
||||
|
@ -23,6 +23,7 @@ import org.teavm.backend.wasm.binary.DataPrimitives;
|
||||
import org.teavm.backend.wasm.binary.DataStructure;
|
||||
import org.teavm.backend.wasm.binary.DataValue;
|
||||
import org.teavm.model.ValueType;
|
||||
import org.teavm.runtime.RuntimeObject;
|
||||
|
||||
public class WasmStringPool {
|
||||
private WasmClassGenerator classGenerator;
|
||||
@ -51,7 +52,8 @@ public class WasmStringPool {
|
||||
DataValue header = wrapper.getValue(0);
|
||||
DataValue characters = wrapper.getValue(1);
|
||||
|
||||
header.setInt(0, classGenerator.getClassPointer(ValueType.arrayOf(ValueType.CHARACTER)));
|
||||
int classPointer = classGenerator.getClassPointer(ValueType.arrayOf(ValueType.CHARACTER));
|
||||
header.setInt(0, (classPointer >>> 3) | RuntimeObject.GC_MARKED);
|
||||
header.setInt(2, str.length());
|
||||
for (int i = 0; i < str.length(); ++i) {
|
||||
characters.setShort(i, (short) str.charAt(i));
|
||||
@ -59,7 +61,8 @@ public class WasmStringPool {
|
||||
|
||||
DataValue stringObject = stringType.createValue();
|
||||
int stringPointer = binaryWriter.append(stringObject);
|
||||
stringObject.setInt(0, classGenerator.getClassPointer(ValueType.object(String.class.getName())));
|
||||
classPointer = classGenerator.getClassPointer(ValueType.object(String.class.getName()));
|
||||
stringObject.setInt(0, (classPointer >>> 3) | RuntimeObject.GC_MARKED);
|
||||
stringObject.setAddress(2, binaryWriter.append(wrapper));
|
||||
|
||||
return stringPointer;
|
||||
|
@ -68,30 +68,22 @@ public class RegisterAllocator {
|
||||
}
|
||||
int[] categories = getVariableCategories(program, method.getReference());
|
||||
String[] names = getVariableNames(program);
|
||||
int[] classCategories = new int[maxClass];
|
||||
String[] classNames = new String[maxClass];
|
||||
for (int i = 0; i < categories.length; ++i) {
|
||||
classCategories[classArray[i]] = categories[i];
|
||||
if (names[i] != null) {
|
||||
classNames[classArray[i]] = names[i];
|
||||
}
|
||||
}
|
||||
colorer.colorize(interferenceGraph, colors, classCategories, classNames);
|
||||
colorer.colorize(interferenceGraph, colors, categories, names);
|
||||
|
||||
int maxColor = 0;
|
||||
for (int i = 0; i < colors.length; ++i) {
|
||||
program.variableAt(i).setRegister(colors[i]);
|
||||
maxColor = Math.max(maxClass, colors[i]);
|
||||
maxColor = Math.max(maxColor, colors[i] + 1);
|
||||
}
|
||||
|
||||
String[] namesByRegister = new String[maxColor];
|
||||
for (int i = 0; i < colors.length; ++i) {
|
||||
for (int i = 0; i < program.variableCount(); ++i) {
|
||||
Variable var = program.variableAt(i);
|
||||
if (var.getDebugName() != null && var.getRegister() >= 0) {
|
||||
namesByRegister[var.getRegister()] = classNames[i];
|
||||
namesByRegister[var.getRegister()] = names[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < colors.length; ++i) {
|
||||
for (int i = 0; i < program.variableCount(); ++i) {
|
||||
Variable var = program.variableAt(i);
|
||||
if (var.getRegister() >= 0) {
|
||||
var.setDebugName(namesByRegister[var.getRegister()]);
|
||||
|
Loading…
Reference in New Issue
Block a user