JVM: Do not traverse all suspension point when looking for end label
when extending local variable range.
This commit is contained in:
committed by
Space Team
parent
95872bd13c
commit
5e2d3737f5
+13
-4
@@ -1285,8 +1285,14 @@ private fun updateLvtAccordingToLiveness(method: MethodNode, isForNamedFunction:
|
|||||||
for (variableIndex in start until method.maxLocals) {
|
for (variableIndex in start until method.maxLocals) {
|
||||||
if (oldLvt.none { it.index == variableIndex }) continue
|
if (oldLvt.none { it.index == variableIndex }) continue
|
||||||
var startLabel: LabelNode? = null
|
var startLabel: LabelNode? = null
|
||||||
|
var nextSuspensionPointIndex = 0
|
||||||
for (insnIndex in 0 until (method.instructions.size() - 1)) {
|
for (insnIndex in 0 until (method.instructions.size() - 1)) {
|
||||||
val insn = method.instructions[insnIndex]
|
val insn = method.instructions[insnIndex]
|
||||||
|
if (insn is LabelNode && nextSuspensionPointIndex < suspensionPoints.size &&
|
||||||
|
suspensionPoints[nextSuspensionPointIndex] == insn
|
||||||
|
) {
|
||||||
|
nextSuspensionPointIndex++
|
||||||
|
}
|
||||||
if (!isAlive(insnIndex, variableIndex) && isAlive(insnIndex + 1, variableIndex)) {
|
if (!isAlive(insnIndex, variableIndex) && isAlive(insnIndex + 1, variableIndex)) {
|
||||||
startLabel = insn as? LabelNode ?: insn.findNextOrNull { it is LabelNode } as? LabelNode
|
startLabel = insn as? LabelNode ?: insn.findNextOrNull { it is LabelNode } as? LabelNode
|
||||||
}
|
}
|
||||||
@@ -1305,13 +1311,14 @@ private fun updateLvtAccordingToLiveness(method: MethodNode, isForNamedFunction:
|
|||||||
// If we can extend the previous range to where the local variable dies, we do not need a
|
// If we can extend the previous range to where the local variable dies, we do not need a
|
||||||
// new entry, we know we cannot extend it to the lvt.endOffset, if we could we would have
|
// new entry, we know we cannot extend it to the lvt.endOffset, if we could we would have
|
||||||
// done so when we added it below.
|
// done so when we added it below.
|
||||||
val extended = latest?.extendRecordIfPossible(method, suspensionPoints, lvtRecord.end, liveness) ?: false
|
val extended =
|
||||||
|
latest?.extendRecordIfPossible(method, suspensionPoints, lvtRecord.end, liveness, nextSuspensionPointIndex) ?: false
|
||||||
if (!extended) {
|
if (!extended) {
|
||||||
val new = LocalVariableNode(lvtRecord.name, lvtRecord.desc, lvtRecord.signature, startLabel, endLabel, lvtRecord.index)
|
val new = LocalVariableNode(lvtRecord.name, lvtRecord.desc, lvtRecord.signature, startLabel, endLabel, lvtRecord.index)
|
||||||
oldLvtNodeToLatestNewLvtNode[lvtRecord] = new
|
oldLvtNodeToLatestNewLvtNode[lvtRecord] = new
|
||||||
method.localVariables.add(new)
|
method.localVariables.add(new)
|
||||||
// See if we can extend it all the way to the old end.
|
// See if we can extend it all the way to the old end.
|
||||||
new.extendRecordIfPossible(method, suspensionPoints, lvtRecord.end, liveness)
|
new.extendRecordIfPossible(method, suspensionPoints, lvtRecord.end, liveness, nextSuspensionPointIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1392,9 +1399,11 @@ private fun LocalVariableNode.extendRecordIfPossible(
|
|||||||
method: MethodNode,
|
method: MethodNode,
|
||||||
suspensionPoints: List<LabelNode>,
|
suspensionPoints: List<LabelNode>,
|
||||||
endLabel: LabelNode,
|
endLabel: LabelNode,
|
||||||
liveness: List<VariableLivenessFrame>
|
liveness: List<VariableLivenessFrame>,
|
||||||
|
nextSuspensionPointIndex: Int
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val nextSuspensionPointLabel = suspensionPoints.find { it in InsnSequence(end, endLabel) } ?: endLabel
|
val nextSuspensionPointLabel =
|
||||||
|
suspensionPoints.drop(nextSuspensionPointIndex).find { it in InsnSequence(end, endLabel) } ?: endLabel
|
||||||
|
|
||||||
var current: AbstractInsnNode? = end
|
var current: AbstractInsnNode? = end
|
||||||
var index = method.instructions.indexOf(current)
|
var index = method.instructions.indexOf(current)
|
||||||
|
|||||||
Reference in New Issue
Block a user