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 40d20a840..bddddc0d9 100644 --- a/core/src/main/java/org/teavm/model/util/PhiUpdater.java +++ b/core/src/main/java/org/teavm/model/util/PhiUpdater.java @@ -354,11 +354,7 @@ public class PhiUpdater { continue; } - Map joints = jointMap.get(tryCatch); - if (joints == null) { - joints = new HashMap<>(); - jointMap.put(tryCatch, joints); - } + Map joints = jointMap.computeIfAbsent(tryCatch, k -> new HashMap<>()); TryCatchJoint joint = joints.get(original); if (joint == null) { joint = new TryCatchJoint(); @@ -398,7 +394,7 @@ public class PhiUpdater { private Variable use(Variable var) { Variable mappedVar = variableMap[var.getIndex()]; if (mappedVar == null) { - throw new AssertionError(); + throw new AssertionError("Variable used before definition: " + var.getIndex()); } return mappedVar; } diff --git a/core/src/main/java/org/teavm/vm/TeaVM.java b/core/src/main/java/org/teavm/vm/TeaVM.java index 900d09b29..d61b5c434 100644 --- a/core/src/main/java/org/teavm/vm/TeaVM.java +++ b/core/src/main/java/org/teavm/vm/TeaVM.java @@ -61,6 +61,7 @@ import org.teavm.model.optimization.MethodOptimization; import org.teavm.model.optimization.RedundantJumpElimination; import org.teavm.model.optimization.UnreachableBasicBlockElimination; import org.teavm.model.optimization.UnusedVariableElimination; +import org.teavm.model.util.ListingBuilder; import org.teavm.model.util.MissingItemsProcessor; import org.teavm.model.util.ModelUtils; import org.teavm.model.util.ProgramUtils; @@ -478,7 +479,15 @@ public class TeaVM implements TeaVMHost, ServiceRepository { do { changed = false; for (MethodOptimization optimization : getOptimizations()) { - changed |= optimization.optimize(method, optimizedProgram); + try { + changed |= optimization.optimize(method, optimizedProgram); + } catch (Exception e) { + ListingBuilder listingBuilder = new ListingBuilder(); + String listing = listingBuilder.buildListing(optimizedProgram, ""); + System.err.println("Error optimizing program for method" + method.getReference() + + ":\n" + listing); + throw new RuntimeException(e); + } } } while (changed);