From 83c75c1edff5e2c9c51fe16eb3046fc256b9b472 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Tue, 5 Sep 2023 17:11:41 +0200 Subject: [PATCH] [JVM] Unify `initLocals` method in `Fast...Analyzer` classes --- .../optimization/common/FastMethodAnalyzer.kt | 12 +++++------- .../optimization/fixStack/BasicTypeInterpreter.kt | 4 ++++ .../optimization/fixStack/FastStackAnalyzer.kt | 15 ++++++++++----- .../temporaryVals/FastStoreLoadAnalyzer.kt | 12 +++++++----- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt index 771a06ee1db..3f9bf46b996 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt @@ -110,20 +110,18 @@ open class FastMethodAnalyzer var local = 0 val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 if (isInstanceMethod) { - current.setLocal(local, interpreter.newParameterValue(true, local, Type.getObjectType(owner))) + val ctype = Type.getObjectType(owner) + current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) local++ } for (arg in args) { - current.setLocal(local, interpreter.newParameterValue(isInstanceMethod, local, arg)) - local++ + current.setLocal(local++, interpreter.newValue(arg)) if (arg.size == 2) { - current.setLocal(local, interpreter.newEmptyValue(local)) - local++ + current.setLocal(local++, interpreter.newValue(null)) } } while (local < method.maxLocals) { - current.setLocal(local, interpreter.newEmptyValue(local)) - local++ + current.setLocal(local++, interpreter.newValue(null)) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/BasicTypeInterpreter.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/BasicTypeInterpreter.kt index 25bceacce77..418faa7ce3f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/BasicTypeInterpreter.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/BasicTypeInterpreter.kt @@ -53,6 +53,10 @@ abstract class BasicTypeInterpreter : Interpreter(API_VERSION) { else -> throw AssertionError("Unexpected type: $type") } + override fun newEmptyValue(local: Int): V { + return uninitializedValue() + } + override fun newOperation(insn: AbstractInsnNode): V? = when (insn.opcode) { ACONST_NULL -> diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt index 830d12233d4..3faccffb432 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt @@ -141,18 +141,23 @@ internal open class FastStackAnalyzer( current.setReturn(interpreter.newValue(Type.getReturnType(method.desc))) val args = Type.getArgumentTypes(method.desc) var local = 0 - if ((method.access and Opcodes.ACC_STATIC) == 0) { + val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 + if (isInstanceMethod) { val ctype = Type.getObjectType(owner) - current.setLocal(local++, interpreter.newValue(ctype)) + current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) + local++ } for (arg in args) { - current.setLocal(local++, interpreter.newValue(arg)) + current.setLocal(local, interpreter.newParameterValue(isInstanceMethod, local, arg)) + local++ if (arg.size == 2) { - current.setLocal(local++, interpreter.newValue(null)) + current.setLocal(local, interpreter.newEmptyValue(local)) + local++ } } while (local < method.maxLocals) { - current.setLocal(local++, interpreter.newValue(null)) + current.setLocal(local, interpreter.newEmptyValue(local)) + local++ } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt index 3915fb56004..48ba4242ec5 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt @@ -189,23 +189,25 @@ class FastStoreLoadAnalyzer( } override fun initLocals(current: StoreLoadFrame) { + current.setReturn(interpreter.newReturnTypeValue(Type.getReturnType(method.desc))) val args = Type.getArgumentTypes(method.desc) var local = 0 - if ((method.access and Opcodes.ACC_STATIC) == 0) { + val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 + if (isInstanceMethod) { val ctype = Type.getObjectType(owner) - current.setLocal(local, interpreter.newValue(ctype)) + current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) local++ } for (arg in args) { - current.setLocal(local, interpreter.newValue(arg)) + current.setLocal(local, interpreter.newParameterValue(isInstanceMethod, local, arg)) local++ if (arg.size == 2) { - current.setLocal(local, interpreter.uninitialized()) + current.setLocal(local, interpreter.newEmptyValue(local)) local++ } } while (local < method.maxLocals) { - current.setLocal(local, interpreter.uninitialized()) + current.setLocal(local, interpreter.newEmptyValue(local)) local++ } }