1 /* |
1 /* |
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
31 * @library ../../testlibrary |
31 * @library ../../testlibrary |
32 * @modules java.rmi/sun.rmi.registry |
32 * @modules java.rmi/sun.rmi.registry |
33 * java.rmi/sun.rmi.server |
33 * java.rmi/sun.rmi.server |
34 * java.rmi/sun.rmi.transport |
34 * java.rmi/sun.rmi.transport |
35 * java.rmi/sun.rmi.transport.tcp |
35 * java.rmi/sun.rmi.transport.tcp |
36 * @build TestLibrary Test TestImpl TestImpl_Stub |
36 * @build TestLibrary Test TestImpl REGISTRY RegistryRunner |
37 * @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock |
37 * @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock |
38 */ |
38 */ |
39 |
39 |
40 /* This test attempts to cause a deadlock between the rmi leaseChecker |
40 /* This test attempts to cause a deadlock between the rmi leaseChecker |
41 * thread and a thread that is servicing a dgc clean call. Before the |
41 * thread and a thread that is servicing a dgc clean call. Before the |
53 |
53 |
54 import java.rmi.*; |
54 import java.rmi.*; |
55 import java.io.*; |
55 import java.io.*; |
56 |
56 |
57 public class DGCDeadLock implements Runnable { |
57 public class DGCDeadLock implements Runnable { |
58 private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); |
|
59 final static public int HOLD_TARGET_TIME = 25000; |
58 final static public int HOLD_TARGET_TIME = 25000; |
60 public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000; |
59 public static final double TEST_FAIL_TIME = |
61 public static boolean finished = false; |
60 (HOLD_TARGET_TIME + 30000) * TestLibrary.getTimeoutFactor(); |
62 static DGCDeadLock test = new DGCDeadLock(); |
61 public static volatile boolean finished = false; |
|
62 static final DGCDeadLock test = new DGCDeadLock(); |
|
63 static volatile int registryPort = -1; |
63 |
64 |
64 static { |
65 static { |
65 System.setProperty("sun.rmi.transport.cleanInterval", "50"); |
66 System.setProperty("sun.rmi.transport.cleanInterval", "50"); |
66 } |
67 } |
67 |
68 |
68 static public void main(String[] args) { |
69 static public void main(String[] args) { |
69 |
70 |
70 JavaVM testImplVM = null; |
71 REGISTRY testImplVM = null; |
71 |
72 |
72 System.err.println("\nregression test for 4118056\n"); |
73 System.err.println("\nregression test for 4118056\n"); |
73 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
74 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
74 |
75 |
75 try { |
76 try { |
76 String options = " -Djava.security.policy=" + |
77 String options = " -Djava.security.policy=" + |
77 TestParams.defaultPolicy + |
78 TestParams.defaultPolicy + |
78 " --add-exports java.rmi/sun.rmi.registry=ALL-UNNAMED" + |
|
79 " --add-exports java.rmi/sun.rmi.server=ALL-UNNAMED" + |
|
80 " --add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED" + |
79 " --add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED" + |
81 " --add-exports java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED" + |
|
82 " -Djava.rmi.dgc.leaseValue=500000" + |
80 " -Djava.rmi.dgc.leaseValue=500000" + |
83 " -Dsun.rmi.dgc.checkInterval=" + |
81 " -Dsun.rmi.dgc.checkInterval=" + |
84 (HOLD_TARGET_TIME - 5000) + |
82 (HOLD_TARGET_TIME - 5000) + |
85 " -Drmi.registry.port=" + REGISTRY_PORT + |
|
86 "" ; |
83 "" ; |
87 |
84 |
88 testImplVM = new JavaVM("TestImpl", options, ""); |
85 testImplVM = REGISTRY.createREGISTRYWithRunner("TestImpl", options); |
89 testImplVM.start(); |
86 testImplVM.start(); |
|
87 registryPort = testImplVM.getPort(); |
90 |
88 |
91 synchronized (test) { |
89 synchronized (test) { |
92 Thread t = new Thread(test); |
90 Thread t = new Thread(test); |
93 t.setDaemon(true); |
91 t.setDaemon(true); |
94 t.start(); |
92 t.start(); |
95 |
93 |
96 // wait for the remote calls to take place |
94 // wait for the remote calls to take place |
97 test.wait(TEST_FAIL_TIME); |
95 test.wait((long)TEST_FAIL_TIME); |
98 } |
96 } |
99 |
97 |
100 if (!finished) { |
98 if (!finished) { |
101 TestLibrary.bomb("Test failed, had exception or exercise" + |
99 TestLibrary.bomb("Test failed, had exception or exercise" + |
102 " routines took too long to " + |
100 " routines took too long to " + |
104 } |
102 } |
105 System.err.println("Test passed, exercises " + |
103 System.err.println("Test passed, exercises " + |
106 "finished in time."); |
104 "finished in time."); |
107 |
105 |
108 } catch (Exception e) { |
106 } catch (Exception e) { |
109 testImplVM = null; |
107 TestLibrary.bomb("test failed in main()", e); |
110 TestLibrary.bomb("test failed", e); |
108 } finally { |
|
109 if (testImplVM != null) { |
|
110 testImplVM.shutdown(); |
|
111 testImplVM = null; |
|
112 } |
111 } |
113 } |
112 } |
114 } |
113 |
115 |
114 public void run() { |
116 public void run() { |
115 try { |
117 try { |
116 String echo = null; |
118 String echo = null; |
117 |
119 |
118 // give the test remote object time to initialize. |
|
119 Thread.currentThread().sleep(8000); |
|
120 |
|
121 // create a test client |
120 // create a test client |
122 Test foo = (Test) Naming.lookup("rmi://:" + |
121 Test foo = (Test) Naming.lookup("rmi://:" + |
123 REGISTRY_PORT + |
122 registryPort + |
124 "/Foo"); |
123 "/Foo"); |
125 echo = foo.echo("Hello world"); |
124 echo = foo.echo("Hello world"); |
126 System.err.println("Test object created."); |
125 System.err.println("Test object created."); |
127 |
126 |
128 /* give TestImpl time to lock the target in the |
127 /* give TestImpl time to lock the target in the |