summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Jensen <jensenp@google.com>2015-03-25 11:00:02 -0700
committerBenoit Lamarche <benoitlamarche@google.com>2015-04-07 19:10:01 +0200
commit635aecf324d618ef45d82183d148d47e08383601 (patch)
tree5dd180faa97e336aa70701acc1ee97fef8c0f4f1
parentbd3b381a74023a63b3713749e4be02429467f789 (diff)
downloadandroid_dalvik-635aecf324d618ef45d82183d148d47e08383601.tar.gz
android_dalvik-635aecf324d618ef45d82183d148d47e08383601.tar.bz2
android_dalvik-635aecf324d618ef45d82183d148d47e08383601.zip
Fix potential dex index overflow in dx
Revert change to dex rotation algorithm made as part of commit: 845d9d0eed0f6556e11ee7f7204fda9c8dd41154 Bug: https://code.google.com/p/android/issues/detail?id=161887 Signed-off-by: Peter Jensen <jensenp@google.com> (cherry picked from commit d024c06726c7e119ee76395611aa7cfe3b0a8b7e) Change-Id: Iede742620854cef3542bf98b77e66aa8a305195e
-rw-r--r--dx/src/com/android/dx/command/dexer/Main.java12
-rw-r--r--dx/tests/128-multidex-option-overflow/expected.txt1
2 files changed, 7 insertions, 6 deletions
diff --git a/dx/src/com/android/dx/command/dexer/Main.java b/dx/src/com/android/dx/command/dexer/Main.java
index 49b750a81..59b5ed94c 100644
--- a/dx/src/com/android/dx/command/dexer/Main.java
+++ b/dx/src/com/android/dx/command/dexer/Main.java
@@ -1721,15 +1721,15 @@ public class Main {
// Calculate max number of indices this class will add to the
// dex file.
- // The constant pool contains at least one entry per method
- // (name and signature), at least one entry per field (name
- // and type), and at least per method/field reference (typed
- // method ref).
+ // The possibility of overloading means that we can't easily
+ // know how many constant are needed for declared methods and
+ // fields. We therefore make the simplifying assumption that
+ // all constants are external method or field references.
int constantPoolSize = cf.getConstantPool().size();
- maxMethodIdsInClass = constantPoolSize - cf.getFields().size()
+ maxMethodIdsInClass = constantPoolSize + cf.getMethods().size()
+ MAX_METHOD_ADDED_DURING_DEX_CREATION;
- maxFieldIdsInClass = constantPoolSize - cf.getMethods().size()
+ maxFieldIdsInClass = constantPoolSize + cf.getFields().size()
+ MAX_FIELD_ADDED_DURING_DEX_CREATION;
synchronized(dexRotationLock) {
diff --git a/dx/tests/128-multidex-option-overflow/expected.txt b/dx/tests/128-multidex-option-overflow/expected.txt
index ac448a63d..3d7a649b8 100644
--- a/dx/tests/128-multidex-option-overflow/expected.txt
+++ b/dx/tests/128-multidex-option-overflow/expected.txt
@@ -1,2 +1,3 @@
classes2.dex
+classes3.dex
classes.dex