[JVM] Replace open functions in FastAnalyzer with constructor args

This commit is contained in:
Ivan Kylchik
2023-09-07 18:04:21 +02:00
committed by Space Team
parent 99655cfa15
commit c1c04376cf
5 changed files with 25 additions and 15 deletions
@@ -20,6 +20,8 @@ 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 useFastComputeExceptionHandlers: Boolean,
private val useFastMergeControlFlowEdge: Boolean,
private val newFrame: (Int, Int) -> F private val newFrame: (Int, Int) -> F
) { ) {
private val nInsns = method.instructions.size() private val nInsns = method.instructions.size()
@@ -139,11 +141,9 @@ abstract class FastAnalyzer<V : Value, F : Frame<V>>(
throw AssertionError("Subroutines are deprecated since Java 6") throw AssertionError("Subroutines are deprecated since Java 6")
} }
protected open fun useFastComputeExceptionHandlers(): Boolean = false
private fun computeExceptionHandlers(m: MethodNode) { private fun computeExceptionHandlers(m: MethodNode) {
for (tcb in m.tryCatchBlocks) { for (tcb in m.tryCatchBlocks) {
if (useFastComputeExceptionHandlers()) computeExceptionHandlerFast(tcb) else computeExceptionHandlersForEachInsn(tcb) if (useFastComputeExceptionHandlers) computeExceptionHandlerFast(tcb) else computeExceptionHandlersForEachInsn(tcb)
} }
} }
@@ -209,8 +209,6 @@ abstract class FastAnalyzer<V : Value, F : Frame<V>>(
} }
} }
protected open fun useFastMergeControlFlowEdge(): Boolean = false
/** /**
* Updates frame at the index [dest] with its old value if provided and previous control flow node frame [frame]. * Updates frame at the index [dest] with its old value if provided and previous control flow node frame [frame].
* Reuses old frame when possible and when [canReuse] is true. * Reuses old frame when possible and when [canReuse] is true.
@@ -231,7 +229,7 @@ abstract class FastAnalyzer<V : Value, F : Frame<V>>(
oldFrame.init(frame) oldFrame.init(frame)
true true
} }
!useFastMergeControlFlowEdge() -> !useFastMergeControlFlowEdge ->
try { try {
oldFrame.merge(frame, interpreter) oldFrame.merge(frame, interpreter)
} catch (e: AnalyzerException) { } catch (e: AnalyzerException) {
@@ -45,4 +45,9 @@ class FastMethodAnalyzer<V : Value>
interpreter: Interpreter<V>, interpreter: Interpreter<V>,
pruneExceptionEdges: Boolean = false, pruneExceptionEdges: Boolean = false,
newFrame: (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, newFrame) ) : FastAnalyzer<V, Frame<V>>(
owner, method, interpreter, pruneExceptionEdges,
useFastComputeExceptionHandlers = false,
useFastMergeControlFlowEdge = false,
newFrame
)
@@ -46,9 +46,11 @@ internal open class FastStackAnalyzer<V : Value, F : Frame<V>>(
method: MethodNode, method: MethodNode,
interpreter: Interpreter<V>, interpreter: Interpreter<V>,
newFrame: (Int, Int) -> F newFrame: (Int, Int) -> F
) : FastAnalyzer<V, F>(owner, method, interpreter, pruneExceptionEdges = false, newFrame) { ) : FastAnalyzer<V, F>(
owner, method, interpreter,
pruneExceptionEdges = false,
// 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 useFastComputeExceptionHandlers = true,
override fun useFastMergeControlFlowEdge(): Boolean = true useFastMergeControlFlowEdge = true,
} newFrame
)
@@ -46,8 +46,7 @@ internal class FixStackAnalyzer(
owner, method, FixStackInterpreter(), { nLocals, nStack -> FixStackFrame(nLocals, nStack) } owner, method, FixStackInterpreter(), { nLocals, nStack -> FixStackFrame(nLocals, nStack) }
) { ) {
override fun visitControlFlowEdge(insnNode: AbstractInsnNode, successor: Int): Boolean { override fun visitControlFlowEdge(insnNode: AbstractInsnNode, successor: Int): Boolean {
if (!skipBreakContinueGotoEdges) return true return !(skipBreakContinueGotoEdges && insnNode is JumpInsnNode && context.breakContinueGotoNodes.contains(insnNode))
return !(insnNode is JumpInsnNode && context.breakContinueGotoNodes.contains(insnNode))
} }
} }
@@ -67,4 +67,10 @@ class FastStoreLoadAnalyzer<V : Value>(
method: MethodNode, method: MethodNode,
interpreter: Interpreter<V>, interpreter: Interpreter<V>,
newFrame: (Int, Int) -> StoreLoadFrame<V> = { nLocals, _ -> StoreLoadFrame(nLocals) } newFrame: (Int, Int) -> StoreLoadFrame<V> = { nLocals, _ -> StoreLoadFrame(nLocals) }
) : FastAnalyzer<V, StoreLoadFrame<V>>(owner, method, interpreter, pruneExceptionEdges = false, newFrame) ) : FastAnalyzer<V, StoreLoadFrame<V>>(
owner, method, interpreter,
pruneExceptionEdges = false,
useFastComputeExceptionHandlers = false,
useFastMergeControlFlowEdge = false,
newFrame
)