< prev index next >

test/hotspot/jtreg/runtime/HiddenClasses/TestHiddenClassUnloading.java

Print this page




 105      *
 106      * The following steps are performed:
 107      * (1) A hidden version of TestHiddenClassUnloading is loaded by a custom class loader
 108      * (2) The method doWork that calls a method of the hidden class is compiled. The call
 109      *     is implemented as an IC referencing Klass* metadata of the hidden class.
 110      * (3) Unloading of the hidden class is enforced. The IC now references dead metadata.
 111      */
 112     static public void main(String[] args) throws Exception {
 113         // (1) Load a hidden version of this class using method lookup.defineHiddenClass().
 114         String rn = TestHiddenClassUnloading.class.getSimpleName() + ".class";
 115         URL classUrl = TestHiddenClassUnloading.class.getResource(rn);
 116         URLConnection connection = classUrl.openConnection();
 117 
 118         int length = connection.getContentLength();
 119         byte[] classBytes = connection.getInputStream().readAllBytes();
 120         if (length != -1 && classBytes.length != length) {
 121             throw new IOException("Expected:" + length + ", actual: " + classBytes.length);
 122         }
 123 
 124         Lookup lookup = MethodHandles.lookup();
 125         Class<?> hiddenClass = lookup.defineHiddenClass(classBytes, true, NESTMATE, WEAK).lookupClass();
 126 
 127         // (2) Make sure all paths of doWork are profiled and compiled
 128         for (int i = 0; i < 100000; ++i) {
 129             doWork(hiddenClass);
 130         }
 131 
 132         // Make sure doWork is compiled now
 133         Method doWork = TestHiddenClassUnloading.class.getDeclaredMethod("doWork", Class.class);
 134         makeSureIsCompiled(doWork);
 135 
 136         // (3) Throw away reference to hiddenClass to allow unloading
 137         hiddenClass = null;
 138 
 139         // Force garbage collection to trigger unloading of hiddenClass
 140         WHITE_BOX.fullGC();
 141     }
 142 }


 105      *
 106      * The following steps are performed:
 107      * (1) A hidden version of TestHiddenClassUnloading is loaded by a custom class loader
 108      * (2) The method doWork that calls a method of the hidden class is compiled. The call
 109      *     is implemented as an IC referencing Klass* metadata of the hidden class.
 110      * (3) Unloading of the hidden class is enforced. The IC now references dead metadata.
 111      */
 112     static public void main(String[] args) throws Exception {
 113         // (1) Load a hidden version of this class using method lookup.defineHiddenClass().
 114         String rn = TestHiddenClassUnloading.class.getSimpleName() + ".class";
 115         URL classUrl = TestHiddenClassUnloading.class.getResource(rn);
 116         URLConnection connection = classUrl.openConnection();
 117 
 118         int length = connection.getContentLength();
 119         byte[] classBytes = connection.getInputStream().readAllBytes();
 120         if (length != -1 && classBytes.length != length) {
 121             throw new IOException("Expected:" + length + ", actual: " + classBytes.length);
 122         }
 123 
 124         Lookup lookup = MethodHandles.lookup();
 125         Class<?> hiddenClass = lookup.defineHiddenClass(classBytes, true, NESTMATE).lookupClass();
 126 
 127         // (2) Make sure all paths of doWork are profiled and compiled
 128         for (int i = 0; i < 100000; ++i) {
 129             doWork(hiddenClass);
 130         }
 131 
 132         // Make sure doWork is compiled now
 133         Method doWork = TestHiddenClassUnloading.class.getDeclaredMethod("doWork", Class.class);
 134         makeSureIsCompiled(doWork);
 135 
 136         // (3) Throw away reference to hiddenClass to allow unloading
 137         hiddenClass = null;
 138 
 139         // Force garbage collection to trigger unloading of hiddenClass
 140         WHITE_BOX.fullGC();
 141     }
 142 }
< prev index next >