author | alexsch |
Thu, 31 Jul 2014 14:28:10 +0400 | |
changeset 26019 | 10a56d28f48d |
parent 21653 | 8cb51c29ab64 |
child 26195 | 64b54ed39429 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
21653
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, 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 { |
|
21653
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
38 |
private final 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 |
||
21653
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
46 |
public static void main(String[] args) throws Exception { |
2 | 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 |
||
21653
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
65 |
while(!testCPUTime()) { |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
66 |
Thread.sleep(100); |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
67 |
} |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
68 |
} |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
69 |
|
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
70 |
private static boolean testCPUTime() { |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
71 |
Map<String, Long> times = mbean.getInternalThreadCpuTimes(); |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
72 |
for(Map.Entry<String, Long> entry : times.entrySet()) { |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
73 |
String threadName = entry.getKey(); |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
74 |
long cpuTime = entry.getValue(); |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
75 |
System.out.println("CPU time = " + cpuTime + " for " + threadName); |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
76 |
if (cpuTime == -1) { |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
77 |
// Can happen when there is a race between a thread being created |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
78 |
// and the request to get its CPU time. The "/proc/..." structure might |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
79 |
// not be ready at that time and the routine will return -1. |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
80 |
System.out.println("Retry, proc structure might not be ready (-1)"); |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
81 |
return false; |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
82 |
} |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
83 |
if (cpuTime < 0) { |
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
84 |
throw new RuntimeException("Illegal CPU time: " + cpuTime); |
2 | 85 |
} |
86 |
} |
|
21653
8cb51c29ab64
6849945: VM Periodic Task Thread CPU time = -1ns in HotspotThreadMBean.getInternalThreadCpuTimes()
egahlin
parents:
5506
diff
changeset
|
87 |
return true; |
2 | 88 |
} |
89 |
} |