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