Refine variables liveness analysis
Do not treat var as alive just because current instruction belongs to an item range in local variables table, but the item has different sort of type As liveness analysis is mostly used in coroutines spilling, not applying this change may lead that to problems on Android (see tests)
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
class Controller {
|
||||
suspend fun suspendHere(x: Continuation<String>) {
|
||||
x.resume("OK")
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
c(Controller()).resume(Unit)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "fail 1"
|
||||
builder {
|
||||
// Initialize var with Int value
|
||||
for (i in 1..1) {
|
||||
if ("".length > 0) continue
|
||||
}
|
||||
|
||||
// This variable should take the same slot as 'i' had
|
||||
var s: String
|
||||
|
||||
// We should not spill 's' to continuation field because it's not initialized
|
||||
// More precisely it contains a value of wrong type (it conflicts with contents of local var table),
|
||||
// so an attempt of spilling may lead to problems on Android
|
||||
if (suspendHere() == "OK") {
|
||||
s = "OK"
|
||||
}
|
||||
else {
|
||||
s = "fail 2"
|
||||
}
|
||||
|
||||
result = s
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// 1 LOCALVARIABLE i I L.* 3
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
||||
// 0 PUTFIELD VarValueConflictsWithTableKt\$box\$1.I\$0 : I
|
||||
/* 2 loads in cycle */
|
||||
// 2 ILOAD 3
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
class Controller {
|
||||
suspend fun suspendHere(x: Continuation<String>) {
|
||||
x.resume("OK")
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
c(Controller()).resume(Unit)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "fail 1"
|
||||
|
||||
builder {
|
||||
// Initialize var with Int value
|
||||
try {
|
||||
var i: String = "abc"
|
||||
i = "123"
|
||||
} finally { }
|
||||
|
||||
// This variable should take the same slot as 'i' had
|
||||
var s: String
|
||||
|
||||
// We shout not spill 's' to continuation field because it's not effectively initialized
|
||||
// But we do this because it's not illegal (at least in Android/OpenJDK VM's)
|
||||
if (suspendHere() == "OK") {
|
||||
s = "OK"
|
||||
}
|
||||
else {
|
||||
s = "fail 2"
|
||||
}
|
||||
|
||||
result = s
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// 1 LOCALVARIABLE i Ljava/lang/String; L.* 3
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
||||
// 1 PUTFIELD VarValueConflictsWithTableSameSortKt\$box\$1.L\$0 : Ljava/lang/Object;
|
||||
/* 1 load in try/finally */
|
||||
/* 1 load in result = s */
|
||||
/* 1 load before suspension point */
|
||||
// 3 ALOAD 3
|
||||
Reference in New Issue
Block a user