// Custom class loader to prevent loading while verifying. class MyClassLoader extends ClassLoader {
MyClassLoader() throws Exception { super(MyClassLoader.class.getClassLoader());
// Some magic to get access to the pathList field of BaseDexClassLoader.
ClassLoader loader = getClass().getClassLoader(); Class<?> baseDexClassLoader = loader.getClass().getSuperclass();
Field f = baseDexClassLoader.getDeclaredField("pathList");
f.setAccessible(true);
Object pathList = f.get(loader);
// Some magic to get access to the dexField field of pathList.
f = pathList.getClass().getDeclaredField("dexElements");
f.setAccessible(true);
dexElements = (Object[]) f.get(pathList);
dexFileField = dexElements[0].getClass().getDeclaredField("dexFile");
dexFileField.setAccessible(true);
}
Object[] dexElements;
Field dexFileField;
protectedClass<?> loadClass(String className, boolean resolve) throws ClassNotFoundException { if (className.equals("p1.OtherInP1") && !p1.PlaceHolder.entered) { // The request comes from the verifier. Return null to get the access check entry // point in the compiled code. returnnull;
} // Mimic what DexPathList.findClass is doing. try { for (Object element : dexElements) {
Object dex = dexFileField.get(element);
Method method = dex.getClass().getDeclaredMethod( "loadClassBinaryName", String.class, ClassLoader.class, List.class);
publicclass Main { publicstaticvoid main(String[] args) throws Exception {
MyClassLoader o = new MyClassLoader(); Class<?> foo = o.loadClass("LoadedByMyClassLoader");
Method m = foo.getDeclaredMethod("main");
m.invoke(null);
}
}
class LoadedByMyClassLoader { publicstaticvoid main() throws Exception { for (int i = 0; i < 10000; ++i) { // Warm up the JIT.
doTheCall(i);
} // Sleep a while to let the JIT compile things. // TODO(ngeoffray): Remove the sleep. b/25414532 Thread.sleep(2000);
doTheCall(10001);
}
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.