Temporary disable smap generation

This commit is contained in:
Michael Bogdanov
2015-03-18 10:25:01 +03:00
parent 6e55ea6480
commit ed62e4972f
15 changed files with 69 additions and 32 deletions
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.inline.FileMapping; import org.jetbrains.kotlin.codegen.inline.FileMapping;
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil;
import org.jetbrains.kotlin.codegen.inline.SMAPBuilder; import org.jetbrains.kotlin.codegen.inline.SMAPBuilder;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
import org.jetbrains.org.objectweb.asm.*; import org.jetbrains.org.objectweb.asm.*;
@@ -103,7 +104,7 @@ public abstract class AbstractClassBuilder implements ClassBuilder {
@Override @Override
public void done() { public void done() {
if (!fileMappings.isEmpty()) { if (!fileMappings.isEmpty() && InlineCodegenUtil.GENERATE_SMAP) {
FileMapping origin = fileMappings.get(0); FileMapping origin = fileMappings.get(0);
assert sourceName == null || origin.getName().equals(sourceName) : "Error " + origin.getName() + " != " + sourceName; assert sourceName == null || origin.getName().equals(sourceName) : "Error " + origin.getName() + " != " + sourceName;
getVisitor().visitSource(origin.getName(), new SMAPBuilder(origin.getName(), origin.getPath(), fileMappings).build()); getVisitor().visitSource(origin.getName(), new SMAPBuilder(origin.getName(), origin.getPath(), fileMappings).build());
@@ -167,9 +167,14 @@ public class AnonymousObjectTransformer {
//seems we can't do any clever mapping cause we don't know any about original class name //seems we can't do any clever mapping cause we don't know any about original class name
sourceMapper = IdenticalSourceMapper.INSTANCE$; sourceMapper = IdenticalSourceMapper.INSTANCE$;
} }
if (sourceInfo != null && !InlineCodegenUtil.GENERATE_SMAP) {
classBuilder.visitSource(sourceInfo, debugInfo);
}
} }
else { else {
classBuilder.visitSource(sourceInfo, debugInfo); if (sourceInfo != null) {
classBuilder.visitSource(sourceInfo, debugInfo);
}
sourceMapper = IdenticalSourceMapper.INSTANCE$; sourceMapper = IdenticalSourceMapper.INSTANCE$;
} }
@@ -87,7 +87,12 @@ public class InlineAdapter extends InstructionAdapter {
@Override @Override
public void visitLineNumber(int line, Label start) { public void visitLineNumber(int line, Label start) {
sourceMapper.visitLineNumber(mv, line, start); if (InlineCodegenUtil.GENERATE_SMAP) {
sourceMapper.visitLineNumber(mv, line, start);
}
else {
super.visitLineNumber(line, start);
}
} }
@Override @Override
@@ -63,6 +63,7 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait;
public class InlineCodegenUtil { public class InlineCodegenUtil {
public static final boolean GENERATE_SMAP = false;
public static final int API = Opcodes.ASM5; public static final int API = Opcodes.ASM5;
public static final String INVOKE = "invoke"; public static final String INVOKE = "invoke";
@@ -124,7 +125,7 @@ public class InlineCodegenUtil {
} }
return null; return null;
} }
}, ClassReader.SKIP_FRAMES); }, ClassReader.SKIP_FRAMES | (GENERATE_SMAP ? 0 : ClassReader.SKIP_DEBUG));
SMAP smap = SMAPParser.parseOrCreateDefault(debugInfo[1], debugInfo[0], classId.toString(), lines[0], lines[1]); SMAP smap = SMAPParser.parseOrCreateDefault(debugInfo[1], debugInfo[0], classId.toString(), lines[0], lines[1]);
return new SMAPAndMethodNode(node[0], smap); return new SMAPAndMethodNode(node[0], smap);
@@ -329,6 +329,13 @@ public class MethodInliner {
super.visitMaxs(maxStack, maxLocals + capturedParamsSize); super.visitMaxs(maxStack, maxLocals + capturedParamsSize);
} }
@Override
public void visitLineNumber(int line, @NotNull Label start) {
if(isInliningLambda || InlineCodegenUtil.GENERATE_SMAP) {
super.visitLineNumber(line, start);
}
}
@Override @Override
public void visitLocalVariable( public void visitLocalVariable(
@NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index @NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index
@@ -368,4 +368,3 @@ data open public class RangeMapping(val source: Int, val dest: Int, var range: I
} }
} }
} }
@@ -12,4 +12,4 @@ fun foo() {
.bar() .bar()
} }
// 2 3 7 8 9 11 12 17 13 // 2 3 7 8 9 11 12 13
@@ -12,4 +12,4 @@ fun foo() {
.bar() .bar()
} }
// 2 3 7 8 9 11 17 12 17 13 // 2 3 7 8 9 11 12 13
@@ -9,4 +9,4 @@ fun foo(i: Int = 1) {
inline fun bar(i: Int = 1) { inline fun bar(i: Int = 1) {
} }
// 2 3 9 4 7 6 10 9 10 // 2 3 4 7 6 10 9
@@ -13,4 +13,4 @@ inline fun foo(f: () -> Unit) {
f() f()
} }
// 2 12 3 6 12 7 9 12 13 14 // 2 3 6 7 9 12 13 14
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.jvm.compiler
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.backend.common.output.OutputFile import org.jetbrains.kotlin.backend.common.output.OutputFile
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetFile
@@ -65,6 +66,10 @@ public trait AbstractSMAPBaseTest {
} }
fun checkSMAP(inputFiles: List<JetFile>, outputFiles: List<OutputFile>) { fun checkSMAP(inputFiles: List<JetFile>, outputFiles: List<OutputFile>) {
if (!InlineCodegenUtil.GENERATE_SMAP) {
return
}
val sourceData = inputFiles.map { extractSmapFromSource(it) }.filterNotNull() val sourceData = inputFiles.map { extractSmapFromSource(it) }.filterNotNull()
val compiledData = extractSMAPFromClasses(outputFiles).groupBy { val compiledData = extractSMAPFromClasses(outputFiles).groupBy {
it.sourceFile it.sourceFile
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollectorPlainTextToStrea
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil;
import org.jetbrains.kotlin.config.CompilerConfiguration; import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor; import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
@@ -222,15 +223,21 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
"-d", tmpdir.getPath() "-d", tmpdir.getPath()
)); ));
ClassWriter cw;
File inlineFunClass = new File(tmpdir.getAbsolutePath(), "test/A.class"); File inlineFunClass = new File(tmpdir.getAbsolutePath(), "test/A.class");
ClassReader reader = new ClassReader(new FileInputStream(inlineFunClass)); FileInputStream is = new FileInputStream(inlineFunClass);
ClassWriter cw = new ClassWriter(Opcodes.ASM5); try {
reader.accept(new ClassVisitor(Opcodes.ASM5, cw) { ClassReader reader = new ClassReader(is);
@Override cw = new ClassWriter(Opcodes.ASM5);
public void visitSource(String source, String debug) { reader.accept(new ClassVisitor(Opcodes.ASM5, cw) {
//skip debug info @Override
} public void visitSource(String source, String debug) {
}, 0); //skip debug info
}
}, 0);
} finally {
is.close();
}
assert inlineFunClass.delete(); assert inlineFunClass.delete();
assert !inlineFunClass.exists(); assert !inlineFunClass.exists();
@@ -250,16 +257,21 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
"-d", tmpdir.getPath() "-d", tmpdir.getPath()
)); ));
File resultFile = new File(tmpdir.getAbsolutePath(), "test/B.class");
reader = new ClassReader(new FileInputStream(resultFile));
final Ref<String> debugInfo = new Ref<String>(); final Ref<String> debugInfo = new Ref<String>();
reader.accept(new ClassVisitor(Opcodes.ASM5) { File resultFile = new File(tmpdir.getAbsolutePath(), "test/B.class");
@Override FileInputStream resultStream = new FileInputStream(resultFile);
public void visitSource(String source, String debug) { try {
//skip debug info ClassReader reader = new ClassReader(resultStream);
debugInfo.set(debug); reader.accept(new ClassVisitor(Opcodes.ASM5) {
} @Override
}, 0); public void visitSource(String source, String debug) {
//skip debug info
debugInfo.set(debug);
}
}, 0);
} finally {
resultStream.close();
}
String expected = "SMAP\n" + String expected = "SMAP\n" +
"source.kt\n" + "source.kt\n" +
@@ -272,6 +284,10 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
"1#1,13:1\n" + "1#1,13:1\n" +
"*E\n"; "*E\n";
assertEquals(expected, debugInfo.get()); if (InlineCodegenUtil.GENERATE_SMAP) {
assertEquals(expected, debugInfo.get());
} else {
assertEquals(null, debugInfo.get());
}
} }
} }
@@ -1,8 +1,6 @@
LineBreakpoint created at stepIntoFromInlineFun.kt:13 LineBreakpoint created at stepIntoFromInlineFun.kt:13
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoFromInlineFun.StepIntoFromInlineFunPackage !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoFromInlineFun.StepIntoFromInlineFunPackage
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
stepIntoFromInlineFun.kt:13
stepIntoFromInlineFun.kt:7
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0 Process finished with exit code 0
@@ -2,8 +2,8 @@ LineBreakpoint created at stepIntoInlineFun.kt:8
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoInlineFun.StepIntoInlineFunPackage !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoInlineFun.StepIntoInlineFunPackage
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
stepIntoInlineFun.kt:8 stepIntoInlineFun.kt:8
stepIntoInlineFun.kt:13
stepIntoInlineFun.kt:8 stepIntoInlineFun.kt:8
stepIntoInlineFun.kt:9
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0 Process finished with exit code 0
@@ -2,7 +2,7 @@ LineBreakpoint created at stepIntoStdLibInlineFun.kt:6
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoStdLibInlineFun.StepIntoStdLibInlineFunPackage !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stepIntoStdLibInlineFun.StepIntoStdLibInlineFunPackage
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
stepIntoStdLibInlineFun.kt:6 stepIntoStdLibInlineFun.kt:6
_Mapping.!EXT! ArrayList.!EXT!
resuming stepIntoStdLibInlineFun.kt:5 resuming stepIntoStdLibInlineFun.kt:5
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'