Skip to content

Commit

Permalink
Skip restoring this when generating spill and unspill for coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
songruiwang committed Dec 10, 2024
1 parent eacf69f commit fa0548c
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,9 @@ class CoroutineTransformerMethodVisitor(
// Also, we spill and unspill null for visible dead variables
// `generateSpillAndUnspill` calls the probe from stdlib for us.
for (referenceToSpill in referencesToSpillBySuspensionPointIndex[suspensionPointIndex]) {
generateSpillAndUnspill(methodNode, suspension, referenceToSpill, suspendLambdaParameters)
// skip restoring this
val isInstanceThisVariable = !isStatic(methodNode.access) && referenceToSpill.slot == 0
generateSpillAndUnspill(methodNode, suspension, referenceToSpill, suspendLambdaParameters, !isInstanceThisVariable)
}

// Then, we cleanup invisible dead variables
Expand Down Expand Up @@ -690,7 +692,8 @@ class CoroutineTransformerMethodVisitor(
methodNode: MethodNode,
suspension: SuspensionPoint,
spillableVariable: SpillableVariable,
suspendLambdaParameters: List<Int>
suspendLambdaParameters: List<Int>,
shouldRestore: Boolean = true
) {
val local: LocalVariableNode? =
findLocalCorrespondingToSpillableVariable(
Expand Down Expand Up @@ -739,7 +742,7 @@ class CoroutineTransformerMethodVisitor(
)
})

if (spillableVariable.slot !in suspendLambdaParameters) {
if (spillableVariable.slot !in suspendLambdaParameters && shouldRestore) {
// restore variable after suspension call
insert(suspension.tryCatchBlockEndLabelAfterSuspensionCall, withInstructionAdapter {
load(continuationIndex, AsmTypes.OBJECT_TYPE)
Expand Down

0 comments on commit fa0548c

Please sign in to comment.