annotate src/share/vm/services/management.cpp @ 20553:417e3b8d04c5

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