mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Modify LivenessAnaylizer to not rely on dominator tree. Fix possible
name clash between virtual methods and fields. Remove tests incompatible between JDK7 and JDK8
This commit is contained in:
parent
e3775890fa
commit
0e3fb1f3d2
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.codegen;
|
package org.teavm.codegen;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import org.teavm.model.FieldReference;
|
import org.teavm.model.FieldReference;
|
||||||
import org.teavm.model.MethodDescriptor;
|
import org.teavm.model.MethodDescriptor;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
@ -26,6 +28,7 @@ import org.teavm.model.MethodReference;
|
||||||
public class DefaultAliasProvider implements AliasProvider {
|
public class DefaultAliasProvider implements AliasProvider {
|
||||||
private int lastSuffix;
|
private int lastSuffix;
|
||||||
private int lastVirtualSuffix;
|
private int lastVirtualSuffix;
|
||||||
|
private Set<String> usedAliases = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlias(String cls) {
|
public String getAlias(String cls) {
|
||||||
|
@ -58,7 +61,11 @@ public class DefaultAliasProvider implements AliasProvider {
|
||||||
} else if (alias.equals("<clinit>")) {
|
} else if (alias.equals("<clinit>")) {
|
||||||
alias = "$clinit";
|
alias = "$clinit";
|
||||||
}
|
}
|
||||||
return alias + lastVirtualSuffix++;
|
String result;
|
||||||
|
do {
|
||||||
|
result = alias + lastVirtualSuffix++;
|
||||||
|
} while (!usedAliases.add(result));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,7 +81,11 @@ public class DefaultAliasProvider implements AliasProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlias(FieldReference field) {
|
public String getAlias(FieldReference field) {
|
||||||
return field.getFieldName() + (lastSuffix++);
|
String result;
|
||||||
|
do {
|
||||||
|
result = field.getFieldName() + lastSuffix++;
|
||||||
|
} while (!usedAliases.add(result));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.codegen;
|
package org.teavm.codegen;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import org.teavm.model.FieldReference;
|
import org.teavm.model.FieldReference;
|
||||||
import org.teavm.model.MethodDescriptor;
|
import org.teavm.model.MethodDescriptor;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
@ -29,10 +31,15 @@ public class MinifyingAliasProvider implements AliasProvider {
|
||||||
private static String startVirtualLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
private static String startVirtualLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
private int lastSuffix;
|
private int lastSuffix;
|
||||||
private int lastVirtual;
|
private int lastVirtual;
|
||||||
|
private Set<String> usedAliases = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlias(FieldReference field) {
|
public String getAlias(FieldReference field) {
|
||||||
return getNewAlias(lastVirtual++, startVirtualLetters);
|
String result;
|
||||||
|
do {
|
||||||
|
result = getNewAlias(lastVirtual++, startVirtualLetters);
|
||||||
|
} while (!usedAliases.add(result));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,7 +49,11 @@ public class MinifyingAliasProvider implements AliasProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAlias(MethodDescriptor method) {
|
public String getAlias(MethodDescriptor method) {
|
||||||
return getNewAlias(lastVirtual++, startVirtualLetters);
|
String result;
|
||||||
|
do {
|
||||||
|
result = getNewAlias(lastVirtual++, startVirtualLetters);
|
||||||
|
} while (!usedAliases.add(result));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.util.ArrayDeque;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import org.teavm.common.Graph;
|
import org.teavm.common.Graph;
|
||||||
import org.teavm.common.GraphUtils;
|
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,8 +27,6 @@ import org.teavm.model.*;
|
||||||
*/
|
*/
|
||||||
public class LivenessAnalyzer {
|
public class LivenessAnalyzer {
|
||||||
private BitSet[] liveVars;
|
private BitSet[] liveVars;
|
||||||
private int[] domLeft;
|
|
||||||
private int[] domRight;
|
|
||||||
|
|
||||||
public boolean liveIn(int block, int var) {
|
public boolean liveIn(int block, int var) {
|
||||||
return liveVars[block].get(var);
|
return liveVars[block].get(var);
|
||||||
|
@ -41,7 +38,6 @@ public class LivenessAnalyzer {
|
||||||
|
|
||||||
public void analyze(Program program) {
|
public void analyze(Program program) {
|
||||||
Graph cfg = ProgramUtils.buildControlFlowGraph(program);
|
Graph cfg = ProgramUtils.buildControlFlowGraph(program);
|
||||||
computeDomLeftRight(GraphUtils.buildDominatorGraph(GraphUtils.buildDominatorTree(cfg), cfg.size()));
|
|
||||||
liveVars = new BitSet[cfg.size()];
|
liveVars = new BitSet[cfg.size()];
|
||||||
for (int i = 0; i < liveVars.length; ++i) {
|
for (int i = 0; i < liveVars.length; ++i) {
|
||||||
liveVars[i] = new BitSet(program.basicBlockCount());
|
liveVars[i] = new BitSet(program.basicBlockCount());
|
||||||
|
@ -84,7 +80,7 @@ public class LivenessAnalyzer {
|
||||||
|
|
||||||
while (!stack.isEmpty()) {
|
while (!stack.isEmpty()) {
|
||||||
Task task = stack.pop();
|
Task task = stack.pop();
|
||||||
if (liveVars[task.block].get(task.var) || !dominates(definitions[task.var], task.block)) {
|
if (liveVars[task.block].get(task.var) || definitions[task.var] == task.block) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
liveVars[task.block].set(task.var, true);
|
liveVars[task.block].set(task.var, true);
|
||||||
|
@ -97,35 +93,6 @@ public class LivenessAnalyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void computeDomLeftRight(Graph domGraph) {
|
|
||||||
domLeft = new int[domGraph.size()];
|
|
||||||
domRight = new int[domGraph.size()];
|
|
||||||
int index = 1;
|
|
||||||
int[] stack = new int[domGraph.size() * 2];
|
|
||||||
int top = 0;
|
|
||||||
for (int i = domGraph.size() - 1; i >= 0; --i) {
|
|
||||||
if (domGraph.incomingEdgesCount(i) == 0) {
|
|
||||||
stack[top++] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (top > 0) {
|
|
||||||
int v = stack[--top];
|
|
||||||
if (domLeft[v] == 0) {
|
|
||||||
domLeft[v] = index++;
|
|
||||||
stack[top++] = v;
|
|
||||||
for (int succ : domGraph.outgoingEdges(v)) {
|
|
||||||
stack[top++] = succ;
|
|
||||||
}
|
|
||||||
} else if (domRight[v] == 0) {
|
|
||||||
domRight[v] = index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean dominates(int a, int b) {
|
|
||||||
return domLeft[a] < domLeft[b] && domRight[a] > domRight[b];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Task {
|
private static class Task {
|
||||||
int block;
|
int block;
|
||||||
int var;
|
int var;
|
||||||
|
|
|
@ -93,25 +93,6 @@ public class UTF8Test {
|
||||||
assertEquals("a\uFFFDbb", new String(result));
|
assertEquals("a\uFFFDbb", new String(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void replaceDecodedSurrogate() {
|
|
||||||
Charset charset = Charset.forName("UTF-8");
|
|
||||||
CharBuffer buffer = charset.decode(ByteBuffer.wrap(new byte[] { 97, (byte)0xED, (byte)0xA0, (byte)0x80, 98 }));
|
|
||||||
char[] result = new char[buffer.remaining()];
|
|
||||||
buffer.get(result);
|
|
||||||
assertEquals("a\uFFFDb", new String(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void replaceDecodedSurrogatePair() {
|
|
||||||
Charset charset = Charset.forName("UTF-8");
|
|
||||||
CharBuffer buffer = charset.decode(ByteBuffer.wrap(new byte[] { 97, (byte)0xED, (byte)0xA0, (byte)0x80,
|
|
||||||
(byte)0xED, (byte)0xBF, (byte)0xBF, 98 }));
|
|
||||||
char[] result = new char[buffer.remaining()];
|
|
||||||
buffer.get(result);
|
|
||||||
assertEquals("a\uFFFD\uFFFDb", new String(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decodeLongUTF8ByteArray() throws UnsupportedEncodingException {
|
public void decodeLongUTF8ByteArray() throws UnsupportedEncodingException {
|
||||||
byte[] bytes = new byte[16384];
|
byte[] bytes = new byte[16384];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user