[JVM] Make newFrame constructor's parameter for FastAnalyzer
This commit is contained in:
@@ -810,7 +810,8 @@ class MethodInliner(
|
||||
|
||||
removeFakeVariablesInitializationIfPresent(node)
|
||||
|
||||
val frames = FastStackAnalyzer("<fake>", node, FixStackInterpreter()).analyze()
|
||||
val analyzer = FastStackAnalyzer("<fake>", node, FixStackInterpreter()) { nLocals, nStack -> Frame(nLocals, nStack) }
|
||||
val frames = analyzer.analyze()
|
||||
|
||||
val localReturnsNormalizer = LocalReturnsNormalizer()
|
||||
|
||||
|
||||
+1
-2
@@ -20,6 +20,7 @@ abstract class FastAnalyzer<V : Value, F : Frame<V>>(
|
||||
private val method: MethodNode,
|
||||
private val interpreter: Interpreter<V>,
|
||||
private val pruneExceptionEdges: Boolean,
|
||||
private val newFrame: (Int, Int) -> F
|
||||
) {
|
||||
private val nInsns = method.instructions.size()
|
||||
private val frames: Array<Frame<V>?> = arrayOfNulls(nInsns)
|
||||
@@ -32,8 +33,6 @@ abstract class FastAnalyzer<V : Value, F : Frame<V>>(
|
||||
private val queue = IntArray(nInsns)
|
||||
private var top = 0
|
||||
|
||||
protected abstract fun newFrame(nLocals: Int, nStack: Int): F
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun getFrame(insn: AbstractInsnNode): F? = frames[insn.indexOf()] as? F
|
||||
|
||||
|
||||
+2
-7
@@ -38,16 +38,11 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Value
|
||||
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.codegen.optimization.fixStack.FastStackAnalyzer
|
||||
*/
|
||||
class FastMethodAnalyzer<V : Value>
|
||||
@JvmOverloads constructor(
|
||||
owner: String,
|
||||
method: MethodNode,
|
||||
interpreter: Interpreter<V>,
|
||||
pruneExceptionEdges: Boolean = false,
|
||||
private val createFrame: (Int, Int) -> Frame<V> = { nLocals, nStack -> Frame<V>(nLocals, nStack) }
|
||||
) : FastAnalyzer<V, Frame<V>>(owner, method, interpreter, pruneExceptionEdges) {
|
||||
override fun newFrame(nLocals: Int, nStack: Int): Frame<V> = createFrame(nLocals, nStack)
|
||||
}
|
||||
newFrame: (Int, Int) -> Frame<V> = { nLocals, nStack -> Frame<V>(nLocals, nStack) }
|
||||
) : FastAnalyzer<V, Frame<V>>(owner, method, interpreter, pruneExceptionEdges, newFrame)
|
||||
|
||||
+2
-7
@@ -39,19 +39,14 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Value
|
||||
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.codegen.optimization.common.FastMethodAnalyzer
|
||||
*/
|
||||
// This is a very specific version of method bytecode analyzer that doesn't perform any DFA,
|
||||
// but infers stack types for reachable instructions instead.
|
||||
internal open class FastStackAnalyzer<V : Value, F : Frame<V>>(
|
||||
owner: String,
|
||||
method: MethodNode,
|
||||
interpreter: Interpreter<V>,
|
||||
private val createFrame: (Int, Int) -> Frame<V> = { nLocals, nStack -> Frame<V>(nLocals, nStack) }
|
||||
) : FastAnalyzer<V, F>(owner, method, interpreter, pruneExceptionEdges = false) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun newFrame(nLocals: Int, nStack: Int): F = createFrame(nLocals, nStack) as F
|
||||
newFrame: (Int, Int) -> F
|
||||
) : FastAnalyzer<V, F>(owner, method, interpreter, pruneExceptionEdges = false, newFrame) {
|
||||
|
||||
// Don't have to visit the same exception handler multiple times - we care only about stack state at TCB start.
|
||||
override fun useFastComputeExceptionHandlers(): Boolean = true
|
||||
|
||||
+3
-4
@@ -65,7 +65,6 @@ class StoreLoadFrame<V : Value>(val maxLocals: Int) : Frame<V>(maxLocals, 0) {
|
||||
class FastStoreLoadAnalyzer<V : Value>(
|
||||
owner: String,
|
||||
method: MethodNode,
|
||||
interpreter: Interpreter<V>
|
||||
) : FastAnalyzer<V, StoreLoadFrame<V>>(owner, method, interpreter, pruneExceptionEdges = false) {
|
||||
override fun newFrame(nLocals: Int, nStack: Int): StoreLoadFrame<V> = StoreLoadFrame(nLocals)
|
||||
}
|
||||
interpreter: Interpreter<V>,
|
||||
newFrame: (Int, Int) -> StoreLoadFrame<V> = { nLocals, _ -> StoreLoadFrame(nLocals) }
|
||||
) : FastAnalyzer<V, StoreLoadFrame<V>>(owner, method, interpreter, pruneExceptionEdges = false, newFrame)
|
||||
|
||||
Reference in New Issue
Block a user