Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace recursive analysis algorithms with iterations to avoid S…
…tackOverflow on big methods (#441)
- Loading branch information
Showing
4 changed files
with
117 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
jadx-core/src/main/java/jadx/core/dex/visitors/ssa/RenameState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package jadx.core.dex.visitors.ssa; | ||
|
||
import java.util.Arrays; | ||
|
||
import jadx.core.dex.instructions.args.RegisterArg; | ||
import jadx.core.dex.instructions.args.SSAVar; | ||
import jadx.core.dex.nodes.BlockNode; | ||
import jadx.core.dex.nodes.MethodNode; | ||
|
||
final class RenameState { | ||
private final MethodNode mth; | ||
private final BlockNode block; | ||
private final SSAVar[] vars; | ||
private final int[] versions; | ||
|
||
public static RenameState init(MethodNode mth) { | ||
int regsCount = mth.getRegsCount(); | ||
RenameState state = new RenameState( | ||
mth, | ||
mth.getEnterBlock(), | ||
new SSAVar[regsCount], | ||
new int[regsCount] | ||
); | ||
for (RegisterArg arg : mth.getArguments(true)) { | ||
state.startVar(arg); | ||
} | ||
return state; | ||
} | ||
|
||
public static RenameState copyFrom(RenameState state, BlockNode block) { | ||
return new RenameState( | ||
state.mth, | ||
block, | ||
Arrays.copyOf(state.vars, state.vars.length), | ||
state.versions | ||
); | ||
} | ||
|
||
private RenameState(MethodNode mth, BlockNode block, SSAVar[] vars, int[] versions) { | ||
this.mth = mth; | ||
this.block = block; | ||
this.vars = vars; | ||
this.versions = versions; | ||
} | ||
|
||
public BlockNode getBlock() { | ||
return block; | ||
} | ||
|
||
public SSAVar getVar(int regNum) { | ||
return vars[regNum]; | ||
} | ||
|
||
public void startVar(RegisterArg regArg) { | ||
int regNum = regArg.getRegNum(); | ||
int version = versions[regNum]++; | ||
vars[regNum] = mth.makeNewSVar(regNum, version, regArg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters