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

Improve performance of Class.getClassLoader()

    XMLWordPrintable

Details

    • b23
    • generic
    • generic

    Backports

      Description

        Currently, Class.getClassLoader() is a relatively expensive operation,
        presumably because of jni overhead.

        Some core library code would like to use it to optimize some operations.
        E.g. when using a Charset to decode a byte stream into a char array,
        one might have to make a defensive copy of the output char array because
        a malicious Charset might keep a reference to it, thereby
        making it possible for a String to change its value in the future,
        which is a big no-no. Being able to ask whether a Charset is
        provided as part of the JDK, cheaply, would be a big help to optimizing this
        for "builtin" classes.

        boolean isTrusted(Object x) {
          return System.getSecurityManager() == null ||
                 x.getClass().getClassLoader() == null;
        }

        One suspects that getClassLoader() can be trivially optimized to a field access,
        just like getClass() was.

        This bug is filed against compiler2, but of course we encourage a fix in compiler1 as well.

        Attachments

          Issue Links

            Activity

              People

                coleenp Coleen Phillimore
                martin Martin Buchholz
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: