Code clean after convertion
This commit is contained in:
@@ -17,12 +17,20 @@
|
||||
package org.jetbrains.kotlin.codegen.inline
|
||||
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
|
||||
open class FieldRemapper(val lambdaInternalName: String?, @JvmField val parent: FieldRemapper?, private val params: Parameters) {
|
||||
open class FieldRemapper(
|
||||
val lambdaInternalName: String?,
|
||||
@JvmField val parent: FieldRemapper?,
|
||||
private val params: Parameters
|
||||
) {
|
||||
val isRoot = parent == null
|
||||
|
||||
open val isInsideInliningLambda: Boolean = parent?.isInsideInliningLambda ?: false
|
||||
|
||||
protected open fun canProcess(fieldOwner: String, fieldName: String, isFolding: Boolean): Boolean {
|
||||
return fieldOwner == lambdaInternalName &&
|
||||
@@ -30,30 +38,24 @@ open class FieldRemapper(val lambdaInternalName: String?, @JvmField val parent:
|
||||
InlineCodegenUtil.isCapturedFieldName(fieldName)
|
||||
}
|
||||
|
||||
fun foldFieldAccessChainIfNeeded(capturedFieldAccess: List<AbstractInsnNode>, node: MethodNode): AbstractInsnNode? {
|
||||
if (capturedFieldAccess.size == 1) {
|
||||
//just aload
|
||||
return null
|
||||
}
|
||||
|
||||
return foldFieldAccessChainIfNeeded(capturedFieldAccess, 1, node)
|
||||
}
|
||||
fun foldFieldAccessChainIfNeeded(capturedFieldAccess: List<AbstractInsnNode>, node: MethodNode): AbstractInsnNode? =
|
||||
if (capturedFieldAccess.size == 1)
|
||||
null //single aload
|
||||
else
|
||||
foldFieldAccessChainIfNeeded(capturedFieldAccess, 1, node)
|
||||
|
||||
//TODO: seems that this method is redundant but it added from safety purposes before new milestone
|
||||
open fun processNonAload0FieldAccessChains(isInlinedLambda: Boolean): Boolean {
|
||||
return false
|
||||
}
|
||||
open fun processNonAload0FieldAccessChains(isInlinedLambda: Boolean): Boolean = false
|
||||
|
||||
private fun foldFieldAccessChainIfNeeded(
|
||||
capturedFieldAccess: List<AbstractInsnNode>,
|
||||
currentInstruction: Int,
|
||||
node: MethodNode
|
||||
): AbstractInsnNode? {
|
||||
val checkParent = !isRoot && currentInstruction < capturedFieldAccess.size - 1
|
||||
if (checkParent) {
|
||||
val transformed = parent!!.foldFieldAccessChainIfNeeded(capturedFieldAccess, currentInstruction + 1, node)
|
||||
if (transformed != null) {
|
||||
return transformed
|
||||
if (currentInstruction < capturedFieldAccess.lastIndex) {
|
||||
//try to fold longest chain first
|
||||
parent?.foldFieldAccessChainIfNeeded(capturedFieldAccess, currentInstruction + 1, node)?.let {
|
||||
return@foldFieldAccessChainIfNeeded it
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,24 +64,15 @@ open class FieldRemapper(val lambdaInternalName: String?, @JvmField val parent:
|
||||
insnNode.name = "$$$" + insnNode.name
|
||||
insnNode.opcode = Opcodes.GETSTATIC
|
||||
|
||||
var next = capturedFieldAccess[0]
|
||||
while (next !== insnNode) {
|
||||
val toDelete = next
|
||||
next = next.next
|
||||
node.instructions.remove(toDelete)
|
||||
}
|
||||
|
||||
node.remove(InsnSequence(capturedFieldAccess[0], insnNode))
|
||||
return capturedFieldAccess[capturedFieldAccess.size - 1]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun findField(fieldInsnNode: FieldInsnNode): CapturedParamInfo? {
|
||||
return findField(fieldInsnNode, params.captured)
|
||||
}
|
||||
|
||||
open fun findField(fieldInsnNode: FieldInsnNode, captured: Collection<CapturedParamInfo>): CapturedParamInfo? {
|
||||
@JvmOverloads
|
||||
open fun findField(fieldInsnNode: FieldInsnNode, captured: Collection<CapturedParamInfo> = params.captured): CapturedParamInfo? {
|
||||
for (valueDescriptor in captured) {
|
||||
if (valueDescriptor.originalFieldName == fieldInsnNode.name && valueDescriptor.containingLambdaName == fieldInsnNode.owner) {
|
||||
return valueDescriptor
|
||||
@@ -88,17 +81,9 @@ open class FieldRemapper(val lambdaInternalName: String?, @JvmField val parent:
|
||||
return null
|
||||
}
|
||||
|
||||
open fun getNewLambdaInternalName(): String {
|
||||
return lambdaInternalName!!
|
||||
}
|
||||
open val newLambdaInternalName: String
|
||||
get() = lambdaInternalName!!
|
||||
|
||||
val isRoot: Boolean
|
||||
get() = parent == null
|
||||
|
||||
open fun getFieldForInline(node: FieldInsnNode, prefix: StackValue?): StackValue? {
|
||||
return MethodInliner.findCapturedField(node, this).remapValue
|
||||
}
|
||||
|
||||
open val isInsideInliningLambda: Boolean
|
||||
get() = !isRoot && parent!!.isInsideInliningLambda
|
||||
open fun getFieldForInline(node: FieldInsnNode, prefix: StackValue?): StackValue? =
|
||||
MethodInliner.findCapturedField(node, this).remapValue
|
||||
}
|
||||
|
||||
@@ -99,6 +99,11 @@ fun parameterOffsets(isStatic: Boolean, valueParameters: List<JvmMethodParameter
|
||||
}
|
||||
}
|
||||
|
||||
fun MethodNode.remove(instructions: Sequence<AbstractInsnNode>) =
|
||||
instructions.forEach {
|
||||
this@remove.instructions.remove(it)
|
||||
}
|
||||
|
||||
fun MethodNode.remove(instructions: Collection<AbstractInsnNode>) {
|
||||
instructions.forEach {
|
||||
this@remove.instructions.remove(it)
|
||||
|
||||
Reference in New Issue
Block a user