jdk-24/jdk/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java
Alan Bateman db4d383614 8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282

Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00

165 lines
5.8 KiB
Java

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