Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the time consume problem in method instructionAtAddress #2060

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;

import org.jf.dexlib2.analysis.ClassPath;
import org.jf.dexlib2.analysis.ClassPathResolver;
Expand Down Expand Up @@ -140,7 +140,7 @@ public class DexBody {
// registers
protected Local[] registerLocals;
protected Local storeResultLocal;
protected Map<Integer, DexlibAbstractInstruction> instructionAtAddress;
protected TreeMap<Integer, DexlibAbstractInstruction> instructionAtAddress;

protected List<DeferableInstruction> deferredInstructions;
protected Set<RetypeableInstruction> instructionsToRetype;
Expand Down Expand Up @@ -263,7 +263,9 @@ protected DexBody(DexEntry<? extends DexFile> dexFile, Method method, RefType de
}

instructions = new ArrayList<DexlibAbstractInstruction>();
instructionAtAddress = new HashMap<Integer, DexlibAbstractInstruction>();

// Use descending order
instructionAtAddress = new TreeMap<Integer, DexlibAbstractInstruction>();
localDebugs = ArrayListMultimap.create();
takenLocalNames = new HashSet<String>();

Expand Down Expand Up @@ -446,27 +448,27 @@ public Local getStoreResultLocal() {
* if address is not part of this body.
*/
public DexlibAbstractInstruction instructionAtAddress(int address) {
DexlibAbstractInstruction i = null;
while (i == null && address >= 0) {
// catch addresses can be in the middlde of last instruction. Ex. in
// com.letang.ldzja.en.apk:
//
// 042c46: 7020 2a15 0100 |008f: invoke-direct {v1, v0},
// Ljavax/mi...
// 042c4c: 2701 |0092: throw v1
// catches : 4
// <any> -> 0x0065
// 0x0069 - 0x0093
//
// SA, 14.05.2014: We originally scanned only two code units back.
// This is not sufficient
// if we e.g., have a wide constant and the line number in the debug
// sections points to
// some address the middle.
i = instructionAtAddress.get(address);
address--;

// catch addresses can be in the middlde of last instruction. Ex. in
// com.letang.ldzja.en.apk:
//
// 042c46: 7020 2a15 0100 |008f: invoke-direct {v1, v0},
// Ljavax/mi...
// 042c4c: 2701 |0092: throw v1
// catches : 4
// <any> -> 0x0065
// 0x0069 - 0x0093
//
// SA, 14.05.2014: We originally scanned only two code units back.
// This is not sufficient
// if we e.g., have a wide constant and the line number in the debug
// sections points to
// some address the middle.
Integer key = instructionAtAddress.floorKey(address);
if (key == null) {
return null;
}
return i;
return instructionAtAddress.get(key);
}

/**
Expand Down
Loading