< prev index next >

test/hotspot/jtreg/runtime/Dictionary/CleanProtectionDomain.java

Print this page




  40 import sun.hotspot.WhiteBox;
  41 
  42 public class CleanProtectionDomain {
  43 
  44   public static void main(String args[]) throws Exception {
  45     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  46                                   "-Xlog:protectiondomain+table=debug",
  47                                   "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
  48                                   "-XX:+UnlockDiagnosticVMOptions",
  49                                   "-XX:+WhiteBoxAPI",
  50                                   "-Xbootclasspath/a:.",
  51                                   Test.class.getName());
  52     OutputAnalyzer output = new OutputAnalyzer(pb.start());
  53     output.shouldContain("protection domain added");
  54     output.shouldContain("protection domain unlinked");
  55     output.shouldHaveExitValue(0);
  56   }
  57 
  58   static class Test {
  59     public static void test() throws Exception {
  60       Unsafe unsafe = Unsafe.getUnsafe();
  61       TestClassLoader classloader = new TestClassLoader();
  62       ProtectionDomain pd = new ProtectionDomain(null, null);
  63       byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }");
  64       Class klass = unsafe.defineClass(null, klassbuf, 0, klassbuf.length, classloader, pd);
  65     }
  66 
  67     public static void main(String[] args) throws Exception {
  68       WhiteBox wb = WhiteBox.getWhiteBox();
  69       int removedCountOrig =  wb.protectionDomainRemovedCount();
  70       int removedCount;
  71 
  72       test();
  73 
  74       // Wait until ServiceThread cleans ProtectionDomain table.
  75       // When the TestClassLoader is unloaded by GC, at least one
  76       // ProtectionDomainCacheEntry will be eligible for removal.
  77       int cnt = 0;
  78       while (true) {
  79         if (cnt++ % 30 == 0) {
  80           System.gc();
  81         }
  82         removedCount = wb.resolvedMethodRemovedCount();
  83         if (removedCountOrig != removedCount) {
  84           break;
  85         }
  86         Thread.sleep(100);
  87       }
  88     }
  89 
  90     private static class TestClassLoader extends ClassLoader {
  91       public TestClassLoader() {
  92         super();
  93       }




  94     }
  95   }
  96 }


  40 import sun.hotspot.WhiteBox;
  41 
  42 public class CleanProtectionDomain {
  43 
  44   public static void main(String args[]) throws Exception {
  45     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  46                                   "-Xlog:protectiondomain+table=debug",
  47                                   "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
  48                                   "-XX:+UnlockDiagnosticVMOptions",
  49                                   "-XX:+WhiteBoxAPI",
  50                                   "-Xbootclasspath/a:.",
  51                                   Test.class.getName());
  52     OutputAnalyzer output = new OutputAnalyzer(pb.start());
  53     output.shouldContain("protection domain added");
  54     output.shouldContain("protection domain unlinked");
  55     output.shouldHaveExitValue(0);
  56   }
  57 
  58   static class Test {
  59     public static void test() throws Exception {

  60       TestClassLoader classloader = new TestClassLoader();
  61       ProtectionDomain pd = new ProtectionDomain(null, null);
  62       byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }");
  63       Class<?> klass = classloader.defineClass("TestClass", klassbuf, pd);
  64     }
  65 
  66     public static void main(String[] args) throws Exception {
  67       WhiteBox wb = WhiteBox.getWhiteBox();
  68       int removedCountOrig =  wb.protectionDomainRemovedCount();
  69       int removedCount;
  70 
  71       test();
  72 
  73       // Wait until ServiceThread cleans ProtectionDomain table.
  74       // When the TestClassLoader is unloaded by GC, at least one
  75       // ProtectionDomainCacheEntry will be eligible for removal.
  76       int cnt = 0;
  77       while (true) {
  78         if (cnt++ % 30 == 0) {
  79           System.gc();
  80         }
  81         removedCount = wb.resolvedMethodRemovedCount();
  82         if (removedCountOrig != removedCount) {
  83           break;
  84         }
  85         Thread.sleep(100);
  86       }
  87     }
  88 
  89     private static class TestClassLoader extends ClassLoader {
  90       public TestClassLoader() {
  91         super();
  92       }
  93 
  94       public Class<?> defineClass(String name, byte[] bytes, ProtectionDomain pd) {
  95         return defineClass(name, bytes, 0, bytes.length, pd);
  96       }
  97     }
  98   }
  99 }
< prev index next >