Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java
38828 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 411805625*26* @summary synopsis: Distributed Garbage Collection Deadlock27* @author Laird Dornin28*29* @library ../../testlibrary30* @build TestLibrary Test TestImpl TestImpl_Stub31* @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock32*/3334/* This test attempts to cause a deadlock between the rmi leaseChecker35* thread and a thread that is servicing a dgc clean call. Before the36* fix for this bug was implemented, deadlock could occur when the37* leaseChecker held the lock on the lease table and the clean thread38* held the lock on a target x. The clean thread would attempt to get39* the lock on the leaseTable to do DGCImpl.unregisterTarget and the40* leaseChecker would attempt to get the lock on x to do41* Target.vmidDead. Each thread held a resource that the other thread42* was attempting to lock.43*44* This test causes the above conditions to occur and waits to see if45* a given set of remote calls finishes "quickly enough."46*/4748import java.rmi.*;49import java.io.*;5051public class DGCDeadLock implements Runnable {52private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();53final static public int HOLD_TARGET_TIME = 25000;54public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000;55public static boolean finished = false;56static DGCDeadLock test = new DGCDeadLock();5758static {59System.setProperty("sun.rmi.transport.cleanInterval", "50");60}6162static public void main(String[] args) {6364JavaVM testImplVM = null;6566System.err.println("\nregression test for 4118056\n");67TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");6869try {70String options = " -Djava.security.policy=" +71TestParams.defaultPolicy +72" -Djava.rmi.dgc.leaseValue=500000" +73" -Dsun.rmi.dgc.checkInterval=" +74(HOLD_TARGET_TIME - 5000) +75" -Drmi.registry.port=" + REGISTRY_PORT +76"" ;7778testImplVM = new JavaVM("TestImpl", options, "");79testImplVM.start();8081synchronized (test) {82Thread t = new Thread(test);83t.setDaemon(true);84t.start();8586// wait for the remote calls to take place87test.wait(TEST_FAIL_TIME);88}8990if (!finished) {91TestLibrary.bomb("Test failed, had exception or exercise" +92" routines took too long to " +93"execute");94}95System.err.println("Test passed, exercises " +96"finished in time.");9798} catch (Exception e) {99testImplVM = null;100TestLibrary.bomb("test failed", e);101}102}103104public void run() {105try {106String echo = null;107108// give the test remote object time to initialize.109Thread.currentThread().sleep(8000);110111// create a test client112Test foo = (Test) Naming.lookup("rmi://:" +113REGISTRY_PORT +114"/Foo");115echo = foo.echo("Hello world");116System.err.println("Test object created.");117118/* give TestImpl time to lock the target in the119* object table and any dirtys finish.120*/121Thread.currentThread().sleep(5000);122123//unreference "Foo"124foo = null;125126//garbage collect and finalize foo127Runtime.getRuntime().gc();128Runtime.getRuntime().runFinalization();129130//import "Bar"131Test bar = (Test) Naming.lookup("rmi://:" +132REGISTRY_PORT +133"/Bar");134135/* infinite loop to show the liveness of Client,136* if we have deadlock remote call will not return137*/138try {139for (int i = 0; i < 500; i++) {140echo = bar.echo("Remote call" + i);141Thread.sleep(10);142}143144// flag exercises finished145finished = true;146147} catch (RemoteException e) {148}149150} catch (Exception e) {151TestLibrary.bomb("test failed", e);152} finally {153}154}155}156157158