< prev index next >

test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java

Print this page




  91                 WHITE_BOX.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
  92             }
  93             // Because background compilation is disabled, method should now be compiled
  94             if(!WHITE_BOX.isMethodCompiled(m)) {
  95                 throw new RuntimeException(m + " not compiled");
  96             }
  97         }
  98     }
  99 
 100     /**
 101      * This test creates stale Klass* metadata referenced by a compiled IC.
 102      *
 103      * The following steps are performed:
 104      * (1) An anonymous version of TestAnonymousClassUnloading is loaded by a custom class loader
 105      * (2) The method doWork that calls a method of the anonymous class is compiled. The call
 106      *     is implemented as an IC referencing Klass* metadata of the anonymous class.
 107      * (3) Unloading of the anonymous class is enforced. The IC now references dead metadata.
 108      */
 109     static public void main(String[] args) throws Exception {
 110         // (1) Load an anonymous version of this class using the corresponding Unsafe method
 111         URL classUrl = TestAnonymousClassUnloading.class.getResource(
 112                 TestAnonymousClassUnloading.class.getName().replace('.', '/') + ".class");
 113         URLConnection connection = classUrl.openConnection();
 114 
 115         int length = connection.getContentLength();
 116         byte[] classBytes = connection.getInputStream().readAllBytes();
 117         if (length != -1 && classBytes.length != length) {
 118             throw new IOException("Expected:" + length + ", actual: " + classBytes.length);
 119         }
 120 
 121         Class<?> anonymousClass = UNSAFE.defineAnonymousClass(TestAnonymousClassUnloading.class, classBytes, null);
 122 
 123         // (2) Make sure all paths of doWork are profiled and compiled
 124         for (int i = 0; i < 100000; ++i) {
 125             doWork(anonymousClass);
 126         }
 127 
 128         // Make sure doWork is compiled now
 129         Method doWork = TestAnonymousClassUnloading.class.getDeclaredMethod("doWork", Class.class);
 130         makeSureIsCompiled(doWork);
 131 
 132         // (3) Throw away reference to anonymousClass to allow unloading


  91                 WHITE_BOX.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
  92             }
  93             // Because background compilation is disabled, method should now be compiled
  94             if(!WHITE_BOX.isMethodCompiled(m)) {
  95                 throw new RuntimeException(m + " not compiled");
  96             }
  97         }
  98     }
  99 
 100     /**
 101      * This test creates stale Klass* metadata referenced by a compiled IC.
 102      *
 103      * The following steps are performed:
 104      * (1) An anonymous version of TestAnonymousClassUnloading is loaded by a custom class loader
 105      * (2) The method doWork that calls a method of the anonymous class is compiled. The call
 106      *     is implemented as an IC referencing Klass* metadata of the anonymous class.
 107      * (3) Unloading of the anonymous class is enforced. The IC now references dead metadata.
 108      */
 109     static public void main(String[] args) throws Exception {
 110         // (1) Load an anonymous version of this class using the corresponding Unsafe method
 111         String rn = TestAnonymousClassUnloading.class.getSimpleName() + ".class";
 112         URL classUrl = TestAnonymousClassUnloading.class.getResource(rn);
 113         URLConnection connection = classUrl.openConnection();
 114 
 115         int length = connection.getContentLength();
 116         byte[] classBytes = connection.getInputStream().readAllBytes();
 117         if (length != -1 && classBytes.length != length) {
 118             throw new IOException("Expected:" + length + ", actual: " + classBytes.length);
 119         }
 120 
 121         Class<?> anonymousClass = UNSAFE.defineAnonymousClass(TestAnonymousClassUnloading.class, classBytes, null);
 122 
 123         // (2) Make sure all paths of doWork are profiled and compiled
 124         for (int i = 0; i < 100000; ++i) {
 125             doWork(anonymousClass);
 126         }
 127 
 128         // Make sure doWork is compiled now
 129         Method doWork = TestAnonymousClassUnloading.class.getDeclaredMethod("doWork", Class.class);
 130         makeSureIsCompiled(doWork);
 131 
 132         // (3) Throw away reference to anonymousClass to allow unloading
< prev index next >