Mercurial > hg > graal-jvmci-8
annotate src/share/vm/services/management.cpp @ 22882:ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
Summary: Check for sun.management.Agent class and print message and exit VM if not found at startup.
Reviewed-by: dholmes, mchung
author | bpittore |
---|---|
date | Wed, 08 Jan 2014 20:23:16 -0500 |
parents | 966601b12d4f |
children | dd9cc155639c eba0866f9379 |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17648
diff
changeset
|
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1326
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1326
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1326
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "compiler/compileBroker.hpp" | |
28 #include "memory/iterator.hpp" | |
29 #include "memory/oopFactory.hpp" | |
30 #include "memory/resourceArea.hpp" | |
31 #include "oops/klass.hpp" | |
32 #include "oops/objArrayKlass.hpp" | |
33 #include "oops/oop.inline.hpp" | |
34 #include "runtime/arguments.hpp" | |
4715
6c995c08526c
7122880: Extend vendor-specific command interface to include manageable switches
phh
parents:
4133
diff
changeset
|
35 #include "runtime/globals.hpp" |
1972 | 36 #include "runtime/handles.inline.hpp" |
37 #include "runtime/interfaceSupport.hpp" | |
38 #include "runtime/javaCalls.hpp" | |
39 #include "runtime/jniHandles.hpp" | |
40 #include "runtime/os.hpp" | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
2177
diff
changeset
|
41 #include "runtime/serviceThread.hpp" |
20197
ce8f6bb717c9
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
17937
diff
changeset
|
42 #include "runtime/thread.inline.hpp" |
1972 | 43 #include "services/classLoadingService.hpp" |
4133 | 44 #include "services/diagnosticCommand.hpp" |
45 #include "services/diagnosticFramework.hpp" | |
1972 | 46 #include "services/heapDumper.hpp" |
4133 | 47 #include "services/jmm.h" |
1972 | 48 #include "services/lowMemoryDetector.hpp" |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
49 #include "services/gcNotifier.hpp" |
6197 | 50 #include "services/nmtDCmd.hpp" |
1972 | 51 #include "services/management.hpp" |
52 #include "services/memoryManager.hpp" | |
53 #include "services/memoryPool.hpp" | |
54 #include "services/memoryService.hpp" | |
55 #include "services/runtimeService.hpp" | |
56 #include "services/threadService.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
6983
diff
changeset
|
57 #include "utilities/macros.hpp" |
0 | 58 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17648
diff
changeset
|
59 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17648
diff
changeset
|
60 |
0 | 61 PerfVariable* Management::_begin_vm_creation_time = NULL; |
62 PerfVariable* Management::_end_vm_creation_time = NULL; | |
63 PerfVariable* Management::_vm_init_done_time = NULL; | |
64 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
65 Klass* Management::_sensor_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
66 Klass* Management::_threadInfo_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
67 Klass* Management::_memoryUsage_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
68 Klass* Management::_memoryPoolMXBean_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
69 Klass* Management::_memoryManagerMXBean_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
70 Klass* Management::_garbageCollectorMXBean_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
71 Klass* Management::_managementFactory_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
72 Klass* Management::_garbageCollectorImpl_klass = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
73 Klass* Management::_gcInfo_klass = NULL; |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
74 Klass* Management::_diagnosticCommandImpl_klass = NULL; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
75 Klass* Management::_managementFactoryHelper_klass = NULL; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
76 |
0 | 77 |
78 jmmOptionalSupport Management::_optional_support = {0}; | |
79 TimeStamp Management::_stamp; | |
80 | |
81 void management_init() { | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
82 #if INCLUDE_MANAGEMENT |
0 | 83 Management::init(); |
84 ThreadService::init(); | |
85 RuntimeService::init(); | |
86 ClassLoadingService::init(); | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
87 #else |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
88 ThreadService::init(); |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
89 // Make sure the VM version is initialized |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
90 // This is normally called by RuntimeService::init(). |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
91 // Since that is conditionalized out, we need to call it here. |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
92 Abstract_VM_Version::initialize(); |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
93 #endif // INCLUDE_MANAGEMENT |
0 | 94 } |
95 | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
96 #if INCLUDE_MANAGEMENT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
97 |
0 | 98 void Management::init() { |
99 EXCEPTION_MARK; | |
100 | |
101 // These counters are for java.lang.management API support. | |
102 // They are created even if -XX:-UsePerfData is set and in | |
103 // that case, they will be allocated on C heap. | |
104 | |
105 _begin_vm_creation_time = | |
106 PerfDataManager::create_variable(SUN_RT, "createVmBeginTime", | |
107 PerfData::U_None, CHECK); | |
108 | |
109 _end_vm_creation_time = | |
110 PerfDataManager::create_variable(SUN_RT, "createVmEndTime", | |
111 PerfData::U_None, CHECK); | |
112 | |
113 _vm_init_done_time = | |
114 PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime", | |
115 PerfData::U_None, CHECK); | |
116 | |
117 // Initialize optional support | |
118 _optional_support.isLowMemoryDetectionSupported = 1; | |
119 _optional_support.isCompilationTimeMonitoringSupported = 1; | |
120 _optional_support.isThreadContentionMonitoringSupported = 1; | |
121 | |
122 if (os::is_thread_cpu_time_supported()) { | |
123 _optional_support.isCurrentThreadCpuTimeSupported = 1; | |
124 _optional_support.isOtherThreadCpuTimeSupported = 1; | |
125 } else { | |
126 _optional_support.isCurrentThreadCpuTimeSupported = 0; | |
127 _optional_support.isOtherThreadCpuTimeSupported = 0; | |
128 } | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
129 |
0 | 130 _optional_support.isBootClassPathSupported = 1; |
131 _optional_support.isObjectMonitorUsageSupported = 1; | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
132 #if INCLUDE_SERVICES |
0 | 133 // This depends on the heap inspector |
134 _optional_support.isSynchronizerUsageSupported = 1; | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
135 #endif // INCLUDE_SERVICES |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
136 _optional_support.isThreadAllocatedMemorySupported = 1; |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
137 _optional_support.isRemoteDiagnosticCommandsSupported = 1; |
4133 | 138 |
4773 | 139 // Registration of the diagnostic commands |
4851
a42c07c38c47
7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents:
4844
diff
changeset
|
140 DCmdRegistrant::register_dcmds(); |
a42c07c38c47
7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents:
4844
diff
changeset
|
141 DCmdRegistrant::register_dcmds_ext(); |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
142 uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
143 | DCmd_Source_MBean; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
144 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(full_export, true, false)); |
0 | 145 } |
146 | |
147 void Management::initialize(TRAPS) { | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
2177
diff
changeset
|
148 // Start the service thread |
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
2177
diff
changeset
|
149 ServiceThread::initialize(); |
0 | 150 |
151 if (ManagementServer) { | |
152 ResourceMark rm(THREAD); | |
153 HandleMark hm(THREAD); | |
154 | |
155 // Load and initialize the sun.management.Agent class | |
156 // invoke startAgent method to start the management server | |
157 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
22882
ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents:
20393
diff
changeset
|
158 Klass* k = SystemDictionary::resolve_or_null(vmSymbols::sun_management_Agent(), |
0 | 159 loader, |
160 Handle(), | |
22882
ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents:
20393
diff
changeset
|
161 THREAD); |
ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents:
20393
diff
changeset
|
162 if (k == NULL) { |
ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents:
20393
diff
changeset
|
163 vm_exit_during_initialization("Management agent initialization failure: " |
ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents:
20393
diff
changeset
|
164 "class sun.management.Agent not found."); |
ffae627760ca
8027914: Client JVM silently exit with fail exit code when running in compact(1,2) with options -Dcom.sun.management and -XX:+ManagementServer
bpittore
parents:
20393
diff
changeset
|
165 } |
0 | 166 instanceKlassHandle ik (THREAD, k); |
167 | |
168 JavaValue result(T_VOID); | |
169 JavaCalls::call_static(&result, | |
170 ik, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
171 vmSymbols::startAgent_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
172 vmSymbols::void_method_signature(), |
0 | 173 CHECK); |
174 } | |
175 } | |
176 | |
177 void Management::get_optional_support(jmmOptionalSupport* support) { | |
178 memcpy(support, &_optional_support, sizeof(jmmOptionalSupport)); | |
179 } | |
180 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
181 Klass* Management::load_and_initialize_klass(Symbol* sh, TRAPS) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
182 Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL); |
0 | 183 instanceKlassHandle ik (THREAD, k); |
184 if (ik->should_be_initialized()) { | |
185 ik->initialize(CHECK_NULL); | |
186 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
187 // If these classes change to not be owned by the boot loader, they need |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
188 // to be walked to keep their class loader alive in oops_do. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
189 assert(ik->class_loader() == NULL, "need to follow in oops_do"); |
0 | 190 return ik(); |
191 } | |
192 | |
193 void Management::record_vm_startup_time(jlong begin, jlong duration) { | |
194 // if the performance counter is not initialized, | |
195 // then vm initialization failed; simply return. | |
196 if (_begin_vm_creation_time == NULL) return; | |
197 | |
198 _begin_vm_creation_time->set_value(begin); | |
199 _end_vm_creation_time->set_value(begin + duration); | |
200 PerfMemory::set_accessible(true); | |
201 } | |
202 | |
203 jlong Management::timestamp() { | |
204 TimeStamp t; | |
205 t.update(); | |
206 return t.ticks() - _stamp.ticks(); | |
207 } | |
208 | |
209 void Management::oops_do(OopClosure* f) { | |
210 MemoryService::oops_do(f); | |
211 ThreadService::oops_do(f); | |
212 } | |
213 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
214 Klass* Management::java_lang_management_ThreadInfo_klass(TRAPS) { |
0 | 215 if (_threadInfo_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
216 _threadInfo_klass = load_and_initialize_klass(vmSymbols::java_lang_management_ThreadInfo(), CHECK_NULL); |
0 | 217 } |
218 return _threadInfo_klass; | |
219 } | |
220 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
221 Klass* Management::java_lang_management_MemoryUsage_klass(TRAPS) { |
0 | 222 if (_memoryUsage_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
223 _memoryUsage_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryUsage(), CHECK_NULL); |
0 | 224 } |
225 return _memoryUsage_klass; | |
226 } | |
227 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
228 Klass* Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) { |
0 | 229 if (_memoryPoolMXBean_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
230 _memoryPoolMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryPoolMXBean(), CHECK_NULL); |
0 | 231 } |
232 return _memoryPoolMXBean_klass; | |
233 } | |
234 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
235 Klass* Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) { |
0 | 236 if (_memoryManagerMXBean_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
237 _memoryManagerMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryManagerMXBean(), CHECK_NULL); |
0 | 238 } |
239 return _memoryManagerMXBean_klass; | |
240 } | |
241 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
242 Klass* Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) { |
0 | 243 if (_garbageCollectorMXBean_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
244 _garbageCollectorMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_GarbageCollectorMXBean(), CHECK_NULL); |
0 | 245 } |
246 return _garbageCollectorMXBean_klass; | |
247 } | |
248 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
249 Klass* Management::sun_management_Sensor_klass(TRAPS) { |
0 | 250 if (_sensor_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
251 _sensor_klass = load_and_initialize_klass(vmSymbols::sun_management_Sensor(), CHECK_NULL); |
0 | 252 } |
253 return _sensor_klass; | |
254 } | |
255 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
256 Klass* Management::sun_management_ManagementFactory_klass(TRAPS) { |
0 | 257 if (_managementFactory_klass == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
258 _managementFactory_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactory(), CHECK_NULL); |
0 | 259 } |
260 return _managementFactory_klass; | |
261 } | |
262 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
263 Klass* Management::sun_management_GarbageCollectorImpl_klass(TRAPS) { |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
264 if (_garbageCollectorImpl_klass == NULL) { |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
265 _garbageCollectorImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_GarbageCollectorImpl(), CHECK_NULL); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
266 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
267 return _garbageCollectorImpl_klass; |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
268 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
269 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
270 Klass* Management::com_sun_management_GcInfo_klass(TRAPS) { |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
271 if (_gcInfo_klass == NULL) { |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
272 _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
273 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
274 return _gcInfo_klass; |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
275 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
276 |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
277 Klass* Management::sun_management_DiagnosticCommandImpl_klass(TRAPS) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
278 if (_diagnosticCommandImpl_klass == NULL) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
279 _diagnosticCommandImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_DiagnosticCommandImpl(), CHECK_NULL); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
280 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
281 return _diagnosticCommandImpl_klass; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
282 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
283 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
284 Klass* Management::sun_management_ManagementFactoryHelper_klass(TRAPS) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
285 if (_managementFactoryHelper_klass == NULL) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
286 _managementFactoryHelper_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactoryHelper(), CHECK_NULL); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
287 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
288 return _managementFactoryHelper_klass; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
289 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
290 |
0 | 291 static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) { |
292 Handle snapshot_thread(THREAD, snapshot->threadObj()); | |
293 | |
294 jlong contended_time; | |
295 jlong waited_time; | |
296 if (ThreadService::is_thread_monitoring_contention()) { | |
297 contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks()); | |
298 waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks()); | |
299 } else { | |
300 // set them to -1 if thread contention monitoring is disabled. | |
301 contended_time = max_julong; | |
302 waited_time = max_julong; | |
303 } | |
304 | |
305 int thread_status = snapshot->thread_status(); | |
306 assert((thread_status & JMM_THREAD_STATE_FLAG_MASK) == 0, "Flags already set in thread_status in Thread object"); | |
307 if (snapshot->is_ext_suspended()) { | |
308 thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED; | |
309 } | |
310 if (snapshot->is_in_native()) { | |
311 thread_status |= JMM_THREAD_STATE_FLAG_NATIVE; | |
312 } | |
313 | |
314 ThreadStackTrace* st = snapshot->get_stack_trace(); | |
315 Handle stacktrace_h; | |
316 if (st != NULL) { | |
317 stacktrace_h = st->allocate_fill_stack_trace_element_array(CHECK); | |
318 } else { | |
319 stacktrace_h = Handle(); | |
320 } | |
321 | |
322 args->push_oop(snapshot_thread); | |
323 args->push_int(thread_status); | |
324 args->push_oop(Handle(THREAD, snapshot->blocker_object())); | |
325 args->push_oop(Handle(THREAD, snapshot->blocker_object_owner())); | |
326 args->push_long(snapshot->contended_enter_count()); | |
327 args->push_long(contended_time); | |
328 args->push_long(snapshot->monitor_wait_count() + snapshot->sleep_count()); | |
329 args->push_long(waited_time); | |
330 args->push_oop(stacktrace_h); | |
331 } | |
332 | |
333 // Helper function to construct a ThreadInfo object | |
334 instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
335 Klass* k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL); |
0 | 336 instanceKlassHandle ik (THREAD, k); |
337 | |
338 JavaValue result(T_VOID); | |
339 JavaCallArguments args(14); | |
340 | |
341 // First allocate a ThreadObj object and | |
342 // push the receiver as the first argument | |
343 Handle element = ik->allocate_instance_handle(CHECK_NULL); | |
344 args.push_oop(element); | |
345 | |
346 // initialize the arguments for the ThreadInfo constructor | |
347 initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL); | |
348 | |
349 // Call ThreadInfo constructor with no locked monitors and synchronizers | |
350 JavaCalls::call_special(&result, | |
351 ik, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
352 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
353 vmSymbols::java_lang_management_ThreadInfo_constructor_signature(), |
0 | 354 &args, |
355 CHECK_NULL); | |
356 | |
357 return (instanceOop) element(); | |
358 } | |
359 | |
360 instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, | |
361 objArrayHandle monitors_array, | |
362 typeArrayHandle depths_array, | |
363 objArrayHandle synchronizers_array, | |
364 TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
365 Klass* k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL); |
0 | 366 instanceKlassHandle ik (THREAD, k); |
367 | |
368 JavaValue result(T_VOID); | |
369 JavaCallArguments args(17); | |
370 | |
371 // First allocate a ThreadObj object and | |
372 // push the receiver as the first argument | |
373 Handle element = ik->allocate_instance_handle(CHECK_NULL); | |
374 args.push_oop(element); | |
375 | |
376 // initialize the arguments for the ThreadInfo constructor | |
377 initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL); | |
378 | |
379 // push the locked monitors and synchronizers in the arguments | |
380 args.push_oop(monitors_array); | |
381 args.push_oop(depths_array); | |
382 args.push_oop(synchronizers_array); | |
383 | |
384 // Call ThreadInfo constructor with locked monitors and synchronizers | |
385 JavaCalls::call_special(&result, | |
386 ik, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
387 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
388 vmSymbols::java_lang_management_ThreadInfo_with_locks_constructor_signature(), |
0 | 389 &args, |
390 CHECK_NULL); | |
391 | |
392 return (instanceOop) element(); | |
393 } | |
394 | |
395 | |
396 static GCMemoryManager* get_gc_memory_manager_from_jobject(jobject mgr, TRAPS) { | |
397 if (mgr == NULL) { | |
398 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); | |
399 } | |
400 oop mgr_obj = JNIHandles::resolve(mgr); | |
401 instanceHandle h(THREAD, (instanceOop) mgr_obj); | |
402 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
403 Klass* k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL); |
0 | 404 if (!h->is_a(k)) { |
405 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
406 "the object is not an instance of java.lang.management.GarbageCollectorMXBean class", | |
407 NULL); | |
408 } | |
409 | |
410 MemoryManager* gc = MemoryService::get_memory_manager(h); | |
411 if (gc == NULL || !gc->is_gc_memory_manager()) { | |
412 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
413 "Invalid GC memory manager", | |
414 NULL); | |
415 } | |
416 return (GCMemoryManager*) gc; | |
417 } | |
418 | |
419 static MemoryPool* get_memory_pool_from_jobject(jobject obj, TRAPS) { | |
420 if (obj == NULL) { | |
421 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); | |
422 } | |
423 | |
424 oop pool_obj = JNIHandles::resolve(obj); | |
425 assert(pool_obj->is_instance(), "Should be an instanceOop"); | |
426 instanceHandle ph(THREAD, (instanceOop) pool_obj); | |
427 | |
428 return MemoryService::get_memory_pool(ph); | |
429 } | |
430 | |
20393 | 431 #endif // INCLUDE_MANAGEMENT |
432 | |
0 | 433 static void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) { |
434 int num_threads = ids_ah->length(); | |
435 | |
436 // Validate input thread IDs | |
437 int i = 0; | |
438 for (i = 0; i < num_threads; i++) { | |
439 jlong tid = ids_ah->long_at(i); | |
440 if (tid <= 0) { | |
441 // throw exception if invalid thread id. | |
442 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
443 "Invalid thread ID entry"); | |
444 } | |
445 } | |
446 } | |
447 | |
20393 | 448 #if INCLUDE_MANAGEMENT |
449 | |
0 | 450 static void validate_thread_info_array(objArrayHandle infoArray_h, TRAPS) { |
451 // check if the element of infoArray is of type ThreadInfo class | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
452 Klass* threadinfo_klass = Management::java_lang_management_ThreadInfo_klass(CHECK); |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6779
diff
changeset
|
453 Klass* element_klass = ObjArrayKlass::cast(infoArray_h->klass())->element_klass(); |
0 | 454 if (element_klass != threadinfo_klass) { |
455 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
456 "infoArray element type is not ThreadInfo class"); | |
457 } | |
458 } | |
459 | |
460 | |
461 static MemoryManager* get_memory_manager_from_jobject(jobject obj, TRAPS) { | |
462 if (obj == NULL) { | |
463 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); | |
464 } | |
465 | |
466 oop mgr_obj = JNIHandles::resolve(obj); | |
467 assert(mgr_obj->is_instance(), "Should be an instanceOop"); | |
468 instanceHandle mh(THREAD, (instanceOop) mgr_obj); | |
469 | |
470 return MemoryService::get_memory_manager(mh); | |
471 } | |
472 | |
473 // Returns a version string and sets major and minor version if | |
474 // the input parameters are non-null. | |
475 JVM_LEAF(jint, jmm_GetVersion(JNIEnv *env)) | |
476 return JMM_VERSION; | |
477 JVM_END | |
478 | |
479 // Gets the list of VM monitoring and management optional supports | |
480 // Returns 0 if succeeded; otherwise returns non-zero. | |
481 JVM_LEAF(jint, jmm_GetOptionalSupport(JNIEnv *env, jmmOptionalSupport* support)) | |
482 if (support == NULL) { | |
483 return -1; | |
484 } | |
485 Management::get_optional_support(support); | |
486 return 0; | |
487 JVM_END | |
488 | |
489 // Returns a java.lang.String object containing the input arguments to the VM. | |
490 JVM_ENTRY(jobject, jmm_GetInputArguments(JNIEnv *env)) | |
491 ResourceMark rm(THREAD); | |
492 | |
493 if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) { | |
494 return NULL; | |
495 } | |
496 | |
497 char** vm_flags = Arguments::jvm_flags_array(); | |
498 char** vm_args = Arguments::jvm_args_array(); | |
499 int num_flags = Arguments::num_jvm_flags(); | |
500 int num_args = Arguments::num_jvm_args(); | |
501 | |
502 size_t length = 1; // null terminator | |
503 int i; | |
504 for (i = 0; i < num_flags; i++) { | |
505 length += strlen(vm_flags[i]); | |
506 } | |
507 for (i = 0; i < num_args; i++) { | |
508 length += strlen(vm_args[i]); | |
509 } | |
510 // add a space between each argument | |
511 length += num_flags + num_args - 1; | |
512 | |
513 // Return the list of input arguments passed to the VM | |
514 // and preserve the order that the VM processes. | |
515 char* args = NEW_RESOURCE_ARRAY(char, length); | |
516 args[0] = '\0'; | |
517 // concatenate all jvm_flags | |
518 if (num_flags > 0) { | |
519 strcat(args, vm_flags[0]); | |
520 for (i = 1; i < num_flags; i++) { | |
521 strcat(args, " "); | |
522 strcat(args, vm_flags[i]); | |
523 } | |
524 } | |
525 | |
526 if (num_args > 0 && num_flags > 0) { | |
527 // append a space if args already contains one or more jvm_flags | |
528 strcat(args, " "); | |
529 } | |
530 | |
531 // concatenate all jvm_args | |
532 if (num_args > 0) { | |
533 strcat(args, vm_args[0]); | |
534 for (i = 1; i < num_args; i++) { | |
535 strcat(args, " "); | |
536 strcat(args, vm_args[i]); | |
537 } | |
538 } | |
539 | |
540 Handle hargs = java_lang_String::create_from_platform_dependent_str(args, CHECK_NULL); | |
541 return JNIHandles::make_local(env, hargs()); | |
542 JVM_END | |
543 | |
544 // Returns an array of java.lang.String object containing the input arguments to the VM. | |
545 JVM_ENTRY(jobjectArray, jmm_GetInputArgumentArray(JNIEnv *env)) | |
546 ResourceMark rm(THREAD); | |
547 | |
548 if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) { | |
549 return NULL; | |
550 } | |
551 | |
552 char** vm_flags = Arguments::jvm_flags_array(); | |
553 char** vm_args = Arguments::jvm_args_array(); | |
554 int num_flags = Arguments::num_jvm_flags(); | |
555 int num_args = Arguments::num_jvm_args(); | |
556 | |
1142 | 557 instanceKlassHandle ik (THREAD, SystemDictionary::String_klass()); |
0 | 558 objArrayOop r = oopFactory::new_objArray(ik(), num_args + num_flags, CHECK_NULL); |
559 objArrayHandle result_h(THREAD, r); | |
560 | |
561 int index = 0; | |
562 for (int j = 0; j < num_flags; j++, index++) { | |
563 Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL); | |
564 result_h->obj_at_put(index, h()); | |
565 } | |
566 for (int i = 0; i < num_args; i++, index++) { | |
567 Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL); | |
568 result_h->obj_at_put(index, h()); | |
569 } | |
570 return (jobjectArray) JNIHandles::make_local(env, result_h()); | |
571 JVM_END | |
572 | |
573 // Returns an array of java/lang/management/MemoryPoolMXBean object | |
574 // one for each memory pool if obj == null; otherwise returns | |
575 // an array of memory pools for a given memory manager if | |
576 // it is a valid memory manager. | |
577 JVM_ENTRY(jobjectArray, jmm_GetMemoryPools(JNIEnv* env, jobject obj)) | |
578 ResourceMark rm(THREAD); | |
579 | |
580 int num_memory_pools; | |
581 MemoryManager* mgr = NULL; | |
582 if (obj == NULL) { | |
583 num_memory_pools = MemoryService::num_memory_pools(); | |
584 } else { | |
585 mgr = get_memory_manager_from_jobject(obj, CHECK_NULL); | |
586 if (mgr == NULL) { | |
587 return NULL; | |
588 } | |
589 num_memory_pools = mgr->num_memory_pools(); | |
590 } | |
591 | |
592 // Allocate the resulting MemoryPoolMXBean[] object | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
593 Klass* k = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL); |
0 | 594 instanceKlassHandle ik (THREAD, k); |
595 objArrayOop r = oopFactory::new_objArray(ik(), num_memory_pools, CHECK_NULL); | |
596 objArrayHandle poolArray(THREAD, r); | |
597 | |
598 if (mgr == NULL) { | |
599 // Get all memory pools | |
600 for (int i = 0; i < num_memory_pools; i++) { | |
601 MemoryPool* pool = MemoryService::get_memory_pool(i); | |
602 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL); | |
603 instanceHandle ph(THREAD, p); | |
604 poolArray->obj_at_put(i, ph()); | |
605 } | |
606 } else { | |
607 // Get memory pools managed by a given memory manager | |
608 for (int i = 0; i < num_memory_pools; i++) { | |
609 MemoryPool* pool = mgr->get_memory_pool(i); | |
610 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL); | |
611 instanceHandle ph(THREAD, p); | |
612 poolArray->obj_at_put(i, ph()); | |
613 } | |
614 } | |
615 return (jobjectArray) JNIHandles::make_local(env, poolArray()); | |
616 JVM_END | |
617 | |
618 // Returns an array of java/lang/management/MemoryManagerMXBean object | |
619 // one for each memory manager if obj == null; otherwise returns | |
620 // an array of memory managers for a given memory pool if | |
621 // it is a valid memory pool. | |
622 JVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj)) | |
623 ResourceMark rm(THREAD); | |
624 | |
625 int num_mgrs; | |
626 MemoryPool* pool = NULL; | |
627 if (obj == NULL) { | |
628 num_mgrs = MemoryService::num_memory_managers(); | |
629 } else { | |
630 pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
631 if (pool == NULL) { | |
632 return NULL; | |
633 } | |
634 num_mgrs = pool->num_memory_managers(); | |
635 } | |
636 | |
637 // Allocate the resulting MemoryManagerMXBean[] object | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
638 Klass* k = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL); |
0 | 639 instanceKlassHandle ik (THREAD, k); |
640 objArrayOop r = oopFactory::new_objArray(ik(), num_mgrs, CHECK_NULL); | |
641 objArrayHandle mgrArray(THREAD, r); | |
642 | |
643 if (pool == NULL) { | |
644 // Get all memory managers | |
645 for (int i = 0; i < num_mgrs; i++) { | |
646 MemoryManager* mgr = MemoryService::get_memory_manager(i); | |
647 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL); | |
648 instanceHandle ph(THREAD, p); | |
649 mgrArray->obj_at_put(i, ph()); | |
650 } | |
651 } else { | |
652 // Get memory managers for a given memory pool | |
653 for (int i = 0; i < num_mgrs; i++) { | |
654 MemoryManager* mgr = pool->get_memory_manager(i); | |
655 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL); | |
656 instanceHandle ph(THREAD, p); | |
657 mgrArray->obj_at_put(i, ph()); | |
658 } | |
659 } | |
660 return (jobjectArray) JNIHandles::make_local(env, mgrArray()); | |
661 JVM_END | |
662 | |
663 | |
664 // Returns a java/lang/management/MemoryUsage object containing the memory usage | |
665 // of a given memory pool. | |
666 JVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj)) | |
667 ResourceMark rm(THREAD); | |
668 | |
669 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
670 if (pool != NULL) { | |
671 MemoryUsage usage = pool->get_memory_usage(); | |
672 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
673 return JNIHandles::make_local(env, h()); | |
674 } else { | |
675 return NULL; | |
676 } | |
677 JVM_END | |
678 | |
679 // Returns a java/lang/management/MemoryUsage object containing the memory usage | |
680 // of a given memory pool. | |
681 JVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj)) | |
682 ResourceMark rm(THREAD); | |
683 | |
684 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
685 if (pool != NULL) { | |
686 MemoryUsage usage = pool->get_peak_memory_usage(); | |
687 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
688 return JNIHandles::make_local(env, h()); | |
689 } else { | |
690 return NULL; | |
691 } | |
692 JVM_END | |
693 | |
694 // Returns a java/lang/management/MemoryUsage object containing the memory usage | |
695 // of a given memory pool after most recent GC. | |
696 JVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj)) | |
697 ResourceMark rm(THREAD); | |
698 | |
699 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
700 if (pool != NULL && pool->is_collected_pool()) { | |
701 MemoryUsage usage = pool->get_last_collection_usage(); | |
702 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
703 return JNIHandles::make_local(env, h()); | |
704 } else { | |
705 return NULL; | |
706 } | |
707 JVM_END | |
708 | |
709 // Sets the memory pool sensor for a threshold type | |
710 JVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj)) | |
711 if (obj == NULL || sensorObj == NULL) { | |
712 THROW(vmSymbols::java_lang_NullPointerException()); | |
713 } | |
714 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
715 Klass* sensor_klass = Management::sun_management_Sensor_klass(CHECK); |
0 | 716 oop s = JNIHandles::resolve(sensorObj); |
717 assert(s->is_instance(), "Sensor should be an instanceOop"); | |
718 instanceHandle sensor_h(THREAD, (instanceOop) s); | |
719 if (!sensor_h->is_a(sensor_klass)) { | |
720 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
721 "Sensor is not an instance of sun.management.Sensor class"); | |
722 } | |
723 | |
724 MemoryPool* mpool = get_memory_pool_from_jobject(obj, CHECK); | |
725 assert(mpool != NULL, "MemoryPool should exist"); | |
726 | |
727 switch (type) { | |
728 case JMM_USAGE_THRESHOLD_HIGH: | |
729 case JMM_USAGE_THRESHOLD_LOW: | |
730 // have only one sensor for threshold high and low | |
731 mpool->set_usage_sensor_obj(sensor_h); | |
732 break; | |
733 case JMM_COLLECTION_USAGE_THRESHOLD_HIGH: | |
734 case JMM_COLLECTION_USAGE_THRESHOLD_LOW: | |
735 // have only one sensor for threshold high and low | |
736 mpool->set_gc_usage_sensor_obj(sensor_h); | |
737 break; | |
738 default: | |
739 assert(false, "Unrecognized type"); | |
740 } | |
741 | |
742 JVM_END | |
743 | |
744 | |
745 // Sets the threshold of a given memory pool. | |
746 // Returns the previous threshold. | |
747 // | |
748 // Input parameters: | |
749 // pool - the MemoryPoolMXBean object | |
750 // type - threshold type | |
751 // threshold - the new threshold (must not be negative) | |
752 // | |
753 JVM_ENTRY(jlong, jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold)) | |
754 if (threshold < 0) { | |
755 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
756 "Invalid threshold value", | |
757 -1); | |
758 } | |
759 | |
489
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
760 if ((size_t)threshold > max_uintx) { |
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
761 stringStream st; |
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
762 st.print("Invalid valid threshold value. Threshold value (" UINT64_FORMAT ") > max value of size_t (" SIZE_FORMAT ")", (size_t)threshold, max_uintx); |
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
763 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), st.as_string(), -1); |
0 | 764 } |
765 | |
766 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_(0L)); | |
767 assert(pool != NULL, "MemoryPool should exist"); | |
768 | |
769 jlong prev = 0; | |
770 switch (type) { | |
771 case JMM_USAGE_THRESHOLD_HIGH: | |
772 if (!pool->usage_threshold()->is_high_threshold_supported()) { | |
773 return -1; | |
774 } | |
775 prev = pool->usage_threshold()->set_high_threshold((size_t) threshold); | |
776 break; | |
777 | |
778 case JMM_USAGE_THRESHOLD_LOW: | |
779 if (!pool->usage_threshold()->is_low_threshold_supported()) { | |
780 return -1; | |
781 } | |
782 prev = pool->usage_threshold()->set_low_threshold((size_t) threshold); | |
783 break; | |
784 | |
785 case JMM_COLLECTION_USAGE_THRESHOLD_HIGH: | |
786 if (!pool->gc_usage_threshold()->is_high_threshold_supported()) { | |
787 return -1; | |
788 } | |
789 // return and the new threshold is effective for the next GC | |
790 return pool->gc_usage_threshold()->set_high_threshold((size_t) threshold); | |
791 | |
792 case JMM_COLLECTION_USAGE_THRESHOLD_LOW: | |
793 if (!pool->gc_usage_threshold()->is_low_threshold_supported()) { | |
794 return -1; | |
795 } | |
796 // return and the new threshold is effective for the next GC | |
797 return pool->gc_usage_threshold()->set_low_threshold((size_t) threshold); | |
798 | |
799 default: | |
800 assert(false, "Unrecognized type"); | |
801 return -1; | |
802 } | |
803 | |
804 // When the threshold is changed, reevaluate if the low memory | |
805 // detection is enabled. | |
806 if (prev != threshold) { | |
807 LowMemoryDetector::recompute_enabled_for_collected_pools(); | |
808 LowMemoryDetector::detect_low_memory(pool); | |
809 } | |
810 return prev; | |
811 JVM_END | |
812 | |
813 // Returns a java/lang/management/MemoryUsage object representing | |
814 // the memory usage for the heap or non-heap memory. | |
815 JVM_ENTRY(jobject, jmm_GetMemoryUsage(JNIEnv* env, jboolean heap)) | |
816 ResourceMark rm(THREAD); | |
817 | |
818 // Calculate the memory usage | |
819 size_t total_init = 0; | |
820 size_t total_used = 0; | |
821 size_t total_committed = 0; | |
822 size_t total_max = 0; | |
823 bool has_undefined_init_size = false; | |
824 bool has_undefined_max_size = false; | |
825 | |
826 for (int i = 0; i < MemoryService::num_memory_pools(); i++) { | |
827 MemoryPool* pool = MemoryService::get_memory_pool(i); | |
828 if ((heap && pool->is_heap()) || (!heap && pool->is_non_heap())) { | |
829 MemoryUsage u = pool->get_memory_usage(); | |
830 total_used += u.used(); | |
831 total_committed += u.committed(); | |
832 | |
833 if (u.init_size() == (size_t)-1) { | |
834 has_undefined_init_size = true; | |
835 } | |
836 if (!has_undefined_init_size) { | |
837 total_init += u.init_size(); | |
838 } | |
839 | |
840 if (u.max_size() == (size_t)-1) { | |
841 has_undefined_max_size = true; | |
842 } | |
843 if (!has_undefined_max_size) { | |
844 total_max += u.max_size(); | |
845 } | |
846 } | |
847 } | |
848 | |
12103
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
849 // if any one of the memory pool has undefined init_size or max_size, |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
850 // set it to -1 |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
851 if (has_undefined_init_size) { |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
852 total_init = (size_t)-1; |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
853 } |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
854 if (has_undefined_max_size) { |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
855 total_max = (size_t)-1; |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
856 } |
a70566600baf
8020530: Non heap memory size calculated incorrectly
poonam
parents:
11986
diff
changeset
|
857 |
1064 | 858 MemoryUsage usage((heap ? InitialHeapSize : total_init), |
0 | 859 total_used, |
860 total_committed, | |
861 (heap ? Universe::heap()->max_capacity() : total_max)); | |
862 | |
863 Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
864 return JNIHandles::make_local(env, obj()); | |
865 JVM_END | |
866 | |
867 // Returns the boolean value of a given attribute. | |
868 JVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att)) | |
869 switch (att) { | |
870 case JMM_VERBOSE_GC: | |
871 return MemoryService::get_verbose(); | |
872 case JMM_VERBOSE_CLASS: | |
873 return ClassLoadingService::get_verbose(); | |
874 case JMM_THREAD_CONTENTION_MONITORING: | |
875 return ThreadService::is_thread_monitoring_contention(); | |
876 case JMM_THREAD_CPU_TIME: | |
877 return ThreadService::is_thread_cpu_time_enabled(); | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
878 case JMM_THREAD_ALLOCATED_MEMORY: |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
879 return ThreadService::is_thread_allocated_memory_enabled(); |
0 | 880 default: |
881 assert(0, "Unrecognized attribute"); | |
882 return false; | |
883 } | |
884 JVM_END | |
885 | |
886 // Sets the given boolean attribute and returns the previous value. | |
887 JVM_ENTRY(jboolean, jmm_SetBoolAttribute(JNIEnv *env, jmmBoolAttribute att, jboolean flag)) | |
888 switch (att) { | |
889 case JMM_VERBOSE_GC: | |
890 return MemoryService::set_verbose(flag != 0); | |
891 case JMM_VERBOSE_CLASS: | |
892 return ClassLoadingService::set_verbose(flag != 0); | |
893 case JMM_THREAD_CONTENTION_MONITORING: | |
894 return ThreadService::set_thread_monitoring_contention(flag != 0); | |
895 case JMM_THREAD_CPU_TIME: | |
896 return ThreadService::set_thread_cpu_time_enabled(flag != 0); | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
897 case JMM_THREAD_ALLOCATED_MEMORY: |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
898 return ThreadService::set_thread_allocated_memory_enabled(flag != 0); |
0 | 899 default: |
900 assert(0, "Unrecognized attribute"); | |
901 return false; | |
902 } | |
903 JVM_END | |
904 | |
905 | |
906 static jlong get_gc_attribute(GCMemoryManager* mgr, jmmLongAttribute att) { | |
907 switch (att) { | |
908 case JMM_GC_TIME_MS: | |
909 return mgr->gc_time_ms(); | |
910 | |
911 case JMM_GC_COUNT: | |
912 return mgr->gc_count(); | |
913 | |
914 case JMM_GC_EXT_ATTRIBUTE_INFO_SIZE: | |
915 // current implementation only has 1 ext attribute | |
916 return 1; | |
917 | |
918 default: | |
919 assert(0, "Unrecognized GC attribute"); | |
920 return -1; | |
921 } | |
922 } | |
923 | |
924 class VmThreadCountClosure: public ThreadClosure { | |
925 private: | |
926 int _count; | |
927 public: | |
928 VmThreadCountClosure() : _count(0) {}; | |
929 void do_thread(Thread* thread); | |
930 int count() { return _count; } | |
931 }; | |
932 | |
933 void VmThreadCountClosure::do_thread(Thread* thread) { | |
934 // exclude externally visible JavaThreads | |
935 if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) { | |
936 return; | |
937 } | |
938 | |
939 _count++; | |
940 } | |
941 | |
942 static jint get_vm_thread_count() { | |
943 VmThreadCountClosure vmtcc; | |
944 { | |
945 MutexLockerEx ml(Threads_lock); | |
946 Threads::threads_do(&vmtcc); | |
947 } | |
948 | |
949 return vmtcc.count(); | |
950 } | |
951 | |
952 static jint get_num_flags() { | |
953 // last flag entry is always NULL, so subtract 1 | |
954 int nFlags = (int) Flag::numFlags - 1; | |
955 int count = 0; | |
956 for (int i = 0; i < nFlags; i++) { | |
957 Flag* flag = &Flag::flags[i]; | |
350 | 958 // Exclude the locked (diagnostic, experimental) flags |
0 | 959 if (flag->is_unlocked() || flag->is_unlocker()) { |
960 count++; | |
961 } | |
962 } | |
963 return count; | |
964 } | |
965 | |
966 static jlong get_long_attribute(jmmLongAttribute att) { | |
967 switch (att) { | |
968 case JMM_CLASS_LOADED_COUNT: | |
969 return ClassLoadingService::loaded_class_count(); | |
970 | |
971 case JMM_CLASS_UNLOADED_COUNT: | |
972 return ClassLoadingService::unloaded_class_count(); | |
973 | |
974 case JMM_THREAD_TOTAL_COUNT: | |
975 return ThreadService::get_total_thread_count(); | |
976 | |
977 case JMM_THREAD_LIVE_COUNT: | |
978 return ThreadService::get_live_thread_count(); | |
979 | |
980 case JMM_THREAD_PEAK_COUNT: | |
981 return ThreadService::get_peak_thread_count(); | |
982 | |
983 case JMM_THREAD_DAEMON_COUNT: | |
984 return ThreadService::get_daemon_thread_count(); | |
985 | |
986 case JMM_JVM_INIT_DONE_TIME_MS: | |
987 return Management::vm_init_done_time(); | |
988 | |
12997
e4f478e7781b
8027294: Prepare hotspot for non TOD based uptime counter
jbachorik
parents:
12322
diff
changeset
|
989 case JMM_JVM_UPTIME_MS: |
e4f478e7781b
8027294: Prepare hotspot for non TOD based uptime counter
jbachorik
parents:
12322
diff
changeset
|
990 return Management::ticks_to_ms(os::elapsed_counter()); |
e4f478e7781b
8027294: Prepare hotspot for non TOD based uptime counter
jbachorik
parents:
12322
diff
changeset
|
991 |
0 | 992 case JMM_COMPILE_TOTAL_TIME_MS: |
993 return Management::ticks_to_ms(CompileBroker::total_compilation_ticks()); | |
994 | |
995 case JMM_OS_PROCESS_ID: | |
996 return os::current_process_id(); | |
997 | |
998 // Hotspot-specific counters | |
999 case JMM_CLASS_LOADED_BYTES: | |
1000 return ClassLoadingService::loaded_class_bytes(); | |
1001 | |
1002 case JMM_CLASS_UNLOADED_BYTES: | |
1003 return ClassLoadingService::unloaded_class_bytes(); | |
1004 | |
1005 case JMM_SHARED_CLASS_LOADED_COUNT: | |
1006 return ClassLoadingService::loaded_shared_class_count(); | |
1007 | |
1008 case JMM_SHARED_CLASS_UNLOADED_COUNT: | |
1009 return ClassLoadingService::unloaded_shared_class_count(); | |
1010 | |
1011 | |
1012 case JMM_SHARED_CLASS_LOADED_BYTES: | |
1013 return ClassLoadingService::loaded_shared_class_bytes(); | |
1014 | |
1015 case JMM_SHARED_CLASS_UNLOADED_BYTES: | |
1016 return ClassLoadingService::unloaded_shared_class_bytes(); | |
1017 | |
1018 case JMM_TOTAL_CLASSLOAD_TIME_MS: | |
1019 return ClassLoader::classloader_time_ms(); | |
1020 | |
1021 case JMM_VM_GLOBAL_COUNT: | |
1022 return get_num_flags(); | |
1023 | |
1024 case JMM_SAFEPOINT_COUNT: | |
1025 return RuntimeService::safepoint_count(); | |
1026 | |
1027 case JMM_TOTAL_SAFEPOINTSYNC_TIME_MS: | |
1028 return RuntimeService::safepoint_sync_time_ms(); | |
1029 | |
1030 case JMM_TOTAL_STOPPED_TIME_MS: | |
1031 return RuntimeService::safepoint_time_ms(); | |
1032 | |
1033 case JMM_TOTAL_APP_TIME_MS: | |
1034 return RuntimeService::application_time_ms(); | |
1035 | |
1036 case JMM_VM_THREAD_COUNT: | |
1037 return get_vm_thread_count(); | |
1038 | |
1039 case JMM_CLASS_INIT_TOTAL_COUNT: | |
1040 return ClassLoader::class_init_count(); | |
1041 | |
1042 case JMM_CLASS_INIT_TOTAL_TIME_MS: | |
1043 return ClassLoader::class_init_time_ms(); | |
1044 | |
1045 case JMM_CLASS_VERIFY_TOTAL_TIME_MS: | |
1046 return ClassLoader::class_verify_time_ms(); | |
1047 | |
1048 case JMM_METHOD_DATA_SIZE_BYTES: | |
1049 return ClassLoadingService::class_method_data_size(); | |
1050 | |
1051 case JMM_OS_MEM_TOTAL_PHYSICAL_BYTES: | |
1052 return os::physical_memory(); | |
1053 | |
1054 default: | |
1055 return -1; | |
1056 } | |
1057 } | |
1058 | |
1059 | |
1060 // Returns the long value of a given attribute. | |
1061 JVM_ENTRY(jlong, jmm_GetLongAttribute(JNIEnv *env, jobject obj, jmmLongAttribute att)) | |
1062 if (obj == NULL) { | |
1063 return get_long_attribute(att); | |
1064 } else { | |
1065 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_(0L)); | |
1066 if (mgr != NULL) { | |
1067 return get_gc_attribute(mgr, att); | |
1068 } | |
1069 } | |
1070 return -1; | |
1071 JVM_END | |
1072 | |
1073 // Gets the value of all attributes specified in the given array | |
1074 // and sets the value in the result array. | |
1075 // Returns the number of attributes found. | |
1076 JVM_ENTRY(jint, jmm_GetLongAttributes(JNIEnv *env, | |
1077 jobject obj, | |
1078 jmmLongAttribute* atts, | |
1079 jint count, | |
1080 jlong* result)) | |
1081 | |
1082 int num_atts = 0; | |
1083 if (obj == NULL) { | |
1084 for (int i = 0; i < count; i++) { | |
1085 result[i] = get_long_attribute(atts[i]); | |
1086 if (result[i] != -1) { | |
1087 num_atts++; | |
1088 } | |
1089 } | |
1090 } else { | |
1091 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_0); | |
1092 for (int i = 0; i < count; i++) { | |
1093 result[i] = get_gc_attribute(mgr, atts[i]); | |
1094 if (result[i] != -1) { | |
1095 num_atts++; | |
1096 } | |
1097 } | |
1098 } | |
1099 return num_atts; | |
1100 JVM_END | |
1101 | |
1102 // Helper function to do thread dump for a specific list of threads | |
1103 static void do_thread_dump(ThreadDumpResult* dump_result, | |
1104 typeArrayHandle ids_ah, // array of thread ID (long[]) | |
1105 int num_threads, | |
1106 int max_depth, | |
1107 bool with_locked_monitors, | |
1108 bool with_locked_synchronizers, | |
1109 TRAPS) { | |
1110 | |
1111 // First get an array of threadObj handles. | |
1112 // A JavaThread may terminate before we get the stack trace. | |
1113 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads); | |
1114 { | |
1115 MutexLockerEx ml(Threads_lock); | |
1116 for (int i = 0; i < num_threads; i++) { | |
1117 jlong tid = ids_ah->long_at(i); | |
20393 | 1118 JavaThread* jt = Threads::find_java_thread_from_java_tid(tid); |
0 | 1119 oop thread_obj = (jt != NULL ? jt->threadObj() : (oop)NULL); |
1120 instanceHandle threadObj_h(THREAD, (instanceOop) thread_obj); | |
1121 thread_handle_array->append(threadObj_h); | |
1122 } | |
1123 } | |
1124 | |
1125 // Obtain thread dumps and thread snapshot information | |
1126 VM_ThreadDump op(dump_result, | |
1127 thread_handle_array, | |
1128 num_threads, | |
1129 max_depth, /* stack depth */ | |
1130 with_locked_monitors, | |
1131 with_locked_synchronizers); | |
1132 VMThread::execute(&op); | |
1133 } | |
1134 | |
1135 // Gets an array of ThreadInfo objects. Each element is the ThreadInfo | |
1136 // for the thread ID specified in the corresponding entry in | |
1137 // the given array of thread IDs; or NULL if the thread does not exist | |
1138 // or has terminated. | |
1139 // | |
1140 // Input parameters: | |
1141 // ids - array of thread IDs | |
1142 // maxDepth - the maximum depth of stack traces to be dumped: | |
1143 // maxDepth == -1 requests to dump entire stack trace. | |
1144 // maxDepth == 0 requests no stack trace. | |
1145 // infoArray - array of ThreadInfo objects | |
1146 // | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1147 // QQQ - Why does this method return a value instead of void? |
0 | 1148 JVM_ENTRY(jint, jmm_GetThreadInfo(JNIEnv *env, jlongArray ids, jint maxDepth, jobjectArray infoArray)) |
1149 // Check if threads is null | |
1150 if (ids == NULL || infoArray == NULL) { | |
1151 THROW_(vmSymbols::java_lang_NullPointerException(), -1); | |
1152 } | |
1153 | |
1154 if (maxDepth < -1) { | |
1155 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1156 "Invalid maxDepth", -1); | |
1157 } | |
1158 | |
1159 ResourceMark rm(THREAD); | |
1160 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); | |
1161 typeArrayHandle ids_ah(THREAD, ta); | |
1162 | |
1163 oop infoArray_obj = JNIHandles::resolve_non_null(infoArray); | |
1164 objArrayOop oa = objArrayOop(infoArray_obj); | |
1165 objArrayHandle infoArray_h(THREAD, oa); | |
1166 | |
1167 // validate the thread id array | |
1168 validate_thread_id_array(ids_ah, CHECK_0); | |
1169 | |
1170 // validate the ThreadInfo[] parameters | |
1171 validate_thread_info_array(infoArray_h, CHECK_0); | |
1172 | |
1173 // infoArray must be of the same length as the given array of thread IDs | |
1174 int num_threads = ids_ah->length(); | |
1175 if (num_threads != infoArray_h->length()) { | |
1176 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1177 "The length of the given ThreadInfo array does not match the length of the given array of thread IDs", -1); | |
1178 } | |
1179 | |
1180 if (JDK_Version::is_gte_jdk16x_version()) { | |
1181 // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots | |
1182 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_0); | |
1183 } | |
1184 | |
1185 // Must use ThreadDumpResult to store the ThreadSnapshot. | |
1186 // GC may occur after the thread snapshots are taken but before | |
1187 // this function returns. The threadObj and other oops kept | |
1188 // in the ThreadSnapshot are marked and adjusted during GC. | |
1189 ThreadDumpResult dump_result(num_threads); | |
1190 | |
1191 if (maxDepth == 0) { | |
1192 // no stack trace dumped - do not need to stop the world | |
1193 { | |
1194 MutexLockerEx ml(Threads_lock); | |
1195 for (int i = 0; i < num_threads; i++) { | |
1196 jlong tid = ids_ah->long_at(i); | |
20393 | 1197 JavaThread* jt = Threads::find_java_thread_from_java_tid(tid); |
0 | 1198 ThreadSnapshot* ts; |
1199 if (jt == NULL) { | |
1200 // if the thread does not exist or now it is terminated, | |
1201 // create dummy snapshot | |
1202 ts = new ThreadSnapshot(); | |
1203 } else { | |
1204 ts = new ThreadSnapshot(jt); | |
1205 } | |
1206 dump_result.add_thread_snapshot(ts); | |
1207 } | |
1208 } | |
1209 } else { | |
1210 // obtain thread dump with the specific list of threads with stack trace | |
1211 do_thread_dump(&dump_result, | |
1212 ids_ah, | |
1213 num_threads, | |
1214 maxDepth, | |
1215 false, /* no locked monitor */ | |
1216 false, /* no locked synchronizers */ | |
1217 CHECK_0); | |
1218 } | |
1219 | |
1220 int num_snapshots = dump_result.num_snapshots(); | |
1221 assert(num_snapshots == num_threads, "Must match the number of thread snapshots"); | |
1222 int index = 0; | |
1223 for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; index++, ts = ts->next()) { | |
1224 // For each thread, create an java/lang/management/ThreadInfo object | |
1225 // and fill with the thread information | |
1226 | |
1227 if (ts->threadObj() == NULL) { | |
1228 // if the thread does not exist or now it is terminated, set threadinfo to NULL | |
1229 infoArray_h->obj_at_put(index, NULL); | |
1230 continue; | |
1231 } | |
1232 | |
1233 // Create java.lang.management.ThreadInfo object | |
1234 instanceOop info_obj = Management::create_thread_info_instance(ts, CHECK_0); | |
1235 infoArray_h->obj_at_put(index, info_obj); | |
1236 } | |
1237 return 0; | |
1238 JVM_END | |
1239 | |
1240 // Dump thread info for the specified threads. | |
1241 // It returns an array of ThreadInfo objects. Each element is the ThreadInfo | |
1242 // for the thread ID specified in the corresponding entry in | |
1243 // the given array of thread IDs; or NULL if the thread does not exist | |
1244 // or has terminated. | |
1245 // | |
1246 // Input parameter: | |
1247 // ids - array of thread IDs; NULL indicates all live threads | |
1248 // locked_monitors - if true, dump locked object monitors | |
1249 // locked_synchronizers - if true, dump locked JSR-166 synchronizers | |
1250 // | |
1251 JVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers)) | |
1252 ResourceMark rm(THREAD); | |
1253 | |
1254 if (JDK_Version::is_gte_jdk16x_version()) { | |
1255 // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots | |
1256 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_NULL); | |
1257 } | |
1258 | |
1259 typeArrayOop ta = typeArrayOop(JNIHandles::resolve(thread_ids)); | |
1260 int num_threads = (ta != NULL ? ta->length() : 0); | |
1261 typeArrayHandle ids_ah(THREAD, ta); | |
1262 | |
1263 ThreadDumpResult dump_result(num_threads); // can safepoint | |
1264 | |
1265 if (ids_ah() != NULL) { | |
1266 | |
1267 // validate the thread id array | |
1268 validate_thread_id_array(ids_ah, CHECK_NULL); | |
1269 | |
1270 // obtain thread dump of a specific list of threads | |
1271 do_thread_dump(&dump_result, | |
1272 ids_ah, | |
1273 num_threads, | |
1274 -1, /* entire stack */ | |
1275 (locked_monitors ? true : false), /* with locked monitors */ | |
1276 (locked_synchronizers ? true : false), /* with locked synchronizers */ | |
1277 CHECK_NULL); | |
1278 } else { | |
1279 // obtain thread dump of all threads | |
1280 VM_ThreadDump op(&dump_result, | |
1281 -1, /* entire stack */ | |
1282 (locked_monitors ? true : false), /* with locked monitors */ | |
1283 (locked_synchronizers ? true : false) /* with locked synchronizers */); | |
1284 VMThread::execute(&op); | |
1285 } | |
1286 | |
1287 int num_snapshots = dump_result.num_snapshots(); | |
1288 | |
1289 // create the result ThreadInfo[] object | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1290 Klass* k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL); |
0 | 1291 instanceKlassHandle ik (THREAD, k); |
1292 objArrayOop r = oopFactory::new_objArray(ik(), num_snapshots, CHECK_NULL); | |
1293 objArrayHandle result_h(THREAD, r); | |
1294 | |
1295 int index = 0; | |
1296 for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; ts = ts->next(), index++) { | |
1297 if (ts->threadObj() == NULL) { | |
1298 // if the thread does not exist or now it is terminated, set threadinfo to NULL | |
1299 result_h->obj_at_put(index, NULL); | |
1300 continue; | |
1301 } | |
1302 | |
1303 ThreadStackTrace* stacktrace = ts->get_stack_trace(); | |
1304 assert(stacktrace != NULL, "Must have a stack trace dumped"); | |
1305 | |
1306 // Create Object[] filled with locked monitors | |
1307 // Create int[] filled with the stack depth where a monitor was locked | |
1308 int num_frames = stacktrace->get_stack_depth(); | |
1309 int num_locked_monitors = stacktrace->num_jni_locked_monitors(); | |
1310 | |
1311 // Count the total number of locked monitors | |
1312 for (int i = 0; i < num_frames; i++) { | |
1313 StackFrameInfo* frame = stacktrace->stack_frame_at(i); | |
1314 num_locked_monitors += frame->num_locked_monitors(); | |
1315 } | |
1316 | |
1317 objArrayHandle monitors_array; | |
1318 typeArrayHandle depths_array; | |
1319 objArrayHandle synchronizers_array; | |
1320 | |
1321 if (locked_monitors) { | |
1322 // Constructs Object[] and int[] to contain the object monitor and the stack depth | |
1323 // where the thread locked it | |
2267
02f78cfa4656
7020992: jmm_DumpThreads should not allocate system object arrays outside the perm gen
stefank
parents:
2231
diff
changeset
|
1324 objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_monitors, CHECK_NULL); |
0 | 1325 objArrayHandle mh(THREAD, array); |
1326 monitors_array = mh; | |
1327 | |
1328 typeArrayOop tarray = oopFactory::new_typeArray(T_INT, num_locked_monitors, CHECK_NULL); | |
1329 typeArrayHandle dh(THREAD, tarray); | |
1330 depths_array = dh; | |
1331 | |
1332 int count = 0; | |
1333 int j = 0; | |
1334 for (int depth = 0; depth < num_frames; depth++) { | |
1335 StackFrameInfo* frame = stacktrace->stack_frame_at(depth); | |
1336 int len = frame->num_locked_monitors(); | |
1337 GrowableArray<oop>* locked_monitors = frame->locked_monitors(); | |
1338 for (j = 0; j < len; j++) { | |
1339 oop monitor = locked_monitors->at(j); | |
1340 assert(monitor != NULL && monitor->is_instance(), "must be a Java object"); | |
1341 monitors_array->obj_at_put(count, monitor); | |
1342 depths_array->int_at_put(count, depth); | |
1343 count++; | |
1344 } | |
1345 } | |
1346 | |
1347 GrowableArray<oop>* jni_locked_monitors = stacktrace->jni_locked_monitors(); | |
1348 for (j = 0; j < jni_locked_monitors->length(); j++) { | |
1349 oop object = jni_locked_monitors->at(j); | |
1350 assert(object != NULL && object->is_instance(), "must be a Java object"); | |
1351 monitors_array->obj_at_put(count, object); | |
1352 // Monitor locked via JNI MonitorEnter call doesn't have stack depth info | |
1353 depths_array->int_at_put(count, -1); | |
1354 count++; | |
1355 } | |
1356 assert(count == num_locked_monitors, "number of locked monitors doesn't match"); | |
1357 } | |
1358 | |
1359 if (locked_synchronizers) { | |
1360 // Create Object[] filled with locked JSR-166 synchronizers | |
1361 assert(ts->threadObj() != NULL, "Must be a valid JavaThread"); | |
1362 ThreadConcurrentLocks* tcl = ts->get_concurrent_locks(); | |
1363 GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL); | |
1364 int num_locked_synchronizers = (locks != NULL ? locks->length() : 0); | |
1365 | |
2267
02f78cfa4656
7020992: jmm_DumpThreads should not allocate system object arrays outside the perm gen
stefank
parents:
2231
diff
changeset
|
1366 objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_synchronizers, CHECK_NULL); |
0 | 1367 objArrayHandle sh(THREAD, array); |
1368 synchronizers_array = sh; | |
1369 | |
1370 for (int k = 0; k < num_locked_synchronizers; k++) { | |
1371 synchronizers_array->obj_at_put(k, locks->at(k)); | |
1372 } | |
1373 } | |
1374 | |
1375 // Create java.lang.management.ThreadInfo object | |
1376 instanceOop info_obj = Management::create_thread_info_instance(ts, | |
1377 monitors_array, | |
1378 depths_array, | |
1379 synchronizers_array, | |
1380 CHECK_NULL); | |
1381 result_h->obj_at_put(index, info_obj); | |
1382 } | |
1383 | |
1384 return (jobjectArray) JNIHandles::make_local(env, result_h()); | |
1385 JVM_END | |
1386 | |
1387 // Returns an array of Class objects. | |
1388 JVM_ENTRY(jobjectArray, jmm_GetLoadedClasses(JNIEnv *env)) | |
1389 ResourceMark rm(THREAD); | |
1390 | |
1391 LoadedClassesEnumerator lce(THREAD); // Pass current Thread as parameter | |
1392 | |
1393 int num_classes = lce.num_loaded_classes(); | |
1142 | 1394 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), num_classes, CHECK_0); |
0 | 1395 objArrayHandle classes_ah(THREAD, r); |
1396 | |
1397 for (int i = 0; i < num_classes; i++) { | |
1398 KlassHandle kh = lce.get_klass(i); | |
6983 | 1399 oop mirror = kh()->java_mirror(); |
0 | 1400 classes_ah->obj_at_put(i, mirror); |
1401 } | |
1402 | |
1403 return (jobjectArray) JNIHandles::make_local(env, classes_ah()); | |
1404 JVM_END | |
1405 | |
1406 // Reset statistic. Return true if the requested statistic is reset. | |
1407 // Otherwise, return false. | |
1408 // | |
1409 // Input parameters: | |
1410 // obj - specify which instance the statistic associated with to be reset | |
1411 // For PEAK_POOL_USAGE stat, obj is required to be a memory pool object. | |
1412 // For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID. | |
1413 // type - the type of statistic to be reset | |
1414 // | |
1415 JVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type)) | |
1416 ResourceMark rm(THREAD); | |
1417 | |
1418 switch (type) { | |
1419 case JMM_STAT_PEAK_THREAD_COUNT: | |
1420 ThreadService::reset_peak_thread_count(); | |
1421 return true; | |
1422 | |
1423 case JMM_STAT_THREAD_CONTENTION_COUNT: | |
1424 case JMM_STAT_THREAD_CONTENTION_TIME: { | |
1425 jlong tid = obj.j; | |
1426 if (tid < 0) { | |
1427 THROW_(vmSymbols::java_lang_IllegalArgumentException(), JNI_FALSE); | |
1428 } | |
1429 | |
1430 // Look for the JavaThread of this given tid | |
1431 MutexLockerEx ml(Threads_lock); | |
1432 if (tid == 0) { | |
1433 // reset contention statistics for all threads if tid == 0 | |
1434 for (JavaThread* java_thread = Threads::first(); java_thread != NULL; java_thread = java_thread->next()) { | |
1435 if (type == JMM_STAT_THREAD_CONTENTION_COUNT) { | |
1436 ThreadService::reset_contention_count_stat(java_thread); | |
1437 } else { | |
1438 ThreadService::reset_contention_time_stat(java_thread); | |
1439 } | |
1440 } | |
1441 } else { | |
1442 // reset contention statistics for a given thread | |
20393 | 1443 JavaThread* java_thread = Threads::find_java_thread_from_java_tid(tid); |
0 | 1444 if (java_thread == NULL) { |
1445 return false; | |
1446 } | |
1447 | |
1448 if (type == JMM_STAT_THREAD_CONTENTION_COUNT) { | |
1449 ThreadService::reset_contention_count_stat(java_thread); | |
1450 } else { | |
1451 ThreadService::reset_contention_time_stat(java_thread); | |
1452 } | |
1453 } | |
1454 return true; | |
1455 break; | |
1456 } | |
1457 case JMM_STAT_PEAK_POOL_USAGE: { | |
1458 jobject o = obj.l; | |
1459 if (o == NULL) { | |
1460 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); | |
1461 } | |
1462 | |
1463 oop pool_obj = JNIHandles::resolve(o); | |
1464 assert(pool_obj->is_instance(), "Should be an instanceOop"); | |
1465 instanceHandle ph(THREAD, (instanceOop) pool_obj); | |
1466 | |
1467 MemoryPool* pool = MemoryService::get_memory_pool(ph); | |
1468 if (pool != NULL) { | |
1469 pool->reset_peak_memory_usage(); | |
1470 return true; | |
1471 } | |
1472 break; | |
1473 } | |
1474 case JMM_STAT_GC_STAT: { | |
1475 jobject o = obj.l; | |
1476 if (o == NULL) { | |
1477 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); | |
1478 } | |
1479 | |
1480 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(o, CHECK_0); | |
1481 if (mgr != NULL) { | |
1482 mgr->reset_gc_stat(); | |
1483 return true; | |
1484 } | |
1485 break; | |
1486 } | |
1487 default: | |
1488 assert(0, "Unknown Statistic Type"); | |
1489 } | |
1490 return false; | |
1491 JVM_END | |
1492 | |
1493 // Returns the fast estimate of CPU time consumed by | |
1494 // a given thread (in nanoseconds). | |
1495 // If thread_id == 0, return CPU time for the current thread. | |
1496 JVM_ENTRY(jlong, jmm_GetThreadCpuTime(JNIEnv *env, jlong thread_id)) | |
1497 if (!os::is_thread_cpu_time_supported()) { | |
1498 return -1; | |
1499 } | |
1500 | |
1501 if (thread_id < 0) { | |
1502 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1503 "Invalid thread ID", -1); | |
1504 } | |
1505 | |
1506 JavaThread* java_thread = NULL; | |
1507 if (thread_id == 0) { | |
1508 // current thread | |
1509 return os::current_thread_cpu_time(); | |
1510 } else { | |
1511 MutexLockerEx ml(Threads_lock); | |
20393 | 1512 java_thread = Threads::find_java_thread_from_java_tid(thread_id); |
0 | 1513 if (java_thread != NULL) { |
1514 return os::thread_cpu_time((Thread*) java_thread); | |
1515 } | |
1516 } | |
1517 return -1; | |
1518 JVM_END | |
1519 | |
1520 // Returns a String array of all VM global flag names | |
1521 JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env)) | |
1522 // last flag entry is always NULL, so subtract 1 | |
1523 int nFlags = (int) Flag::numFlags - 1; | |
1524 // allocate a temp array | |
1142 | 1525 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), |
0 | 1526 nFlags, CHECK_0); |
1527 objArrayHandle flags_ah(THREAD, r); | |
1528 int num_entries = 0; | |
1529 for (int i = 0; i < nFlags; i++) { | |
1530 Flag* flag = &Flag::flags[i]; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1531 // Exclude notproduct and develop flags in product builds. |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1532 if (flag->is_constant_in_binary()) { |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1533 continue; |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1534 } |
350 | 1535 // Exclude the locked (experimental, diagnostic) flags |
0 | 1536 if (flag->is_unlocked() || flag->is_unlocker()) { |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1537 Handle s = java_lang_String::create_from_str(flag->_name, CHECK_0); |
0 | 1538 flags_ah->obj_at_put(num_entries, s()); |
1539 num_entries++; | |
1540 } | |
1541 } | |
1542 | |
1543 if (num_entries < nFlags) { | |
1544 // Return array of right length | |
1142 | 1545 objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0); |
0 | 1546 for(int i = 0; i < num_entries; i++) { |
1547 res->obj_at_put(i, flags_ah->obj_at(i)); | |
1548 } | |
1549 return (jobjectArray)JNIHandles::make_local(env, res); | |
1550 } | |
1551 | |
1552 return (jobjectArray)JNIHandles::make_local(env, flags_ah()); | |
1553 JVM_END | |
1554 | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1555 // Utility function used by jmm_GetVMGlobals. Returns false if flag type |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1556 // can't be determined, true otherwise. If false is returned, then *global |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1557 // will be incomplete and invalid. |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1558 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) { |
0 | 1559 Handle flag_name; |
1560 if (name() == NULL) { | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1561 flag_name = java_lang_String::create_from_str(flag->_name, CHECK_false); |
0 | 1562 } else { |
1563 flag_name = name; | |
1564 } | |
1565 global->name = (jstring)JNIHandles::make_local(env, flag_name()); | |
1566 | |
1567 if (flag->is_bool()) { | |
1568 global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE; | |
1569 global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN; | |
1570 } else if (flag->is_intx()) { | |
1571 global->value.j = (jlong)flag->get_intx(); | |
1572 global->type = JMM_VMGLOBAL_TYPE_JLONG; | |
1573 } else if (flag->is_uintx()) { | |
1574 global->value.j = (jlong)flag->get_uintx(); | |
1575 global->type = JMM_VMGLOBAL_TYPE_JLONG; | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1576 } else if (flag->is_uint64_t()) { |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1577 global->value.j = (jlong)flag->get_uint64_t(); |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1578 global->type = JMM_VMGLOBAL_TYPE_JLONG; |
0 | 1579 } else if (flag->is_ccstr()) { |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1580 Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false); |
0 | 1581 global->value.l = (jobject)JNIHandles::make_local(env, str()); |
1582 global->type = JMM_VMGLOBAL_TYPE_JSTRING; | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1583 } else { |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1584 global->type = JMM_VMGLOBAL_TYPE_UNKNOWN; |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1585 return false; |
0 | 1586 } |
1587 | |
1588 global->writeable = flag->is_writeable(); | |
1589 global->external = flag->is_external(); | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1590 switch (flag->get_origin()) { |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1591 case Flag::DEFAULT: |
0 | 1592 global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT; |
1593 break; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1594 case Flag::COMMAND_LINE: |
0 | 1595 global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE; |
1596 break; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1597 case Flag::ENVIRON_VAR: |
0 | 1598 global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR; |
1599 break; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1600 case Flag::CONFIG_FILE: |
0 | 1601 global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE; |
1602 break; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1603 case Flag::MANAGEMENT: |
0 | 1604 global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT; |
1605 break; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1606 case Flag::ERGONOMIC: |
0 | 1607 global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC; |
1608 break; | |
1609 default: | |
1610 global->origin = JMM_VMGLOBAL_ORIGIN_OTHER; | |
1611 } | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1612 |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1613 return true; |
0 | 1614 } |
1615 | |
1616 // Fill globals array of count length with jmmVMGlobal entries | |
1617 // specified by names. If names == NULL, fill globals array | |
1618 // with all Flags. Return value is number of entries | |
1619 // created in globals. | |
1620 // If a Flag with a given name in an array element does not | |
1621 // exist, globals[i].name will be set to NULL. | |
1622 JVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env, | |
1623 jobjectArray names, | |
1624 jmmVMGlobal *globals, | |
1625 jint count)) | |
1626 | |
1627 | |
1628 if (globals == NULL) { | |
1629 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1630 } | |
1631 | |
1632 ResourceMark rm(THREAD); | |
1633 | |
1634 if (names != NULL) { | |
1635 // return the requested globals | |
1636 objArrayOop ta = objArrayOop(JNIHandles::resolve_non_null(names)); | |
1637 objArrayHandle names_ah(THREAD, ta); | |
1638 // Make sure we have a String array | |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6779
diff
changeset
|
1639 Klass* element_klass = ObjArrayKlass::cast(names_ah->klass())->element_klass(); |
1142 | 1640 if (element_klass != SystemDictionary::String_klass()) { |
0 | 1641 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
1642 "Array element type is not String class", 0); | |
1643 } | |
1644 | |
1645 int names_length = names_ah->length(); | |
1646 int num_entries = 0; | |
1647 for (int i = 0; i < names_length && i < count; i++) { | |
1648 oop s = names_ah->obj_at(i); | |
1649 if (s == NULL) { | |
1650 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1651 } | |
1652 | |
1653 Handle sh(THREAD, s); | |
1654 char* str = java_lang_String::as_utf8_string(s); | |
1655 Flag* flag = Flag::find_flag(str, strlen(str)); | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1656 if (flag != NULL && |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1657 add_global_entry(env, sh, &globals[i], flag, THREAD)) { |
0 | 1658 num_entries++; |
1659 } else { | |
1660 globals[i].name = NULL; | |
1661 } | |
1662 } | |
1663 return num_entries; | |
1664 } else { | |
1665 // return all globals if names == NULL | |
1666 | |
1667 // last flag entry is always NULL, so subtract 1 | |
1668 int nFlags = (int) Flag::numFlags - 1; | |
1669 Handle null_h; | |
1670 int num_entries = 0; | |
1671 for (int i = 0; i < nFlags && num_entries < count; i++) { | |
1672 Flag* flag = &Flag::flags[i]; | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1673 // Exclude notproduct and develop flags in product builds. |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1674 if (flag->is_constant_in_binary()) { |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1675 continue; |
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1676 } |
350 | 1677 // Exclude the locked (diagnostic, experimental) flags |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1678 if ((flag->is_unlocked() || flag->is_unlocker()) && |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1679 add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) { |
0 | 1680 num_entries++; |
1681 } | |
1682 } | |
1683 return num_entries; | |
1684 } | |
1685 JVM_END | |
1686 | |
1687 JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value)) | |
1688 ResourceMark rm(THREAD); | |
1689 | |
1690 oop fn = JNIHandles::resolve_external_guard(flag_name); | |
1691 if (fn == NULL) { | |
1692 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
1693 "The flag name cannot be null."); | |
1694 } | |
1695 char* name = java_lang_String::as_utf8_string(fn); | |
1696 Flag* flag = Flag::find_flag(name, strlen(name)); | |
1697 if (flag == NULL) { | |
1698 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
1699 "Flag does not exist."); | |
1700 } | |
1701 if (!flag->is_writeable()) { | |
1702 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
1703 "This flag is not writeable."); | |
1704 } | |
1705 | |
20248 | 1706 bool succeed = false; |
0 | 1707 if (flag->is_bool()) { |
1708 bool bvalue = (new_value.z == JNI_TRUE ? true : false); | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1709 succeed = CommandLineFlags::boolAtPut(name, &bvalue, Flag::MANAGEMENT); |
0 | 1710 } else if (flag->is_intx()) { |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1711 intx ivalue = (intx)new_value.j; |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1712 succeed = CommandLineFlags::intxAtPut(name, &ivalue, Flag::MANAGEMENT); |
0 | 1713 } else if (flag->is_uintx()) { |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1714 uintx uvalue = (uintx)new_value.j; |
17648
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1715 |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1716 if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) { |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17648
diff
changeset
|
1717 FormatBuffer<80> err_msg("%s", ""); |
17648
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1718 if (!Arguments::verify_MaxHeapFreeRatio(err_msg, uvalue)) { |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1719 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), err_msg.buffer()); |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1720 } |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1721 } else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) { |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17648
diff
changeset
|
1722 FormatBuffer<80> err_msg("%s", ""); |
17648
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1723 if (!Arguments::verify_MinHeapFreeRatio(err_msg, uvalue)) { |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1724 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), err_msg.buffer()); |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1725 } |
a034dc5e910b
8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents:
12997
diff
changeset
|
1726 } |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1727 succeed = CommandLineFlags::uintxAtPut(name, &uvalue, Flag::MANAGEMENT); |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1728 } else if (flag->is_uint64_t()) { |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1729 uint64_t uvalue = (uint64_t)new_value.j; |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1730 succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, Flag::MANAGEMENT); |
0 | 1731 } else if (flag->is_ccstr()) { |
1732 oop str = JNIHandles::resolve_external_guard(new_value.l); | |
1733 if (str == NULL) { | |
1734 THROW(vmSymbols::java_lang_NullPointerException()); | |
1735 } | |
1736 ccstr svalue = java_lang_String::as_utf8_string(str); | |
12322
72b7e96c1922
8024545: make develop and notproduct flag values available in product builds
twisti
parents:
12103
diff
changeset
|
1737 succeed = CommandLineFlags::ccstrAtPut(name, &svalue, Flag::MANAGEMENT); |
20248 | 1738 if (succeed) { |
1739 FREE_C_HEAP_ARRAY(char, svalue, mtInternal); | |
1740 } | |
0 | 1741 } |
1742 assert(succeed, "Setting flag should succeed"); | |
1743 JVM_END | |
1744 | |
1745 class ThreadTimesClosure: public ThreadClosure { | |
1746 private: | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1747 objArrayHandle _names_strings; |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1748 char **_names_chars; |
11986
c01913206da5
8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents:
11039
diff
changeset
|
1749 typeArrayHandle _times; |
0 | 1750 int _names_len; |
1751 int _times_len; | |
1752 int _count; | |
1753 | |
1754 public: | |
11986
c01913206da5
8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents:
11039
diff
changeset
|
1755 ThreadTimesClosure(objArrayHandle names, typeArrayHandle times); |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1756 ~ThreadTimesClosure(); |
0 | 1757 virtual void do_thread(Thread* thread); |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1758 void do_unlocked(); |
0 | 1759 int count() { return _count; } |
1760 }; | |
1761 | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1762 ThreadTimesClosure::ThreadTimesClosure(objArrayHandle names, |
11986
c01913206da5
8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents:
11039
diff
changeset
|
1763 typeArrayHandle times) { |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1764 assert(names() != NULL, "names was NULL"); |
11986
c01913206da5
8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents:
11039
diff
changeset
|
1765 assert(times() != NULL, "times was NULL"); |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1766 _names_strings = names; |
0 | 1767 _names_len = names->length(); |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1768 _names_chars = NEW_C_HEAP_ARRAY(char*, _names_len, mtInternal); |
0 | 1769 _times = times; |
1770 _times_len = times->length(); | |
1771 _count = 0; | |
1772 } | |
1773 | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1774 // |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1775 // Called with Threads_lock held |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1776 // |
0 | 1777 void ThreadTimesClosure::do_thread(Thread* thread) { |
1778 assert(thread != NULL, "thread was NULL"); | |
1779 | |
1780 // exclude externally visible JavaThreads | |
1781 if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) { | |
1782 return; | |
1783 } | |
1784 | |
1785 if (_count >= _names_len || _count >= _times_len) { | |
1786 // skip if the result array is not big enough | |
1787 return; | |
1788 } | |
1789 | |
1790 EXCEPTION_MARK; | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1791 ResourceMark rm(THREAD); // thread->name() uses ResourceArea |
0 | 1792 |
1793 assert(thread->name() != NULL, "All threads should have a name"); | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1794 _names_chars[_count] = strdup(thread->name()); |
0 | 1795 _times->long_at_put(_count, os::is_thread_cpu_time_supported() ? |
1796 os::thread_cpu_time(thread) : -1); | |
1797 _count++; | |
1798 } | |
1799 | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1800 // Called without Threads_lock, we can allocate String objects. |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1801 void ThreadTimesClosure::do_unlocked() { |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1802 |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1803 EXCEPTION_MARK; |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1804 for (int i = 0; i < _count; i++) { |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1805 Handle s = java_lang_String::create_from_str(_names_chars[i], CHECK); |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1806 _names_strings->obj_at_put(i, s()); |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1807 } |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1808 } |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1809 |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1810 ThreadTimesClosure::~ThreadTimesClosure() { |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1811 for (int i = 0; i < _count; i++) { |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1812 free(_names_chars[i]); |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1813 } |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1814 FREE_C_HEAP_ARRAY(char *, _names_chars, mtInternal); |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1815 } |
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1816 |
0 | 1817 // Fills names with VM internal thread names and times with the corresponding |
1818 // CPU times. If names or times is NULL, a NullPointerException is thrown. | |
1819 // If the element type of names is not String, an IllegalArgumentException is | |
1820 // thrown. | |
1821 // If an array is not large enough to hold all the entries, only the entries | |
1822 // that fit will be returned. Return value is the number of VM internal | |
1823 // threads entries. | |
1824 JVM_ENTRY(jint, jmm_GetInternalThreadTimes(JNIEnv *env, | |
1825 jobjectArray names, | |
1826 jlongArray times)) | |
1827 if (names == NULL || times == NULL) { | |
1828 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1829 } | |
1830 objArrayOop na = objArrayOop(JNIHandles::resolve_non_null(names)); | |
1831 objArrayHandle names_ah(THREAD, na); | |
1832 | |
1833 // Make sure we have a String array | |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6779
diff
changeset
|
1834 Klass* element_klass = ObjArrayKlass::cast(names_ah->klass())->element_klass(); |
1142 | 1835 if (element_klass != SystemDictionary::String_klass()) { |
0 | 1836 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
1837 "Array element type is not String class", 0); | |
1838 } | |
1839 | |
1840 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(times)); | |
1841 typeArrayHandle times_ah(THREAD, ta); | |
1842 | |
11986
c01913206da5
8014294: Assert in ThreadTimesClosure::do_thread() due to use of naked oop instead of handle
ctornqvi
parents:
11039
diff
changeset
|
1843 ThreadTimesClosure ttc(names_ah, times_ah); |
0 | 1844 { |
1845 MutexLockerEx ml(Threads_lock); | |
1846 Threads::threads_do(&ttc); | |
1847 } | |
6779
6af8f3562069
7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
6725
diff
changeset
|
1848 ttc.do_unlocked(); |
0 | 1849 return ttc.count(); |
1850 JVM_END | |
1851 | |
1852 static Handle find_deadlocks(bool object_monitors_only, TRAPS) { | |
1853 ResourceMark rm(THREAD); | |
1854 | |
1855 VM_FindDeadlocks op(!object_monitors_only /* also check concurrent locks? */); | |
1856 VMThread::execute(&op); | |
1857 | |
1858 DeadlockCycle* deadlocks = op.result(); | |
1859 if (deadlocks == NULL) { | |
1860 // no deadlock found and return | |
1861 return Handle(); | |
1862 } | |
1863 | |
1864 int num_threads = 0; | |
1865 DeadlockCycle* cycle; | |
1866 for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) { | |
1867 num_threads += cycle->num_threads(); | |
1868 } | |
1869 | |
1142 | 1870 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NH); |
0 | 1871 objArrayHandle threads_ah(THREAD, r); |
1872 | |
1873 int index = 0; | |
1874 for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) { | |
1875 GrowableArray<JavaThread*>* deadlock_threads = cycle->threads(); | |
1876 int len = deadlock_threads->length(); | |
1877 for (int i = 0; i < len; i++) { | |
1878 threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj()); | |
1879 index++; | |
1880 } | |
1881 } | |
1882 return threads_ah; | |
1883 } | |
1884 | |
1885 // Finds cycles of threads that are deadlocked involved in object monitors | |
1886 // and JSR-166 synchronizers. | |
1887 // Returns an array of Thread objects which are in deadlock, if any. | |
1888 // Otherwise, returns NULL. | |
1889 // | |
1890 // Input parameter: | |
1891 // object_monitors_only - if true, only check object monitors | |
1892 // | |
1893 JVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only)) | |
1894 Handle result = find_deadlocks(object_monitors_only != 0, CHECK_0); | |
1895 return (jobjectArray) JNIHandles::make_local(env, result()); | |
1896 JVM_END | |
1897 | |
1898 // Finds cycles of threads that are deadlocked on monitor locks | |
1899 // Returns an array of Thread objects which are in deadlock, if any. | |
1900 // Otherwise, returns NULL. | |
1901 JVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env)) | |
1902 Handle result = find_deadlocks(true, CHECK_0); | |
1903 return (jobjectArray) JNIHandles::make_local(env, result()); | |
1904 JVM_END | |
1905 | |
1906 // Gets the information about GC extension attributes including | |
1907 // the name of the attribute, its type, and a short description. | |
1908 // | |
1909 // Input parameters: | |
1910 // mgr - GC memory manager | |
1911 // info - caller allocated array of jmmExtAttributeInfo | |
1912 // count - number of elements of the info array | |
1913 // | |
1914 // Returns the number of GC extension attributes filled in the info array; or | |
1915 // -1 if info is not big enough | |
1916 // | |
1917 JVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count)) | |
1918 // All GC memory managers have 1 attribute (number of GC threads) | |
1919 if (count == 0) { | |
1920 return 0; | |
1921 } | |
1922 | |
1923 if (info == NULL) { | |
1924 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1925 } | |
1926 | |
1927 info[0].name = "GcThreadCount"; | |
1928 info[0].type = 'I'; | |
1929 info[0].description = "Number of GC threads"; | |
1930 return 1; | |
1931 JVM_END | |
1932 | |
1933 // verify the given array is an array of java/lang/management/MemoryUsage objects | |
1934 // of a given length and return the objArrayOop | |
1935 static objArrayOop get_memory_usage_objArray(jobjectArray array, int length, TRAPS) { | |
1936 if (array == NULL) { | |
1937 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1938 } | |
1939 | |
1940 objArrayOop oa = objArrayOop(JNIHandles::resolve_non_null(array)); | |
1941 objArrayHandle array_h(THREAD, oa); | |
1942 | |
1943 // array must be of the given length | |
1944 if (length != array_h->length()) { | |
1945 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1946 "The length of the given MemoryUsage array does not match the number of memory pools.", 0); | |
1947 } | |
1948 | |
1949 // check if the element of array is of type MemoryUsage class | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
1950 Klass* usage_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_0); |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6779
diff
changeset
|
1951 Klass* element_klass = ObjArrayKlass::cast(array_h->klass())->element_klass(); |
0 | 1952 if (element_klass != usage_klass) { |
1953 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1954 "The element type is not MemoryUsage class", 0); | |
1955 } | |
1956 | |
1957 return array_h(); | |
1958 } | |
1959 | |
1960 // Gets the statistics of the last GC of a given GC memory manager. | |
1961 // Input parameters: | |
1962 // obj - GarbageCollectorMXBean object | |
1963 // gc_stat - caller allocated jmmGCStat where: | |
1964 // a. before_gc_usage - array of MemoryUsage objects | |
1965 // b. after_gc_usage - array of MemoryUsage objects | |
1966 // c. gc_ext_attributes_values_size is set to the | |
1967 // gc_ext_attribute_values array allocated | |
1968 // d. gc_ext_attribute_values is a caller allocated array of jvalue. | |
1969 // | |
1970 // On return, | |
1971 // gc_index == 0 indicates no GC statistics available | |
1972 // | |
1973 // before_gc_usage and after_gc_usage - filled with per memory pool | |
1974 // before and after GC usage in the same order as the memory pools | |
1975 // returned by GetMemoryPools for a given GC memory manager. | |
1976 // num_gc_ext_attributes indicates the number of elements in | |
1977 // the gc_ext_attribute_values array is filled; or | |
1978 // -1 if the gc_ext_attributes_values array is not big enough | |
1979 // | |
1980 JVM_ENTRY(void, jmm_GetLastGCStat(JNIEnv *env, jobject obj, jmmGCStat *gc_stat)) | |
1981 ResourceMark rm(THREAD); | |
1982 | |
1983 if (gc_stat->gc_ext_attribute_values_size > 0 && gc_stat->gc_ext_attribute_values == NULL) { | |
1984 THROW(vmSymbols::java_lang_NullPointerException()); | |
1985 } | |
1986 | |
1987 // Get the GCMemoryManager | |
1988 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK); | |
1989 | |
1990 // Make a copy of the last GC statistics | |
1991 // GC may occur while constructing the last GC information | |
1992 int num_pools = MemoryService::num_memory_pools(); | |
4844
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
1993 GCStatInfo stat(num_pools); |
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
1994 if (mgr->get_last_gc_stat(&stat) == 0) { |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1995 gc_stat->gc_index = 0; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1996 return; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
1997 } |
0 | 1998 |
4844
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
1999 gc_stat->gc_index = stat.gc_index(); |
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
2000 gc_stat->start_time = Management::ticks_to_ms(stat.start_time()); |
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
2001 gc_stat->end_time = Management::ticks_to_ms(stat.end_time()); |
0 | 2002 |
2003 // Current implementation does not have GC extension attributes | |
2004 gc_stat->num_gc_ext_attributes = 0; | |
2005 | |
2006 // Fill the arrays of MemoryUsage objects with before and after GC | |
2007 // per pool memory usage | |
2008 objArrayOop bu = get_memory_usage_objArray(gc_stat->usage_before_gc, | |
2009 num_pools, | |
2010 CHECK); | |
2011 objArrayHandle usage_before_gc_ah(THREAD, bu); | |
2012 | |
2013 objArrayOop au = get_memory_usage_objArray(gc_stat->usage_after_gc, | |
2014 num_pools, | |
2015 CHECK); | |
2016 objArrayHandle usage_after_gc_ah(THREAD, au); | |
2017 | |
2018 for (int i = 0; i < num_pools; i++) { | |
4844
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
2019 Handle before_usage = MemoryService::create_MemoryUsage_obj(stat.before_gc_usage_for_pool(i), CHECK); |
0 | 2020 Handle after_usage; |
2021 | |
4844
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
2022 MemoryUsage u = stat.after_gc_usage_for_pool(i); |
0 | 2023 if (u.max_size() == 0 && u.used() > 0) { |
2024 // If max size == 0, this pool is a survivor space. | |
2025 // Set max size = -1 since the pools will be swapped after GC. | |
2026 MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1); | |
2027 after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK); | |
2028 } else { | |
4844
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
4773
diff
changeset
|
2029 after_usage = MemoryService::create_MemoryUsage_obj(stat.after_gc_usage_for_pool(i), CHECK); |
0 | 2030 } |
2031 usage_before_gc_ah->obj_at_put(i, before_usage()); | |
2032 usage_after_gc_ah->obj_at_put(i, after_usage()); | |
2033 } | |
2034 | |
2035 if (gc_stat->gc_ext_attribute_values_size > 0) { | |
2036 // Current implementation only has 1 attribute (number of GC threads) | |
2037 // The type is 'I' | |
2038 gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads(); | |
2039 } | |
2040 JVM_END | |
2041 | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2042 JVM_ENTRY(void, jmm_SetGCNotificationEnabled(JNIEnv *env, jobject obj, jboolean enabled)) |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2043 ResourceMark rm(THREAD); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2044 // Get the GCMemoryManager |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2045 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2046 mgr->set_notification_enabled(enabled?true:false); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2047 JVM_END |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2048 |
0 | 2049 // Dump heap - Returns 0 if succeeds. |
2050 JVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live)) | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
2051 #if INCLUDE_SERVICES |
0 | 2052 ResourceMark rm(THREAD); |
2053 oop on = JNIHandles::resolve_external_guard(outputfile); | |
2054 if (on == NULL) { | |
2055 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), | |
2056 "Output file name cannot be null.", -1); | |
2057 } | |
10134
a527ddd44e07
6729929: I18N - Taking Heap Dump failed if project path contains multibyte characters
mgronlun
parents:
8001
diff
changeset
|
2058 char* name = java_lang_String::as_platform_dependent_str(on, CHECK_(-1)); |
0 | 2059 if (name == NULL) { |
2060 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), | |
2061 "Output file name cannot be null.", -1); | |
2062 } | |
2063 HeapDumper dumper(live ? true : false); | |
2064 if (dumper.dump(name) != 0) { | |
2065 const char* errmsg = dumper.error_as_C_string(); | |
2066 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1); | |
2067 } | |
2068 return 0; | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
2069 #else // INCLUDE_SERVICES |
0 | 2070 return -1; |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
2071 #endif // INCLUDE_SERVICES |
0 | 2072 JVM_END |
2073 | |
4133 | 2074 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env)) |
2075 ResourceMark rm(THREAD); | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2076 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(DCmd_Source_MBean); |
4133 | 2077 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(), |
2078 dcmd_list->length(), CHECK_NULL); | |
2079 objArrayHandle cmd_array(THREAD, cmd_array_oop); | |
2080 for (int i = 0; i < dcmd_list->length(); i++) { | |
2081 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL); | |
2082 cmd_array->obj_at_put(i, cmd_name); | |
2083 } | |
2084 return (jobjectArray) JNIHandles::make_local(env, cmd_array()); | |
2085 JVM_END | |
2086 | |
2087 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds, | |
2088 dcmdInfo* infoArray)) | |
2089 if (cmds == NULL || infoArray == NULL) { | |
2090 THROW(vmSymbols::java_lang_NullPointerException()); | |
2091 } | |
2092 | |
2093 ResourceMark rm(THREAD); | |
2094 | |
2095 objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds)); | |
2096 objArrayHandle cmds_ah(THREAD, ca); | |
2097 | |
2098 // Make sure we have a String array | |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6779
diff
changeset
|
2099 Klass* element_klass = ObjArrayKlass::cast(cmds_ah->klass())->element_klass(); |
4133 | 2100 if (element_klass != SystemDictionary::String_klass()) { |
2101 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2102 "Array element type is not String class"); | |
2103 } | |
2104 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2105 GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(DCmd_Source_MBean); |
4133 | 2106 |
2107 int num_cmds = cmds_ah->length(); | |
2108 for (int i = 0; i < num_cmds; i++) { | |
2109 oop cmd = cmds_ah->obj_at(i); | |
2110 if (cmd == NULL) { | |
2111 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2112 "Command name cannot be null."); | |
2113 } | |
2114 char* cmd_name = java_lang_String::as_utf8_string(cmd); | |
2115 if (cmd_name == NULL) { | |
2116 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2117 "Command name cannot be null."); | |
2118 } | |
2119 int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name); | |
2120 if (pos == -1) { | |
2121 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2122 "Unknown diagnostic command"); | |
2123 } | |
2124 DCmdInfo* info = info_list->at(pos); | |
2125 infoArray[i].name = info->name(); | |
2126 infoArray[i].description = info->description(); | |
2127 infoArray[i].impact = info->impact(); | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2128 JavaPermission p = info->permission(); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2129 infoArray[i].permission_class = p._class; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2130 infoArray[i].permission_name = p._name; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2131 infoArray[i].permission_action = p._action; |
4133 | 2132 infoArray[i].num_arguments = info->num_arguments(); |
2133 infoArray[i].enabled = info->is_enabled(); | |
2134 } | |
2135 JVM_END | |
2136 | |
2137 JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env, | |
2138 jstring command, dcmdArgInfo* infoArray)) | |
2139 ResourceMark rm(THREAD); | |
2140 oop cmd = JNIHandles::resolve_external_guard(command); | |
2141 if (cmd == NULL) { | |
2142 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2143 "Command line cannot be null."); | |
2144 } | |
2145 char* cmd_name = java_lang_String::as_utf8_string(cmd); | |
2146 if (cmd_name == NULL) { | |
2147 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2148 "Command line content cannot be null."); | |
2149 } | |
2150 DCmd* dcmd = NULL; | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2151 DCmdFactory*factory = DCmdFactory::factory(DCmd_Source_MBean, cmd_name, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2152 strlen(cmd_name)); |
4133 | 2153 if (factory != NULL) { |
2154 dcmd = factory->create_resource_instance(NULL); | |
2155 } | |
2156 if (dcmd == NULL) { | |
2157 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2158 "Unknown diagnostic command"); | |
2159 } | |
2160 DCmdMark mark(dcmd); | |
2161 GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array(); | |
2162 if (array->length() == 0) { | |
2163 return; | |
2164 } | |
2165 for (int i = 0; i < array->length(); i++) { | |
2166 infoArray[i].name = array->at(i)->name(); | |
2167 infoArray[i].description = array->at(i)->description(); | |
2168 infoArray[i].type = array->at(i)->type(); | |
2169 infoArray[i].default_string = array->at(i)->default_string(); | |
2170 infoArray[i].mandatory = array->at(i)->is_mandatory(); | |
2171 infoArray[i].option = array->at(i)->is_option(); | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2172 infoArray[i].multiple = array->at(i)->is_multiple(); |
4133 | 2173 infoArray[i].position = array->at(i)->position(); |
2174 } | |
2175 return; | |
2176 JVM_END | |
2177 | |
2178 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline)) | |
2179 ResourceMark rm(THREAD); | |
2180 oop cmd = JNIHandles::resolve_external_guard(commandline); | |
2181 if (cmd == NULL) { | |
2182 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), | |
2183 "Command line cannot be null."); | |
2184 } | |
2185 char* cmdline = java_lang_String::as_utf8_string(cmd); | |
2186 if (cmdline == NULL) { | |
2187 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), | |
2188 "Command line content cannot be null."); | |
2189 } | |
2190 bufferedStream output; | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2191 DCmd::parse_and_execute(DCmd_Source_MBean, &output, cmdline, ' ', CHECK_NULL); |
4133 | 2192 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL); |
2193 return (jstring) JNIHandles::make_local(env, result); | |
2194 JVM_END | |
2195 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2196 JVM_ENTRY(void, jmm_SetDiagnosticFrameworkNotificationEnabled(JNIEnv *env, jboolean enabled)) |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2197 DCmdFactory::set_jmx_notification_enabled(enabled?true:false); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2198 JVM_END |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2199 |
0 | 2200 jlong Management::ticks_to_ms(jlong ticks) { |
2201 assert(os::elapsed_frequency() > 0, "Must be non-zero"); | |
2202 return (jlong)(((double)ticks / (double)os::elapsed_frequency()) | |
2203 * (double)1000.0); | |
2204 } | |
20393 | 2205 #endif // INCLUDE_MANAGEMENT |
0 | 2206 |
20393 | 2207 // Gets an array containing the amount of memory allocated on the Java |
2208 // heap for a set of threads (in bytes). Each element of the array is | |
2209 // the amount of memory allocated for the thread ID specified in the | |
2210 // corresponding entry in the given array of thread IDs; or -1 if the | |
2211 // thread does not exist or has terminated. | |
2212 JVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids, | |
2213 jlongArray sizeArray)) | |
2214 // Check if threads is null | |
2215 if (ids == NULL || sizeArray == NULL) { | |
2216 THROW(vmSymbols::java_lang_NullPointerException()); | |
2217 } | |
2218 | |
2219 ResourceMark rm(THREAD); | |
2220 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); | |
2221 typeArrayHandle ids_ah(THREAD, ta); | |
2222 | |
2223 typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray)); | |
2224 typeArrayHandle sizeArray_h(THREAD, sa); | |
2225 | |
2226 // validate the thread id array | |
2227 validate_thread_id_array(ids_ah, CHECK); | |
2228 | |
2229 // sizeArray must be of the same length as the given array of thread IDs | |
2230 int num_threads = ids_ah->length(); | |
2231 if (num_threads != sizeArray_h->length()) { | |
2232 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2233 "The length of the given long array does not match the length of " | |
2234 "the given array of thread IDs"); | |
2235 } | |
2236 | |
2237 MutexLockerEx ml(Threads_lock); | |
2238 for (int i = 0; i < num_threads; i++) { | |
2239 JavaThread* java_thread = Threads::find_java_thread_from_java_tid(ids_ah->long_at(i)); | |
2240 if (java_thread != NULL) { | |
2241 sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes()); | |
2242 } | |
2243 } | |
2244 JVM_END | |
2245 | |
2246 // Returns the CPU time consumed by a given thread (in nanoseconds). | |
2247 // If thread_id == 0, CPU time for the current thread is returned. | |
2248 // If user_sys_cpu_time = true, user level and system CPU time of | |
2249 // a given thread is returned; otherwise, only user level CPU time | |
2250 // is returned. | |
2251 JVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time)) | |
2252 if (!os::is_thread_cpu_time_supported()) { | |
2253 return -1; | |
2254 } | |
2255 | |
2256 if (thread_id < 0) { | |
2257 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
2258 "Invalid thread ID", -1); | |
2259 } | |
2260 | |
2261 JavaThread* java_thread = NULL; | |
2262 if (thread_id == 0) { | |
2263 // current thread | |
2264 return os::current_thread_cpu_time(user_sys_cpu_time != 0); | |
2265 } else { | |
2266 MutexLockerEx ml(Threads_lock); | |
2267 java_thread = Threads::find_java_thread_from_java_tid(thread_id); | |
2268 if (java_thread != NULL) { | |
2269 return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0); | |
2270 } | |
2271 } | |
2272 return -1; | |
2273 JVM_END | |
2274 | |
2275 // Gets an array containing the CPU times consumed by a set of threads | |
2276 // (in nanoseconds). Each element of the array is the CPU time for the | |
2277 // thread ID specified in the corresponding entry in the given array | |
2278 // of thread IDs; or -1 if the thread does not exist or has terminated. | |
2279 // If user_sys_cpu_time = true, the sum of user level and system CPU time | |
2280 // for the given thread is returned; otherwise, only user level CPU time | |
2281 // is returned. | |
2282 JVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids, | |
2283 jlongArray timeArray, | |
2284 jboolean user_sys_cpu_time)) | |
2285 // Check if threads is null | |
2286 if (ids == NULL || timeArray == NULL) { | |
2287 THROW(vmSymbols::java_lang_NullPointerException()); | |
2288 } | |
2289 | |
2290 ResourceMark rm(THREAD); | |
2291 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); | |
2292 typeArrayHandle ids_ah(THREAD, ta); | |
2293 | |
2294 typeArrayOop tia = typeArrayOop(JNIHandles::resolve_non_null(timeArray)); | |
2295 typeArrayHandle timeArray_h(THREAD, tia); | |
2296 | |
2297 // validate the thread id array | |
2298 validate_thread_id_array(ids_ah, CHECK); | |
2299 | |
2300 // timeArray must be of the same length as the given array of thread IDs | |
2301 int num_threads = ids_ah->length(); | |
2302 if (num_threads != timeArray_h->length()) { | |
2303 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2304 "The length of the given long array does not match the length of " | |
2305 "the given array of thread IDs"); | |
2306 } | |
2307 | |
2308 MutexLockerEx ml(Threads_lock); | |
2309 for (int i = 0; i < num_threads; i++) { | |
2310 JavaThread* java_thread = Threads::find_java_thread_from_java_tid(ids_ah->long_at(i)); | |
2311 if (java_thread != NULL) { | |
2312 timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread, | |
2313 user_sys_cpu_time != 0)); | |
2314 } | |
2315 } | |
2316 JVM_END | |
2317 | |
2318 | |
2319 | |
2320 #if INCLUDE_MANAGEMENT | |
0 | 2321 const struct jmmInterface_1_ jmm_interface = { |
2322 NULL, | |
2323 NULL, | |
2324 jmm_GetVersion, | |
2325 jmm_GetOptionalSupport, | |
2326 jmm_GetInputArguments, | |
2327 jmm_GetThreadInfo, | |
2328 jmm_GetInputArgumentArray, | |
2329 jmm_GetMemoryPools, | |
2330 jmm_GetMemoryManagers, | |
2331 jmm_GetMemoryPoolUsage, | |
2332 jmm_GetPeakMemoryPoolUsage, | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
2333 jmm_GetThreadAllocatedMemory, |
0 | 2334 jmm_GetMemoryUsage, |
2335 jmm_GetLongAttribute, | |
2336 jmm_GetBoolAttribute, | |
2337 jmm_SetBoolAttribute, | |
2338 jmm_GetLongAttributes, | |
2339 jmm_FindMonitorDeadlockedThreads, | |
2340 jmm_GetThreadCpuTime, | |
2341 jmm_GetVMGlobalNames, | |
2342 jmm_GetVMGlobals, | |
2343 jmm_GetInternalThreadTimes, | |
2344 jmm_ResetStatistic, | |
2345 jmm_SetPoolSensor, | |
2346 jmm_SetPoolThreshold, | |
2347 jmm_GetPoolCollectionUsage, | |
2348 jmm_GetGCExtAttributeInfo, | |
2349 jmm_GetLastGCStat, | |
2350 jmm_GetThreadCpuTimeWithKind, | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
2351 jmm_GetThreadCpuTimesWithKind, |
0 | 2352 jmm_DumpHeap0, |
2353 jmm_FindDeadlockedThreads, | |
2354 jmm_SetVMGlobal, | |
2355 NULL, | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2356 jmm_DumpThreads, |
4133 | 2357 jmm_SetGCNotificationEnabled, |
2358 jmm_GetDiagnosticCommands, | |
2359 jmm_GetDiagnosticCommandInfo, | |
2360 jmm_GetDiagnosticCommandArgumentsInfo, | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2361 jmm_ExecuteDiagnosticCommand, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
10134
diff
changeset
|
2362 jmm_SetDiagnosticFrameworkNotificationEnabled |
0 | 2363 }; |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
2364 #endif // INCLUDE_MANAGEMENT |
0 | 2365 |
2366 void* Management::get_jmm_interface(int version) { | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
2367 #if INCLUDE_MANAGEMENT |
0 | 2368 if (version == JMM_VERSION_1_0) { |
2369 return (void*) &jmm_interface; | |
2370 } | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6779
diff
changeset
|
2371 #endif // INCLUDE_MANAGEMENT |
0 | 2372 return NULL; |
2373 } |