479 }
480 } else {
481 return loadClass(name);
482 }
483 }
484
485 // Invoked by the VM after loading class with this loader.
486 private void checkPackageAccess(Class<?> cls, ProtectionDomain pd) {
487 final SecurityManager sm = System.getSecurityManager();
488 if (sm != null) {
489 if (ReflectUtil.isNonPublicProxyClass(cls)) {
490 for (Class<?> intf: cls.getInterfaces()) {
491 checkPackageAccess(intf, pd);
492 }
493 return;
494 }
495
496 final String name = cls.getName();
497 final int i = name.lastIndexOf('.');
498 if (i != -1) {
499 AccessController.doPrivileged(new PrivilegedAction<Void>() {
500 public Void run() {
501 sm.checkPackageAccess(name.substring(0, i));
502 return null;
503 }
504 }, new AccessControlContext(new ProtectionDomain[] {pd}));
505 }
506 }
507 domains.add(pd);
508 }
509
510 /**
511 * Finds the class with the specified <a href="#name">binary name</a>.
512 * This method should be overridden by class loader implementations that
513 * follow the delegation model for loading classes, and will be invoked by
514 * the {@link #loadClass <tt>loadClass</tt>} method after checking the
515 * parent class loader for the requested class. The default implementation
516 * throws a <tt>ClassNotFoundException</tt>.
517 *
518 * @param name
519 * The <a href="#name">binary name</a> of the class
1248 return system.getResources(name);
1249 }
1250
1251 /**
1252 * Find resources from the VM's built-in classloader.
1253 */
1254 private static URL getBootstrapResource(String name) {
1255 URLClassPath ucp = getBootstrapClassPath();
1256 Resource res = ucp.getResource(name);
1257 return res != null ? res.getURL() : null;
1258 }
1259
1260 /**
1261 * Find resources from the VM's built-in classloader.
1262 */
1263 private static Enumeration<URL> getBootstrapResources(String name)
1264 throws IOException
1265 {
1266 final Enumeration<Resource> e =
1267 getBootstrapClassPath().getResources(name);
1268 return new Enumeration<URL> () {
1269 public URL nextElement() {
1270 return e.nextElement().getURL();
1271 }
1272 public boolean hasMoreElements() {
1273 return e.hasMoreElements();
1274 }
1275 };
1276 }
1277
1278 // Returns the URLClassPath that is used for finding system resources.
1279 static URLClassPath getBootstrapClassPath() {
1280 return sun.misc.Launcher.getBootstrapClassPath();
1281 }
1282
1283
1284 /**
1285 * Returns an input stream for reading the specified resource.
1286 *
1287 * <p> The search order is described in the documentation for {@link
1288 * #getResource(String)}. </p>
1850 File libfile = new File(usr_path, System.mapLibraryName(name));
1851 if (loadLibrary0(fromClass, libfile)) {
1852 return;
1853 }
1854 libfile = ClassLoaderHelper.mapAlternativeName(libfile);
1855 if (libfile != null && loadLibrary0(fromClass, libfile)) {
1856 return;
1857 }
1858 }
1859 }
1860 // Oops, it failed
1861 throw new UnsatisfiedLinkError("no " + name + " in java.library.path");
1862 }
1863
1864 private static boolean loadLibrary0(Class<?> fromClass, final File file) {
1865 // Check to see if we're attempting to access a static library
1866 String name = NativeLibrary.findBuiltinLib(file.getName());
1867 boolean isBuiltin = (name != null);
1868 if (!isBuiltin) {
1869 name = AccessController.doPrivileged(
1870 new PrivilegedAction<String>() {
1871 public String run() {
1872 try {
1873 return file.exists() ? file.getCanonicalPath() : null;
1874 } catch (IOException e) {
1875 return null;
1876 }
1877 }
1878 });
1879 if (name == null) {
1880 return false;
1881 }
1882 }
1883 ClassLoader loader =
1884 (fromClass == null) ? null : fromClass.getClassLoader();
1885 Vector<NativeLibrary> libs =
1886 loader != null ? loader.nativeLibraries : systemNativeLibraries;
1887 synchronized (libs) {
1888 int size = libs.size();
1889 for (int i = 0; i < size; i++) {
1890 NativeLibrary lib = libs.elementAt(i);
|
479 }
480 } else {
481 return loadClass(name);
482 }
483 }
484
485 // Invoked by the VM after loading class with this loader.
486 private void checkPackageAccess(Class<?> cls, ProtectionDomain pd) {
487 final SecurityManager sm = System.getSecurityManager();
488 if (sm != null) {
489 if (ReflectUtil.isNonPublicProxyClass(cls)) {
490 for (Class<?> intf: cls.getInterfaces()) {
491 checkPackageAccess(intf, pd);
492 }
493 return;
494 }
495
496 final String name = cls.getName();
497 final int i = name.lastIndexOf('.');
498 if (i != -1) {
499 AccessController.doPrivileged(new PrivilegedAction<>() {
500 public Void run() {
501 sm.checkPackageAccess(name.substring(0, i));
502 return null;
503 }
504 }, new AccessControlContext(new ProtectionDomain[] {pd}));
505 }
506 }
507 domains.add(pd);
508 }
509
510 /**
511 * Finds the class with the specified <a href="#name">binary name</a>.
512 * This method should be overridden by class loader implementations that
513 * follow the delegation model for loading classes, and will be invoked by
514 * the {@link #loadClass <tt>loadClass</tt>} method after checking the
515 * parent class loader for the requested class. The default implementation
516 * throws a <tt>ClassNotFoundException</tt>.
517 *
518 * @param name
519 * The <a href="#name">binary name</a> of the class
1248 return system.getResources(name);
1249 }
1250
1251 /**
1252 * Find resources from the VM's built-in classloader.
1253 */
1254 private static URL getBootstrapResource(String name) {
1255 URLClassPath ucp = getBootstrapClassPath();
1256 Resource res = ucp.getResource(name);
1257 return res != null ? res.getURL() : null;
1258 }
1259
1260 /**
1261 * Find resources from the VM's built-in classloader.
1262 */
1263 private static Enumeration<URL> getBootstrapResources(String name)
1264 throws IOException
1265 {
1266 final Enumeration<Resource> e =
1267 getBootstrapClassPath().getResources(name);
1268 return new Enumeration<> () {
1269 public URL nextElement() {
1270 return e.nextElement().getURL();
1271 }
1272 public boolean hasMoreElements() {
1273 return e.hasMoreElements();
1274 }
1275 };
1276 }
1277
1278 // Returns the URLClassPath that is used for finding system resources.
1279 static URLClassPath getBootstrapClassPath() {
1280 return sun.misc.Launcher.getBootstrapClassPath();
1281 }
1282
1283
1284 /**
1285 * Returns an input stream for reading the specified resource.
1286 *
1287 * <p> The search order is described in the documentation for {@link
1288 * #getResource(String)}. </p>
1850 File libfile = new File(usr_path, System.mapLibraryName(name));
1851 if (loadLibrary0(fromClass, libfile)) {
1852 return;
1853 }
1854 libfile = ClassLoaderHelper.mapAlternativeName(libfile);
1855 if (libfile != null && loadLibrary0(fromClass, libfile)) {
1856 return;
1857 }
1858 }
1859 }
1860 // Oops, it failed
1861 throw new UnsatisfiedLinkError("no " + name + " in java.library.path");
1862 }
1863
1864 private static boolean loadLibrary0(Class<?> fromClass, final File file) {
1865 // Check to see if we're attempting to access a static library
1866 String name = NativeLibrary.findBuiltinLib(file.getName());
1867 boolean isBuiltin = (name != null);
1868 if (!isBuiltin) {
1869 name = AccessController.doPrivileged(
1870 new PrivilegedAction<>() {
1871 public String run() {
1872 try {
1873 return file.exists() ? file.getCanonicalPath() : null;
1874 } catch (IOException e) {
1875 return null;
1876 }
1877 }
1878 });
1879 if (name == null) {
1880 return false;
1881 }
1882 }
1883 ClassLoader loader =
1884 (fromClass == null) ? null : fromClass.getClassLoader();
1885 Vector<NativeLibrary> libs =
1886 loader != null ? loader.nativeLibraries : systemNativeLibraries;
1887 synchronized (libs) {
1888 int size = libs.size();
1889 for (int i = 0; i < size; i++) {
1890 NativeLibrary lib = libs.elementAt(i);
|