annotate src/share/vm/services/management.cpp @ 4133:3b688d6ff3d0

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