use of java.lang.ref.WeakReference in project jdk8u_jdk by JetBrains.
the class LWDispatcherMemoryLeakTest method init.
public static void init() throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame();
frame.setLayout(new FlowLayout());
button = new WeakReference<JButton>(new JButton("Text"));
p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
p.get().add(button.get());
frame.add(p.get());
frame.setBounds(500, 400, 200, 200);
frame.setVisible(true);
}
});
Util.waitTillShown(button.get());
Util.clickOnComp(button.get(), new Robot());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.remove(p.get());
}
});
Util.waitForIdle(null);
assertGC();
}
use of java.lang.ref.WeakReference in project jdk8u_jdk by JetBrains.
the class InputContextMemoryLeakTest method init.
public static void init() throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame();
frame.setLayout(new FlowLayout());
JPanel p1 = new JPanel();
button = new JButton("Test");
p1.add(button);
frame.add(p1);
text = new WeakReference<JTextField>(new JTextField("Text"));
p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
p.get().add(text.get());
frame.add(p.get());
frame.setBounds(500, 400, 200, 200);
frame.setVisible(true);
}
});
Util.focusComponent(text.get(), 500);
Util.clickOnComp(button, new Robot());
//References to objects testes for memory leak are stored in Util.
//Need to clean them
Util.cleanUp();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.remove(p.get());
}
});
Util.waitForIdle(null);
//After the next caret blink it automatically TextField references
Thread.sleep(text.get().getCaret().getBlinkRate() * 2);
Util.waitForIdle(null);
assertGC();
}
use of java.lang.ref.WeakReference in project jdk8u_jdk by JetBrains.
the class RuntimeThreadInheritanceLeak method main.
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4404702\n");
/*
* HACK: Work around the fact that java.util.logging.LogManager's
* (singleton) construction also has this bug-- it will register a
* "shutdown hook", i.e. a thread, which will inherit and pin the
* current thread's context class loader for the lifetime of the VM--
* by causing the LogManager to be initialized now, instead of by
* RMI when our special context class loader is set.
*/
java.util.logging.LogManager.getLogManager();
/*
* HACK: Work around the fact that the non-native, thread-based
* SecureRandom seed generator (ThreadedSeedGenerator) seems to
* have this bug too (which had been causing this test to fail
* when run with jtreg on Windows XP-- see 4910382).
*/
(new java.security.SecureRandom()).nextInt();
RuntimeThreadInheritanceLeak obj = new RuntimeThreadInheritanceLeak();
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);
UnicastRemoteObject.exportObject(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");
UnicastRemoteObject.unexportObject(obj, true);
System.err.println("unexported remote object");
/*
* 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(2000);
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");
dumpThreads();
throw new RuntimeException("TEST FAILED: loader not detected weakly reachable");
}
System.err.println("TEST PASSED: loader detected weakly reachable");
dumpThreads();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("TEST FAILED: unexpected exception", e);
} finally {
try {
UnicastRemoteObject.unexportObject(obj, true);
} catch (RemoteException e) {
}
}
}
use of java.lang.ref.WeakReference in project jdk8u_jdk by JetBrains.
the class PinClientSocketFactory method main.
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 4486732\n");
Factory factoryImpl = new FactoryImpl();
Factory factoryStub = (Factory) UnicastRemoteObject.exportObject(factoryImpl, 0);
for (int i = 0; i < SESSIONS; i++) {
Session session = factoryStub.getSession();
session.ping();
}
UnicastRemoteObject.unexportObject(factoryImpl, true);
Registry registryImpl = TestLibrary.createRegistryOnEphemeralPort();
int port = TestLibrary.getRegistryPort(registryImpl);
System.out.println("Registry listening on port " + port);
CSF csf = new CSF();
Reference<CSF> registryRef = new WeakReference<CSF>(csf);
Registry registryStub = LocateRegistry.getRegistry("", port, csf);
csf = null;
registryStub.list();
registryStub = null;
UnicastRemoteObject.unexportObject(registryImpl, true);
System.gc();
// allow connections to time out
Thread.sleep(3 * Long.getLong("sun.rmi.transport.connectionTimeout", 15000));
System.gc();
if (CSF.deserializedInstances.size() != SESSIONS) {
throw new Error("unexpected number of deserialized instances: " + CSF.deserializedInstances.size());
}
int nonNullCount = 0;
for (Reference<CSF> ref : CSF.deserializedInstances) {
csf = ref.get();
if (csf != null) {
System.err.println("non-null deserialized instance: " + csf);
nonNullCount++;
}
}
if (nonNullCount > 0) {
throw new Error("TEST FAILED: " + nonNullCount + " non-null deserialized instances");
}
csf = registryRef.get();
if (csf != null) {
System.err.println("non-null registry instance: " + csf);
throw new Error("TEST FAILED: non-null registry instance");
}
System.err.println("TEST PASSED");
}
use of java.lang.ref.WeakReference in project jdk8u_jdk by JetBrains.
the class PinLastArguments method main.
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6332349\n");
Ping impl = new PingImpl();
Reference<?> ref = new WeakReference<Ping>(impl);
try {
Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
Object notSerializable = new Object();
stub.ping(impl, null);
try {
stub.ping(impl, notSerializable);
} catch (MarshalException e) {
if (e.getCause() instanceof NotSerializableException) {
System.err.println("ping invocation failed as expected");
} else {
throw e;
}
}
} finally {
UnicastRemoteObject.unexportObject(impl, true);
}
impl = null;
// expected we will hang here until timed out by the test harness.
while (true) {
System.gc();
Thread.sleep(20);
if (ref.get() == null) {
break;
}
}
System.err.println("TEST PASSED");
}
Aggregations