History log of /dalvik/dx/src/com/android/dx/merge/DexMerger.java
Revision Date Author Comments
cdab79083aae45f792dc5416f8ccc158d816bf88 31-Oct-2012 yroussel <yroussel@google.com> Fix alignment when recompacting a DexMerger result.

(cherry picked from commit a659fe6f8a0b7d32eafc9a2ff7aa1387702da053)

Change-Id: I7c93e7d45b52655cd7adfdc3fc783757ee71079b
5b7285481d0f9ece6aad7f1bceddf903e3dde82d 22-Sep-2011 Jesse Wilson <jessewilson@google.com> Use zero filled alignment padding before method code

(cherry picked from commit d8760772c49647ab197c34b8e46438c410decb42)

Change-Id: I092ff646b02abf7b3ee6285361e4e256c1ade37d
c2a804c050cbd6aa60da7ffaea46c8c99aaf53ad 26-Oct-2012 yroussel <yroussel@google.com> Allow the merging of more than 2 dex file at a time.

(cherry picked from commit f9f7020a0a181ffba3bb9ed123f5bb211a61738e)

Change-Id: I2dd875399c2d30d214b6a025ffea995155ff48c1
3ef1ad8ccca8dff0ca0e3b07309b0e1c2a2591cf 19-Sep-2011 Jesse Wilson <jessewilson@google.com> Switch Dex from byte[] to ByteBuffer for backing store. Part 2.

Change-Id: Ifd3672027d075b6c9f8df208a04bc33122c883af
(cherry picked from commit f8357511efd16d76ce4410459c15dbb08b0140b6)

Conflicts:
dx/src/com/android/dx/merge/DexMerger.java
fe107fb6e3f308ac5174ebdc5a794ee880c741d9 17-Sep-2011 Jesse Wilson <jessewilson@google.com> Mechanical refactoring of dx into two parts.

This splits off a new package, com.android.dex that contains
code for parsing and modelling dex files. This code is usable
both at build time (for compilation and analysis) and at runtime
(for introspection).

The original package, com.android.dx is the tool that compiles
.class files into .dex files. That package also includes utilities
for merging and querying dex files, all visible to the dx command
line application.

In a follow up change I'll move the new com.android.dex package
into the libcore/ project, and configure build rules so that it's
included in both dx.jar and core.jar. The core.jar will then be
able to use it for annotation processing.

Change-Id: I3c58cf87e728e4dda1925a0992c1ee7b8130e81a
(cherry picked from commit bab4abb07335d162ecdb8091fc395cf84803a580)

Conflicts:
dx/junit-tests/com/android/dx/util/BitIntSetTest.java
dx/junit-tests/com/android/dx/util/BitsTest.java
dx/junit-tests/com/android/dx/util/IntListTest.java
dx/junit-tests/com/android/dx/util/ListIntSetTest.java
dx/src/com/android/dex/Dex.java
dx/src/com/android/dex/TableOfContents.java
dx/src/com/android/dx/annotations/AnnotationAccess.java
dx/src/com/android/dx/command/Main.java
dx/src/com/android/dx/dex/code/OutputFinisher.java
dx/src/com/android/dx/dex/code/form/Form32s.java
dx/src/com/android/dx/dex/code/form/Form33x.java
dx/src/com/android/dx/dex/code/form/Form41c.java
dx/src/com/android/dx/dex/code/form/Form52c.java
dx/src/com/android/dx/gen/DexGenerator.java
dx/src/com/android/dx/merge/DexMerger.java
fe48ac9bd8b37501192c675adedaf1193b9c74cb 05-Apr-2013 jwilson <jwilson@squareup.com> Don't duplicate annotation set ref lists when merging.

See exception reported on this thread:
https://groups.google.com/d/msg/android-contrib/h0sDMo5DVBI/MAMiBv5XR44J

Change-Id: I867a8d2328b32625e5baa0b029f55e373fe11271
519975591eba13ae7ac4e494a0dfb88a34ca191b 17-Dec-2012 jwilson <jwilson@squareup.com> Fail if the new index is out of range. do not merge.

We were silently truncating, which made an obvious problem
into a non-obvious one.

Bug: http://code.google.com/p/android/issues/detail?id=40409

(cherry picked from commit 0a752f071fbbdfeab5dd9a230efe0f4f47b8cd94)

Change-Id: I6adbe6309bdcb2882f0e5500d6e1e149d08dbd2d
0a752f071fbbdfeab5dd9a230efe0f4f47b8cd94 17-Dec-2012 jwilson <jwilson@squareup.com> Fail if the new index is out of range.

We were silently truncating, which made an obvious problem
into a non-obvious one.

Bug: http://code.google.com/p/android/issues/detail?id=40409
Change-Id: I15576357c72ac0e98cf85c0a1d289fd5009468f9
288f22800c8fe1eb44afff78ec1fff815379183e 07-Nov-2012 Yohann Roussel <yroussel@google.com> Revert "Fix alignment when recompacting a DexMerger result. do not merge."

This reverts commit 707ebe9f1984f7b1ed2e3465012c7c0eb3ef2bd6

Looks like jb-dev is missing some other patches before it possible to cherry-pick this one.

Change-Id: I8cbdd649d03696cb80be0dacc8640275468ef162
707ebe9f1984f7b1ed2e3465012c7c0eb3ef2bd6 31-Oct-2012 yroussel <yroussel@google.com> Fix alignment when recompacting a DexMerger result. do not merge.

(cherry picked from commit e0e7b076e427a327e27247aa409d0b0fa8b0e0aa)

Change-Id: Ib8092bd9ce9ba5490040a41c5d604e6a138acc7d
15e631eb8bdee248b350fd3eee0b7aa04378eb98 01-Sep-2012 Jesse Wilson <jwilson@squareup.com> Fix an ugly bug where try/catch offsets weren't being mapped properly. do not merge.

In dex files, there are several places where one object refers
to another object by its position in the file. The dex merger
is generally very careful to adjust these mappings when combining
dex files.

Unfortunately one of these cases was broken. Each try_item refers
to a corresponding encoded_catch_handler by its byte offset in a
list. Most of the time this byte offset is the same in the input
dex file and the output dex file. But encoded_catch_handlers are
variable-length because they use a variable-length uleb128 encoding
to address the type_idx being caught. When dex files are merged,
some exception types may go from having a small index to having
a large index, increasing the number of bytes required to encode
that index. This breaks our ability to directly copy over offsets
as we were doing previously.

Bug: http://code.google.com/p/android/issues/detail?id=36490

(cherry picked from commit d43341a24abe339d474b0b0d92669917ae2eb9bf)

Change-Id: I4e6ab791925a918513122b46e039c02dfef62ace
52dc08d463f7c44a01acacfd30d23768c73fa78a 01-Sep-2012 Jesse Wilson <jwilson@squareup.com> Fix a bug where the max blowup of annotations was incorrect. do not merge.

I'm not sure where the 1.34 number comes from but it's incorrect.
From the spec, the encoded_annotation is made up of a single byte
plus an unlimited number of uleb128 values. Each of these values
can double in width in the worst case. I received (personal) email
from one user who'd run into a case worse than the incorrect 1.34
limit.

(cherry picked from commit bf7dfeea94f21dd0e097cf5f786f9995722fd70d)

Change-Id: I033a0d76ea0324d434d732e7757df0c3fd925b68
963b13a8d955af94bffa1231a79614f3e7f7a1e5 23-Aug-2012 Jesse Wilson <jwilson@squareup.com> Fix a bug where debugInfos' size wasn't being computed. do not merge.

Previously debugInfos' size of 0 caused a malformed dex file
because debug data was present but not mentioned in the table
of contents.

(cherry picked from commit 55ac44b64744cd5692d6495bca99dfc8181e0cfc)

Change-Id: I2084c06521ea200772c523cdaa28c8019fa76025
bf7dfeea94f21dd0e097cf5f786f9995722fd70d 01-Sep-2012 Jesse Wilson <jwilson@squareup.com> Fix a bug where the max blowup of annotations was incorrect.

I'm not sure where the 1.34 number comes from but it's incorrect.
From the spec, the encoded_annotation is made up of a single byte
plus an unlimited number of uleb128 values. Each of these values
can double in width in the worst case. I received (personal) email
from one user who'd run into a case worse than the incorrect 1.34
limit.

Change-Id: I3b676e6d2b274aaa538ca61ce23945b3d49aff04
d43341a24abe339d474b0b0d92669917ae2eb9bf 01-Sep-2012 Jesse Wilson <jwilson@squareup.com> Fix an ugly bug where try/catch offsets weren't being mapped properly.

In dex files, there are several places where one object refers
to another object by its position in the file. The dex merger
is generally very careful to adjust these mappings when combining
dex files.

Unfortunately one of these cases was broken. Each try_item refers
to a corresponding encoded_catch_handler by its byte offset in a
list. Most of the time this byte offset is the same in the input
dex file and the output dex file. But encoded_catch_handlers are
variable-length because they use a variable-length uleb128 encoding
to address the type_idx being caught. When dex files are merged,
some exception types may go from having a small index to having
a large index, increasing the number of bytes required to encode
that index. This breaks our ability to directly copy over offsets
as we were doing previously.

Bug: http://code.google.com/p/android/issues/detail?id=36490
Change-Id: I3bdadf20899fdb5d4d074e69103b33c0404a31f8
822a722b412511cd1322d9d32107981c009c470c 08-Jun-2012 Elliott Hughes <enh@google.com> Support debug info in dexmerge. do not merge.

Bug: 4090053

Signed-off-by: Jesse Wilson <jesse@swank.ca>

(cherry picked from commit bc23c4f3ebaefebb3f1be7732767631f91e165ea)

Change-Id: Ic59d3cc1866c2e4328e406f22cb23fc08d5c6d91
55ac44b64744cd5692d6495bca99dfc8181e0cfc 23-Aug-2012 Jesse Wilson <jwilson@squareup.com> Fix a bug where debugInfos' size wasn't being computed.

Previously debugInfos' size of 0 caused a malformed dex file
because debug data was present but not mentioned in the table
of contents.

Change-Id: I07171aaee12fef9f303fc505909f44ef1a714114
89b53f727b579850a777a99b822aab1d31093db0 08-Jun-2012 Elliott Hughes <enh@google.com> Support debug info in dexmerge.

Bug: 4090053

(cherry-pick of bc23c4f3ebaefebb3f1be7732767631f91e165ea.)

Change-Id: I1108933fc03330ff91be3a2edef8b4966977dcd7
Signed-off-by: Jesse Wilson <jesse@swank.ca>
bc23c4f3ebaefebb3f1be7732767631f91e165ea 08-Jun-2012 Elliott Hughes <enh@google.com> Support debug info in dexmerge.

Bug: 4090053

Change-Id: Ided1979b306539bfe3576ef17b72689fc9705abb
Signed-off-by: Jesse Wilson <jesse@swank.ca>
fa3b293a068fd521a6ba6019a051ad502dfaca55 26-Mar-2012 Jesse Wilson <jessewilson@google.com> Transform static values eagerly rather than on use.

Apparently there is some situations where a single static value
may be referenced by multiple sites. Not transforming them eagerly
lead to oversized dex files (and could crash the merge).

Change-Id: I4ac5b9cd621b0fff1e5ba247c9590aa0d562cd65
5094108bb410a24a89580d4c64b3440bc13e8110 11-Mar-2012 Charlie Groves <charlie.groves@gmail.com> Compact merged dexes on their byte aligned size

Previously, if a merged dex had too much free space, the compaction step
would subtract the unused space from the section sizes generated by
adding the merged dexes section sizes. The merged sizes weren't 4-byte
aligned, which meant if a section had been bumped in size for the
boundary, the compaction would fail when loading into a section eg
'Section limit 3665072 exceeded by string data'.

This gets the compacted section size from the actual used space instead
of from the non-aligned estimate, so everything fits.

Change-Id: I1aee1abd721ec21998bb3ea78f6f424e7421b614
a6264bd14e66bd05f98d0b1b98ee9e044b93faf9 19-Aug-2011 Jesse Wilson <jessewilson@google.com> Permit code size to grow when merging dex files.

The throws clauses use variable-length encodings (sleb and uleb)
which will have different lengths when the number of types grows.

Bug: http://b/5127963
Change-Id: I50598a807596955e458d4ec87a730e62e12168d9
09d308b04b7c4fd3ed83a8f8f4c07be67a25478c 17-Mar-2011 Jesse Wilson <jessewilson@google.com> Add support for pre-dexed libraries to dx.

http://b/4090053

Change-Id: Ifb8b9230939cb2a72a767128f79cbfbd042e95a6
bd3dba4346223593ac6033a3d2a7d8ec6f20738b 16-Mar-2011 Jesse Wilson <jessewilson@google.com> Don't emit multiple copies of annotations when merging dex files.

This change requires all annotations to be loaded into memory
so they can be sorted. There does not appear to be a required
order to the annotations in .dex files. Loading annotations also
requires loading encoded values, which makes this into a large
refactoring.

Change-Id: Ib7e2656c595018be4e9936eb84a22f1c1de56750
http://b/4090053
0ebdfc22385095c75fbced79edc1d1e75b504213 15-Mar-2011 Jesse Wilson <jessewilson@google.com> Fix bugs in instruction parsing for incremental dx.

Change-Id: I9557e835e846d42689786833395eecdbbbe6174c
http://b/3447216
d1e1668224cde06bbe5ad8953c7fb86d1d0d40e4 11-Mar-2011 Jesse Wilson <jessewilson@google.com> Fix bugs in incremental dx.

The compaction code used to merge a dex with itself. This caused
problems because annotations would be duplicated. Now the dex is
merged with an empty dex. I've changed the section default from
-1 to 0 to make the empty dex trivial to construct.

It also had a correctness problem where we were using the wrong
offsets when merging indexed values. Move the offsets out of the
loop so they aren't reset.

Change-Id: Ibcf24de8f96c2c525ca2e2ac44550239e3cf689e
http://b/3447216
ae38a1e705253b53abf1beff7dc3467d52c58f32 08-Mar-2011 Jesse Wilson <jessewilson@google.com> Add a tool to grep the strings in a dex file.

Change-Id: I21b8537518718350def2f847e9c76ae4154bd4d6
http://b/4026001
20d269ea2a9e8d41b298134f3937c6d959288b53 19-Feb-2011 Jesse Wilson <jessewilson@google.com> Retain annotations when merging dex files.

This change has one major limitation: it doesn't deduplicate
equal annotation directories or annotation sets across dex
files. That will result in unnecessarily large dex files.

Change-Id: If63273d16eba1d989c6b5695d102b378d4047119
http://b/3447216
4ceb6bc262c780c456c4d40222a2d0a56eaec02a 16-Feb-2011 Jesse Wilson <jessewilson@google.com> Emit compact ouput .dex files.

Change-Id: I69ca23b53a542db7e7a18d819795e795bf0822c0
http://b/3447216
cdef3ed061e2a045d956ea613556a67f9ac6e9d0 15-Feb-2011 Jesse Wilson <jessewilson@google.com> Deduplicate type lists on merged .dex files.

Change-Id: Ic089fecebb66544dfdb422421cce47a6f203a31a
http://b/3447216
dc86cd9edc8b80953c8b698a83cdaebf6825d798 18-Jan-2011 Jesse Wilson <jessewilson@google.com> Add an undocumented --incremental option to dx.

Change-Id: I48879b2f724e9b92c99c669803f9c8de01487327
e31a42442bbd2cdc69e959f5209b793cf0aa7217 17-Jan-2011 Jesse Wilson <jessewilson@google.com> Make DexMerger's dex reader general purpose.

Use this to implement FindUsages, which prints references to
fields and methods within a dex. This is the FindUsages output
for "Ljava/lang/Number;", "longValue" on libcore's dex file:

Method referenced by Ljava/io/EmulatedFields;#get invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/io/EmulatedFieldsForDumping;#write invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/io/ObjectOutputStream;#writeFieldValues invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method declared by Ljava/lang/Number;#longValue
Method declared by Ljava/lang/Byte;#longValue
Method declared by Ljava/lang/Double;#longValue
Method declared by Ljava/lang/Float;#longValue
Method declared by Ljava/lang/Integer;#longValue
Method declared by Ljava/lang/Long;#longValue
Method declared by Ljava/lang/Short;#longValue
Method referenced by Ljava/lang/reflect/Array;#set invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#divideBigIntegers invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#divideBigIntegers invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#divideBigIntegers invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#readObject invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#setUnscaledValue invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#valueExact invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/BigDecimal;#doubleValue invoke-virtual/range {vCCCC..vNNNN}, meth@BBBB
Method referenced by Ljava/math/BigDecimal;#doubleValue invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method declared by Ljava/math/BigDecimal;#longValue
Method referenced by Ljava/math/BigDecimal;#longValue invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method declared by Ljava/math/BigInteger;#longValue
Method referenced by Ljava/math/Conversion;#bigInteger2Double invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/math/Conversion;#bigInteger2Double invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/text/NumberFormat;#format invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/text/DateFormat;#format invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/text/DecimalFormat;#format invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/text/DecimalFormat;#parse invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/text/SimpleDateFormat;#formatToCharacterIterator invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transform invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transformFromDateTime invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transformFromInteger invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transformFromInteger invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transformFromInteger invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transformFromInteger invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transform_g invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transform_g invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transform_g invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Formatter;#transform_g invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Ljava/util/Scanner;#nextLong invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method declared by Ljava/util/concurrent/atomic/AtomicInteger;#longValue
Method declared by Ljava/util/concurrent/atomic/AtomicLong;#longValue
Method referenced by Llibcore/icu/NativeDecimalFormat;#formatToCharacterIterator invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/apache/xalan/xslt/SecuritySupport12;#getLastModified invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/apache/xml/dtm/SecuritySupport12;#getLastModified invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/apache/xml/dtm/ref/SecuritySupport12;#getLastModified invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/apache/xml/serializer/SecuritySupport12;#getLastModified invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/apache/xml/utils/SecuritySupport12;#getLastModified invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/apache/xpath/functions/SecuritySupport12;#getLastModified invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/json/JSON;#toLong invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/json/JSONArray;#getLong invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/json/JSONArray;#optLong invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/json/JSONObject;#numberToString invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/json/JSONObject;#getLong invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC
Method referenced by Lorg/json/JSONObject;#optLong invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC

Change-Id: Ia50f28f53ce5838799e2d5f03a7a2f1c551299de
dc8ad6cbf19b62d8c50527a0a38fe82b937370f1 15-Jan-2011 Jesse Wilson <jessewilson@google.com> Improve the interface for reading Dex files.

I'm planning on making this code reusable for grepping
dex files.

Change-Id: Iebf545ed6d6a4eb347ccc4a39fe40c02d75d69e4
dfc5e8e159e7df3efa47d553b7725be22839665d 14-Jan-2011 Jesse Wilson <jessewilson@google.com> Read Dex files from a byte[] rather than a RandomAccessFile.

This improves time to merge a trivial file with core.dex from
3.8 seconds to 0.8 seconds.

Also fixing read method names to be consistent with the spec.

Change-Id: I9033bcb497afe7a0d73e00cca14fa046b53a62bf
081c7142b29ccd6e1744b26e097b6a4d7c12f2bd 04-Jan-2011 Jesse Wilson <jessewilson@google.com> New tool merge two dex files into one.

This code isn't yet ready for general use, but I have booted a device
using a core.jar from the product of a merge. In particular, I still
need to better size the output dex.

The motivation is to support incremental builds in dx. Given a
"--incremental" flag, dx would create a dex file containing only those
classes newer than the target .dex. Then it would merge that small
.dex with the current .dex. Hopefully this yields a nice speedup
over dexing everything.

It would also be possible to use this to do parallel builds. We would
manually partition the input files, dx them, and then merge the result
together.

Change-Id: I8997fb3c8bfe73b64ef38a7cb3d6456fbe799d0f