author | lana |
Thu, 10 Jun 2010 18:58:31 -0700 | |
changeset 5753 | e0ee3917e318 |
parent 5506 | 202f599c92aa |
child 21653 | 8cb51c29ab64 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, 2008, 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 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4530538 |
|
27 |
* @summary Basic Test for HotspotThreadMBean.getInternalThreadCount() |
|
28 |
* and getInternalThreadCpuTime() |
|
29 |
* @author Mandy Chung |
|
30 |
*/ |
|
31 |
||
32 |
import sun.management.*; |
|
33 |
import java.util.*; |
|
34 |
import java.lang.management.ThreadMXBean; |
|
403
dc6f4ca08b81
6687508: Update test/sun/management jtreg tests due to sun.management.ManagementFactory class rename
mchung
parents:
2
diff
changeset
|
35 |
import java.lang.management.ManagementFactory; |
2 | 36 |
|
37 |
public class GetInternalThreads { |
|
38 |
private static HotspotThreadMBean mbean = |
|
403
dc6f4ca08b81
6687508: Update test/sun/management jtreg tests due to sun.management.ManagementFactory class rename
mchung
parents:
2
diff
changeset
|
39 |
ManagementFactoryHelper.getHotspotThreadMBean(); |
2 | 40 |
|
41 |
// Minimum number of VM internal threads |
|
42 |
// VM thread, watcher thread, Low memory detector, compiler thread |
|
43 |
private static final long MIN_VALUE_FOR_PASS = 4; |
|
44 |
private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE; |
|
45 |
||
46 |
public static void main(String[] args) { |
|
47 |
long value = mbean.getInternalThreadCount(); |
|
48 |
||
49 |
if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) { |
|
50 |
throw new RuntimeException("Internal thread count " + |
|
51 |
"illegal value: " + value + " " + |
|
52 |
"(MIN = " + MIN_VALUE_FOR_PASS + "; " + |
|
53 |
"MAX = " + MAX_VALUE_FOR_PASS + ")"); |
|
54 |
} |
|
55 |
||
56 |
System.out.println("Internal Thread Count = " + value); |
|
57 |
||
58 |
ThreadMXBean thread = |
|
403
dc6f4ca08b81
6687508: Update test/sun/management jtreg tests due to sun.management.ManagementFactory class rename
mchung
parents:
2
diff
changeset
|
59 |
ManagementFactory.getThreadMXBean(); |
2 | 60 |
if (!thread.isThreadCpuTimeSupported()) { |
61 |
System.out.println("Thread Cpu Time is not supported."); |
|
62 |
return; |
|
63 |
} |
|
64 |
||
65 |
Map times = mbean.getInternalThreadCpuTimes(); |
|
66 |
Iterator iter = times.entrySet().iterator(); |
|
67 |
for (; iter.hasNext(); ) { |
|
68 |
Map.Entry entry = (Map.Entry) iter.next(); |
|
69 |
System.out.println(entry.getKey() + |
|
70 |
" CPU time = " + entry.getValue() + "ns"); |
|
71 |
if (((Long) entry.getValue()).longValue() < 0) { |
|
72 |
throw new RuntimeException("Thread CPU time" + |
|
73 |
"illegal value: " + entry.getValue()); |
|
74 |
} |
|
75 |
} |
|
76 |
System.out.println("Test passed."); |
|
77 |
} |
|
78 |
} |