169N/A/*
5266N/A * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4118056
0N/A *
0N/A * @summary synopsis: Distributed Garbage Collection Deadlock
0N/A * @author Laird Dornin
0N/A *
0N/A * @library ../../testlibrary
5551N/A * @build TestLibrary Test TestImpl TestImpl_Stub
0N/A * @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock
0N/A */
0N/A
0N/A/* This test attempts to cause a deadlock between the rmi leaseChecker
0N/A * thread and a thread that is servicing a dgc clean call. Before the
0N/A * fix for this bug was implemented, deadlock could occur when the
0N/A * leaseChecker held the lock on the lease table and the clean thread
0N/A * held the lock on a target x. The clean thread would attempt to get
0N/A * the lock on the leaseTable to do DGCImpl.unregisterTarget and the
0N/A * leaseChecker would attempt to get the lock on x to do
0N/A * Target.vmidDead. Each thread held a resource that the other thread
0N/A * was attempting to lock.
0N/A *
0N/A * This test causes the above conditions to occur and waits to see if
169N/A * a given set of remote calls finishes "quickly enough."
0N/A */
0N/A
0N/Aimport java.rmi.*;
0N/Aimport java.io.*;
0N/A
0N/Apublic class DGCDeadLock implements Runnable {
5266N/A private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
0N/A final static public int HOLD_TARGET_TIME = 25000;
0N/A public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000;
0N/A public static boolean finished = false;
0N/A static DGCDeadLock test = new DGCDeadLock();
0N/A
0N/A static {
169N/A System.setProperty("sun.rmi.transport.cleanInterval", "50");
0N/A }
0N/A
0N/A static public void main(String[] args) {
0N/A
169N/A JavaVM testImplVM = null;
169N/A
169N/A System.err.println("\nregression test for 4118056\n");
169N/A TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
0N/A
0N/A try {
169N/A String options = " -Djava.security.policy=" +
169N/A TestParams.defaultPolicy +
169N/A " -Djava.rmi.dgc.leaseValue=500000" +
169N/A " -Dsun.rmi.dgc.checkInterval=" +
5266N/A (HOLD_TARGET_TIME - 5000) +
5266N/A " -Drmi.registry.port=" + REGISTRY_PORT +
5266N/A "" ;
0N/A
169N/A testImplVM = new JavaVM("TestImpl", options, "");
169N/A testImplVM.start();
0N/A
169N/A synchronized (test) {
169N/A Thread t = new Thread(test);
169N/A t.setDaemon(true);
169N/A t.start();
0N/A
169N/A // wait for the remote calls to take place
169N/A test.wait(TEST_FAIL_TIME);
169N/A }
0N/A
169N/A if (!finished) {
169N/A TestLibrary.bomb("Test failed, had exception or exercise" +
169N/A " routines took too long to " +
169N/A "execute");
169N/A }
169N/A System.err.println("Test passed, exercises " +
169N/A "finished in time.");
0N/A
0N/A } catch (Exception e) {
169N/A testImplVM = null;
169N/A TestLibrary.bomb("test failed", e);
0N/A }
0N/A }
0N/A
0N/A public void run() {
169N/A try {
169N/A String echo = null;
0N/A
169N/A // give the test remote object time to initialize.
169N/A Thread.currentThread().sleep(8000);
0N/A
169N/A // create a test client
169N/A Test foo = (Test) Naming.lookup("rmi://:" +
5266N/A REGISTRY_PORT +
169N/A "/Foo");
169N/A echo = foo.echo("Hello world");
169N/A System.err.println("Test object created.");
0N/A
169N/A /* give TestImpl time to lock the target in the
169N/A * object table and any dirtys finish.
169N/A */
169N/A Thread.currentThread().sleep(5000);
0N/A
169N/A //unreference "Foo"
169N/A foo = null;
169N/A
169N/A //garbage collect and finalize foo
169N/A Runtime.getRuntime().gc();
169N/A Runtime.getRuntime().runFinalization();
0N/A
169N/A //import "Bar"
169N/A Test bar = (Test) Naming.lookup("rmi://:" +
5266N/A REGISTRY_PORT +
169N/A "/Bar");
0N/A
169N/A /* infinite loop to show the liveness of Client,
169N/A * if we have deadlock remote call will not return
169N/A */
169N/A try {
169N/A for (int i = 0; i < 500; i++) {
169N/A echo = bar.echo("Remote call" + i);
169N/A Thread.sleep(10);
169N/A }
0N/A
169N/A // flag exercises finished
169N/A finished = true;
169N/A
169N/A } catch (RemoteException e) {
169N/A }
169N/A
169N/A } catch (Exception e) {
169N/A TestLibrary.bomb("test failed", e);
169N/A } finally {
169N/A }
0N/A }
0N/A}