Analyzer error handling: fix for printing bytecode in case of exception within optimization package
This commit is contained in:
committed by
Alexander Udalov
parent
ea9e4375b0
commit
149ffdc8b9
@@ -31,6 +31,7 @@ import org.jetbrains.jet.codegen.bridges.BridgesPackage;
|
|||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
import org.jetbrains.jet.codegen.context.MethodContext;
|
||||||
import org.jetbrains.jet.codegen.context.PackageFacadeContext;
|
import org.jetbrains.jet.codegen.context.PackageFacadeContext;
|
||||||
|
import org.jetbrains.jet.codegen.optimization.OptimizationMethodVisitor;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -396,6 +397,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
|||||||
public static void endVisit(MethodVisitor mv, @Nullable String description, @Nullable PsiElement method) {
|
public static void endVisit(MethodVisitor mv, @Nullable String description, @Nullable PsiElement method) {
|
||||||
try {
|
try {
|
||||||
mv.visitMaxs(-1, -1);
|
mv.visitMaxs(-1, -1);
|
||||||
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
catch (ProcessCanceledException e) {
|
catch (ProcessCanceledException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -411,11 +413,15 @@ public class FunctionCodegen extends ParentCodegenAware {
|
|||||||
(bytecode != null ? "\nbytecode:\n" + bytecode : ""),
|
(bytecode != null ? "\nbytecode:\n" + bytecode : ""),
|
||||||
t, method);
|
t, method);
|
||||||
}
|
}
|
||||||
mv.visitEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String renderByteCodeIfAvailable(MethodVisitor mv) {
|
private static String renderByteCodeIfAvailable(MethodVisitor mv) {
|
||||||
String bytecode = null;
|
String bytecode = null;
|
||||||
|
|
||||||
|
if (mv instanceof OptimizationMethodVisitor) {
|
||||||
|
mv = ((OptimizationMethodVisitor) mv).getTraceMethodVisitorIfPossible();
|
||||||
|
}
|
||||||
|
|
||||||
if (mv instanceof TraceMethodVisitor) {
|
if (mv instanceof TraceMethodVisitor) {
|
||||||
TraceMethodVisitor traceMethodVisitor = (TraceMethodVisitor) mv;
|
TraceMethodVisitor traceMethodVisitor = (TraceMethodVisitor) mv;
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
|
|||||||
+15
@@ -25,6 +25,8 @@ import org.jetbrains.jet.codegen.optimization.transformer.MethodTransformer;
|
|||||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.LocalVariableNode;
|
import org.jetbrains.org.objectweb.asm.tree.LocalVariableNode;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
|
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
|
||||||
|
import org.jetbrains.org.objectweb.asm.util.Textifier;
|
||||||
|
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -95,4 +97,17 @@ public class OptimizationMethodVisitor extends MethodVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public TraceMethodVisitor getTraceMethodVisitorIfPossible() {
|
||||||
|
TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(new Textifier());
|
||||||
|
try {
|
||||||
|
methodNode.accept(traceMethodVisitor);
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return traceMethodVisitor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user