Skip to content

Commit e0f38c7

Browse files
authored
Merge pull request #2060 from wangnianwu/develop
Fix the time consume problem in method `instructionAtAddress`
2 parents 58ec81a + 53821d5 commit e0f38c7

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/main/java/soot/dexpler/DexBody.java

+26-24
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import java.io.IOException;
3636
import java.util.ArrayList;
3737
import java.util.Collections;
38-
import java.util.HashMap;
3938
import java.util.HashSet;
4039
import java.util.LinkedList;
4140
import java.util.List;
42-
import java.util.Map;
4341
import java.util.Set;
42+
import java.util.TreeMap;
43+
import java.util.concurrent.atomic.AtomicReference;
4444

4545
import org.jf.dexlib2.analysis.ClassPath;
4646
import org.jf.dexlib2.analysis.ClassPathResolver;
@@ -140,7 +140,7 @@ public class DexBody {
140140
// registers
141141
protected Local[] registerLocals;
142142
protected Local storeResultLocal;
143-
protected Map<Integer, DexlibAbstractInstruction> instructionAtAddress;
143+
protected TreeMap<Integer, DexlibAbstractInstruction> instructionAtAddress;
144144

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

265265
instructions = new ArrayList<DexlibAbstractInstruction>();
266-
instructionAtAddress = new HashMap<Integer, DexlibAbstractInstruction>();
266+
267+
// Use descending order
268+
instructionAtAddress = new TreeMap<Integer, DexlibAbstractInstruction>();
267269
localDebugs = ArrayListMultimap.create();
268270
takenLocalNames = new HashSet<String>();
269271

@@ -446,27 +448,27 @@ public Local getStoreResultLocal() {
446448
* if address is not part of this body.
447449
*/
448450
public DexlibAbstractInstruction instructionAtAddress(int address) {
449-
DexlibAbstractInstruction i = null;
450-
while (i == null && address >= 0) {
451-
// catch addresses can be in the middlde of last instruction. Ex. in
452-
// com.letang.ldzja.en.apk:
453-
//
454-
// 042c46: 7020 2a15 0100 |008f: invoke-direct {v1, v0},
455-
// Ljavax/mi...
456-
// 042c4c: 2701 |0092: throw v1
457-
// catches : 4
458-
// <any> -> 0x0065
459-
// 0x0069 - 0x0093
460-
//
461-
// SA, 14.05.2014: We originally scanned only two code units back.
462-
// This is not sufficient
463-
// if we e.g., have a wide constant and the line number in the debug
464-
// sections points to
465-
// some address the middle.
466-
i = instructionAtAddress.get(address);
467-
address--;
451+
452+
// catch addresses can be in the middlde of last instruction. Ex. in
453+
// com.letang.ldzja.en.apk:
454+
//
455+
// 042c46: 7020 2a15 0100 |008f: invoke-direct {v1, v0},
456+
// Ljavax/mi...
457+
// 042c4c: 2701 |0092: throw v1
458+
// catches : 4
459+
// <any> -> 0x0065
460+
// 0x0069 - 0x0093
461+
//
462+
// SA, 14.05.2014: We originally scanned only two code units back.
463+
// This is not sufficient
464+
// if we e.g., have a wide constant and the line number in the debug
465+
// sections points to
466+
// some address the middle.
467+
Integer key = instructionAtAddress.floorKey(address);
468+
if (key == null) {
469+
return null;
468470
}
469-
return i;
471+
return instructionAtAddress.get(key);
470472
}
471473

472474
/**

0 commit comments

Comments
 (0)