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