author | mli |
Wed, 11 Jan 2017 19:36:11 -0800 | |
changeset 43066 | bc2234c64fbd |
parent 42918 | 038d77430a46 |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
2 |
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4118056 |
|
38776
d2dbeb04d06f
8158560: Mark java/rmi/transport/dgcDeadLock/DGCDeadLock.java as intermittently faiing
rhalade
parents:
36928
diff
changeset
|
26 |
* @key intermittent |
2 | 27 |
* |
28 |
* @summary synopsis: Distributed Garbage Collection Deadlock |
|
29 |
* @author Laird Dornin |
|
30 |
* |
|
31 |
* @library ../../testlibrary |
|
30820 | 32 |
* @modules java.rmi/sun.rmi.registry |
33 |
* java.rmi/sun.rmi.server |
|
34 |
* java.rmi/sun.rmi.transport |
|
35 |
* java.rmi/sun.rmi.transport.tcp |
|
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
36 |
* @build TestLibrary Test TestImpl RegistryVM RegistryRunner |
2 | 37 |
* @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock |
38 |
*/ |
|
39 |
||
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 |
|
42 |
* fix for this bug was implemented, deadlock could occur when the |
|
43 |
* leaseChecker held the lock on the lease table and the clean thread |
|
44 |
* held the lock on a target x. The clean thread would attempt to get |
|
45 |
* the lock on the leaseTable to do DGCImpl.unregisterTarget and the |
|
46 |
* leaseChecker would attempt to get the lock on x to do |
|
47 |
* Target.vmidDead. Each thread held a resource that the other thread |
|
48 |
* was attempting to lock. |
|
49 |
* |
|
50 |
* This test causes the above conditions to occur and waits to see if |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
51 |
* a given set of remote calls finishes "quickly enough." |
2 | 52 |
*/ |
53 |
||
54 |
import java.rmi.*; |
|
55 |
import java.io.*; |
|
56 |
||
57 |
public class DGCDeadLock implements Runnable { |
|
58 |
final static public int HOLD_TARGET_TIME = 25000; |
|
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
59 |
public static final double TEST_FAIL_TIME = |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
60 |
(HOLD_TARGET_TIME + 30000) * TestLibrary.getTimeoutFactor(); |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
61 |
public static volatile boolean finished = false; |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
62 |
static final DGCDeadLock test = new DGCDeadLock(); |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
63 |
static volatile int registryPort = -1; |
2 | 64 |
|
65 |
static { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
66 |
System.setProperty("sun.rmi.transport.cleanInterval", "50"); |
2 | 67 |
} |
68 |
||
69 |
static public void main(String[] args) { |
|
70 |
||
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
71 |
RegistryVM testImplVM = null; |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
72 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
73 |
System.err.println("\nregression test for 4118056\n"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
74 |
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
2 | 75 |
|
76 |
try { |
|
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
77 |
String options = " --add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED" + |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
78 |
" -Djava.rmi.dgc.leaseValue=500000" + |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
79 |
" -Dsun.rmi.dgc.checkInterval=" + |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
80 |
(HOLD_TARGET_TIME - 5000); |
2 | 81 |
|
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
82 |
testImplVM = RegistryVM.createRegistryVMWithRunner("TestImpl", options); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
83 |
testImplVM.start(); |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
84 |
registryPort = testImplVM.getPort(); |
2 | 85 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
86 |
synchronized (test) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
87 |
Thread t = new Thread(test); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
88 |
t.setDaemon(true); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
89 |
t.start(); |
2 | 90 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
91 |
// wait for the remote calls to take place |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
92 |
test.wait((long)TEST_FAIL_TIME); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
93 |
} |
2 | 94 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
95 |
if (!finished) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
96 |
TestLibrary.bomb("Test failed, had exception or exercise" + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
97 |
" routines took too long to " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
98 |
"execute"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
99 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
100 |
System.err.println("Test passed, exercises " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
101 |
"finished in time."); |
2 | 102 |
|
103 |
} catch (Exception e) { |
|
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
104 |
TestLibrary.bomb("test failed in main()", e); |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
105 |
} finally { |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
106 |
if (testImplVM != null) { |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
42918
diff
changeset
|
107 |
testImplVM.cleanup(); |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
108 |
testImplVM = null; |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
109 |
} |
2 | 110 |
} |
111 |
} |
|
112 |
||
113 |
public void run() { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
114 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
115 |
String echo = null; |
2 | 116 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
117 |
// create a test client |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
118 |
Test foo = (Test) Naming.lookup("rmi://:" + |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
119 |
registryPort + |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
120 |
"/Foo"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
121 |
echo = foo.echo("Hello world"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
122 |
System.err.println("Test object created."); |
2 | 123 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
124 |
/* give TestImpl time to lock the target in the |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
125 |
* object table and any dirtys finish. |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
126 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
127 |
Thread.currentThread().sleep(5000); |
2 | 128 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
129 |
//unreference "Foo" |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
130 |
foo = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
131 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
132 |
//garbage collect and finalize foo |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
133 |
Runtime.getRuntime().gc(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
134 |
Runtime.getRuntime().runFinalization(); |
2 | 135 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
136 |
//import "Bar" |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
137 |
Test bar = (Test) Naming.lookup("rmi://:" + |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
138 |
registryPort + |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
139 |
"/Bar"); |
2 | 140 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
141 |
/* infinite loop to show the liveness of Client, |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
142 |
* if we have deadlock remote call will not return |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
143 |
*/ |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
144 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
145 |
for (int i = 0; i < 500; i++) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
146 |
echo = bar.echo("Remote call" + i); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
147 |
Thread.sleep(10); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
148 |
} |
2 | 149 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
150 |
// flag exercises finished |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
151 |
finished = true; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
152 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
153 |
} catch (RemoteException e) { |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
154 |
System.err.println("catch RemoteException"); |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
155 |
e.printStackTrace(); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
156 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
157 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
158 |
} catch (Exception e) { |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
159 |
TestLibrary.bomb("test failed in run()", e); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
160 |
} finally { |
42918
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
161 |
synchronized(this) { |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
162 |
notify(); |
038d77430a46
8029360: java/rmi/transport/dgcDeadLock/DGCDeadLock.java failing intermittently
mli
parents:
42338
diff
changeset
|
163 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
164 |
} |
2 | 165 |
} |
166 |
} |