[JVM] Extract unique code in Fast...Analyzer into analyzeInstruction
This commit is contained in:
+30
-19
@@ -84,10 +84,39 @@ open class FastMethodAnalyzer<V : Value>
|
|||||||
queued[insn] = false
|
queued[insn] = false
|
||||||
|
|
||||||
val insnNode = method.instructions[insn]
|
val insnNode = method.instructions[insn]
|
||||||
try {
|
|
||||||
val insnOpcode = insnNode.opcode
|
val insnOpcode = insnNode.opcode
|
||||||
val insnType = insnNode.type
|
val insnType = insnNode.type
|
||||||
|
|
||||||
|
try {
|
||||||
|
analyzeInstruction(insnType, insnOpcode, insn, f, current, insnNode, isTcbStart, handler)
|
||||||
|
} catch (e: AnalyzerException) {
|
||||||
|
throw AnalyzerException(
|
||||||
|
e.node,
|
||||||
|
"Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}\ncurrent: ${current.dump()}",
|
||||||
|
e
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw AnalyzerException(
|
||||||
|
insnNode,
|
||||||
|
"Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}\ncurrent: ${current.dump()}",
|
||||||
|
e
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return frames
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun analyzeInstruction(
|
||||||
|
insnType: Int,
|
||||||
|
insnOpcode: Int,
|
||||||
|
insn: Int,
|
||||||
|
f: Frame<V>,
|
||||||
|
current: Frame<V>,
|
||||||
|
insnNode: AbstractInsnNode,
|
||||||
|
isTcbStart: BooleanArray,
|
||||||
|
handler: Frame<V>,
|
||||||
|
) {
|
||||||
if (insnType == AbstractInsnNode.LABEL ||
|
if (insnType == AbstractInsnNode.LABEL ||
|
||||||
insnType == AbstractInsnNode.LINE ||
|
insnType == AbstractInsnNode.LINE ||
|
||||||
insnType == AbstractInsnNode.FRAME ||
|
insnType == AbstractInsnNode.FRAME ||
|
||||||
@@ -118,24 +147,6 @@ open class FastMethodAnalyzer<V : Value>
|
|||||||
mergeControlFlowEdge(jump, handler)
|
mergeControlFlowEdge(jump, handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e: AnalyzerException) {
|
|
||||||
throw AnalyzerException(
|
|
||||||
e.node,
|
|
||||||
"Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}\ncurrent: ${current.dump()}",
|
|
||||||
e
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw AnalyzerException(
|
|
||||||
insnNode,
|
|
||||||
"Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}\ncurrent: ${current.dump()}",
|
|
||||||
e
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return frames
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initLocals(current: Frame<V>) {
|
private fun initLocals(current: Frame<V>) {
|
||||||
|
|||||||
+20
-10
@@ -88,6 +88,26 @@ internal open class FastStackAnalyzer<V : Value>(
|
|||||||
val insnType = insnNode.type
|
val insnType = insnNode.type
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
analyzeInstruction(insnType, insnNode, f, insn, current, insnOpcode, handler)
|
||||||
|
} catch (e: AnalyzerException) {
|
||||||
|
throw AnalyzerException(e.node, "Error at instruction #$insn ${insnNode.insnText}: ${e.message}", e)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw AnalyzerException(insnNode, "Error at instruction #$insn ${insnNode.insnText}: ${e.message}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return frames
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun analyzeInstruction(
|
||||||
|
insnType: Int,
|
||||||
|
insnNode: AbstractInsnNode,
|
||||||
|
f: Frame<V>,
|
||||||
|
insn: Int,
|
||||||
|
current: Frame<V>,
|
||||||
|
insnOpcode: Int,
|
||||||
|
handler: Frame<V>,
|
||||||
|
) {
|
||||||
if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) {
|
if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) {
|
||||||
visitNopInsn(insnNode, f, insn)
|
visitNopInsn(insnNode, f, insn)
|
||||||
} else {
|
} else {
|
||||||
@@ -109,16 +129,6 @@ internal open class FastStackAnalyzer<V : Value>(
|
|||||||
mergeControlFlowEdge(jump, handler)
|
mergeControlFlowEdge(jump, handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e: AnalyzerException) {
|
|
||||||
throw AnalyzerException(e.node, "Error at instruction #$insn ${insnNode.insnText}: ${e.message}", e)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw AnalyzerException(insnNode, "Error at instruction #$insn ${insnNode.insnText}: ${e.message}", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return frames
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFrame(insn: AbstractInsnNode): Frame<V>? =
|
fun getFrame(insn: AbstractInsnNode): Frame<V>? =
|
||||||
|
|||||||
+21
-10
@@ -131,10 +131,30 @@ class FastStoreLoadAnalyzer<V : StoreLoadValue>(
|
|||||||
queued[insn] = false
|
queued[insn] = false
|
||||||
|
|
||||||
val insnNode = method.instructions[insn]
|
val insnNode = method.instructions[insn]
|
||||||
try {
|
|
||||||
val insnOpcode = insnNode.opcode
|
val insnOpcode = insnNode.opcode
|
||||||
val insnType = insnNode.type
|
val insnType = insnNode.type
|
||||||
|
|
||||||
|
try {
|
||||||
|
analyzeInstruction(insnType, insn, f, current, insnNode, insnOpcode, handler)
|
||||||
|
} catch (e: AnalyzerException) {
|
||||||
|
throw AnalyzerException(e.node, "Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}", e)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw AnalyzerException(insnNode, "Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return frames
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun analyzeInstruction(
|
||||||
|
insnType: Int,
|
||||||
|
insn: Int,
|
||||||
|
f: StoreLoadFrame<V>,
|
||||||
|
current: StoreLoadFrame<V>,
|
||||||
|
insnNode: AbstractInsnNode,
|
||||||
|
insnOpcode: Int,
|
||||||
|
handler: StoreLoadFrame<V>,
|
||||||
|
) {
|
||||||
if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) {
|
if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) {
|
||||||
mergeControlFlowEdge(insn + 1, f)
|
mergeControlFlowEdge(insn + 1, f)
|
||||||
} else {
|
} else {
|
||||||
@@ -147,15 +167,6 @@ class FastStoreLoadAnalyzer<V : StoreLoadValue>(
|
|||||||
handler.init(f)
|
handler.init(f)
|
||||||
mergeControlFlowEdge(jump, handler)
|
mergeControlFlowEdge(jump, handler)
|
||||||
}
|
}
|
||||||
} catch (e: AnalyzerException) {
|
|
||||||
throw AnalyzerException(e.node, "Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}", e)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw AnalyzerException(insnNode, "Error at instruction #$insn ${insnNode.insnText(method.instructions)}: ${e.message}", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return frames
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newFrame(maxLocals: Int) =
|
private fun newFrame(maxLocals: Int) =
|
||||||
|
|||||||
Reference in New Issue
Block a user