* when run with jtreg on Windows XP-- see 4910382).
*/
(new java.security.SecureRandom()).nextInt();
RuntimeThreadInheritanceLeak obj = new RuntimeThreadInheritanceLeak();
Exporter exporter = null;
try {
ClassLoader loader = URLClassLoader.newInstance(new URL[0]);
ReferenceQueue refQueue = new ReferenceQueue();
Reference loaderRef = new WeakReference(loader, refQueue);
System.err.println("created loader: " + loader);
Thread.currentThread().setContextClassLoader(loader);
exporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
new BasicILFactory(), true, true);
exporter.export(obj);
Thread.currentThread().setContextClassLoader(
ClassLoader.getSystemClassLoader());
System.err.println(
"exported remote object with loader as context class loader");
loader = null;
System.err.println("nulled strong reference to loader");
exporter.unexport(true);
System.err.println("unexported remote object");
exporter = null; // required to work around 4403470
/*
* HACK: Work around the fact that the sun.misc.GC daemon thread
* also has this bug-- it will have inherited our loader as its
* context class loader-- by giving it a chance to pass away.
*/
Thread.sleep(1000);
System.gc();
System.err.println(
"waiting to be notified of loader being weakly reachable...");
Reference dequeued = refQueue.remove(TIMEOUT);
if (dequeued == null) {
System.err.println(
"TEST FAILED: loader not deteced weakly reachable");
throw new RuntimeException(
"TEST FAILED: loader not detected weakly reachable");
}
System.err.println(
"TEST PASSED: loader detected weakly reachable");
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("TEST FAILED: unexpected exception", e);
} finally {
try {
exporter.unexport(true);
} catch (Exception e) {
}
}
}