annotate test/runtime/7194254/Test7194254.java @ 12986:1b422ef5288a

8025728: Missing volatile specifier for field G1AllocRegion::_alloc_region Summary: The field G1AllocRegion::_alloc_region needs to be declared volatile as it is used with that intention. Otherwise the compiler may generate the code that reloads the value which might have changed in the meantime, leading to spurious crashes. Reviewed-by: iveresov, simonis, tschatzl Contributed-by: Axel Siebenborn <axel.siebenborn@sap.com>
author tschatzl
date Wed, 23 Oct 2013 10:23:06 +0200
parents 48087f745a86
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6766
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
1 /*
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
4 *
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
7 * published by the Free Software Foundation.
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
8 *
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
13 * accompanied this code).
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
14 *
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
18 *
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
21 * questions.
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
22 */
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
23
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
24 /*
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
25 * @test
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
26 * @bug 7194254
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
27 * @summary Creates several threads with different java priorities and checks
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
28 * whether jstack reports correct priorities for them.
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
29 *
6835
48087f745a86 7199186: runtime/7194254/Test7194254.java fails - wrong test name on @run
dholmes
parents: 6766
diff changeset
30 * @run main Test7194254
6766
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
31 */
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
32
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
33 import java.io.BufferedReader;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
34 import java.io.InputStreamReader;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
35 import java.lang.management.ManagementFactory;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
36 import java.lang.management.RuntimeMXBean;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
37 import java.util.ArrayList;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
38 import java.util.List;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
39 import java.util.concurrent.CyclicBarrier;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
40 import java.util.regex.Matcher;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
41 import java.util.regex.Pattern;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
42
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
43 public class Test7194254 {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
44
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
45 public static void main(String[] args) throws Exception {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
46 final int NUMBER_OF_JAVA_PRIORITIES =
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
47 Thread.MAX_PRIORITY - Thread.MIN_PRIORITY + 1;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
48 final CyclicBarrier barrier =
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
49 new CyclicBarrier(NUMBER_OF_JAVA_PRIORITIES + 1);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
50
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
51 for (int p = Thread.MIN_PRIORITY; p <= Thread.MAX_PRIORITY; ++p) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
52 final int priority = p;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
53 new Thread("Priority=" + p) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
54 {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
55 setPriority(priority);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
56 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
57 public void run() {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
58 try {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
59 barrier.await(); // 1st
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
60 barrier.await(); // 2nd
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
61 } catch (Exception exc) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
62 // ignore
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
63 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
64 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
65 }.start();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
66 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
67 barrier.await(); // 1st
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
68
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
69 int matches = 0;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
70 List<String> failed = new ArrayList<>();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
71 try {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
72 String pid = getPid();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
73 String jstack = System.getProperty("java.home") + "/../bin/jstack";
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
74 Process process = new ProcessBuilder(jstack, pid)
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
75 .redirectErrorStream(true).start();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
76 Pattern pattern = Pattern.compile(
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
77 "\\\"Priority=(\\d+)\\\".* prio=(\\d+).*");
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
78 try (BufferedReader reader = new BufferedReader(
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
79 new InputStreamReader(process.getInputStream()))) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
80 String line;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
81 while((line = reader.readLine()) != null) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
82 Matcher matcher = pattern.matcher(line);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
83 if (matcher.matches()) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
84 matches += 1;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
85 String expected = matcher.group(1);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
86 String actual = matcher.group(2);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
87 if (!expected.equals(actual)) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
88 failed.add(line);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
89 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
90 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
91 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
92 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
93 barrier.await(); // 2nd
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
94 } finally {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
95 barrier.reset();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
96 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
97
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
98 if (matches != NUMBER_OF_JAVA_PRIORITIES) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
99 throw new AssertionError("matches: expected " +
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
100 NUMBER_OF_JAVA_PRIORITIES + ", but was " + matches);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
101 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
102 if (!failed.isEmpty()) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
103 throw new AssertionError(failed.size() + ":" + failed);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
104 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
105 System.out.println("Test passes.");
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
106 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
107
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
108 static String getPid() {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
109 RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
110 String vmname = runtimebean.getName();
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
111 int i = vmname.indexOf('@');
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
112 if (i != -1) {
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
113 vmname = vmname.substring(0, i);
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
114 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
115 return vmname;
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
116 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
117
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
118 }
a7509aff1b06 7194254: jstack reports wrong thread priorities
dholmes
parents:
diff changeset
119