Skip to content

Instantly share code, notes, and snippets.

@dsendkowski
Created May 31, 2014 17:36
Show Gist options
  • Select an option

  • Save dsendkowski/25228186c34e7edba933 to your computer and use it in GitHub Desktop.

Select an option

Save dsendkowski/25228186c34e7edba933 to your computer and use it in GitHub Desktop.

Revisions

  1. Dariusz Sendkowski created this gist May 31, 2014.
    37 changes: 37 additions & 0 deletions loadclass.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    protected Class<?> loadClass(String name, boolean resolve)
    throws ClassNotFoundException
    {
    synchronized (getClassLoadingLock(name)) {
    // First, check if the class has already been loaded
    Class c = findLoadedClass(name);
    if (c == null) {
    long t0 = System.nanoTime();
    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.
    long t1 = 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;
    }
    }