src/share/classes/java/lang/ClassLoader.java

Print this page
rev 10452 : imported patch lang-Typos


 188 
 189     // The parent class loader for delegation
 190     // Note: VM hardcoded the offset of this field, thus all new fields
 191     // must be added *after* it.
 192     private final ClassLoader parent;
 193 
 194     /**
 195      * Encapsulates the set of parallel capable loader types.
 196      */
 197     private static class ParallelLoaders {
 198         private ParallelLoaders() {}
 199 
 200         // the set of parallel capable loader types
 201         private static final Set<Class<? extends ClassLoader>> loaderTypes =
 202             Collections.newSetFromMap(new WeakHashMap<>());
 203         static {
 204             synchronized (loaderTypes) { loaderTypes.add(ClassLoader.class); }
 205         }
 206 
 207         /**
 208          * Registers the given class loader type as parallel capabale.
 209          * Returns {@code true} is successfully registered; {@code false} if
 210          * loader's super class is not registered.
 211          */
 212         static boolean register(Class<? extends ClassLoader> c) {
 213             synchronized (loaderTypes) {
 214                 if (loaderTypes.contains(c.getSuperclass())) {
 215                     // register the class loader as parallel capable
 216                     // if and only if all of its super classes are.
 217                     // Note: given current classloading sequence, if
 218                     // the immediate super class is parallel capable,
 219                     // all the super classes higher up must be too.
 220                     loaderTypes.add(c);
 221                     return true;
 222                 } else {
 223                     return false;
 224                 }
 225             }
 226         }
 227 
 228         /**


 815      * @throws  NoClassDefFoundError
 816      *          If <tt>name</tt> is not equal to the <a href="#name">binary
 817      *          name</a> of the class specified by <tt>b</tt>
 818      *
 819      * @throws  SecurityException
 820      *          If an attempt is made to add this class to a package that
 821      *          contains classes that were signed by a different set of
 822      *          certificates than this class, or if <tt>name</tt> begins with
 823      *          "<tt>java.</tt>".
 824      *
 825      * @see      #defineClass(String, byte[], int, int, ProtectionDomain)
 826      *
 827      * @since  1.5
 828      */
 829     protected final Class<?> defineClass(String name, java.nio.ByteBuffer b,
 830                                          ProtectionDomain protectionDomain)
 831         throws ClassFormatError
 832     {
 833         int len = b.remaining();
 834 
 835         // Use byte[] if not a direct ByteBufer:
 836         if (!b.isDirect()) {
 837             if (b.hasArray()) {
 838                 return defineClass(name, b.array(),
 839                                    b.position() + b.arrayOffset(), len,
 840                                    protectionDomain);
 841             } else {
 842                 // no array, or read-only array
 843                 byte[] tb = new byte[len];
 844                 b.get(tb);  // get bytes out of byte buffer.
 845                 return defineClass(name, tb, 0, len, protectionDomain);
 846             }
 847         }
 848 
 849         protectionDomain = preDefineClass(name, protectionDomain);
 850         String source = defineClassSourceLocation(protectionDomain);
 851         Class<?> c = defineClass2(name, b, b.position(), len, protectionDomain, source);
 852         postDefineClass(c, protectionDomain);
 853         return c;
 854     }
 855 




 188 
 189     // The parent class loader for delegation
 190     // Note: VM hardcoded the offset of this field, thus all new fields
 191     // must be added *after* it.
 192     private final ClassLoader parent;
 193 
 194     /**
 195      * Encapsulates the set of parallel capable loader types.
 196      */
 197     private static class ParallelLoaders {
 198         private ParallelLoaders() {}
 199 
 200         // the set of parallel capable loader types
 201         private static final Set<Class<? extends ClassLoader>> loaderTypes =
 202             Collections.newSetFromMap(new WeakHashMap<>());
 203         static {
 204             synchronized (loaderTypes) { loaderTypes.add(ClassLoader.class); }
 205         }
 206 
 207         /**
 208          * Registers the given class loader type as parallel capable.
 209          * Returns {@code true} is successfully registered; {@code false} if
 210          * loader's super class is not registered.
 211          */
 212         static boolean register(Class<? extends ClassLoader> c) {
 213             synchronized (loaderTypes) {
 214                 if (loaderTypes.contains(c.getSuperclass())) {
 215                     // register the class loader as parallel capable
 216                     // if and only if all of its super classes are.
 217                     // Note: given current classloading sequence, if
 218                     // the immediate super class is parallel capable,
 219                     // all the super classes higher up must be too.
 220                     loaderTypes.add(c);
 221                     return true;
 222                 } else {
 223                     return false;
 224                 }
 225             }
 226         }
 227 
 228         /**


 815      * @throws  NoClassDefFoundError
 816      *          If <tt>name</tt> is not equal to the <a href="#name">binary
 817      *          name</a> of the class specified by <tt>b</tt>
 818      *
 819      * @throws  SecurityException
 820      *          If an attempt is made to add this class to a package that
 821      *          contains classes that were signed by a different set of
 822      *          certificates than this class, or if <tt>name</tt> begins with
 823      *          "<tt>java.</tt>".
 824      *
 825      * @see      #defineClass(String, byte[], int, int, ProtectionDomain)
 826      *
 827      * @since  1.5
 828      */
 829     protected final Class<?> defineClass(String name, java.nio.ByteBuffer b,
 830                                          ProtectionDomain protectionDomain)
 831         throws ClassFormatError
 832     {
 833         int len = b.remaining();
 834 
 835         // Use byte[] if not a direct ByteBuffer:
 836         if (!b.isDirect()) {
 837             if (b.hasArray()) {
 838                 return defineClass(name, b.array(),
 839                                    b.position() + b.arrayOffset(), len,
 840                                    protectionDomain);
 841             } else {
 842                 // no array, or read-only array
 843                 byte[] tb = new byte[len];
 844                 b.get(tb);  // get bytes out of byte buffer.
 845                 return defineClass(name, tb, 0, len, protectionDomain);
 846             }
 847         }
 848 
 849         protectionDomain = preDefineClass(name, protectionDomain);
 850         String source = defineClassSourceLocation(protectionDomain);
 851         Class<?> c = defineClass2(name, b, b.position(), len, protectionDomain, source);
 852         postDefineClass(c, protectionDomain);
 853         return c;
 854     }
 855