Shrink and split LVT records of variables according to their liveness
Otherwise, debugger will show uninitialized values of dead variables after resume. #KT-16222 #KT-28016 Fixed #KT-20571 Fixed
This commit is contained in:
+3
-4
@@ -17,10 +17,9 @@ suspend fun SequenceScope<Int>.awaitSeq(): Int = 42
|
||||
// label numbers differ in BEs
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 1 LOCALVARIABLE a I L[0-9]+ L20
|
||||
// 1 LINENUMBER 9 L20
|
||||
// 1 LOCALVARIABLE a I L[0-9]+ L18
|
||||
// 1 LINENUMBER 9 L19
|
||||
|
||||
/* TODO: JVM_IR does not generate LINENUMBER at the end of the lambda */
|
||||
// JVM_IR_TEMPLATES
|
||||
// 1 LOCALVARIABLE a I L[0-9]+ L5
|
||||
// 1 LINENUMBER 8 L14
|
||||
// 1 LOCALVARIABLE a I L[0-9]+ L16
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
suspend fun blackhole(a: Any) {}
|
||||
|
||||
suspend fun topLevel(a: String, b: String) {
|
||||
blackhole(a) // one spill
|
||||
blackhole(b) // no spills
|
||||
}
|
||||
|
||||
// 1 PUTFIELD .*L\$0 : Ljava/lang/Object;
|
||||
// 0 PUTFIELD .*L\$1 : Ljava/lang/Object;
|
||||
+19
-21
@@ -5,37 +5,35 @@ val c: suspend () -> Unit = {
|
||||
dummy()
|
||||
}
|
||||
|
||||
fun blackhole(a: Any) {}
|
||||
|
||||
class A {
|
||||
suspend fun foo(a: A, s: String = "", block: suspend A.() -> Unit) {
|
||||
block()
|
||||
block()
|
||||
blackhole(this)
|
||||
blackhole(a)
|
||||
blackhole(s)
|
||||
blackhole(block)
|
||||
}
|
||||
}
|
||||
|
||||
// BEs generate continuation classes differently, JVM_IR generates more correctly
|
||||
|
||||
// foo, c's lambda and foo's continuation
|
||||
// 3 LOCALVARIABLE \$result Ljava/lang/Object;
|
||||
|
||||
// foo and <init>
|
||||
// 2 LOCALVARIABLE this LA;
|
||||
// 1 LOCALVARIABLE a LA;
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String;
|
||||
// 1 LOCALVARIABLE block Lkotlin/jvm/functions/Function2;
|
||||
// 1 LOCALVARIABLE \$continuation Lkotlin/coroutines/Continuation;
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// invokeSuspend
|
||||
// 1 LOCALVARIABLE this LThisAndResultInLvtKt\$c\$1; L0 L.* 0
|
||||
// c's lambda and foo's continuation
|
||||
// 2 LOCALVARIABLE \$result Ljava/lang/Object; L0 L.* 1
|
||||
|
||||
// foo and <init>
|
||||
// 2 LOCALVARIABLE this LA; L0 L.* 0
|
||||
// 1 LOCALVARIABLE a LA; L0 L.* 1
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String; L0 L.* 2
|
||||
// 1 LOCALVARIABLE block Lkotlin/jvm/functions/Function2; L0 L.* 3
|
||||
// 1 LOCALVARIABLE \$continuation Lkotlin/coroutines/Continuation; L2 L.* 6
|
||||
// 1 LOCALVARIABLE this LThisAndResultInLvtKt\$c\$1;
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
// <init>, invoke, invokeSuspend, create
|
||||
// 4 LOCALVARIABLE this LThisAndResultInLvtKt\$c\$1; L0 L.* 0
|
||||
// c's lambda and foo's continuation
|
||||
// 2 LOCALVARIABLE \$result Ljava/lang/Object; L0 L.* 1
|
||||
|
||||
// foo and <init>
|
||||
// 2 LOCALVARIABLE this LA; L0 L.* 0
|
||||
// 1 LOCALVARIABLE a LA; L0 L.* 1
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String; L0 L.* 2
|
||||
// 1 LOCALVARIABLE block Lkotlin/jvm/functions/Function2; L0 L.* 3
|
||||
// 1 LOCALVARIABLE \$continuation Lkotlin/coroutines/Continuation; L2 L.* 6
|
||||
// <init>, invoke, invokeSuspend
|
||||
// 3 LOCALVARIABLE this LThisAndResultInLvtKt\$c\$1; L0 L.* 0
|
||||
|
||||
+7
-4
@@ -19,6 +19,8 @@ fun box(): String {
|
||||
try {
|
||||
var i: String = "abc"
|
||||
i = "123"
|
||||
// We need to use the variable, otherwise, it is considered dead.
|
||||
println(i)
|
||||
} finally { }
|
||||
|
||||
// This variable should take the same slot as 'i' had
|
||||
@@ -40,7 +42,8 @@ fun box(): String {
|
||||
}
|
||||
|
||||
// 1 LOCALVARIABLE i Ljava/lang/String; L.* 3
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
||||
// From liveness point of view, 's' is dead between 'println' and 's == "OK"', thus the range is split
|
||||
// 2 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
||||
// 1 PUTFIELD VarValueConflictsWithTableSameSortKt\$box\$1.L\$0 : Ljava/lang/Object;
|
||||
/* 1 load in the catch (e: Throwable) { throw e } block which is implicitly wrapped around try/finally */
|
||||
// 1 ALOAD 3\s+ATHROW
|
||||
@@ -48,7 +51,7 @@ fun box(): String {
|
||||
// 1 ALOAD 3\s+PUTFIELD kotlin/jvm/internal/Ref\$ObjectRef\.element
|
||||
/* 1 load in spill */
|
||||
// 1 ALOAD 3\s+PUTFIELD VarValueConflictsWithTableSameSortKt\$box\$1\.L\$0 : Ljava/lang/Object;
|
||||
/* 1 load in println(s) */
|
||||
// 1 ALOAD 3\s+INVOKEVIRTUAL java/io/PrintStream.println \(Ljava/lang/Object;\)V
|
||||
/* 2 loads in println(s) */
|
||||
// 2 ALOAD 3\s+INVOKEVIRTUAL java/io/PrintStream.println \(Ljava/lang/Object;\)V
|
||||
/* But no further load when spilling 's' to the continuation */
|
||||
// 4 ALOAD 3
|
||||
// 5 ALOAD 3
|
||||
|
||||
Reference in New Issue
Block a user