mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Further refactoring of exception handling
This commit is contained in:
parent
a26eed7c51
commit
e82518b88f
|
@ -66,8 +66,8 @@ public class ProgramIO {
|
|||
data.writeInt(tryCatch.getExceptionType() != null ? symbolTable.lookup(
|
||||
tryCatch.getExceptionType()) : -1);
|
||||
data.writeShort(tryCatch.getHandler().getIndex());
|
||||
data.writeShort(tryCatch.getTryCatchJoints().size());
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
data.writeShort(tryCatch.getJoints().size());
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
data.writeShort(joint.getReceiver().getIndex());
|
||||
data.writeShort(joint.getSourceVariables().size());
|
||||
for (Variable sourceVar : joint.getSourceVariables()) {
|
||||
|
@ -152,7 +152,7 @@ public class ProgramIO {
|
|||
for (int m = 0; m < jointSourceCount; ++m) {
|
||||
joint.getSourceVariables().add(program.variableAt(data.readShort()));
|
||||
}
|
||||
tryCatch.getTryCatchJoints().add(joint);
|
||||
tryCatch.getJoints().add(joint);
|
||||
}
|
||||
|
||||
block.getTryCatchBlocks().add(tryCatch);
|
||||
|
|
|
@ -65,7 +65,7 @@ public class DataFlowGraphBuilder implements InstructionReader {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readTryCatchJoints()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readJoints()) {
|
||||
for (VariableReader sourceVar : joint.readSourceVariables()) {
|
||||
builder.addEdge(sourceVar.getIndex(), joint.getReceiver().getIndex());
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ class DependencyGraphBuilder {
|
|||
dependencyChecker.linkClass(tryCatch.getExceptionType(), new CallLocation(caller.getMethod()));
|
||||
}
|
||||
|
||||
for (TryCatchJointReader joint : tryCatch.readTryCatchJoints()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readJoints()) {
|
||||
DependencyNode receiverNode = nodes[joint.getReceiver().getIndex()];
|
||||
if (receiverNode == null) {
|
||||
continue;
|
||||
|
@ -289,7 +289,9 @@ class DependencyGraphBuilder {
|
|||
if (tryCatch.getExceptionType() != null) {
|
||||
exceptions[i] = dependencyChecker.getClassSource().get(tryCatch.getExceptionType());
|
||||
}
|
||||
vars[i] = methodDep.getVariable(tryCatch.getHandler().getExceptionVariable().getIndex());
|
||||
if (tryCatch.getHandler().getExceptionVariable() != null) {
|
||||
vars[i] = methodDep.getVariable(tryCatch.getHandler().getExceptionVariable().getIndex());
|
||||
}
|
||||
}
|
||||
return new ExceptionConsumer(dependencyChecker, exceptions, vars, methodDep);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class ReadWriteStatsBuilder {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
writes[joint.getReceiver().getIndex()] += joint.getSourceVariables().size();
|
||||
for (Variable var : joint.getSourceVariables()) {
|
||||
reads[var.getIndex()]++;
|
||||
|
|
|
@ -111,6 +111,9 @@ public class Program implements ProgramReader {
|
|||
|
||||
@Override
|
||||
public Variable variableAt(int index) {
|
||||
if (index < 0) {
|
||||
throw new IllegalArgumentException("Index " + index + " is negative");
|
||||
}
|
||||
return variables.get(index);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,12 +97,12 @@ public class TryCatchBlock implements TryCatchBlockReader {
|
|||
return protectedBlock;
|
||||
}
|
||||
|
||||
public List<TryCatchJoint> getTryCatchJoints() {
|
||||
public List<TryCatchJoint> getJoints() {
|
||||
return safeJoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TryCatchJointReader> readTryCatchJoints() {
|
||||
public List<TryCatchJointReader> readJoints() {
|
||||
if (immutableJoints == null) {
|
||||
immutableJoints = Collections.unmodifiableList(safeJoints);
|
||||
}
|
||||
|
|
|
@ -24,5 +24,5 @@ public interface TryCatchBlockReader {
|
|||
|
||||
String getExceptionType();
|
||||
|
||||
List<TryCatchJointReader> readTryCatchJoints();
|
||||
List<TryCatchJointReader> readJoints();
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class InstructionVariableMapper implements InstructionVisitor {
|
|||
|
||||
public void applyToTryCatchBlocks(BasicBlock block) {
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
joint.setReceiver(map(joint.getReceiver()));
|
||||
for (int i = 0; i < joint.getSourceVariables().size(); ++i) {
|
||||
Variable var = joint.getSourceVariables().get(i);
|
||||
|
|
|
@ -53,7 +53,7 @@ class InterferenceGraphBuilder {
|
|||
}
|
||||
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
for (Variable sourceVar : joint.getSourceVariables()) {
|
||||
live.add(nodes.get(sourceVar.getIndex()));
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ListingBuilder {
|
|||
for (int i = 0; i < program.variableCount(); ++i) {
|
||||
sb.append(prefix).append("var @").append(i);
|
||||
VariableReader var = program.variableAt(i);
|
||||
if (!var.readDebugNames().isEmpty()) {
|
||||
if (var != null && !var.readDebugNames().isEmpty()) {
|
||||
sb.append(" as ");
|
||||
boolean first = true;
|
||||
for (String debugName : var.readDebugNames()) {
|
||||
|
@ -49,7 +49,7 @@ public class ListingBuilder {
|
|||
}
|
||||
|
||||
if (block.getExceptionVariable() != null) {
|
||||
sb.append("@").append(block.getExceptionVariable().getIndex()).append(" = exception");
|
||||
sb.append(" @").append(block.getExceptionVariable().getIndex()).append(" = exception\n");
|
||||
}
|
||||
|
||||
for (PhiReader phi : block.readPhis()) {
|
||||
|
@ -82,7 +82,7 @@ public class ListingBuilder {
|
|||
sb.append(prefix).append(" catch ").append(tryCatch.getExceptionType())
|
||||
.append(" -> $").append(tryCatch.getHandler().getIndex());
|
||||
sb.append("\n");
|
||||
for (TryCatchJointReader joint : tryCatch.readTryCatchJoints()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readJoints()) {
|
||||
sb.append(" @").append(joint.getReceiver().getIndex()).append(" := e-phi(");
|
||||
sb.append(joint.readSourceVariables().stream().map(sourceVar -> "@" + sourceVar.getIndex())
|
||||
.collect(Collectors.joining(", ")));
|
||||
|
|
|
@ -71,7 +71,7 @@ public class LivenessAnalyzer {
|
|||
}
|
||||
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
definitions[joint.getReceiver().getIndex()] = i;
|
||||
for (Variable sourceVar : joint.getSourceVariables()) {
|
||||
Task task = new Task();
|
||||
|
|
|
@ -15,11 +15,16 @@
|
|||
*/
|
||||
package org.teavm.model.util;
|
||||
|
||||
import com.carrotsearch.hppc.IntOpenHashSet;
|
||||
import com.carrotsearch.hppc.IntSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.teavm.common.DominatorTree;
|
||||
import org.teavm.common.Graph;
|
||||
import org.teavm.common.GraphUtils;
|
||||
|
@ -78,8 +83,10 @@ public class PhiUpdater {
|
|||
private BasicBlock currentBlock;
|
||||
private Phi[][] phiMap;
|
||||
private int[][] phiIndexMap;
|
||||
private List<Map<BasicBlock, Map<Variable, TryCatchJoint>>> jointMap = new ArrayList<>();
|
||||
private Map<TryCatchBlock, Map<Variable, TryCatchJoint>> jointMap = new HashMap<>();
|
||||
private List<List<Phi>> synthesizedPhis = new ArrayList<>();
|
||||
private List<List<List<TryCatchJoint>>> synthesizedJoints = new ArrayList<>();
|
||||
private Variable[] originalExceptionVariables;
|
||||
private boolean[] usedDefinitions;
|
||||
|
||||
public void updatePhis(Program program, Variable[] arguments) {
|
||||
|
@ -98,18 +105,28 @@ public class PhiUpdater {
|
|||
}
|
||||
phiMap = new Phi[program.basicBlockCount()][];
|
||||
phiIndexMap = new int[program.basicBlockCount()][];
|
||||
jointMap = new ArrayList<>();
|
||||
jointMap.clear();
|
||||
for (int i = 0; i < phiMap.length; ++i) {
|
||||
phiMap[i] = new Phi[program.variableCount()];
|
||||
phiIndexMap[i] = new int[program.variableCount()];
|
||||
jointMap.add(new HashMap<>());
|
||||
}
|
||||
domFrontiers = GraphUtils.findDominanceFrontiers(cfg, domTree);
|
||||
|
||||
synthesizedPhis.clear();
|
||||
synthesizedJoints.clear();
|
||||
|
||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||
synthesizedPhis.add(new ArrayList<>());
|
||||
synthesizedJoints.add(new ArrayList<>());
|
||||
int catchCount = program.basicBlockAt(i).getTryCatchBlocks().size();
|
||||
for (int j = 0; j < catchCount; ++j) {
|
||||
synthesizedJoints.get(i).add(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
originalExceptionVariables = new Variable[program.basicBlockCount()];
|
||||
Arrays.setAll(originalExceptionVariables, i -> program.basicBlockAt(i).getExceptionVariable());
|
||||
|
||||
estimatePhis();
|
||||
renameVariables();
|
||||
}
|
||||
|
@ -128,14 +145,22 @@ public class PhiUpdater {
|
|||
}
|
||||
|
||||
for (Instruction insn : currentBlock.getInstructions()) {
|
||||
currentBlock = program.basicBlockAt(i);
|
||||
insn.acceptVisitor(definitionExtractor);
|
||||
Set<Variable> definedVariables = new HashSet<>();
|
||||
for (Variable var : definitionExtractor.getDefinedVariables()) {
|
||||
markAssignment(var);
|
||||
definedVariables.add(var);
|
||||
}
|
||||
}
|
||||
for (TryCatchBlock tryCatch : currentBlock.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
markAssignment(joint.getReceiver());
|
||||
|
||||
Set<BasicBlock> handlers = currentBlock.getTryCatchBlocks().stream()
|
||||
.map(tryCatch -> tryCatch.getHandler())
|
||||
.collect(Collectors.toSet());
|
||||
for (BasicBlock handler : handlers) {
|
||||
currentBlock = handler;
|
||||
for (Variable var : definedVariables) {
|
||||
markAssignment(var);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +169,6 @@ public class PhiUpdater {
|
|||
private static class Task {
|
||||
Variable[] variables;
|
||||
BasicBlock block;
|
||||
TryCatchBlock tryCatch;
|
||||
}
|
||||
|
||||
private void renameVariables() {
|
||||
|
@ -156,7 +180,7 @@ public class PhiUpdater {
|
|||
if (domGraph.incomingEdgesCount(i) == 0) {
|
||||
Task task = new Task();
|
||||
task.block = program.basicBlockAt(i);
|
||||
task.variables = Arrays.copyOf(variableMap, variableMap.length);
|
||||
task.variables = variableMap.clone();
|
||||
stack[head++] = task;
|
||||
}
|
||||
}
|
||||
|
@ -166,63 +190,68 @@ public class PhiUpdater {
|
|||
while (head > 0) {
|
||||
Task task = stack[--head];
|
||||
|
||||
if (task.tryCatch != null) {
|
||||
TryCatchBlock tryCatch = task.tryCatch;
|
||||
if (domTree.dominates(tryCatch.getProtectedBlock().getIndex(), tryCatch.getHandler().getIndex())) {
|
||||
Task next = new Task();
|
||||
next.block = tryCatch.getProtectedBlock();
|
||||
next.variables = Arrays.copyOf(variableMap, variableMap.length);
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
Variable mappedReceiver = introduce(joint.getReceiver());
|
||||
for (Variable sourceVariable : joint.getSourceVariables()) {
|
||||
next.variables[sourceVariable.getIndex()] = mappedReceiver;
|
||||
}
|
||||
next.variables[joint.getReceiver().getIndex()] = mappedReceiver;
|
||||
for (int i = 0; i < joint.getSourceVariables().size(); ++i) {
|
||||
Variable var = joint.getSourceVariables().get(i);
|
||||
joint.getSourceVariables().set(i, use(var));
|
||||
}
|
||||
joint.setReceiver(mappedReceiver);
|
||||
currentBlock = task.block;
|
||||
int index = currentBlock.getIndex();
|
||||
variableMap = task.variables.clone();
|
||||
|
||||
if (currentBlock.getExceptionVariable() != null) {
|
||||
currentBlock.setExceptionVariable(define(currentBlock.getExceptionVariable()));
|
||||
}
|
||||
|
||||
for (Phi phi : synthesizedPhis.get(index)) {
|
||||
Variable var = program.createVariable();
|
||||
var.getDebugNames().addAll(phi.getReceiver().getDebugNames());
|
||||
variableMap[phi.getReceiver().getIndex()] = var;
|
||||
phi.setReceiver(var);
|
||||
}
|
||||
for (Phi phi : currentBlock.getPhis()) {
|
||||
phi.setReceiver(define(phi.getReceiver()));
|
||||
}
|
||||
|
||||
for (Instruction insn : currentBlock.getInstructions()) {
|
||||
insn.acceptVisitor(consumer);
|
||||
}
|
||||
|
||||
for (Incoming output : phiOutputs.get(index)) {
|
||||
Variable var = output.getValue();
|
||||
output.setValue(use(var));
|
||||
}
|
||||
|
||||
for (TryCatchBlock tryCatch : currentBlock.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
for (int i = 0; i < joint.getSourceVariables().size(); ++i) {
|
||||
joint.getSourceVariables().set(i, use(joint.getSourceVariables().get(i)));
|
||||
}
|
||||
stack[head++] = next;
|
||||
joint.setReceiver(define(joint.getReceiver()));
|
||||
}
|
||||
renameOutgoingPhis(tryCatch.getHandler().getIndex());
|
||||
} else {
|
||||
currentBlock = task.block;
|
||||
int index = currentBlock.getIndex();
|
||||
variableMap = Arrays.copyOf(task.variables, task.variables.length);
|
||||
}
|
||||
|
||||
for (Phi phi : synthesizedPhis.get(index)) {
|
||||
Variable var = program.createVariable();
|
||||
var.getDebugNames().addAll(phi.getReceiver().getDebugNames());
|
||||
propagateToTryCatch(phi.getReceiver(), var, null);
|
||||
variableMap[phi.getReceiver().getIndex()] = var;
|
||||
phi.setReceiver(var);
|
||||
}
|
||||
for (Phi phi : currentBlock.getPhis()) {
|
||||
phi.setReceiver(define(phi.getReceiver()));
|
||||
}
|
||||
IntSet catchSuccessors = new IntOpenHashSet();
|
||||
Variable[] regularVariableMap = variableMap;
|
||||
Variable[] catchVariableMap = variableMap.clone();
|
||||
|
||||
for (Instruction insn : currentBlock.getInstructions()) {
|
||||
insn.acceptVisitor(consumer);
|
||||
variableMap = catchVariableMap;
|
||||
for (int i = 0; i < currentBlock.getTryCatchBlocks().size(); ++i) {
|
||||
TryCatchBlock tryCatch = currentBlock.getTryCatchBlocks().get(i);
|
||||
catchSuccessors.add(tryCatch.getHandler().getIndex());
|
||||
for (TryCatchJoint joint : synthesizedJoints.get(index).get(i)) {
|
||||
joint.setReceiver(define(joint.getReceiver()));
|
||||
}
|
||||
}
|
||||
variableMap = regularVariableMap;
|
||||
|
||||
for (Incoming output : phiOutputs.get(index)) {
|
||||
Variable var = output.getValue();
|
||||
output.setValue(use(var));
|
||||
}
|
||||
int[] successors = domGraph.outgoingEdges(index);
|
||||
for (int successor : successors) {
|
||||
Task next = new Task();
|
||||
next.variables = (catchSuccessors.contains(successor) ? catchVariableMap : variableMap).clone();
|
||||
next.block = program.basicBlockAt(successor);
|
||||
stack[head++] = next;
|
||||
}
|
||||
|
||||
int[] successors = domGraph.outgoingEdges(index);
|
||||
for (int successor : successors) {
|
||||
Task next = new Task();
|
||||
next.variables = Arrays.copyOf(variableMap, variableMap.length);
|
||||
next.block = program.basicBlockAt(successor);
|
||||
stack[head++] = next;
|
||||
}
|
||||
successors = cfg.outgoingEdges(index);
|
||||
for (int successor : successors) {
|
||||
renameOutgoingPhis(successor);
|
||||
}
|
||||
successors = cfg.outgoingEdges(index);
|
||||
for (int successor : successors) {
|
||||
variableMap = catchSuccessors.contains(successor) ? catchVariableMap : variableMap;
|
||||
renameOutgoingPhis(successor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,6 +261,17 @@ public class PhiUpdater {
|
|||
program.basicBlockAt(i).getPhis().add(phi);
|
||||
}
|
||||
}
|
||||
|
||||
List<List<TryCatchJoint>> joints = synthesizedJoints.get(i);
|
||||
for (int j = 0; j < joints.size(); ++j) {
|
||||
List<TryCatchJoint> jointList = joints.get(j);
|
||||
TryCatchBlock targetTryCatch = program.basicBlockAt(i).getTryCatchBlocks().get(j);
|
||||
for (TryCatchJoint joint : jointList) {
|
||||
if (!joint.getSourceVariables().isEmpty()) {
|
||||
targetTryCatch.getJoints().add(joint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,19 +336,28 @@ public class PhiUpdater {
|
|||
}
|
||||
|
||||
private void propagateToTryCatch(Variable original, Variable var, Variable old) {
|
||||
for (TryCatchBlock tryCatch : currentBlock.getTryCatchBlocks()) {
|
||||
if (tryCatch.getHandler().getExceptionVariable() == original) {
|
||||
for (int i = 0; i < currentBlock.getTryCatchBlocks().size(); ++i) {
|
||||
TryCatchBlock tryCatch = currentBlock.getTryCatchBlocks().get(i);
|
||||
if (originalExceptionVariables[tryCatch.getHandler().getIndex()] == original) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<Variable, TryCatchJoint> joints = jointMap.get(tryCatch.getHandler().getIndex()).get(currentBlock);
|
||||
Map<Variable, TryCatchJoint> joints = jointMap.get(tryCatch);
|
||||
if (joints == null) {
|
||||
continue;
|
||||
joints = new HashMap<>();
|
||||
jointMap.put(tryCatch, joints);
|
||||
}
|
||||
TryCatchJoint joint = joints.get(original);
|
||||
if (joint == null) {
|
||||
joint = new TryCatchJoint();
|
||||
joint.setReceiver(original);
|
||||
joints.put(original, joint);
|
||||
synthesizedJoints.get(currentBlock.getIndex()).get(i).add(joint);
|
||||
}
|
||||
if (joint.getReceiver() == var) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (joint.getSourceVariables().isEmpty() && old != null) {
|
||||
joint.getSourceVariables().add(old);
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ public final class ProgramUtils {
|
|||
TryCatchBlock tryCatchCopy = new TryCatchBlock();
|
||||
tryCatchCopy.setExceptionType(tryCatch.getExceptionType());
|
||||
tryCatchCopy.setHandler(target.basicBlockAt(tryCatch.getHandler().getIndex()));
|
||||
tryCatchCopy.getTryCatchJoints().addAll(copyTryCatchJoints(tryCatch, target));
|
||||
tryCatchCopy.getJoints().addAll(copyTryCatchJoints(tryCatch, target));
|
||||
result.add(tryCatchCopy);
|
||||
}
|
||||
return result;
|
||||
|
@ -128,7 +128,7 @@ public final class ProgramUtils {
|
|||
|
||||
public static List<TryCatchJoint> copyTryCatchJoints(TryCatchBlockReader block, Program target) {
|
||||
List<TryCatchJoint> result = new ArrayList<>();
|
||||
for (TryCatchJointReader joint : block.readTryCatchJoints()) {
|
||||
for (TryCatchJointReader joint : block.readJoints()) {
|
||||
TryCatchJoint jointCopy = new TryCatchJoint();
|
||||
jointCopy.setReceiver(target.variableAt(joint.getReceiver().getIndex()));
|
||||
for (VariableReader sourceVar : joint.readSourceVariables()) {
|
||||
|
@ -180,7 +180,7 @@ public final class ProgramUtils {
|
|||
}
|
||||
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
places[joint.getReceiver().getIndex()] = block;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class RegisterAllocator {
|
|||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||
program.basicBlockAt(i).getPhis().clear();
|
||||
for (TryCatchBlock tryCatch : program.basicBlockAt(i).getTryCatchBlocks()) {
|
||||
tryCatch.getTryCatchJoints().clear();
|
||||
tryCatch.getJoints().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class RegisterAllocator {
|
|||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||
BasicBlock block = program.basicBlockAt(i);
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
tryCatch.getTryCatchJoints().forEach(this::insertCopy);
|
||||
tryCatch.getJoints().forEach(this::insertCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ public class RegisterAllocator {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
for (Variable sourceVar : joint.getSourceVariables()) {
|
||||
classes.union(sourceVar.getIndex(), joint.getReceiver().getIndex());
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class TypeInferer {
|
|||
}
|
||||
|
||||
for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readTryCatchJoints()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readJoints()) {
|
||||
for (VariableReader sourceVar : joint.readSourceVariables()) {
|
||||
builder.addEdge(sourceVar.getIndex(), joint.getReceiver().getIndex());
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public class GlobalValueNumbering implements MethodOptimization {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
for (int i = 0; i < joint.getSourceVariables().size(); ++i) {
|
||||
int sourceVar = map[joint.getSourceVariables().get(i).getIndex()];
|
||||
joint.getSourceVariables().set(i, program.variableAt(sourceVar));
|
||||
|
|
|
@ -197,11 +197,11 @@ public class Inlining {
|
|||
tryCatchCopy.setHandler(target.getProgram().basicBlockAt(handler));
|
||||
target.getTryCatchBlocks().add(tryCatchCopy);
|
||||
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
TryCatchJoint jointCopy = new TryCatchJoint();
|
||||
jointCopy.setReceiver(joint.getReceiver());
|
||||
jointCopy.getSourceVariables().addAll(joint.getSourceVariables());
|
||||
tryCatchCopy.getTryCatchJoints().add(joint);
|
||||
tryCatchCopy.getJoints().add(joint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,11 +348,11 @@ class LoopInversionImpl {
|
|||
tryCatchCopy.setHandler(program.basicBlockAt(copiedNodes.getOrDefault(handler, handler)));
|
||||
targetBlock.getTryCatchBlocks().add(tryCatchCopy);
|
||||
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
TryCatchJoint jointCopy = new TryCatchJoint();
|
||||
jointCopy.setReceiver(joint.getReceiver());
|
||||
jointCopy.getSourceVariables().addAll(joint.getSourceVariables());
|
||||
tryCatchCopy.getTryCatchJoints().add(joint);
|
||||
tryCatchCopy.getJoints().add(joint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,10 @@ public class UnusedVariableElimination implements MethodOptimization {
|
|||
InstructionOptimizer insnOptimizer = new InstructionOptimizer(used);
|
||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||
BasicBlock block = program.basicBlockAt(i);
|
||||
if (block.getExceptionVariable() != null && !used[block.getExceptionVariable().getIndex()]) {
|
||||
block.setExceptionVariable(null);
|
||||
}
|
||||
|
||||
for (int j = 0; j < block.getInstructions().size(); ++j) {
|
||||
insnOptimizer.eliminate = false;
|
||||
block.getInstructions().get(j).acceptVisitor(insnOptimizer);
|
||||
|
@ -62,10 +66,10 @@ public class UnusedVariableElimination implements MethodOptimization {
|
|||
}
|
||||
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (int j = 0; j < tryCatch.getTryCatchJoints().size(); ++j) {
|
||||
TryCatchJoint joint = tryCatch.getTryCatchJoints().get(j);
|
||||
for (int j = 0; j < tryCatch.getJoints().size(); ++j) {
|
||||
TryCatchJoint joint = tryCatch.getJoints().get(j);
|
||||
if (!used[joint.getReceiver().getIndex()]) {
|
||||
tryCatch.getTryCatchJoints().remove(j--);
|
||||
tryCatch.getJoints().remove(j--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public final class VariableUsageGraphBuilder {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
for (Variable sourceVar : joint.getSourceVariables()) {
|
||||
builder.addEdge(sourceVar.getIndex(), joint.getReceiver().getIndex());
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class AliasFinder {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readTryCatchJoints()) {
|
||||
for (TryCatchJointReader joint : tryCatch.readJoints()) {
|
||||
Set<Integer> inputs = joint.readSourceVariables().stream()
|
||||
.map(sourceVar -> sourceVar.getIndex())
|
||||
.collect(Collectors.toSet());
|
||||
|
|
|
@ -113,7 +113,7 @@ public class BoxingElimination {
|
|||
}
|
||||
}
|
||||
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
|
||||
for (TryCatchJoint joint : tryCatch.getTryCatchJoints()) {
|
||||
for (TryCatchJoint joint : tryCatch.getJoints()) {
|
||||
for (Variable sourceVar : joint.getSourceVariables()) {
|
||||
union(sourceVar.getIndex(), joint.getReceiver().getIndex());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user