Mon, 17 Sep 2012 08:44:19 -0400
Merge
1.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.cpp Mon Sep 17 11:46:19 2012 +0200 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.cpp Mon Sep 17 08:44:19 2012 -0400 1.3 @@ -230,6 +230,7 @@ 1.4 void ConcurrentMarkSweepThread::print_all_on(outputStream* st) { 1.5 if (_cmst != NULL) { 1.6 _cmst->print_on(st); 1.7 + st->cr(); 1.8 } 1.9 if (_collector != NULL) { 1.10 AbstractWorkGang* gang = _collector->conc_workers();
2.1 --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Mon Sep 17 11:46:19 2012 +0200 2.2 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Mon Sep 17 08:44:19 2012 -0400 2.3 @@ -3420,7 +3420,6 @@ 2.4 st->cr(); 2.5 _cm->print_worker_threads_on(st); 2.6 _cg1r->print_worker_threads_on(st); 2.7 - st->cr(); 2.8 } 2.9 2.10 void G1CollectedHeap::gc_threads_do(ThreadClosure* tc) const {
3.1 --- a/src/share/vm/runtime/os.cpp Mon Sep 17 11:46:19 2012 +0200 3.2 +++ b/src/share/vm/runtime/os.cpp Mon Sep 17 08:44:19 2012 -0400 3.3 @@ -201,14 +201,21 @@ 3.4 } 3.5 } 3.6 3.7 - 3.8 +// The mapping from OS priority back to Java priority may be inexact because 3.9 +// Java priorities can map M:1 with native priorities. If you want the definite 3.10 +// Java priority then use JavaThread::java_priority() 3.11 OSReturn os::get_priority(const Thread* const thread, ThreadPriority& priority) { 3.12 int p; 3.13 int os_prio; 3.14 OSReturn ret = get_native_priority(thread, &os_prio); 3.15 if (ret != OS_OK) return ret; 3.16 3.17 - for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] > os_prio; p--) ; 3.18 + if (java_to_os_priority[MaxPriority] > java_to_os_priority[MinPriority]) { 3.19 + for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] > os_prio; p--) ; 3.20 + } else { 3.21 + // niceness values are in reverse order 3.22 + for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] < os_prio; p--) ; 3.23 + } 3.24 priority = (ThreadPriority)p; 3.25 return OS_OK; 3.26 }
4.1 --- a/src/share/vm/runtime/thread.cpp Mon Sep 17 11:46:19 2012 +0200 4.2 +++ b/src/share/vm/runtime/thread.cpp Mon Sep 17 08:44:19 2012 -0400 4.3 @@ -836,7 +836,11 @@ 4.4 void Thread::print_on(outputStream* st) const { 4.5 // get_priority assumes osthread initialized 4.6 if (osthread() != NULL) { 4.7 - st->print("prio=%d tid=" INTPTR_FORMAT " ", get_priority(this), this); 4.8 + int os_prio; 4.9 + if (os::get_native_priority(this, &os_prio) == OS_OK) { 4.10 + st->print("os_prio=%d ", os_prio); 4.11 + } 4.12 + st->print("tid=" INTPTR_FORMAT " ", this); 4.13 osthread()->print_on(st); 4.14 } 4.15 debug_only(if (WizardMode) print_owned_locks_on(st);) 4.16 @@ -2743,7 +2747,11 @@ 4.17 void JavaThread::print_on(outputStream *st) const { 4.18 st->print("\"%s\" ", get_thread_name()); 4.19 oop thread_oop = threadObj(); 4.20 - if (thread_oop != NULL && java_lang_Thread::is_daemon(thread_oop)) st->print("daemon "); 4.21 + if (thread_oop != NULL) { 4.22 + st->print("#" INT64_FORMAT " ", java_lang_Thread::thread_id(thread_oop)); 4.23 + if (java_lang_Thread::is_daemon(thread_oop)) st->print("daemon "); 4.24 + st->print("prio=%d ", java_lang_Thread::priority(thread_oop)); 4.25 + } 4.26 Thread::print_on(st); 4.27 // print guess for valid stack memory region (assume 4K pages); helps lock debugging 4.28 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12)); 4.29 @@ -4270,8 +4278,10 @@ 4.30 st->cr(); 4.31 Universe::heap()->print_gc_threads_on(st); 4.32 WatcherThread* wt = WatcherThread::watcher_thread(); 4.33 - if (wt != NULL) wt->print_on(st); 4.34 - st->cr(); 4.35 + if (wt != NULL) { 4.36 + wt->print_on(st); 4.37 + st->cr(); 4.38 + } 4.39 CompileBroker::print_compiler_threads_on(st); 4.40 st->flush(); 4.41 }
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/runtime/7194254/Test7194254.java Mon Sep 17 08:44:19 2012 -0400 5.3 @@ -0,0 +1,119 @@ 5.4 +/* 5.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 7194254 5.30 + * @summary Creates several threads with different java priorities and checks 5.31 + * whether jstack reports correct priorities for them. 5.32 + * 5.33 + * @run main T7194254 5.34 + */ 5.35 + 5.36 +import java.io.BufferedReader; 5.37 +import java.io.InputStreamReader; 5.38 +import java.lang.management.ManagementFactory; 5.39 +import java.lang.management.RuntimeMXBean; 5.40 +import java.util.ArrayList; 5.41 +import java.util.List; 5.42 +import java.util.concurrent.CyclicBarrier; 5.43 +import java.util.regex.Matcher; 5.44 +import java.util.regex.Pattern; 5.45 + 5.46 +public class Test7194254 { 5.47 + 5.48 + public static void main(String[] args) throws Exception { 5.49 + final int NUMBER_OF_JAVA_PRIORITIES = 5.50 + Thread.MAX_PRIORITY - Thread.MIN_PRIORITY + 1; 5.51 + final CyclicBarrier barrier = 5.52 + new CyclicBarrier(NUMBER_OF_JAVA_PRIORITIES + 1); 5.53 + 5.54 + for (int p = Thread.MIN_PRIORITY; p <= Thread.MAX_PRIORITY; ++p) { 5.55 + final int priority = p; 5.56 + new Thread("Priority=" + p) { 5.57 + { 5.58 + setPriority(priority); 5.59 + } 5.60 + public void run() { 5.61 + try { 5.62 + barrier.await(); // 1st 5.63 + barrier.await(); // 2nd 5.64 + } catch (Exception exc) { 5.65 + // ignore 5.66 + } 5.67 + } 5.68 + }.start(); 5.69 + } 5.70 + barrier.await(); // 1st 5.71 + 5.72 + int matches = 0; 5.73 + List<String> failed = new ArrayList<>(); 5.74 + try { 5.75 + String pid = getPid(); 5.76 + String jstack = System.getProperty("java.home") + "/../bin/jstack"; 5.77 + Process process = new ProcessBuilder(jstack, pid) 5.78 + .redirectErrorStream(true).start(); 5.79 + Pattern pattern = Pattern.compile( 5.80 + "\\\"Priority=(\\d+)\\\".* prio=(\\d+).*"); 5.81 + try (BufferedReader reader = new BufferedReader( 5.82 + new InputStreamReader(process.getInputStream()))) { 5.83 + String line; 5.84 + while((line = reader.readLine()) != null) { 5.85 + Matcher matcher = pattern.matcher(line); 5.86 + if (matcher.matches()) { 5.87 + matches += 1; 5.88 + String expected = matcher.group(1); 5.89 + String actual = matcher.group(2); 5.90 + if (!expected.equals(actual)) { 5.91 + failed.add(line); 5.92 + } 5.93 + } 5.94 + } 5.95 + } 5.96 + barrier.await(); // 2nd 5.97 + } finally { 5.98 + barrier.reset(); 5.99 + } 5.100 + 5.101 + if (matches != NUMBER_OF_JAVA_PRIORITIES) { 5.102 + throw new AssertionError("matches: expected " + 5.103 + NUMBER_OF_JAVA_PRIORITIES + ", but was " + matches); 5.104 + } 5.105 + if (!failed.isEmpty()) { 5.106 + throw new AssertionError(failed.size() + ":" + failed); 5.107 + } 5.108 + System.out.println("Test passes."); 5.109 + } 5.110 + 5.111 + static String getPid() { 5.112 + RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean(); 5.113 + String vmname = runtimebean.getName(); 5.114 + int i = vmname.indexOf('@'); 5.115 + if (i != -1) { 5.116 + vmname = vmname.substring(0, i); 5.117 + } 5.118 + return vmname; 5.119 + } 5.120 + 5.121 +} 5.122 +