try..catch vs loops

This commit is contained in:
Jindra Petřík
2021-02-07 11:10:19 +01:00
parent 7644eddfd3
commit bca83c3bb4
20 changed files with 342 additions and 109 deletions

View File

@@ -89,6 +89,8 @@ public class AVM2LocalData extends BaseLocalData {
*/
public Map<Integer, GraphPart> finallyThrowParts = new HashMap<>();
public Map<Integer, GraphPart> finallyTargetParts = new HashMap<>();
//switchedPart -> index of nextpart
public Map<GraphPart, Integer> defaultWays = new HashMap<>();
@@ -156,6 +158,7 @@ public class AVM2LocalData extends BaseLocalData {
finallyThrowParts = localData.finallyThrowParts;
inGetLoops = localData.inGetLoops;
parsedExceptionIds = localData.parsedExceptionIds;
finallyTargetParts = localData.finallyTargetParts;
}
public AVM2ConstantPool getConstants() {

View File

@@ -160,9 +160,27 @@ public class AVM2Graph extends Graph {
}
@Override
protected boolean canBeBreakCandidate(BaseLocalData localData, GraphPart part) {
AVM2LocalData aLocalData = (AVM2LocalData) localData;
if (aLocalData.finallyTargetParts.containsValue(part)) {
return false;
}
return true;
}
@Override
protected void beforeGetLoops(BaseLocalData localData, String path, Set<GraphPart> allParts, List<ThrowState> throwStates) throws InterruptedException {
AVM2LocalData avm2LocalData = ((AVM2LocalData) localData);
for (int e = 0; e < body.exceptions.length; e++) {
ABCException ex = body.exceptions[e];
if (ex.isFinally()) {
avm2LocalData.finallyTargetParts.put(e, searchPart(code.adr2pos(ex.target), allParts));
}
}
avm2LocalData.codeStats = avm2LocalData.code.getStats(avm2LocalData.abc, avm2LocalData.methodBody, avm2LocalData.methodBody.init_scope_depth, false);
getIgnoredSwitches((AVM2LocalData) localData, allParts);
Set<Integer> integerSwitchesIps = new HashSet<>();

View File

@@ -143,7 +143,7 @@ public class ActionGraph extends Graph {
}
@Override
protected boolean canBeBreakCandidate(GraphPart part) {
protected boolean canBeBreakCandidate(BaseLocalData localData, GraphPart part) {
if (part.refs.size() <= 1) {
return true;
}