summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Brazdil <dbrazdil@google.com>2019-04-03 04:55:14 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-04-03 04:55:14 -0700
commiteb8b4319bcc4d7afb60dd14c7dac770cfc967337 (patch)
treee21478ba98426138a4267ba03c51cdfed1c2e15c
parentcf942b14639a38197fc98b6f02a5f4bc45c9c56c (diff)
parent2cd293b2fe4247419fa98e23f5c06b7e3a25e067 (diff)
Merge "Adjust in-memory dex loading logic when backed by oat" am: 525fb7f2da am: ecace0f38c
am: 2cd293b2fe Change-Id: I42f78c64f61448c20f4099213793382f8c729f11
-rw-r--r--dalvik/src/main/java/dalvik/system/DexFile.java12
-rw-r--r--dalvik/src/main/java/dalvik/system/DexPathList.java17
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);