public PathClassLoader(String dexPath, ClassLoader parent) {
super((String)null, (File)null, (String)null, (ClassLoader)null);
throw new RuntimeException("Stub!");
}
public PathClassLoader(String dexPath, String librarySearchPath, ClassLoader parent) {
super((String)null, (File)null, (String)null, (ClassLoader)null);
throw new RuntimeException("Stub!");
}
public DexClassLoader(String dexPath, String optimizedDirectory, String librarySearchPath, ClassLoader parent) {
super((String)null, (File)null, (String)null, (ClassLoader)null);
throw new RuntimeException("Stub!");
}
public BaseDexClassLoader(String dexPath, File optimizedDirectory, String librarySearchPath, ClassLoader parent) {
this(dexPath, optimizedDirectory, librarySearchPath, parent, false);
}
public BaseDexClassLoader(String dexPath, File optimizedDirectory, String librarySearchPath, ClassLoader parent, boolean isTrusted) {
super(parent);
this.pathList = new DexPathList(this, dexPath, librarySearchPath, null, isTrusted);
if (reporter != null) {
reportClassLoaderChain();
}
}
复制代码
//构造方法
public BaseDexClassLoader(String dexPath, File optimizedDirectory, String librarySearchPath, ClassLoader parent) {
this(dexPath, optimizedDirectory, librarySearchPath, parent, false);
}
/** * @hide */
public BaseDexClassLoader(String dexPath, File optimizedDirectory, String librarySearchPath, ClassLoader parent, boolean isTrusted) {
super(parent);
this.pathList = new DexPathList(this, dexPath, librarySearchPath, null, isTrusted);
if (reporter != null) {
reportClassLoaderChain();
}
}
/** * Reports the current class loader chain to the registered {@code reporter}. * The chain is reported only if all its elements are {@code BaseDexClassLoader}. */
private void reportClassLoaderChain() {
ArrayList<BaseDexClassLoader> classLoadersChain = new ArrayList<>();
ArrayList<String> classPaths = new ArrayList<>();
classLoadersChain.add(this);
classPaths.add(String.join(File.pathSeparator, pathList.getDexPaths()));
boolean onlySawSupportedClassLoaders = true;
ClassLoader bootClassLoader = ClassLoader.getSystemClassLoader().getParent();
ClassLoader current = getParent();
while (current != null && current != bootClassLoader) {
if (current instanceof BaseDexClassLoader) {
BaseDexClassLoader bdcCurrent = (BaseDexClassLoader) current;
classLoadersChain.add(bdcCurrent);
classPaths.add(String.join(File.pathSeparator, bdcCurrent.pathList.getDexPaths()));
} else {
onlySawSupportedClassLoaders = false;
break;
}
current = current.getParent();
}
if (onlySawSupportedClassLoaders) {
reporter.report(classLoadersChain, classPaths);
}
}
复制代码
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null) {
try {
if (parent != null) {
c = parent.loadClass(name, false);
} else {
c = findBootstrapClassOrNull(name);
}
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
}
if (c == null) {
// If still not found, then invoke findClass in order
// to find the class.
c = findClass(name);
}
}
return c;
}
复制代码
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
List<Throwable> suppressedExceptions = new ArrayList<Throwable>();
Class c = pathList.findClass(name, suppressedExceptions);
if (c == null) {
ClassNotFoundException cnfe = new ClassNotFoundException("Didn't find class \"" + name + "\" on path: " + pathList);
for (Throwable t : suppressedExceptions) {
cnfe.addSuppressed(t);
}
throw cnfe;
}
return c;
}
public Class<?> findClass(String name, List<Throwable> suppressed) {
for (Element element : dexElements) {
Class<?> clazz = element.findClass(name, definingContext, suppressed);
if (clazz != null) { return clazz;}
}
if (dexElementsSuppressedExceptions != null) { suppressed.addAll(Arrays.asList(dexElementsSuppressedExceptions));}
return null;
}
复制代码
@Deprecated
protected final Class<?> defineClass(byte[] b, int off, int len)
throws ClassFormatError
{
throw new UnsupportedOperationException("can't load this type of class file");
}
复制代码
Android Runtime(缩写为ART),在Android 5.0及后续Android版本中做为正式的运行时库取代了以往的Dalvik虚拟机。ART可以把应用程序的字节码转换为机器码,是Android所使用的一种新的虚拟机。java
它与Dalvik的主要不一样在于:android
可是,运行时内存占用空间较少一样意味着编译二进制须要更高的存储c++
- class:java 编译后的⽂件,每一个类对应⼀个 class ⽂件
- dex:Dalvik EXecutable 把 class 打包在⼀起,⼀个 dex 能够包含多个 class ⽂件
- odex:Optimized DEX 针对系统的优化,例如某个⽅法的调⽤指令,会把虚拟的调⽤转换为使⽤具体的 index,这样在执⾏的时候就不⽤再查找了
- oat:Optimized Android fifile Type。使⽤ AOT 策略对 dex 预先编译(解释)成本地指令,这样再运⾏阶段就不需再经历⼀次解释过程,程序的运⾏能够更快AOT:Ahead-Of-Time compilation 预先编译