Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4917309

(cl) Reduce internal usage of ClassNotFoundExceptions during class-loading

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 7
    • Component/s: core-libs

      Backports

        Description

        Name: jl125535 Date: 09/04/2003


        A DESCRIPTION OF THE REQUEST :
        When starting a Java program, Java needs to load lots of Java classes. java.lang.ClassLoader.findBootstrapClass() and java.net.URLClassLoader.findClass() both throw ClassNotFoundExceptions for each application class or class from third party libraries to be loaded.

        I modified java.lang.Throwable.java (see attached source code and method _logThrowable() ) to print information about ClassNotFoundExceptions to stdout. Compile it and put the .class file in a newly created empty directory-tree c:\jdkpatch\java\lang.

        When starting SwingSet with
            java -Xbootclasspath/p:c:\jdkpatch -jar SwingSet2.jar
        285 instances of ClassNotFoundException are thrown.

        In our application, consisting of thousands of classes, thousands of ClassNotFoundExceptions are thrown during startup.

        JUSTIFICATION :
        Throwing and catching exceptions slows down the application. In addition to that for keeping stack-traces objects need to be created and garbage-collected. This has an impact on application startup time.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        I suggest using return-codes instead of exceptions wherever possible. e.g. java.lang.ClassLoader.findBootstrapClass0() could simply return null if the class was not found.

        ---------- BEGIN SOURCE ----------
        My changes to Throwable.java:
        - added new static variable "count"
        - added new method "_logThrowable" (please note that the method's
          implementation is slightly different bug 4917307)
        - called method "_logThrowable" from the constructor

        Here is the code:

            private static int count = 0;
            private void _logThrowable()
            {
                if (getClass() == ClassNotFoundException.class)
                {
                    count++;
                    System.out.println("ClassNotFoundException #" + count);
                    printStackTrace();
                }
            }
            public Throwable() {
                fillInStackTrace();
                _logThrowable();
            }
            public Throwable(String message) {
                fillInStackTrace();
                detailMessage = message;
                _logThrowable();
            }
            public Throwable(String message, Throwable cause) {
                fillInStackTrace();
                detailMessage = message;
                this.cause = cause;
                _logThrowable();
            }
            public Throwable(Throwable cause) {
                fillInStackTrace();
                detailMessage = (cause==null ? null : cause.toString());
                this.cause = cause;
                _logThrowable();
            }

        ---------- END SOURCE ----------
        (Incident Review ID: 201376)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mchung Mandy Chung
                  Reporter:
                  jleesunw Jon Lee (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: