Merge "Provide class loader context to DexFile.verifyInBackground"
diff --git a/dalvik/src/main/java/dalvik/system/DexFile.java b/dalvik/src/main/java/dalvik/system/DexFile.java
index 48e34c8..2a81be1 100644
--- a/dalvik/src/main/java/dalvik/system/DexFile.java
+++ b/dalvik/src/main/java/dalvik/system/DexFile.java
@@ -394,11 +394,15 @@
* DexPathList to have been initialized for its classes to be resolvable by ART.
* DexPathList will open the dex files first, finalize `dexElements` and then call this.
*/
- /*package*/ void verifyInBackground(ClassLoader classLoader) {
- verifyInBackgroundNative(mCookie, classLoader);
+ /*package*/ void verifyInBackground(ClassLoader classLoader, String classLoaderContext) {
+ verifyInBackgroundNative(mCookie, classLoader, classLoaderContext);
}
- private static native void verifyInBackgroundNative(Object mCookie, ClassLoader classLoader);
+ private static native void verifyInBackgroundNative(Object mCookie, ClassLoader classLoader,
+ String classLoaderContext);
+
+ /*package*/ static native String getClassLoaderContext(ClassLoader classLoader,
+ DexPathList.Element[] elements);
/*
* Returns true if the dex file is backed by a valid oat file.
diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java
index 5efefdd..227231a 100644
--- a/dalvik/src/main/java/dalvik/system/DexPathList.java
+++ b/dalvik/src/main/java/dalvik/system/DexPathList.java
@@ -267,12 +267,17 @@
try {
Element[] null_elements = null;
DexFile dex = new DexFile(dexFiles);
+ // Capture class loader context from *before* `dexElements` is set (see comment below).
+ String classLoaderContext = 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
// its classes (the field is hardcoded in ART and dex files iterated over in
- // the order of the array).
- dex.verifyInBackground(definingContext);
+ // 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);
} catch (IOException suppressed) {
System.logE("Unable to load dex files", suppressed);
suppressedExceptions.add(suppressed);