[JVM] Unify initLocals method in Fast...Analyzer classes

This commit is contained in:
Ivan Kylchik
2023-09-05 17:11:41 +02:00
committed by Space Team
parent 02d8a62cb0
commit 83c75c1edf
4 changed files with 26 additions and 17 deletions
@@ -110,20 +110,18 @@ open class FastMethodAnalyzer<V : Value>
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))
}
}
@@ -53,6 +53,10 @@ abstract class BasicTypeInterpreter<V : Value> : Interpreter<V>(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 ->
@@ -141,18 +141,23 @@ internal open class FastStackAnalyzer<V : Value>(
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++
}
}
@@ -189,23 +189,25 @@ class FastStoreLoadAnalyzer<V : StoreLoadValue>(
}
override fun initLocals(current: StoreLoadFrame<V>) {
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++
}
}