< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/LoaderSegregation.java

Print this page




  65         }
  66 
  67         // [C] BUILTIN and UNREGISTERED classes can be loaded only by their corresponding
  68         //     type of loaders.
  69 
  70         String path = args[0];
  71         File jarFile = new File(path);
  72         URL url = new File(path).toURI().toURL();
  73         URL[] urls = new URL[] {url};
  74         ClassLoader appLoader = LoaderSegregation.class.getClassLoader();
  75 
  76         { // BUILTIN LOADER
  77             try {
  78                 appLoader.loadClass(ONLY_UNREGISTERED);
  79                 throw new RuntimeException("BUILTIN loader cannot load archived UNREGISTERED class");
  80             } catch (ClassNotFoundException expected) {}
  81         }
  82 
  83         { // UNREGISTERED LOADER
  84             URLClassLoader urlClassLoader = new URLClassLoader(urls);
  85             Class c2 = Util.defineClassFromJAR(urlClassLoader, jarFile, ONLY_BUILTIN);

  86 
  87             if (c2.getClassLoader() != urlClassLoader) {
  88                 throw new RuntimeException("Error in test");
  89             }
  90 
  91             if (wb.isSharedClass(LoaderSegregation.class)) {
  92                 if (wb.isSharedClass(c2)) {
  93                     throw new RuntimeException("wb.isSharedClass(c2) should be false - " +
  94                                                "unregistered loader cannot load an archived BUILTIN class");
  95                 }
  96             }
  97         }
  98     }
  99 }


  65         }
  66 
  67         // [C] BUILTIN and UNREGISTERED classes can be loaded only by their corresponding
  68         //     type of loaders.
  69 
  70         String path = args[0];
  71         File jarFile = new File(path);
  72         URL url = new File(path).toURI().toURL();
  73         URL[] urls = new URL[] {url};
  74         ClassLoader appLoader = LoaderSegregation.class.getClassLoader();
  75 
  76         { // BUILTIN LOADER
  77             try {
  78                 appLoader.loadClass(ONLY_UNREGISTERED);
  79                 throw new RuntimeException("BUILTIN loader cannot load archived UNREGISTERED class");
  80             } catch (ClassNotFoundException expected) {}
  81         }
  82 
  83         { // UNREGISTERED LOADER
  84             URLClassLoader urlClassLoader = new URLClassLoader(urls);
  85             Class<?> peerClass = Class.forName("Hello", false, urlClassLoader);
  86             Class c2 = Util.defineClassFromJAR(peerClass, jarFile, ONLY_BUILTIN);
  87 
  88             if (c2.getClassLoader() != urlClassLoader) {
  89                 throw new RuntimeException("Error in test");
  90             }
  91 
  92             if (wb.isSharedClass(LoaderSegregation.class)) {
  93                 if (wb.isSharedClass(c2)) {
  94                     throw new RuntimeException("wb.isSharedClass(c2) should be false - " +
  95                                                "unregistered loader cannot load an archived BUILTIN class");
  96                 }
  97             }
  98         }
  99     }
 100 }
< prev index next >