summaryrefslogtreecommitdiffstats
path: root/dx
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2014-04-11 09:28:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-04-11 09:28:18 +0000
commit18d990d24d1f1daf87d20fee4605ee1de7c4b4ac (patch)
treef57c23036740086d91cb085be986bfdaab4e592a /dx
parent96d2943092031f6201093754c808f29dec7c6e6c (diff)
parentf227060968f467c0aac1a435333d73e938567171 (diff)
downloadtoolchain_jack-18d990d24d1f1daf87d20fee4605ee1de7c4b4ac.zip
toolchain_jack-18d990d24d1f1daf87d20fee4605ee1de7c4b4ac.tar.gz
toolchain_jack-18d990d24d1f1daf87d20fee4605ee1de7c4b4ac.tar.bz2
Merge "Split dex file writing into prepare and writing stage" into jack-wip-dev
Diffstat (limited to 'dx')
-rw-r--r--dx/src/com/android/jack/dx/dex/file/DexFile.java65
-rw-r--r--dx/src/com/android/jack/dx/dex/file/ImportedCodeItem.java14
2 files changed, 49 insertions, 30 deletions
diff --git a/dx/src/com/android/jack/dx/dex/file/DexFile.java b/dx/src/com/android/jack/dx/dex/file/DexFile.java
index 027cb25..413911b 100644
--- a/dx/src/com/android/jack/dx/dex/file/DexFile.java
+++ b/dx/src/com/android/jack/dx/dex/file/DexFile.java
@@ -105,11 +105,10 @@ public final class DexFile {
/** {@code >= 40;} maximum width of the file dump */
private int dumpWidth;
- /** List of constant index mapping that must be used to remap binary */
- private List<CstIndexMap> cstIndexMaps;
-
- public DexFile(DexOptions dexOptions, List<CstIndexMap> cstIndexMaps) {
- this.cstIndexMaps = cstIndexMaps;
+ /**
+ * Constructs an instance. It is initially empty.
+ */
+ public DexFile(DexOptions dexOptions) {
this.dexOptions = dexOptions;
header = new HeaderSection(this);
@@ -149,13 +148,6 @@ public final class DexFile {
}
/**
- * Constructs an instance. It is initially empty.
- */
- public DexFile(DexOptions dexOptions) {
- this(dexOptions, null);
- }
-
- /**
* Returns true if this dex doesn't contain any class defs.
*/
public boolean isEmpty() {
@@ -496,26 +488,23 @@ public final class DexFile {
}
/**
- * Returns the contents of this instance as a {@code .dex} file,
- * in a {@link ByteArrayAnnotatedOutput} instance.
+ * Prepares this instance for writing. This performs any necessary prerequisites, including
+ * particularly adding stuff to other sections and places all the items in this instance at
+ * particular offsets.
*
- * @param annotate whether or not to keep annotations
- * @param verbose if annotating, whether to be verbose
- * @return {@code non-null;} a {@code .dex} file for this instance
+ * @param cstIndexMaps list used to map offsets from a dex file to this instance
*/
- private ByteArrayAnnotatedOutput toDex0(boolean annotate, boolean verbose) {
- /*
- * The following is ordered so that the prepare() calls which
- * add items happen before the calls to the sections that get
- * added to.
- */
-
-if (cstIndexMaps != null) {
+ public void prepare(List<CstIndexMap> cstIndexMaps) {
+ if (cstIndexMaps != null) {
for (CstIndexMap cstIndexMap : cstIndexMaps) {
cstIndexMap.mergeConstantsIntoDexFile(this);
}
}
+ /**
+ * The following is ordered so that the prepare() calls which add items happen before the calls
+ * to the sections that get added to.
+ */
classDefs.prepare();
classData.prepare();
wordData.prepare();
@@ -569,6 +558,32 @@ if (cstIndexMaps != null) {
// Write out all the sections.
fileSize = offset;
+ }
+
+ /**
+ * Returns the contents of this instance as a {@code .dex} file,
+ * in a {@link ByteArrayAnnotatedOutput} instance.
+ *
+ * @param annotate whether or not to keep annotations
+ * @param verbose if annotating, whether to be verbose
+ * @return {@code non-null;} a {@code .dex} file for this instance
+ */
+ private ByteArrayAnnotatedOutput toDex0(boolean annotate, boolean verbose) {
+ classDefs.throwIfNotPrepared();
+ classData.throwIfNotPrepared();
+ wordData.throwIfNotPrepared();
+ byteData.throwIfNotPrepared();
+ methodIds.throwIfNotPrepared();
+ fieldIds.throwIfNotPrepared();
+ protoIds.throwIfNotPrepared();
+ typeLists.throwIfNotPrepared();
+ typeIds.throwIfNotPrepared();
+ stringIds.throwIfNotPrepared();
+ stringData.throwIfNotPrepared();
+ header.throwIfNotPrepared();
+
+ // Write out all the sections.
+ int count = sections.length;
byte[] barr = new byte[fileSize];
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(barr);
diff --git a/dx/src/com/android/jack/dx/dex/file/ImportedCodeItem.java b/dx/src/com/android/jack/dx/dex/file/ImportedCodeItem.java
index 0bf8a04..09d368b 100644
--- a/dx/src/com/android/jack/dx/dex/file/ImportedCodeItem.java
+++ b/dx/src/com/android/jack/dx/dex/file/ImportedCodeItem.java
@@ -51,7 +51,7 @@ public final class ImportedCodeItem extends OffsettedItem implements
* {@code non-null;} map index values used into code that references {@link Constant} from one
* dex file into index values compliant with another dex file.
*/
- private CstIndexMap cstIndexMap;
+ private final CstIndexMap cstIndexMap;
/** Array of remapped instructions */
private DecodedInstruction[] remappedInstructions;
@@ -314,6 +314,10 @@ public final class ImportedCodeItem extends OffsettedItem implements
throw new AssertionError("Not yet supported");
}
+ public CstIndexMap getCstIndexMap() {
+ return cstIndexMap;
+ }
+
private class GenericVisitor implements CodeReader.Visitor {
@Override
@@ -327,7 +331,7 @@ public final class ImportedCodeItem extends OffsettedItem implements
*/
private class StringRemapper implements CodeReader.Visitor {
- private DexFile file;
+ private final DexFile file;
public StringRemapper(DexFile dex) {
this.file = dex;
@@ -351,7 +355,7 @@ public final class ImportedCodeItem extends OffsettedItem implements
*/
private class FieldRemapper implements CodeReader.Visitor {
- private DexFile file;
+ private final DexFile file;
public FieldRemapper(DexFile dex) {
this.file = dex;
@@ -369,7 +373,7 @@ public final class ImportedCodeItem extends OffsettedItem implements
*/
private class TypeRemapper implements CodeReader.Visitor {
- private DexFile file;
+ private final DexFile file;
public TypeRemapper(DexFile dex) {
this.file = dex;
@@ -387,7 +391,7 @@ public final class ImportedCodeItem extends OffsettedItem implements
*/
private class MethodRemapper implements CodeReader.Visitor {
- private DexFile file;
+ private final DexFile file;
public MethodRemapper(DexFile dex) {
this.file = dex;