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