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 }
|
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.protectionDomainRemovedCount();
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 }
|