protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { synchronized (getClassLoadingLock(name)) { // First, check if the class has already been loaded // 首先检查是否已经被本类加载器加载过了,findLoadedClass 本地方法不去关注 Class<?> c = findLoadedClass(name); if (c == null) { longt0= System.nanoTime(); try { // 如果父类加载器不为空就调用 父类加载器的loadClass方法,即委托父类去加载 if (parent != null) { c = parent.loadClass(name, false); } else { // 如果父类加载器为空就调用 BootstraploadClass方法,即委托Bootstrap类加载器去加载 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. longt1= System.nanoTime(); c = findClass(name);
// this is the defining class loader; record the stats sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0); sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1); sun.misc.PerfCounter.getFindClasses().increment(); } } if (resolve) { resolveClass(c); } return c; } }
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.