author | coleenp |
Wed, 01 May 2019 08:56:38 -0400 | |
changeset 54663 | f03d5a093093 |
child 54676 | 5b6177741464 |
permissions | -rw-r--r-- |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
1 |
/* |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
4 |
* |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
8 |
* |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
14 |
* |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
18 |
* |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
21 |
* questions. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
22 |
*/ |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
23 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
24 |
/* |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
25 |
* @test |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
26 |
* @bug 4656449 4945125 8074355 |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
27 |
* @summary Make MutexLocker smarter about non-Java threads |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
28 |
* @library /test/lib |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
29 |
* @run driver/timeout=240 ShutdownTest |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
30 |
*/ |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
31 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
32 |
// This test is adapted from an old regression test for bug 4945125, where VerifyBeforeExit |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
33 |
// crashes before exit for the regression test for bug 4656449. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
34 |
// The fix is to acquire the Heap_lock before exit after the JavaThread is removed from |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
35 |
// the threads list. This fix is still valid. This code requires Heap_lock be acquired |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
36 |
// without a safepoint check at exit. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
37 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
38 |
import jdk.test.lib.process.OutputAnalyzer; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
39 |
import jdk.test.lib.process.ProcessTools; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
40 |
import java.util.ArrayList; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
41 |
import java.util.Collections; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
42 |
import java.util.List; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
43 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
44 |
public class ShutdownTest { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
45 |
Object[] obj; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
46 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
47 |
ShutdownTest() { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
48 |
// Allocate to get some GC pressure. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
49 |
obj = new Object[100000]; |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
50 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
51 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
52 |
static class ShutdownTestThread extends Thread { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
53 |
public void run() { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
54 |
while (true) { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
55 |
ShutdownTest st = new ShutdownTest(); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
56 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
57 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
58 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
59 |
public static void main(String args[]) { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
60 |
System.out.println("- ShutdownTest -"); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
61 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
62 |
for (int i = 0; i < 100; i++) { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
63 |
ShutdownTestThread st = new ShutdownTestThread(); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
64 |
st.setDaemon(true); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
65 |
st.start(); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
66 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
67 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
68 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
69 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
70 |
private static void startVM(List<String> options) throws Throwable { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
71 |
// Combine VM flags given from command-line and your additional options |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
72 |
OutputAnalyzer output = ProcessTools.executeTestJvm(options.toArray(new String[options.size()])); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
73 |
output.shouldContain("- ShutdownTest -"); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
74 |
output.shouldHaveExitValue(0); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
75 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
76 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
77 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
78 |
public static void main(String[] args) throws Throwable { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
79 |
List<String> options = new ArrayList<>(); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
80 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
81 |
Collections.addAll(options, |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
82 |
"-Xmx2500k", |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
83 |
"-XX:+UnlockDiagnosticVMOptions", |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
84 |
"-XX:+VerifyBeforeExit"); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
85 |
options.add(ShutdownTestThread.class.getName()); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
86 |
|
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
87 |
for (int iteration = 0; iteration < 5; ++iteration) { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
88 |
startVM(options); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
89 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
90 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
diff
changeset
|
91 |
} |