diff --git a/core/src/main/java/org/teavm/cache/ProgramIO.java b/core/src/main/java/org/teavm/cache/ProgramIO.java index 470fc074e..f34a2754a 100644 --- a/core/src/main/java/org/teavm/cache/ProgramIO.java +++ b/core/src/main/java/org/teavm/cache/ProgramIO.java @@ -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); diff --git a/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java b/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java index 7f2213d5f..1d0cff0f1 100644 --- a/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java +++ b/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java @@ -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()); } diff --git a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java index 22c5d404c..1038121b3 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java +++ b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java @@ -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); } diff --git a/core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java b/core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java index 215ff7a3c..7d4ab35af 100644 --- a/core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java +++ b/core/src/main/java/org/teavm/javascript/ReadWriteStatsBuilder.java @@ -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()]++; diff --git a/core/src/main/java/org/teavm/model/Program.java b/core/src/main/java/org/teavm/model/Program.java index e8043b8e6..ff52e88ce 100644 --- a/core/src/main/java/org/teavm/model/Program.java +++ b/core/src/main/java/org/teavm/model/Program.java @@ -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); } diff --git a/core/src/main/java/org/teavm/model/TryCatchBlock.java b/core/src/main/java/org/teavm/model/TryCatchBlock.java index 9ce3d8fe0..9a5846dc1 100644 --- a/core/src/main/java/org/teavm/model/TryCatchBlock.java +++ b/core/src/main/java/org/teavm/model/TryCatchBlock.java @@ -97,12 +97,12 @@ public class TryCatchBlock implements TryCatchBlockReader { return protectedBlock; } - public List getTryCatchJoints() { + public List getJoints() { return safeJoints; } @Override - public List readTryCatchJoints() { + public List readJoints() { if (immutableJoints == null) { immutableJoints = Collections.unmodifiableList(safeJoints); } diff --git a/core/src/main/java/org/teavm/model/TryCatchBlockReader.java b/core/src/main/java/org/teavm/model/TryCatchBlockReader.java index f2c4ed38f..a49344476 100644 --- a/core/src/main/java/org/teavm/model/TryCatchBlockReader.java +++ b/core/src/main/java/org/teavm/model/TryCatchBlockReader.java @@ -24,5 +24,5 @@ public interface TryCatchBlockReader { String getExceptionType(); - List readTryCatchJoints(); + List readJoints(); } diff --git a/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java b/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java index 5f1041b3c..55e1aeb67 100644 --- a/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java +++ b/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java @@ -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); diff --git a/core/src/main/java/org/teavm/model/util/InterferenceGraphBuilder.java b/core/src/main/java/org/teavm/model/util/InterferenceGraphBuilder.java index b77da9d93..5f78e8943 100644 --- a/core/src/main/java/org/teavm/model/util/InterferenceGraphBuilder.java +++ b/core/src/main/java/org/teavm/model/util/InterferenceGraphBuilder.java @@ -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())); } diff --git a/core/src/main/java/org/teavm/model/util/ListingBuilder.java b/core/src/main/java/org/teavm/model/util/ListingBuilder.java index 5a736c8d0..545c4dee1 100644 --- a/core/src/main/java/org/teavm/model/util/ListingBuilder.java +++ b/core/src/main/java/org/teavm/model/util/ListingBuilder.java @@ -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(", "))); diff --git a/core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java b/core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java index c6ebb7db9..429a8538b 100644 --- a/core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java +++ b/core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java @@ -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(); diff --git a/core/src/main/java/org/teavm/model/util/PhiUpdater.java b/core/src/main/java/org/teavm/model/util/PhiUpdater.java index b48c273e4..2bc02d7e2 100644 --- a/core/src/main/java/org/teavm/model/util/PhiUpdater.java +++ b/core/src/main/java/org/teavm/model/util/PhiUpdater.java @@ -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>> jointMap = new ArrayList<>(); + private Map> jointMap = new HashMap<>(); private List> synthesizedPhis = new ArrayList<>(); + private List>> 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 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 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> joints = synthesizedJoints.get(i); + for (int j = 0; j < joints.size(); ++j) { + List 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 joints = jointMap.get(tryCatch.getHandler().getIndex()).get(currentBlock); + Map 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); } diff --git a/core/src/main/java/org/teavm/model/util/ProgramUtils.java b/core/src/main/java/org/teavm/model/util/ProgramUtils.java index 89af3142a..2e0f6002c 100644 --- a/core/src/main/java/org/teavm/model/util/ProgramUtils.java +++ b/core/src/main/java/org/teavm/model/util/ProgramUtils.java @@ -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 copyTryCatchJoints(TryCatchBlockReader block, Program target) { List 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; } } diff --git a/core/src/main/java/org/teavm/model/util/RegisterAllocator.java b/core/src/main/java/org/teavm/model/util/RegisterAllocator.java index 70305e3ac..b5f9be8d1 100644 --- a/core/src/main/java/org/teavm/model/util/RegisterAllocator.java +++ b/core/src/main/java/org/teavm/model/util/RegisterAllocator.java @@ -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()); } diff --git a/core/src/main/java/org/teavm/model/util/TypeInferer.java b/core/src/main/java/org/teavm/model/util/TypeInferer.java index c62564997..a1d015f0b 100644 --- a/core/src/main/java/org/teavm/model/util/TypeInferer.java +++ b/core/src/main/java/org/teavm/model/util/TypeInferer.java @@ -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()); } diff --git a/core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java b/core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java index 0da23278e..d555e54be 100644 --- a/core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java +++ b/core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java @@ -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)); diff --git a/core/src/main/java/org/teavm/optimization/Inlining.java b/core/src/main/java/org/teavm/optimization/Inlining.java index 20273cd5e..9757fb238 100644 --- a/core/src/main/java/org/teavm/optimization/Inlining.java +++ b/core/src/main/java/org/teavm/optimization/Inlining.java @@ -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); } } } diff --git a/core/src/main/java/org/teavm/optimization/LoopInversionImpl.java b/core/src/main/java/org/teavm/optimization/LoopInversionImpl.java index bedd5843e..65b91d417 100644 --- a/core/src/main/java/org/teavm/optimization/LoopInversionImpl.java +++ b/core/src/main/java/org/teavm/optimization/LoopInversionImpl.java @@ -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); } } } diff --git a/core/src/main/java/org/teavm/optimization/UnusedVariableElimination.java b/core/src/main/java/org/teavm/optimization/UnusedVariableElimination.java index 01cd5fb50..56f60a72a 100644 --- a/core/src/main/java/org/teavm/optimization/UnusedVariableElimination.java +++ b/core/src/main/java/org/teavm/optimization/UnusedVariableElimination.java @@ -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--); } } } diff --git a/core/src/main/java/org/teavm/optimization/VariableUsageGraphBuilder.java b/core/src/main/java/org/teavm/optimization/VariableUsageGraphBuilder.java index 3e58eaba8..702cdc332 100644 --- a/core/src/main/java/org/teavm/optimization/VariableUsageGraphBuilder.java +++ b/core/src/main/java/org/teavm/optimization/VariableUsageGraphBuilder.java @@ -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()); } diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/AliasFinder.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/AliasFinder.java index 1e7303340..3b081345e 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/AliasFinder.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/AliasFinder.java @@ -67,7 +67,7 @@ class AliasFinder { } } for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { - for (TryCatchJointReader joint : tryCatch.readTryCatchJoints()) { + for (TryCatchJointReader joint : tryCatch.readJoints()) { Set inputs = joint.readSourceVariables().stream() .map(sourceVar -> sourceVar.getIndex()) .collect(Collectors.toSet()); diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/optimization/BoxingElimination.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/optimization/BoxingElimination.java index 2e69146f0..36fc6ebf5 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/optimization/BoxingElimination.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/optimization/BoxingElimination.java @@ -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()); }