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