// ClassLoader not delegating for non java. packages. class DelegateLastPathClassLoader extends PathClassLoader {
public DelegateLastPathClassLoader(String dexPath, ClassLoader parent) { super(dexPath, parent);
}
@Override protectedClass<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (!name.startsWith("java.")) { try { return findClass(name);
} catch (ClassNotFoundException ignore) { // Ignore and fall through to parent class loader.
}
} returnsuper.loadClass(name, resolve);
}
}
publicclass Main {
publicstaticvoid main(String[] args) throws Exception {
System.loadLibrary(args[0]); final String DEX_FILE = System.getenv("DEX_LOCATION") + "/613-inlining-dex-cache-ex.jar";
ClassLoader loader = new DelegateLastPathClassLoader(DEX_FILE, Main.class.getClassLoader()); Class cls = loader.loadClass("LoadedByAppClassLoader");
Method m = cls.getDeclaredMethod("letMeInlineYou"); // Invoke the method enough times to get JITted. for (int i = 0; i < 10000; ++i) {
m.invoke(null);
}
ensureJitCompiled(cls, "letMeInlineYou");
ClassLoader bLoader = areYouB(); if (bLoader != Main.class.getClassLoader()) { thrownew Error("Wrong class loader");
}
}
publicstaticvoid foo(Main o) { // LoadedByAppClassLoader.letMeInlineYou will try to inline this // method but used to pass the wrong class loader. As a result, // the lookup of B.foo was updating the dex cache with the other // class loader's B class. if (o != null) {
o.myField.foo();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.