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:
Alexey Andreev 2015-03-27 15:42:47 +04:00
parent e3775890fa
commit 0e3fb1f3d2
4 changed files with 27 additions and 57 deletions

View File

@ -15,6 +15,8 @@
*/
package org.teavm.codegen;
import java.util.HashSet;
import java.util.Set;
import org.teavm.model.FieldReference;
import org.teavm.model.MethodDescriptor;
import org.teavm.model.MethodReference;
@ -26,6 +28,7 @@ import org.teavm.model.MethodReference;
public class DefaultAliasProvider implements AliasProvider {
private int lastSuffix;
private int lastVirtualSuffix;
private Set<String> usedAliases = new HashSet<>();
@Override
public String getAlias(String cls) {
@ -58,7 +61,11 @@ public class DefaultAliasProvider implements AliasProvider {
} else if (alias.equals("<clinit>")) {
alias = "$clinit";
}
return alias + lastVirtualSuffix++;
String result;
do {
result = alias + lastVirtualSuffix++;
} while (!usedAliases.add(result));
return result;
}
@Override
@ -74,7 +81,11 @@ public class DefaultAliasProvider implements AliasProvider {
@Override
public String getAlias(FieldReference field) {
return field.getFieldName() + (lastSuffix++);
String result;
do {
result = field.getFieldName() + lastSuffix++;
} while (!usedAliases.add(result));
return result;
}
@Override

View File

@ -15,6 +15,8 @@
*/
package org.teavm.codegen;
import java.util.HashSet;
import java.util.Set;
import org.teavm.model.FieldReference;
import org.teavm.model.MethodDescriptor;
import org.teavm.model.MethodReference;
@ -29,10 +31,15 @@ public class MinifyingAliasProvider implements AliasProvider {
private static String startVirtualLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private int lastSuffix;
private int lastVirtual;
private Set<String> usedAliases = new HashSet<>();
@Override
public String getAlias(FieldReference field) {
return getNewAlias(lastVirtual++, startVirtualLetters);
String result;
do {
result = getNewAlias(lastVirtual++, startVirtualLetters);
} while (!usedAliases.add(result));
return result;
}
@Override
@ -42,7 +49,11 @@ public class MinifyingAliasProvider implements AliasProvider {
@Override
public String getAlias(MethodDescriptor method) {
return getNewAlias(lastVirtual++, startVirtualLetters);
String result;
do {
result = getNewAlias(lastVirtual++, startVirtualLetters);
} while (!usedAliases.add(result));
return result;
}
@Override

View File

@ -19,7 +19,6 @@ import java.util.ArrayDeque;
import java.util.BitSet;
import java.util.Deque;
import org.teavm.common.Graph;
import org.teavm.common.GraphUtils;
import org.teavm.model.*;
/**
@ -28,8 +27,6 @@ import org.teavm.model.*;
*/
public class LivenessAnalyzer {
private BitSet[] liveVars;
private int[] domLeft;
private int[] domRight;
public boolean liveIn(int block, int var) {
return liveVars[block].get(var);
@ -41,7 +38,6 @@ public class LivenessAnalyzer {
public void analyze(Program program) {
Graph cfg = ProgramUtils.buildControlFlowGraph(program);
computeDomLeftRight(GraphUtils.buildDominatorGraph(GraphUtils.buildDominatorTree(cfg), cfg.size()));
liveVars = new BitSet[cfg.size()];
for (int i = 0; i < liveVars.length; ++i) {
liveVars[i] = new BitSet(program.basicBlockCount());
@ -84,7 +80,7 @@ public class LivenessAnalyzer {
while (!stack.isEmpty()) {
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;
}
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 {
int block;
int var;

View File

@ -93,25 +93,6 @@ public class UTF8Test {
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
public void decodeLongUTF8ByteArray() throws UnsupportedEncodingException {
byte[] bytes = new byte[16384];