diff options
author | David Brazdil <dbrazdil@google.com> | 2019-04-03 04:43:53 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-04-03 04:43:53 -0700 |
commit | ecace0f38c96ea9f93aab35d0993d8750f4bb60d (patch) | |
tree | e2aaa78617b96f02361f69e47e08451399ed152d | |
parent | bd526779c1381b2686d73e5b328d008af6e0f4f1 (diff) | |
parent | 525fb7f2dacc715d27c964001886dd66b4ae9a86 (diff) |
Merge "Adjust in-memory dex loading logic when backed by oat"
am: 525fb7f2da
Change-Id: I6f25a6b8c1144c4424fecb9f4d17e4f9f70dd925
-rw-r--r-- | dalvik/src/main/java/dalvik/system/DexFile.java | 12 | ||||
-rw-r--r-- | dalvik/src/main/java/dalvik/system/DexPathList.java | 17 |
2 files changed, 19 insertions, 10 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DexFile.java b/dalvik/src/main/java/dalvik/system/DexFile.java index 2a81be1064..486ee90830 100644 --- a/dalvik/src/main/java/dalvik/system/DexFile.java +++ b/dalvik/src/main/java/dalvik/system/DexFile.java @@ -110,8 +110,9 @@ public final class DexFile { //System.out.println("DEX FILE cookie is " + mCookie + " fileName=" + fileName); } - DexFile(ByteBuffer[] bufs) throws IOException { - mCookie = openInMemoryDexFiles(bufs); + DexFile(ByteBuffer[] bufs, ClassLoader loader, DexPathList.Element[] elements) + throws IOException { + mCookie = openInMemoryDexFiles(bufs, loader, elements); mInternalCookie = mCookie; mFileName = null; } @@ -370,7 +371,8 @@ public final class DexFile { elements); } - private static Object openInMemoryDexFiles(ByteBuffer[] bufs) throws IOException { + private static Object openInMemoryDexFiles(ByteBuffer[] bufs, ClassLoader loader, + DexPathList.Element[] elements) throws IOException { // Preprocess the ByteBuffers for openInMemoryDexFilesNative. We extract // the backing array (non-direct buffers only) and start/end positions // so that the native method does not have to call Java methods anymore. @@ -382,11 +384,11 @@ public final class DexFile { starts[i] = bufs[i].position(); ends[i] = bufs[i].limit(); } - return openInMemoryDexFilesNative(bufs, arrays, starts, ends); + return openInMemoryDexFilesNative(bufs, arrays, starts, ends, loader, elements); } private static native Object openInMemoryDexFilesNative(ByteBuffer[] bufs, byte[][] arrays, - int[] starts, int[] ends); + int[] starts, int[] ends, ClassLoader loader, DexPathList.Element[] elements); /* * Initiates background verification of this DexFile. This is a sepearate down-call diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java index 227231a7d2..c63bb13477 100644 --- a/dalvik/src/main/java/dalvik/system/DexPathList.java +++ b/dalvik/src/main/java/dalvik/system/DexPathList.java @@ -266,10 +266,10 @@ public final class DexPathList { try { Element[] null_elements = null; - DexFile dex = new DexFile(dexFiles); + DexFile dex = new DexFile(dexFiles, definingContext, null_elements); // Capture class loader context from *before* `dexElements` is set (see comment below). - String classLoaderContext = DexFile.getClassLoaderContext(definingContext, - null_elements); + String classLoaderContext = dex.isBackedByOatFile() + ? null : DexFile.getClassLoaderContext(definingContext, null_elements); dexElements = new Element[] { new Element(dex) }; // Spawn background thread to verify all classes and cache verification results. // Must be called *after* `dexElements` has been initialized for ART to find @@ -277,7 +277,13 @@ public final class DexPathList { // the order of the array), but with class loader context from *before* // `dexElements` was set because that is what it will be compared against next // time the same bytecode is loaded. - dex.verifyInBackground(definingContext, classLoaderContext); + // We only spawn the background thread if the bytecode is not backed by an oat + // file, i.e. this is the first time this bytecode is being loaded and/or + // verification results have not been cached yet. Skip spawning the thread on + // all subsequent loads of the same bytecode in the same class loader context. + if (classLoaderContext != null) { + dex.verifyInBackground(definingContext, classLoaderContext); + } } catch (IOException suppressed) { System.logE("Unable to load dex files", suppressed); suppressedExceptions.add(suppressed); @@ -340,7 +346,8 @@ public final class DexPathList { int elementPos = 0; for (ByteBuffer buf : dexFiles) { try { - DexFile dex = new DexFile(new ByteBuffer[] { buf }); + DexFile dex = new DexFile(new ByteBuffer[] { buf }, /* classLoader */ null, + /* dexElements */ null); elements[elementPos++] = new Element(dex); } catch (IOException suppressed) { System.logE("Unable to load dex file: " + buf, suppressed); |