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