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

Print this page

        

*** 256,266 **** // The initiating protection domains for all classes loaded by this loader private final Set<ProtectionDomain> domains; // Invoked by the VM to record every loaded class with this loader. ! void addClass(Class c) { classes.addElement(c); } // The packages defined in this class loader. Each package name is mapped // to its corresponding Package object. --- 256,266 ---- // The initiating protection domains for all classes loaded by this loader private final Set<ProtectionDomain> domains; // Invoked by the VM to record every loaded class with this loader. ! void addClass(Class<?> c) { classes.addElement(c); } // The packages defined in this class loader. Each package name is mapped // to its corresponding Package object.
*** 400,410 **** 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); --- 400,410 ---- 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);
*** 466,476 **** } return lock; } // This method is invoked by the virtual machine to load a class. ! private Class loadClassInternal(String name) throws ClassNotFoundException { // For backward compatibility, explicitly lock on 'this' when // the current class loader is not parallel capable. if (parallelLockMap == null) { --- 466,476 ---- } return lock; } // This method is invoked by the virtual machine to load a class. ! private Class<?> loadClassInternal(String name) throws ClassNotFoundException { // For backward compatibility, explicitly lock on 'this' when // the current class loader is not parallel capable. if (parallelLockMap == null) {
*** 481,491 **** return loadClass(name); } } // Invoked by the VM after loading class with this loader. ! private void checkPackageAccess(Class cls, ProtectionDomain pd) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { final String name = cls.getName(); final int i = name.lastIndexOf('.'); if (i != -1) { --- 481,491 ---- return loadClass(name); } } // Invoked by the VM after loading class with this loader. ! private void checkPackageAccess(Class<?> cls, ProtectionDomain pd) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { final String name = cls.getName(); final int i = name.lastIndexOf('.'); if (i != -1) {
*** 667,687 **** source = cs.getLocation().toString(); } return source; } ! private Class defineTransformedClass(String name, byte[] b, int off, int len, ProtectionDomain pd, ClassFormatError cfe, String source) throws ClassFormatError { // Class format error - try to transform the bytecode and // define the class again // ClassFileTransformer[] transformers = ClassFileTransformer.getTransformers(); ! Class c = null; if (transformers != null) { for (ClassFileTransformer transformer : transformers) { try { // Transform byte code using transformer --- 667,687 ---- source = cs.getLocation().toString(); } return source; } ! private Class<?> defineTransformedClass(String name, byte[] b, int off, int len, ProtectionDomain pd, ClassFormatError cfe, String source) throws ClassFormatError { // Class format error - try to transform the bytecode and // define the class again // ClassFileTransformer[] transformers = ClassFileTransformer.getTransformers(); ! Class<?> c = null; if (transformers != null) { for (ClassFileTransformer transformer : transformers) { try { // Transform byte code using transformer
*** 702,712 **** throw cfe; return c; } ! private void postDefineClass(Class c, ProtectionDomain pd) { if (pd.getCodeSource() != null) { Certificate certs[] = pd.getCodeSource().getCertificates(); if (certs != null) setSigners(c, certs); --- 702,712 ---- throw cfe; return c; } ! private void postDefineClass(Class<?> c, ProtectionDomain pd) { if (pd.getCodeSource() != null) { Certificate certs[] = pd.getCodeSource().getCertificates(); if (certs != null) setSigners(c, certs);
*** 782,792 **** ProtectionDomain protectionDomain) throws ClassFormatError { protectionDomain = preDefineClass(name, protectionDomain); ! Class c = null; String source = defineClassSourceLocation(protectionDomain); try { c = defineClass1(name, b, off, len, protectionDomain, source); } catch (ClassFormatError cfe) { --- 782,792 ---- ProtectionDomain protectionDomain) throws ClassFormatError { protectionDomain = preDefineClass(name, protectionDomain); ! Class<?> c = null; String source = defineClassSourceLocation(protectionDomain); try { c = defineClass1(name, b, off, len, protectionDomain, source); } catch (ClassFormatError cfe) {
*** 880,890 **** } } protectionDomain = preDefineClass(name, protectionDomain); ! Class c = null; String source = defineClassSourceLocation(protectionDomain); try { c = defineClass2(name, b, b.position(), len, protectionDomain, source); --- 880,890 ---- } } protectionDomain = preDefineClass(name, protectionDomain); ! Class<?> c = null; String source = defineClassSourceLocation(protectionDomain); try { c = defineClass2(name, b, b.position(), len, protectionDomain, source);
*** 897,913 **** postDefineClass(c, protectionDomain); return c; } ! private native Class defineClass0(String name, byte[] b, int off, int len, ProtectionDomain pd); ! private native Class defineClass1(String name, byte[] b, int off, int len, ProtectionDomain pd, String source); ! private native Class defineClass2(String name, java.nio.ByteBuffer b, int off, int len, ProtectionDomain pd, String source); // true if the name is null or has the potential to be a valid binary name private boolean checkName(String name) { --- 897,913 ---- postDefineClass(c, protectionDomain); return c; } ! private native Class<?> defineClass0(String name, byte[] b, int off, int len, ProtectionDomain pd); ! private native Class<?> defineClass1(String name, byte[] b, int off, int len, ProtectionDomain pd, String source); ! private native Class<?> defineClass2(String name, java.nio.ByteBuffer b, int off, int len, ProtectionDomain pd, String source); // true if the name is null or has the potential to be a valid binary name private boolean checkName(String name) {
*** 1008,1018 **** */ protected final void resolveClass(Class<?> c) { resolveClass0(c); } ! private native void resolveClass0(Class c); /** * Finds a class with the specified <a href="#name">binary name</a>, * loading it if necessary. * --- 1008,1018 ---- */ protected final void resolveClass(Class<?> c) { resolveClass0(c); } ! private native void resolveClass0(Class<?> c); /** * Finds a class with the specified <a href="#name">binary name</a>, * loading it if necessary. *
*** 1039,1049 **** { ClassLoader system = getSystemClassLoader(); if (system == null) { if (!checkName(name)) throw new ClassNotFoundException(name); ! Class cls = findBootstrapClass(name); if (cls == null) { throw new ClassNotFoundException(name); } return cls; } --- 1039,1049 ---- { ClassLoader system = getSystemClassLoader(); if (system == null) { if (!checkName(name)) throw new ClassNotFoundException(name); ! Class<?> cls = findBootstrapClass(name); if (cls == null) { throw new ClassNotFoundException(name); } return cls; }
*** 1052,1070 **** /** * Returns a class loaded by the bootstrap class loader; * or return null if not found. */ ! private Class findBootstrapClassOrNull(String name) { if (!checkName(name)) return null; return findBootstrapClass(name); } // return null if not found ! private native Class findBootstrapClass(String name); /** * Returns the class with the given <a href="#name">binary name</a> if this * loader has been recorded by the Java virtual machine as an initiating * loader of a class with that <a href="#name">binary name</a>. Otherwise --- 1052,1070 ---- /** * Returns a class loaded by the bootstrap class loader; * or return null if not found. */ ! private Class<?> findBootstrapClassOrNull(String name) { if (!checkName(name)) return null; return findBootstrapClass(name); } // return null if not found ! private native Class<?> findBootstrapClass(String name); /** * Returns the class with the given <a href="#name">binary name</a> if this * loader has been recorded by the Java virtual machine as an initiating * loader of a class with that <a href="#name">binary name</a>. Otherwise
*** 1082,1092 **** if (!checkName(name)) return null; return findLoadedClass0(name); } ! private native final Class findLoadedClass0(String name); /** * Sets the signers of a class. This should be invoked after defining a * class. </p> * --- 1082,1092 ---- if (!checkName(name)) return null; return findLoadedClass0(name); } ! private native final Class<?> findLoadedClass0(String name); /** * Sets the signers of a class. This should be invoked after defining a * class. </p> *
*** 1526,1536 **** // NOTE: This must always be invoked when there is exactly one intervening // frame from the core libraries on the stack between this method's // invocation and the desired invoker. static ClassLoader getCallerClassLoader() { // NOTE use of more generic Reflection.getCallerClass() ! Class caller = Reflection.getCallerClass(3); // This can be null if the VM is requesting it if (caller == null) { return null; } // Circumvent security check since this is package-private --- 1526,1536 ---- // NOTE: This must always be invoked when there is exactly one intervening // frame from the core libraries on the stack between this method's // invocation and the desired invoker. static ClassLoader getCallerClassLoader() { // NOTE use of more generic Reflection.getCallerClass() ! Class<?> caller = Reflection.getCallerClass(3); // This can be null if the VM is requesting it if (caller == null) { return null; } // Circumvent security check since this is package-private
*** 1720,1738 **** long handle; // the version of JNI environment the native library requires. private int jniVersion; // the class from which the library is loaded, also indicates // the loader this native library belongs. ! private Class fromClass; // the canonicalized name of the native library. String name; native void load(String name); native long find(String name); native void unload(); ! public NativeLibrary(Class fromClass, String name) { this.name = name; this.fromClass = fromClass; } protected void finalize() { --- 1720,1738 ---- long handle; // the version of JNI environment the native library requires. private int jniVersion; // the class from which the library is loaded, also indicates // the loader this native library belongs. ! private Class<?> fromClass; // the canonicalized name of the native library. String name; native void load(String name); native long find(String name); native void unload(); ! public NativeLibrary(Class<?> fromClass, String name) { this.name = name; this.fromClass = fromClass; } protected void finalize() {
*** 1756,1766 **** } } } // Invoked in the VM to determine the context class in // JNI_Load/JNI_Unload ! static Class getFromClass() { return ClassLoader.nativeLibraryContext.peek().fromClass; } } // All native library names we've loaded. --- 1756,1766 ---- } } } // Invoked in the VM to determine the context class in // JNI_Load/JNI_Unload ! static Class<?> getFromClass() { return ClassLoader.nativeLibraryContext.peek().fromClass; } } // All native library names we've loaded.
*** 1811,1821 **** paths[n] = ldpath.substring(i, ldlen); return paths; } // Invoked in the java.lang.Runtime class to implement load and loadLibrary. ! static void loadLibrary(Class fromClass, String name, boolean isAbsolute) { ClassLoader loader = (fromClass == null) ? null : fromClass.getClassLoader(); if (sys_paths == null) { usr_paths = initializePath("java.library.path"); --- 1811,1821 ---- paths[n] = ldpath.substring(i, ldlen); return paths; } // Invoked in the java.lang.Runtime class to implement load and loadLibrary. ! static void loadLibrary(Class<?> fromClass, String name, boolean isAbsolute) { ClassLoader loader = (fromClass == null) ? null : fromClass.getClassLoader(); if (sys_paths == null) { usr_paths = initializePath("java.library.path");
*** 1858,1868 **** } // Oops, it failed throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); } ! private static boolean loadLibrary0(Class fromClass, final File file) { boolean exists = AccessController.doPrivileged( new PrivilegedAction<Object>() { public Object run() { return file.exists() ? Boolean.TRUE : null; }}) --- 1858,1868 ---- } // Oops, it failed throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); } ! private static boolean loadLibrary0(Class<?> fromClass, final File file) { boolean exists = AccessController.doPrivileged( new PrivilegedAction<Object>() { public Object run() { return file.exists() ? Boolean.TRUE : null; }})
*** 2192,2203 **** String cls = System.getProperty("java.system.class.loader"); if (cls == null) { return parent; } ! Constructor ctor = Class.forName(cls, true, parent) ! .getDeclaredConstructor(new Class[] { ClassLoader.class }); ClassLoader sys = (ClassLoader) ctor.newInstance( new Object[] { parent }); Thread.currentThread().setContextClassLoader(sys); return sys; } --- 2192,2203 ---- String cls = System.getProperty("java.system.class.loader"); if (cls == null) { return parent; } ! Constructor<?> ctor = Class.forName(cls, true, parent) ! .getDeclaredConstructor(new Class<?>[] { ClassLoader.class }); ClassLoader sys = (ClassLoader) ctor.newInstance( new Object[] { parent }); Thread.currentThread().setContextClassLoader(sys); return sys; }