0N/A/*
4170N/A * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "compiler/compileBroker.hpp"
1879N/A#include "memory/iterator.hpp"
1879N/A#include "memory/oopFactory.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "oops/klass.hpp"
1879N/A#include "oops/klassOop.hpp"
1879N/A#include "oops/objArrayKlass.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "runtime/arguments.hpp"
2991N/A#include "runtime/globals.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/interfaceSupport.hpp"
1879N/A#include "runtime/javaCalls.hpp"
1879N/A#include "runtime/jniHandles.hpp"
1879N/A#include "runtime/os.hpp"
2076N/A#include "runtime/serviceThread.hpp"
1879N/A#include "services/classLoadingService.hpp"
2976N/A#include "services/diagnosticCommand.hpp"
2976N/A#include "services/diagnosticFramework.hpp"
1879N/A#include "services/heapDumper.hpp"
2976N/A#include "services/jmm.h"
1879N/A#include "services/lowMemoryDetector.hpp"
2453N/A#include "services/gcNotifier.hpp"
3863N/A#include "services/nmtDCmd.hpp"
1879N/A#include "services/management.hpp"
1879N/A#include "services/memoryManager.hpp"
1879N/A#include "services/memoryPool.hpp"
1879N/A#include "services/memoryService.hpp"
1879N/A#include "services/runtimeService.hpp"
1879N/A#include "services/threadService.hpp"
0N/A
0N/APerfVariable* Management::_begin_vm_creation_time = NULL;
0N/APerfVariable* Management::_end_vm_creation_time = NULL;
0N/APerfVariable* Management::_vm_init_done_time = NULL;
0N/A
0N/AklassOop Management::_sensor_klass = NULL;
0N/AklassOop Management::_threadInfo_klass = NULL;
0N/AklassOop Management::_memoryUsage_klass = NULL;
0N/AklassOop Management::_memoryPoolMXBean_klass = NULL;
0N/AklassOop Management::_memoryManagerMXBean_klass = NULL;
0N/AklassOop Management::_garbageCollectorMXBean_klass = NULL;
0N/AklassOop Management::_managementFactory_klass = NULL;
2453N/AklassOop Management::_garbageCollectorImpl_klass = NULL;
2453N/AklassOop Management::_gcInfo_klass = NULL;
0N/A
0N/AjmmOptionalSupport Management::_optional_support = {0};
0N/ATimeStamp Management::_stamp;
0N/A
0N/Avoid management_init() {
0N/A Management::init();
0N/A ThreadService::init();
0N/A RuntimeService::init();
0N/A ClassLoadingService::init();
0N/A}
0N/A
0N/Avoid Management::init() {
0N/A EXCEPTION_MARK;
0N/A
0N/A // These counters are for java.lang.management API support.
0N/A // They are created even if -XX:-UsePerfData is set and in
0N/A // that case, they will be allocated on C heap.
0N/A
0N/A _begin_vm_creation_time =
0N/A PerfDataManager::create_variable(SUN_RT, "createVmBeginTime",
0N/A PerfData::U_None, CHECK);
0N/A
0N/A _end_vm_creation_time =
0N/A PerfDataManager::create_variable(SUN_RT, "createVmEndTime",
0N/A PerfData::U_None, CHECK);
0N/A
0N/A _vm_init_done_time =
0N/A PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime",
0N/A PerfData::U_None, CHECK);
0N/A
0N/A // Initialize optional support
0N/A _optional_support.isLowMemoryDetectionSupported = 1;
0N/A _optional_support.isCompilationTimeMonitoringSupported = 1;
0N/A _optional_support.isThreadContentionMonitoringSupported = 1;
0N/A
0N/A if (os::is_thread_cpu_time_supported()) {
0N/A _optional_support.isCurrentThreadCpuTimeSupported = 1;
0N/A _optional_support.isOtherThreadCpuTimeSupported = 1;
0N/A } else {
0N/A _optional_support.isCurrentThreadCpuTimeSupported = 0;
0N/A _optional_support.isOtherThreadCpuTimeSupported = 0;
0N/A }
1988N/A
0N/A _optional_support.isBootClassPathSupported = 1;
0N/A _optional_support.isObjectMonitorUsageSupported = 1;
0N/A // This depends on the heap inspector
0N/A _optional_support.isSynchronizerUsageSupported = 1;
1988N/A _optional_support.isThreadAllocatedMemorySupported = 1;
2976N/A
3053N/A // Registration of the diagnostic commands
3134N/A DCmdRegistrant::register_dcmds();
3134N/A DCmdRegistrant::register_dcmds_ext();
3863N/A DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(true, false));
0N/A}
0N/A
0N/Avoid Management::initialize(TRAPS) {
2076N/A // Start the service thread
2076N/A ServiceThread::initialize();
0N/A
0N/A if (ManagementServer) {
0N/A ResourceMark rm(THREAD);
0N/A HandleMark hm(THREAD);
0N/A
0N/A // Load and initialize the sun.management.Agent class
0N/A // invoke startAgent method to start the management server
0N/A Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
2062N/A klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(),
0N/A loader,
0N/A Handle(),
0N/A true,
0N/A CHECK);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A
0N/A JavaValue result(T_VOID);
0N/A JavaCalls::call_static(&result,
0N/A ik,
2062N/A vmSymbols::startAgent_name(),
2062N/A vmSymbols::void_method_signature(),
0N/A CHECK);
0N/A }
0N/A}
0N/A
0N/Avoid Management::get_optional_support(jmmOptionalSupport* support) {
0N/A memcpy(support, &_optional_support, sizeof(jmmOptionalSupport));
0N/A}
0N/A
2062N/AklassOop Management::load_and_initialize_klass(Symbol* sh, TRAPS) {
0N/A klassOop k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A if (ik->should_be_initialized()) {
0N/A ik->initialize(CHECK_NULL);
0N/A }
0N/A return ik();
0N/A}
0N/A
0N/Avoid Management::record_vm_startup_time(jlong begin, jlong duration) {
0N/A // if the performance counter is not initialized,
0N/A // then vm initialization failed; simply return.
0N/A if (_begin_vm_creation_time == NULL) return;
0N/A
0N/A _begin_vm_creation_time->set_value(begin);
0N/A _end_vm_creation_time->set_value(begin + duration);
0N/A PerfMemory::set_accessible(true);
0N/A}
0N/A
0N/Ajlong Management::timestamp() {
0N/A TimeStamp t;
0N/A t.update();
0N/A return t.ticks() - _stamp.ticks();
0N/A}
0N/A
0N/Avoid Management::oops_do(OopClosure* f) {
0N/A MemoryService::oops_do(f);
0N/A ThreadService::oops_do(f);
0N/A
0N/A f->do_oop((oop*) &_sensor_klass);
0N/A f->do_oop((oop*) &_threadInfo_klass);
0N/A f->do_oop((oop*) &_memoryUsage_klass);
0N/A f->do_oop((oop*) &_memoryPoolMXBean_klass);
0N/A f->do_oop((oop*) &_memoryManagerMXBean_klass);
0N/A f->do_oop((oop*) &_garbageCollectorMXBean_klass);
0N/A f->do_oop((oop*) &_managementFactory_klass);
2453N/A f->do_oop((oop*) &_garbageCollectorImpl_klass);
2453N/A f->do_oop((oop*) &_gcInfo_klass);
0N/A}
0N/A
0N/AklassOop Management::java_lang_management_ThreadInfo_klass(TRAPS) {
0N/A if (_threadInfo_klass == NULL) {
2062N/A _threadInfo_klass = load_and_initialize_klass(vmSymbols::java_lang_management_ThreadInfo(), CHECK_NULL);
0N/A }
0N/A return _threadInfo_klass;
0N/A}
0N/A
0N/AklassOop Management::java_lang_management_MemoryUsage_klass(TRAPS) {
0N/A if (_memoryUsage_klass == NULL) {
2062N/A _memoryUsage_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryUsage(), CHECK_NULL);
0N/A }
0N/A return _memoryUsage_klass;
0N/A}
0N/A
0N/AklassOop Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) {
0N/A if (_memoryPoolMXBean_klass == NULL) {
2062N/A _memoryPoolMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryPoolMXBean(), CHECK_NULL);
0N/A }
0N/A return _memoryPoolMXBean_klass;
0N/A}
0N/A
0N/AklassOop Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) {
0N/A if (_memoryManagerMXBean_klass == NULL) {
2062N/A _memoryManagerMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryManagerMXBean(), CHECK_NULL);
0N/A }
0N/A return _memoryManagerMXBean_klass;
0N/A}
0N/A
0N/AklassOop Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) {
0N/A if (_garbageCollectorMXBean_klass == NULL) {
2062N/A _garbageCollectorMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_GarbageCollectorMXBean(), CHECK_NULL);
0N/A }
0N/A return _garbageCollectorMXBean_klass;
0N/A}
0N/A
0N/AklassOop Management::sun_management_Sensor_klass(TRAPS) {
0N/A if (_sensor_klass == NULL) {
2062N/A _sensor_klass = load_and_initialize_klass(vmSymbols::sun_management_Sensor(), CHECK_NULL);
0N/A }
0N/A return _sensor_klass;
0N/A}
0N/A
0N/AklassOop Management::sun_management_ManagementFactory_klass(TRAPS) {
0N/A if (_managementFactory_klass == NULL) {
2062N/A _managementFactory_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactory(), CHECK_NULL);
0N/A }
0N/A return _managementFactory_klass;
0N/A}
0N/A
2453N/AklassOop Management::sun_management_GarbageCollectorImpl_klass(TRAPS) {
2453N/A if (_garbageCollectorImpl_klass == NULL) {
2453N/A _garbageCollectorImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_GarbageCollectorImpl(), CHECK_NULL);
2453N/A }
2453N/A return _garbageCollectorImpl_klass;
2453N/A}
2453N/A
2453N/AklassOop Management::com_sun_management_GcInfo_klass(TRAPS) {
2453N/A if (_gcInfo_klass == NULL) {
2453N/A _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL);
2453N/A }
2453N/A return _gcInfo_klass;
2453N/A}
2453N/A
0N/Astatic void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) {
0N/A Handle snapshot_thread(THREAD, snapshot->threadObj());
0N/A
0N/A jlong contended_time;
0N/A jlong waited_time;
0N/A if (ThreadService::is_thread_monitoring_contention()) {
0N/A contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks());
0N/A waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks());
0N/A } else {
0N/A // set them to -1 if thread contention monitoring is disabled.
0N/A contended_time = max_julong;
0N/A waited_time = max_julong;
0N/A }
0N/A
0N/A int thread_status = snapshot->thread_status();
0N/A assert((thread_status & JMM_THREAD_STATE_FLAG_MASK) == 0, "Flags already set in thread_status in Thread object");
0N/A if (snapshot->is_ext_suspended()) {
0N/A thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED;
0N/A }
0N/A if (snapshot->is_in_native()) {
0N/A thread_status |= JMM_THREAD_STATE_FLAG_NATIVE;
0N/A }
0N/A
0N/A ThreadStackTrace* st = snapshot->get_stack_trace();
0N/A Handle stacktrace_h;
0N/A if (st != NULL) {
0N/A stacktrace_h = st->allocate_fill_stack_trace_element_array(CHECK);
0N/A } else {
0N/A stacktrace_h = Handle();
0N/A }
0N/A
0N/A args->push_oop(snapshot_thread);
0N/A args->push_int(thread_status);
0N/A args->push_oop(Handle(THREAD, snapshot->blocker_object()));
0N/A args->push_oop(Handle(THREAD, snapshot->blocker_object_owner()));
0N/A args->push_long(snapshot->contended_enter_count());
0N/A args->push_long(contended_time);
0N/A args->push_long(snapshot->monitor_wait_count() + snapshot->sleep_count());
0N/A args->push_long(waited_time);
0N/A args->push_oop(stacktrace_h);
0N/A}
0N/A
0N/A// Helper function to construct a ThreadInfo object
0N/AinstanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS) {
0N/A klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A
0N/A JavaValue result(T_VOID);
0N/A JavaCallArguments args(14);
0N/A
0N/A // First allocate a ThreadObj object and
0N/A // push the receiver as the first argument
0N/A Handle element = ik->allocate_instance_handle(CHECK_NULL);
0N/A args.push_oop(element);
0N/A
0N/A // initialize the arguments for the ThreadInfo constructor
0N/A initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL);
0N/A
0N/A // Call ThreadInfo constructor with no locked monitors and synchronizers
0N/A JavaCalls::call_special(&result,
0N/A ik,
2062N/A vmSymbols::object_initializer_name(),
2062N/A vmSymbols::java_lang_management_ThreadInfo_constructor_signature(),
0N/A &args,
0N/A CHECK_NULL);
0N/A
0N/A return (instanceOop) element();
0N/A}
0N/A
0N/AinstanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot,
0N/A objArrayHandle monitors_array,
0N/A typeArrayHandle depths_array,
0N/A objArrayHandle synchronizers_array,
0N/A TRAPS) {
0N/A klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A
0N/A JavaValue result(T_VOID);
0N/A JavaCallArguments args(17);
0N/A
0N/A // First allocate a ThreadObj object and
0N/A // push the receiver as the first argument
0N/A Handle element = ik->allocate_instance_handle(CHECK_NULL);
0N/A args.push_oop(element);
0N/A
0N/A // initialize the arguments for the ThreadInfo constructor
0N/A initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL);
0N/A
0N/A // push the locked monitors and synchronizers in the arguments
0N/A args.push_oop(monitors_array);
0N/A args.push_oop(depths_array);
0N/A args.push_oop(synchronizers_array);
0N/A
0N/A // Call ThreadInfo constructor with locked monitors and synchronizers
0N/A JavaCalls::call_special(&result,
0N/A ik,
2062N/A vmSymbols::object_initializer_name(),
2062N/A vmSymbols::java_lang_management_ThreadInfo_with_locks_constructor_signature(),
0N/A &args,
0N/A CHECK_NULL);
0N/A
0N/A return (instanceOop) element();
0N/A}
0N/A
0N/A// Helper functions
0N/Astatic JavaThread* find_java_thread_from_id(jlong thread_id) {
0N/A assert(Threads_lock->owned_by_self(), "Must hold Threads_lock");
0N/A
0N/A JavaThread* java_thread = NULL;
0N/A // Sequential search for now. Need to do better optimization later.
0N/A for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) {
0N/A oop tobj = thread->threadObj();
0N/A if (!thread->is_exiting() &&
0N/A tobj != NULL &&
0N/A thread_id == java_lang_Thread::thread_id(tobj)) {
0N/A java_thread = thread;
0N/A break;
0N/A }
0N/A }
0N/A return java_thread;
0N/A}
0N/A
0N/Astatic GCMemoryManager* get_gc_memory_manager_from_jobject(jobject mgr, TRAPS) {
0N/A if (mgr == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
0N/A }
0N/A oop mgr_obj = JNIHandles::resolve(mgr);
0N/A instanceHandle h(THREAD, (instanceOop) mgr_obj);
0N/A
0N/A klassOop k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL);
0N/A if (!h->is_a(k)) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "the object is not an instance of java.lang.management.GarbageCollectorMXBean class",
0N/A NULL);
0N/A }
0N/A
0N/A MemoryManager* gc = MemoryService::get_memory_manager(h);
0N/A if (gc == NULL || !gc->is_gc_memory_manager()) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Invalid GC memory manager",
0N/A NULL);
0N/A }
0N/A return (GCMemoryManager*) gc;
0N/A}
0N/A
0N/Astatic MemoryPool* get_memory_pool_from_jobject(jobject obj, TRAPS) {
0N/A if (obj == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
0N/A }
0N/A
0N/A oop pool_obj = JNIHandles::resolve(obj);
0N/A assert(pool_obj->is_instance(), "Should be an instanceOop");
0N/A instanceHandle ph(THREAD, (instanceOop) pool_obj);
0N/A
0N/A return MemoryService::get_memory_pool(ph);
0N/A}
0N/A
0N/Astatic void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) {
0N/A int num_threads = ids_ah->length();
0N/A
0N/A // Validate input thread IDs
0N/A int i = 0;
0N/A for (i = 0; i < num_threads; i++) {
0N/A jlong tid = ids_ah->long_at(i);
0N/A if (tid <= 0) {
0N/A // throw exception if invalid thread id.
0N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Invalid thread ID entry");
0N/A }
0N/A }
0N/A}
0N/A
0N/Astatic void validate_thread_info_array(objArrayHandle infoArray_h, TRAPS) {
0N/A // check if the element of infoArray is of type ThreadInfo class
0N/A klassOop threadinfo_klass = Management::java_lang_management_ThreadInfo_klass(CHECK);
0N/A klassOop element_klass = objArrayKlass::cast(infoArray_h->klass())->element_klass();
0N/A if (element_klass != threadinfo_klass) {
0N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "infoArray element type is not ThreadInfo class");
0N/A }
0N/A}
0N/A
0N/A
0N/Astatic MemoryManager* get_memory_manager_from_jobject(jobject obj, TRAPS) {
0N/A if (obj == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
0N/A }
0N/A
0N/A oop mgr_obj = JNIHandles::resolve(obj);
0N/A assert(mgr_obj->is_instance(), "Should be an instanceOop");
0N/A instanceHandle mh(THREAD, (instanceOop) mgr_obj);
0N/A
0N/A return MemoryService::get_memory_manager(mh);
0N/A}
0N/A
0N/A// Returns a version string and sets major and minor version if
0N/A// the input parameters are non-null.
0N/AJVM_LEAF(jint, jmm_GetVersion(JNIEnv *env))
0N/A return JMM_VERSION;
0N/AJVM_END
0N/A
0N/A// Gets the list of VM monitoring and management optional supports
0N/A// Returns 0 if succeeded; otherwise returns non-zero.
0N/AJVM_LEAF(jint, jmm_GetOptionalSupport(JNIEnv *env, jmmOptionalSupport* support))
0N/A if (support == NULL) {
0N/A return -1;
0N/A }
0N/A Management::get_optional_support(support);
0N/A return 0;
0N/AJVM_END
0N/A
0N/A// Returns a java.lang.String object containing the input arguments to the VM.
0N/AJVM_ENTRY(jobject, jmm_GetInputArguments(JNIEnv *env))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) {
0N/A return NULL;
0N/A }
0N/A
0N/A char** vm_flags = Arguments::jvm_flags_array();
0N/A char** vm_args = Arguments::jvm_args_array();
0N/A int num_flags = Arguments::num_jvm_flags();
0N/A int num_args = Arguments::num_jvm_args();
0N/A
0N/A size_t length = 1; // null terminator
0N/A int i;
0N/A for (i = 0; i < num_flags; i++) {
0N/A length += strlen(vm_flags[i]);
0N/A }
0N/A for (i = 0; i < num_args; i++) {
0N/A length += strlen(vm_args[i]);
0N/A }
0N/A // add a space between each argument
0N/A length += num_flags + num_args - 1;
0N/A
0N/A // Return the list of input arguments passed to the VM
0N/A // and preserve the order that the VM processes.
0N/A char* args = NEW_RESOURCE_ARRAY(char, length);
0N/A args[0] = '\0';
0N/A // concatenate all jvm_flags
0N/A if (num_flags > 0) {
0N/A strcat(args, vm_flags[0]);
0N/A for (i = 1; i < num_flags; i++) {
0N/A strcat(args, " ");
0N/A strcat(args, vm_flags[i]);
0N/A }
0N/A }
0N/A
0N/A if (num_args > 0 && num_flags > 0) {
0N/A // append a space if args already contains one or more jvm_flags
0N/A strcat(args, " ");
0N/A }
0N/A
0N/A // concatenate all jvm_args
0N/A if (num_args > 0) {
0N/A strcat(args, vm_args[0]);
0N/A for (i = 1; i < num_args; i++) {
0N/A strcat(args, " ");
0N/A strcat(args, vm_args[i]);
0N/A }
0N/A }
0N/A
0N/A Handle hargs = java_lang_String::create_from_platform_dependent_str(args, CHECK_NULL);
0N/A return JNIHandles::make_local(env, hargs());
0N/AJVM_END
0N/A
0N/A// Returns an array of java.lang.String object containing the input arguments to the VM.
0N/AJVM_ENTRY(jobjectArray, jmm_GetInputArgumentArray(JNIEnv *env))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) {
0N/A return NULL;
0N/A }
0N/A
0N/A char** vm_flags = Arguments::jvm_flags_array();
0N/A char** vm_args = Arguments::jvm_args_array();
0N/A int num_flags = Arguments::num_jvm_flags();
0N/A int num_args = Arguments::num_jvm_args();
0N/A
1142N/A instanceKlassHandle ik (THREAD, SystemDictionary::String_klass());
0N/A objArrayOop r = oopFactory::new_objArray(ik(), num_args + num_flags, CHECK_NULL);
0N/A objArrayHandle result_h(THREAD, r);
0N/A
0N/A int index = 0;
0N/A for (int j = 0; j < num_flags; j++, index++) {
0N/A Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
0N/A result_h->obj_at_put(index, h());
0N/A }
0N/A for (int i = 0; i < num_args; i++, index++) {
0N/A Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
0N/A result_h->obj_at_put(index, h());
0N/A }
0N/A return (jobjectArray) JNIHandles::make_local(env, result_h());
0N/AJVM_END
0N/A
0N/A// Returns an array of java/lang/management/MemoryPoolMXBean object
0N/A// one for each memory pool if obj == null; otherwise returns
0N/A// an array of memory pools for a given memory manager if
0N/A// it is a valid memory manager.
0N/AJVM_ENTRY(jobjectArray, jmm_GetMemoryPools(JNIEnv* env, jobject obj))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A int num_memory_pools;
0N/A MemoryManager* mgr = NULL;
0N/A if (obj == NULL) {
0N/A num_memory_pools = MemoryService::num_memory_pools();
0N/A } else {
0N/A mgr = get_memory_manager_from_jobject(obj, CHECK_NULL);
0N/A if (mgr == NULL) {
0N/A return NULL;
0N/A }
0N/A num_memory_pools = mgr->num_memory_pools();
0N/A }
0N/A
0N/A // Allocate the resulting MemoryPoolMXBean[] object
0N/A klassOop k = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A objArrayOop r = oopFactory::new_objArray(ik(), num_memory_pools, CHECK_NULL);
0N/A objArrayHandle poolArray(THREAD, r);
0N/A
0N/A if (mgr == NULL) {
0N/A // Get all memory pools
0N/A for (int i = 0; i < num_memory_pools; i++) {
0N/A MemoryPool* pool = MemoryService::get_memory_pool(i);
0N/A instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
0N/A instanceHandle ph(THREAD, p);
0N/A poolArray->obj_at_put(i, ph());
0N/A }
0N/A } else {
0N/A // Get memory pools managed by a given memory manager
0N/A for (int i = 0; i < num_memory_pools; i++) {
0N/A MemoryPool* pool = mgr->get_memory_pool(i);
0N/A instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
0N/A instanceHandle ph(THREAD, p);
0N/A poolArray->obj_at_put(i, ph());
0N/A }
0N/A }
0N/A return (jobjectArray) JNIHandles::make_local(env, poolArray());
0N/AJVM_END
0N/A
0N/A// Returns an array of java/lang/management/MemoryManagerMXBean object
0N/A// one for each memory manager if obj == null; otherwise returns
0N/A// an array of memory managers for a given memory pool if
0N/A// it is a valid memory pool.
0N/AJVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A int num_mgrs;
0N/A MemoryPool* pool = NULL;
0N/A if (obj == NULL) {
0N/A num_mgrs = MemoryService::num_memory_managers();
0N/A } else {
0N/A pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
0N/A if (pool == NULL) {
0N/A return NULL;
0N/A }
0N/A num_mgrs = pool->num_memory_managers();
0N/A }
0N/A
0N/A // Allocate the resulting MemoryManagerMXBean[] object
0N/A klassOop k = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A objArrayOop r = oopFactory::new_objArray(ik(), num_mgrs, CHECK_NULL);
0N/A objArrayHandle mgrArray(THREAD, r);
0N/A
0N/A if (pool == NULL) {
0N/A // Get all memory managers
0N/A for (int i = 0; i < num_mgrs; i++) {
0N/A MemoryManager* mgr = MemoryService::get_memory_manager(i);
0N/A instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
0N/A instanceHandle ph(THREAD, p);
0N/A mgrArray->obj_at_put(i, ph());
0N/A }
0N/A } else {
0N/A // Get memory managers for a given memory pool
0N/A for (int i = 0; i < num_mgrs; i++) {
0N/A MemoryManager* mgr = pool->get_memory_manager(i);
0N/A instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
0N/A instanceHandle ph(THREAD, p);
0N/A mgrArray->obj_at_put(i, ph());
0N/A }
0N/A }
0N/A return (jobjectArray) JNIHandles::make_local(env, mgrArray());
0N/AJVM_END
0N/A
0N/A
0N/A// Returns a java/lang/management/MemoryUsage object containing the memory usage
0N/A// of a given memory pool.
0N/AJVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
0N/A if (pool != NULL) {
0N/A MemoryUsage usage = pool->get_memory_usage();
0N/A Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
0N/A return JNIHandles::make_local(env, h());
0N/A } else {
0N/A return NULL;
0N/A }
0N/AJVM_END
0N/A
0N/A// Returns a java/lang/management/MemoryUsage object containing the memory usage
0N/A// of a given memory pool.
0N/AJVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
0N/A if (pool != NULL) {
0N/A MemoryUsage usage = pool->get_peak_memory_usage();
0N/A Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
0N/A return JNIHandles::make_local(env, h());
0N/A } else {
0N/A return NULL;
0N/A }
0N/AJVM_END
0N/A
0N/A// Returns a java/lang/management/MemoryUsage object containing the memory usage
0N/A// of a given memory pool after most recent GC.
0N/AJVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
0N/A if (pool != NULL && pool->is_collected_pool()) {
0N/A MemoryUsage usage = pool->get_last_collection_usage();
0N/A Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
0N/A return JNIHandles::make_local(env, h());
0N/A } else {
0N/A return NULL;
0N/A }
0N/AJVM_END
0N/A
0N/A// Sets the memory pool sensor for a threshold type
0N/AJVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj))
0N/A if (obj == NULL || sensorObj == NULL) {
0N/A THROW(vmSymbols::java_lang_NullPointerException());
0N/A }
0N/A
0N/A klassOop sensor_klass = Management::sun_management_Sensor_klass(CHECK);
0N/A oop s = JNIHandles::resolve(sensorObj);
0N/A assert(s->is_instance(), "Sensor should be an instanceOop");
0N/A instanceHandle sensor_h(THREAD, (instanceOop) s);
0N/A if (!sensor_h->is_a(sensor_klass)) {
0N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Sensor is not an instance of sun.management.Sensor class");
0N/A }
0N/A
0N/A MemoryPool* mpool = get_memory_pool_from_jobject(obj, CHECK);
0N/A assert(mpool != NULL, "MemoryPool should exist");
0N/A
0N/A switch (type) {
0N/A case JMM_USAGE_THRESHOLD_HIGH:
0N/A case JMM_USAGE_THRESHOLD_LOW:
0N/A // have only one sensor for threshold high and low
0N/A mpool->set_usage_sensor_obj(sensor_h);
0N/A break;
0N/A case JMM_COLLECTION_USAGE_THRESHOLD_HIGH:
0N/A case JMM_COLLECTION_USAGE_THRESHOLD_LOW:
0N/A // have only one sensor for threshold high and low
0N/A mpool->set_gc_usage_sensor_obj(sensor_h);
0N/A break;
0N/A default:
0N/A assert(false, "Unrecognized type");
0N/A }
0N/A
0N/AJVM_END
0N/A
0N/A
0N/A// Sets the threshold of a given memory pool.
0N/A// Returns the previous threshold.
0N/A//
0N/A// Input parameters:
0N/A// pool - the MemoryPoolMXBean object
0N/A// type - threshold type
0N/A// threshold - the new threshold (must not be negative)
0N/A//
0N/AJVM_ENTRY(jlong, jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold))
0N/A if (threshold < 0) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Invalid threshold value",
0N/A -1);
0N/A }
0N/A
489N/A if ((size_t)threshold > max_uintx) {
489N/A stringStream st;
489N/A st.print("Invalid valid threshold value. Threshold value (" UINT64_FORMAT ") > max value of size_t (" SIZE_FORMAT ")", (size_t)threshold, max_uintx);
489N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), st.as_string(), -1);
0N/A }
0N/A
0N/A MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_(0L));
0N/A assert(pool != NULL, "MemoryPool should exist");
0N/A
0N/A jlong prev = 0;
0N/A switch (type) {
0N/A case JMM_USAGE_THRESHOLD_HIGH:
0N/A if (!pool->usage_threshold()->is_high_threshold_supported()) {
0N/A return -1;
0N/A }
0N/A prev = pool->usage_threshold()->set_high_threshold((size_t) threshold);
0N/A break;
0N/A
0N/A case JMM_USAGE_THRESHOLD_LOW:
0N/A if (!pool->usage_threshold()->is_low_threshold_supported()) {
0N/A return -1;
0N/A }
0N/A prev = pool->usage_threshold()->set_low_threshold((size_t) threshold);
0N/A break;
0N/A
0N/A case JMM_COLLECTION_USAGE_THRESHOLD_HIGH:
0N/A if (!pool->gc_usage_threshold()->is_high_threshold_supported()) {
0N/A return -1;
0N/A }
0N/A // return and the new threshold is effective for the next GC
0N/A return pool->gc_usage_threshold()->set_high_threshold((size_t) threshold);
0N/A
0N/A case JMM_COLLECTION_USAGE_THRESHOLD_LOW:
0N/A if (!pool->gc_usage_threshold()->is_low_threshold_supported()) {
0N/A return -1;
0N/A }
0N/A // return and the new threshold is effective for the next GC
0N/A return pool->gc_usage_threshold()->set_low_threshold((size_t) threshold);
0N/A
0N/A default:
0N/A assert(false, "Unrecognized type");
0N/A return -1;
0N/A }
0N/A
0N/A // When the threshold is changed, reevaluate if the low memory
0N/A // detection is enabled.
0N/A if (prev != threshold) {
0N/A LowMemoryDetector::recompute_enabled_for_collected_pools();
0N/A LowMemoryDetector::detect_low_memory(pool);
0N/A }
0N/A return prev;
0N/AJVM_END
0N/A
1988N/A// Gets an array containing the amount of memory allocated on the Java
1988N/A// heap for a set of threads (in bytes). Each element of the array is
1988N/A// the amount of memory allocated for the thread ID specified in the
1988N/A// corresponding entry in the given array of thread IDs; or -1 if the
1988N/A// thread does not exist or has terminated.
1988N/AJVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids,
1988N/A jlongArray sizeArray))
1988N/A // Check if threads is null
1988N/A if (ids == NULL || sizeArray == NULL) {
1988N/A THROW(vmSymbols::java_lang_NullPointerException());
1988N/A }
1988N/A
1988N/A ResourceMark rm(THREAD);
1988N/A typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
1988N/A typeArrayHandle ids_ah(THREAD, ta);
1988N/A
1988N/A typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray));
1988N/A typeArrayHandle sizeArray_h(THREAD, sa);
1988N/A
1988N/A // validate the thread id array
1988N/A validate_thread_id_array(ids_ah, CHECK);
1988N/A
1988N/A // sizeArray must be of the same length as the given array of thread IDs
1988N/A int num_threads = ids_ah->length();
1988N/A if (num_threads != sizeArray_h->length()) {
1988N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1988N/A "The length of the given long array does not match the length of "
1988N/A "the given array of thread IDs");
1988N/A }
1988N/A
1988N/A MutexLockerEx ml(Threads_lock);
1988N/A for (int i = 0; i < num_threads; i++) {
1988N/A JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i));
1988N/A if (java_thread != NULL) {
1988N/A sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes());
1988N/A }
1988N/A }
1988N/AJVM_END
1988N/A
0N/A// Returns a java/lang/management/MemoryUsage object representing
0N/A// the memory usage for the heap or non-heap memory.
0N/AJVM_ENTRY(jobject, jmm_GetMemoryUsage(JNIEnv* env, jboolean heap))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A // Calculate the memory usage
0N/A size_t total_init = 0;
0N/A size_t total_used = 0;
0N/A size_t total_committed = 0;
0N/A size_t total_max = 0;
0N/A bool has_undefined_init_size = false;
0N/A bool has_undefined_max_size = false;
0N/A
0N/A for (int i = 0; i < MemoryService::num_memory_pools(); i++) {
0N/A MemoryPool* pool = MemoryService::get_memory_pool(i);
0N/A if ((heap && pool->is_heap()) || (!heap && pool->is_non_heap())) {
0N/A MemoryUsage u = pool->get_memory_usage();
0N/A total_used += u.used();
0N/A total_committed += u.committed();
0N/A
0N/A // if any one of the memory pool has undefined init_size or max_size,
0N/A // set it to -1
0N/A if (u.init_size() == (size_t)-1) {
0N/A has_undefined_init_size = true;
0N/A }
0N/A if (!has_undefined_init_size) {
0N/A total_init += u.init_size();
0N/A }
0N/A
0N/A if (u.max_size() == (size_t)-1) {
0N/A has_undefined_max_size = true;
0N/A }
0N/A if (!has_undefined_max_size) {
0N/A total_max += u.max_size();
0N/A }
0N/A }
0N/A }
0N/A
1677N/A // In our current implementation, we make sure that all non-heap
1677N/A // pools have defined init and max sizes. Heap pools do not matter,
1677N/A // as we never use total_init and total_max for them.
1677N/A assert(heap || !has_undefined_init_size, "Undefined init size");
1677N/A assert(heap || !has_undefined_max_size, "Undefined max size");
0N/A
1064N/A MemoryUsage usage((heap ? InitialHeapSize : total_init),
0N/A total_used,
0N/A total_committed,
0N/A (heap ? Universe::heap()->max_capacity() : total_max));
0N/A
0N/A Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
0N/A return JNIHandles::make_local(env, obj());
0N/AJVM_END
0N/A
0N/A// Returns the boolean value of a given attribute.
0N/AJVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att))
0N/A switch (att) {
0N/A case JMM_VERBOSE_GC:
0N/A return MemoryService::get_verbose();
0N/A case JMM_VERBOSE_CLASS:
0N/A return ClassLoadingService::get_verbose();
0N/A case JMM_THREAD_CONTENTION_MONITORING:
0N/A return ThreadService::is_thread_monitoring_contention();
0N/A case JMM_THREAD_CPU_TIME:
0N/A return ThreadService::is_thread_cpu_time_enabled();
1988N/A case JMM_THREAD_ALLOCATED_MEMORY:
1988N/A return ThreadService::is_thread_allocated_memory_enabled();
0N/A default:
0N/A assert(0, "Unrecognized attribute");
0N/A return false;
0N/A }
0N/AJVM_END
0N/A
0N/A// Sets the given boolean attribute and returns the previous value.
0N/AJVM_ENTRY(jboolean, jmm_SetBoolAttribute(JNIEnv *env, jmmBoolAttribute att, jboolean flag))
0N/A switch (att) {
0N/A case JMM_VERBOSE_GC:
0N/A return MemoryService::set_verbose(flag != 0);
0N/A case JMM_VERBOSE_CLASS:
0N/A return ClassLoadingService::set_verbose(flag != 0);
0N/A case JMM_THREAD_CONTENTION_MONITORING:
0N/A return ThreadService::set_thread_monitoring_contention(flag != 0);
0N/A case JMM_THREAD_CPU_TIME:
0N/A return ThreadService::set_thread_cpu_time_enabled(flag != 0);
1988N/A case JMM_THREAD_ALLOCATED_MEMORY:
1988N/A return ThreadService::set_thread_allocated_memory_enabled(flag != 0);
0N/A default:
0N/A assert(0, "Unrecognized attribute");
0N/A return false;
0N/A }
0N/AJVM_END
0N/A
0N/A
0N/Astatic jlong get_gc_attribute(GCMemoryManager* mgr, jmmLongAttribute att) {
0N/A switch (att) {
0N/A case JMM_GC_TIME_MS:
0N/A return mgr->gc_time_ms();
0N/A
0N/A case JMM_GC_COUNT:
0N/A return mgr->gc_count();
0N/A
0N/A case JMM_GC_EXT_ATTRIBUTE_INFO_SIZE:
0N/A // current implementation only has 1 ext attribute
0N/A return 1;
0N/A
0N/A default:
0N/A assert(0, "Unrecognized GC attribute");
0N/A return -1;
0N/A }
0N/A}
0N/A
0N/Aclass VmThreadCountClosure: public ThreadClosure {
0N/A private:
0N/A int _count;
0N/A public:
0N/A VmThreadCountClosure() : _count(0) {};
0N/A void do_thread(Thread* thread);
0N/A int count() { return _count; }
0N/A};
0N/A
0N/Avoid VmThreadCountClosure::do_thread(Thread* thread) {
0N/A // exclude externally visible JavaThreads
0N/A if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
0N/A return;
0N/A }
0N/A
0N/A _count++;
0N/A}
0N/A
0N/Astatic jint get_vm_thread_count() {
0N/A VmThreadCountClosure vmtcc;
0N/A {
0N/A MutexLockerEx ml(Threads_lock);
0N/A Threads::threads_do(&vmtcc);
0N/A }
0N/A
0N/A return vmtcc.count();
0N/A}
0N/A
0N/Astatic jint get_num_flags() {
0N/A // last flag entry is always NULL, so subtract 1
0N/A int nFlags = (int) Flag::numFlags - 1;
0N/A int count = 0;
0N/A for (int i = 0; i < nFlags; i++) {
0N/A Flag* flag = &Flag::flags[i];
350N/A // Exclude the locked (diagnostic, experimental) flags
0N/A if (flag->is_unlocked() || flag->is_unlocker()) {
0N/A count++;
0N/A }
0N/A }
0N/A return count;
0N/A}
0N/A
0N/Astatic jlong get_long_attribute(jmmLongAttribute att) {
0N/A switch (att) {
0N/A case JMM_CLASS_LOADED_COUNT:
0N/A return ClassLoadingService::loaded_class_count();
0N/A
0N/A case JMM_CLASS_UNLOADED_COUNT:
0N/A return ClassLoadingService::unloaded_class_count();
0N/A
0N/A case JMM_THREAD_TOTAL_COUNT:
0N/A return ThreadService::get_total_thread_count();
0N/A
0N/A case JMM_THREAD_LIVE_COUNT:
0N/A return ThreadService::get_live_thread_count();
0N/A
0N/A case JMM_THREAD_PEAK_COUNT:
0N/A return ThreadService::get_peak_thread_count();
0N/A
0N/A case JMM_THREAD_DAEMON_COUNT:
0N/A return ThreadService::get_daemon_thread_count();
0N/A
0N/A case JMM_JVM_INIT_DONE_TIME_MS:
0N/A return Management::vm_init_done_time();
0N/A
0N/A case JMM_COMPILE_TOTAL_TIME_MS:
0N/A return Management::ticks_to_ms(CompileBroker::total_compilation_ticks());
0N/A
0N/A case JMM_OS_PROCESS_ID:
0N/A return os::current_process_id();
0N/A
0N/A // Hotspot-specific counters
0N/A case JMM_CLASS_LOADED_BYTES:
0N/A return ClassLoadingService::loaded_class_bytes();
0N/A
0N/A case JMM_CLASS_UNLOADED_BYTES:
0N/A return ClassLoadingService::unloaded_class_bytes();
0N/A
0N/A case JMM_SHARED_CLASS_LOADED_COUNT:
0N/A return ClassLoadingService::loaded_shared_class_count();
0N/A
0N/A case JMM_SHARED_CLASS_UNLOADED_COUNT:
0N/A return ClassLoadingService::unloaded_shared_class_count();
0N/A
0N/A
0N/A case JMM_SHARED_CLASS_LOADED_BYTES:
0N/A return ClassLoadingService::loaded_shared_class_bytes();
0N/A
0N/A case JMM_SHARED_CLASS_UNLOADED_BYTES:
0N/A return ClassLoadingService::unloaded_shared_class_bytes();
0N/A
0N/A case JMM_TOTAL_CLASSLOAD_TIME_MS:
0N/A return ClassLoader::classloader_time_ms();
0N/A
0N/A case JMM_VM_GLOBAL_COUNT:
0N/A return get_num_flags();
0N/A
0N/A case JMM_SAFEPOINT_COUNT:
0N/A return RuntimeService::safepoint_count();
0N/A
0N/A case JMM_TOTAL_SAFEPOINTSYNC_TIME_MS:
0N/A return RuntimeService::safepoint_sync_time_ms();
0N/A
0N/A case JMM_TOTAL_STOPPED_TIME_MS:
0N/A return RuntimeService::safepoint_time_ms();
0N/A
0N/A case JMM_TOTAL_APP_TIME_MS:
0N/A return RuntimeService::application_time_ms();
0N/A
0N/A case JMM_VM_THREAD_COUNT:
0N/A return get_vm_thread_count();
0N/A
0N/A case JMM_CLASS_INIT_TOTAL_COUNT:
0N/A return ClassLoader::class_init_count();
0N/A
0N/A case JMM_CLASS_INIT_TOTAL_TIME_MS:
0N/A return ClassLoader::class_init_time_ms();
0N/A
0N/A case JMM_CLASS_VERIFY_TOTAL_TIME_MS:
0N/A return ClassLoader::class_verify_time_ms();
0N/A
0N/A case JMM_METHOD_DATA_SIZE_BYTES:
0N/A return ClassLoadingService::class_method_data_size();
0N/A
0N/A case JMM_OS_MEM_TOTAL_PHYSICAL_BYTES:
0N/A return os::physical_memory();
0N/A
0N/A default:
0N/A return -1;
0N/A }
0N/A}
0N/A
0N/A
0N/A// Returns the long value of a given attribute.
0N/AJVM_ENTRY(jlong, jmm_GetLongAttribute(JNIEnv *env, jobject obj, jmmLongAttribute att))
0N/A if (obj == NULL) {
0N/A return get_long_attribute(att);
0N/A } else {
0N/A GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_(0L));
0N/A if (mgr != NULL) {
0N/A return get_gc_attribute(mgr, att);
0N/A }
0N/A }
0N/A return -1;
0N/AJVM_END
0N/A
0N/A// Gets the value of all attributes specified in the given array
0N/A// and sets the value in the result array.
0N/A// Returns the number of attributes found.
0N/AJVM_ENTRY(jint, jmm_GetLongAttributes(JNIEnv *env,
0N/A jobject obj,
0N/A jmmLongAttribute* atts,
0N/A jint count,
0N/A jlong* result))
0N/A
0N/A int num_atts = 0;
0N/A if (obj == NULL) {
0N/A for (int i = 0; i < count; i++) {
0N/A result[i] = get_long_attribute(atts[i]);
0N/A if (result[i] != -1) {
0N/A num_atts++;
0N/A }
0N/A }
0N/A } else {
0N/A GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_0);
0N/A for (int i = 0; i < count; i++) {
0N/A result[i] = get_gc_attribute(mgr, atts[i]);
0N/A if (result[i] != -1) {
0N/A num_atts++;
0N/A }
0N/A }
0N/A }
0N/A return num_atts;
0N/AJVM_END
0N/A
0N/A// Helper function to do thread dump for a specific list of threads
0N/Astatic void do_thread_dump(ThreadDumpResult* dump_result,
0N/A typeArrayHandle ids_ah, // array of thread ID (long[])
0N/A int num_threads,
0N/A int max_depth,
0N/A bool with_locked_monitors,
0N/A bool with_locked_synchronizers,
0N/A TRAPS) {
0N/A
0N/A // First get an array of threadObj handles.
0N/A // A JavaThread may terminate before we get the stack trace.
0N/A GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
0N/A {
0N/A MutexLockerEx ml(Threads_lock);
0N/A for (int i = 0; i < num_threads; i++) {
0N/A jlong tid = ids_ah->long_at(i);
0N/A JavaThread* jt = find_java_thread_from_id(tid);
0N/A oop thread_obj = (jt != NULL ? jt->threadObj() : (oop)NULL);
0N/A instanceHandle threadObj_h(THREAD, (instanceOop) thread_obj);
0N/A thread_handle_array->append(threadObj_h);
0N/A }
0N/A }
0N/A
0N/A // Obtain thread dumps and thread snapshot information
0N/A VM_ThreadDump op(dump_result,
0N/A thread_handle_array,
0N/A num_threads,
0N/A max_depth, /* stack depth */
0N/A with_locked_monitors,
0N/A with_locked_synchronizers);
0N/A VMThread::execute(&op);
0N/A}
0N/A
0N/A// Gets an array of ThreadInfo objects. Each element is the ThreadInfo
0N/A// for the thread ID specified in the corresponding entry in
0N/A// the given array of thread IDs; or NULL if the thread does not exist
0N/A// or has terminated.
0N/A//
0N/A// Input parameters:
0N/A// ids - array of thread IDs
0N/A// maxDepth - the maximum depth of stack traces to be dumped:
0N/A// maxDepth == -1 requests to dump entire stack trace.
0N/A// maxDepth == 0 requests no stack trace.
0N/A// infoArray - array of ThreadInfo objects
0N/A//
1988N/A// QQQ - Why does this method return a value instead of void?
0N/AJVM_ENTRY(jint, jmm_GetThreadInfo(JNIEnv *env, jlongArray ids, jint maxDepth, jobjectArray infoArray))
0N/A // Check if threads is null
0N/A if (ids == NULL || infoArray == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), -1);
0N/A }
0N/A
0N/A if (maxDepth < -1) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Invalid maxDepth", -1);
0N/A }
0N/A
0N/A ResourceMark rm(THREAD);
0N/A typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
0N/A typeArrayHandle ids_ah(THREAD, ta);
0N/A
0N/A oop infoArray_obj = JNIHandles::resolve_non_null(infoArray);
0N/A objArrayOop oa = objArrayOop(infoArray_obj);
0N/A objArrayHandle infoArray_h(THREAD, oa);
0N/A
0N/A // validate the thread id array
0N/A validate_thread_id_array(ids_ah, CHECK_0);
0N/A
0N/A // validate the ThreadInfo[] parameters
0N/A validate_thread_info_array(infoArray_h, CHECK_0);
0N/A
0N/A // infoArray must be of the same length as the given array of thread IDs
0N/A int num_threads = ids_ah->length();
0N/A if (num_threads != infoArray_h->length()) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "The length of the given ThreadInfo array does not match the length of the given array of thread IDs", -1);
0N/A }
0N/A
0N/A if (JDK_Version::is_gte_jdk16x_version()) {
0N/A // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots
0N/A java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_0);
0N/A }
0N/A
0N/A // Must use ThreadDumpResult to store the ThreadSnapshot.
0N/A // GC may occur after the thread snapshots are taken but before
0N/A // this function returns. The threadObj and other oops kept
0N/A // in the ThreadSnapshot are marked and adjusted during GC.
0N/A ThreadDumpResult dump_result(num_threads);
0N/A
0N/A if (maxDepth == 0) {
0N/A // no stack trace dumped - do not need to stop the world
0N/A {
0N/A MutexLockerEx ml(Threads_lock);
0N/A for (int i = 0; i < num_threads; i++) {
0N/A jlong tid = ids_ah->long_at(i);
0N/A JavaThread* jt = find_java_thread_from_id(tid);
0N/A ThreadSnapshot* ts;
0N/A if (jt == NULL) {
0N/A // if the thread does not exist or now it is terminated,
0N/A // create dummy snapshot
0N/A ts = new ThreadSnapshot();
0N/A } else {
0N/A ts = new ThreadSnapshot(jt);
0N/A }
0N/A dump_result.add_thread_snapshot(ts);
0N/A }
0N/A }
0N/A } else {
0N/A // obtain thread dump with the specific list of threads with stack trace
0N/A do_thread_dump(&dump_result,
0N/A ids_ah,
0N/A num_threads,
0N/A maxDepth,
0N/A false, /* no locked monitor */
0N/A false, /* no locked synchronizers */
0N/A CHECK_0);
0N/A }
0N/A
0N/A int num_snapshots = dump_result.num_snapshots();
0N/A assert(num_snapshots == num_threads, "Must match the number of thread snapshots");
0N/A int index = 0;
0N/A for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; index++, ts = ts->next()) {
0N/A // For each thread, create an java/lang/management/ThreadInfo object
0N/A // and fill with the thread information
0N/A
0N/A if (ts->threadObj() == NULL) {
0N/A // if the thread does not exist or now it is terminated, set threadinfo to NULL
0N/A infoArray_h->obj_at_put(index, NULL);
0N/A continue;
0N/A }
0N/A
0N/A // Create java.lang.management.ThreadInfo object
0N/A instanceOop info_obj = Management::create_thread_info_instance(ts, CHECK_0);
0N/A infoArray_h->obj_at_put(index, info_obj);
0N/A }
0N/A return 0;
0N/AJVM_END
0N/A
0N/A// Dump thread info for the specified threads.
0N/A// It returns an array of ThreadInfo objects. Each element is the ThreadInfo
0N/A// for the thread ID specified in the corresponding entry in
0N/A// the given array of thread IDs; or NULL if the thread does not exist
0N/A// or has terminated.
0N/A//
0N/A// Input parameter:
0N/A// ids - array of thread IDs; NULL indicates all live threads
0N/A// locked_monitors - if true, dump locked object monitors
0N/A// locked_synchronizers - if true, dump locked JSR-166 synchronizers
0N/A//
0N/AJVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A if (JDK_Version::is_gte_jdk16x_version()) {
0N/A // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots
0N/A java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_NULL);
0N/A }
0N/A
0N/A typeArrayOop ta = typeArrayOop(JNIHandles::resolve(thread_ids));
0N/A int num_threads = (ta != NULL ? ta->length() : 0);
0N/A typeArrayHandle ids_ah(THREAD, ta);
0N/A
0N/A ThreadDumpResult dump_result(num_threads); // can safepoint
0N/A
0N/A if (ids_ah() != NULL) {
0N/A
0N/A // validate the thread id array
0N/A validate_thread_id_array(ids_ah, CHECK_NULL);
0N/A
0N/A // obtain thread dump of a specific list of threads
0N/A do_thread_dump(&dump_result,
0N/A ids_ah,
0N/A num_threads,
0N/A -1, /* entire stack */
0N/A (locked_monitors ? true : false), /* with locked monitors */
0N/A (locked_synchronizers ? true : false), /* with locked synchronizers */
0N/A CHECK_NULL);
0N/A } else {
0N/A // obtain thread dump of all threads
0N/A VM_ThreadDump op(&dump_result,
0N/A -1, /* entire stack */
0N/A (locked_monitors ? true : false), /* with locked monitors */
0N/A (locked_synchronizers ? true : false) /* with locked synchronizers */);
0N/A VMThread::execute(&op);
0N/A }
0N/A
0N/A int num_snapshots = dump_result.num_snapshots();
0N/A
0N/A // create the result ThreadInfo[] object
0N/A klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL);
0N/A instanceKlassHandle ik (THREAD, k);
0N/A objArrayOop r = oopFactory::new_objArray(ik(), num_snapshots, CHECK_NULL);
0N/A objArrayHandle result_h(THREAD, r);
0N/A
0N/A int index = 0;
0N/A for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; ts = ts->next(), index++) {
0N/A if (ts->threadObj() == NULL) {
0N/A // if the thread does not exist or now it is terminated, set threadinfo to NULL
0N/A result_h->obj_at_put(index, NULL);
0N/A continue;
0N/A }
0N/A
0N/A ThreadStackTrace* stacktrace = ts->get_stack_trace();
0N/A assert(stacktrace != NULL, "Must have a stack trace dumped");
0N/A
0N/A // Create Object[] filled with locked monitors
0N/A // Create int[] filled with the stack depth where a monitor was locked
0N/A int num_frames = stacktrace->get_stack_depth();
0N/A int num_locked_monitors = stacktrace->num_jni_locked_monitors();
0N/A
0N/A // Count the total number of locked monitors
0N/A for (int i = 0; i < num_frames; i++) {
0N/A StackFrameInfo* frame = stacktrace->stack_frame_at(i);
0N/A num_locked_monitors += frame->num_locked_monitors();
0N/A }
0N/A
0N/A objArrayHandle monitors_array;
0N/A typeArrayHandle depths_array;
0N/A objArrayHandle synchronizers_array;
0N/A
0N/A if (locked_monitors) {
0N/A // Constructs Object[] and int[] to contain the object monitor and the stack depth
0N/A // where the thread locked it
2139N/A objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_monitors, CHECK_NULL);
0N/A objArrayHandle mh(THREAD, array);
0N/A monitors_array = mh;
0N/A
0N/A typeArrayOop tarray = oopFactory::new_typeArray(T_INT, num_locked_monitors, CHECK_NULL);
0N/A typeArrayHandle dh(THREAD, tarray);
0N/A depths_array = dh;
0N/A
0N/A int count = 0;
0N/A int j = 0;
0N/A for (int depth = 0; depth < num_frames; depth++) {
0N/A StackFrameInfo* frame = stacktrace->stack_frame_at(depth);
0N/A int len = frame->num_locked_monitors();
0N/A GrowableArray<oop>* locked_monitors = frame->locked_monitors();
0N/A for (j = 0; j < len; j++) {
0N/A oop monitor = locked_monitors->at(j);
0N/A assert(monitor != NULL && monitor->is_instance(), "must be a Java object");
0N/A monitors_array->obj_at_put(count, monitor);
0N/A depths_array->int_at_put(count, depth);
0N/A count++;
0N/A }
0N/A }
0N/A
0N/A GrowableArray<oop>* jni_locked_monitors = stacktrace->jni_locked_monitors();
0N/A for (j = 0; j < jni_locked_monitors->length(); j++) {
0N/A oop object = jni_locked_monitors->at(j);
0N/A assert(object != NULL && object->is_instance(), "must be a Java object");
0N/A monitors_array->obj_at_put(count, object);
0N/A // Monitor locked via JNI MonitorEnter call doesn't have stack depth info
0N/A depths_array->int_at_put(count, -1);
0N/A count++;
0N/A }
0N/A assert(count == num_locked_monitors, "number of locked monitors doesn't match");
0N/A }
0N/A
0N/A if (locked_synchronizers) {
0N/A // Create Object[] filled with locked JSR-166 synchronizers
0N/A assert(ts->threadObj() != NULL, "Must be a valid JavaThread");
0N/A ThreadConcurrentLocks* tcl = ts->get_concurrent_locks();
0N/A GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL);
0N/A int num_locked_synchronizers = (locks != NULL ? locks->length() : 0);
0N/A
2139N/A objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_synchronizers, CHECK_NULL);
0N/A objArrayHandle sh(THREAD, array);
0N/A synchronizers_array = sh;
0N/A
0N/A for (int k = 0; k < num_locked_synchronizers; k++) {
0N/A synchronizers_array->obj_at_put(k, locks->at(k));
0N/A }
0N/A }
0N/A
0N/A // Create java.lang.management.ThreadInfo object
0N/A instanceOop info_obj = Management::create_thread_info_instance(ts,
0N/A monitors_array,
0N/A depths_array,
0N/A synchronizers_array,
0N/A CHECK_NULL);
0N/A result_h->obj_at_put(index, info_obj);
0N/A }
0N/A
0N/A return (jobjectArray) JNIHandles::make_local(env, result_h());
0N/AJVM_END
0N/A
0N/A// Returns an array of Class objects.
0N/AJVM_ENTRY(jobjectArray, jmm_GetLoadedClasses(JNIEnv *env))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A LoadedClassesEnumerator lce(THREAD); // Pass current Thread as parameter
0N/A
0N/A int num_classes = lce.num_loaded_classes();
1142N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), num_classes, CHECK_0);
0N/A objArrayHandle classes_ah(THREAD, r);
0N/A
0N/A for (int i = 0; i < num_classes; i++) {
0N/A KlassHandle kh = lce.get_klass(i);
0N/A oop mirror = Klass::cast(kh())->java_mirror();
0N/A classes_ah->obj_at_put(i, mirror);
0N/A }
0N/A
0N/A return (jobjectArray) JNIHandles::make_local(env, classes_ah());
0N/AJVM_END
0N/A
0N/A// Reset statistic. Return true if the requested statistic is reset.
0N/A// Otherwise, return false.
0N/A//
0N/A// Input parameters:
0N/A// obj - specify which instance the statistic associated with to be reset
0N/A// For PEAK_POOL_USAGE stat, obj is required to be a memory pool object.
0N/A// For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID.
0N/A// type - the type of statistic to be reset
0N/A//
0N/AJVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A switch (type) {
0N/A case JMM_STAT_PEAK_THREAD_COUNT:
0N/A ThreadService::reset_peak_thread_count();
0N/A return true;
0N/A
0N/A case JMM_STAT_THREAD_CONTENTION_COUNT:
0N/A case JMM_STAT_THREAD_CONTENTION_TIME: {
0N/A jlong tid = obj.j;
0N/A if (tid < 0) {
0N/A THROW_(vmSymbols::java_lang_IllegalArgumentException(), JNI_FALSE);
0N/A }
0N/A
0N/A // Look for the JavaThread of this given tid
0N/A MutexLockerEx ml(Threads_lock);
0N/A if (tid == 0) {
0N/A // reset contention statistics for all threads if tid == 0
0N/A for (JavaThread* java_thread = Threads::first(); java_thread != NULL; java_thread = java_thread->next()) {
0N/A if (type == JMM_STAT_THREAD_CONTENTION_COUNT) {
0N/A ThreadService::reset_contention_count_stat(java_thread);
0N/A } else {
0N/A ThreadService::reset_contention_time_stat(java_thread);
0N/A }
0N/A }
0N/A } else {
0N/A // reset contention statistics for a given thread
0N/A JavaThread* java_thread = find_java_thread_from_id(tid);
0N/A if (java_thread == NULL) {
0N/A return false;
0N/A }
0N/A
0N/A if (type == JMM_STAT_THREAD_CONTENTION_COUNT) {
0N/A ThreadService::reset_contention_count_stat(java_thread);
0N/A } else {
0N/A ThreadService::reset_contention_time_stat(java_thread);
0N/A }
0N/A }
0N/A return true;
0N/A break;
0N/A }
0N/A case JMM_STAT_PEAK_POOL_USAGE: {
0N/A jobject o = obj.l;
0N/A if (o == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
0N/A }
0N/A
0N/A oop pool_obj = JNIHandles::resolve(o);
0N/A assert(pool_obj->is_instance(), "Should be an instanceOop");
0N/A instanceHandle ph(THREAD, (instanceOop) pool_obj);
0N/A
0N/A MemoryPool* pool = MemoryService::get_memory_pool(ph);
0N/A if (pool != NULL) {
0N/A pool->reset_peak_memory_usage();
0N/A return true;
0N/A }
0N/A break;
0N/A }
0N/A case JMM_STAT_GC_STAT: {
0N/A jobject o = obj.l;
0N/A if (o == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
0N/A }
0N/A
0N/A GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(o, CHECK_0);
0N/A if (mgr != NULL) {
0N/A mgr->reset_gc_stat();
0N/A return true;
0N/A }
0N/A break;
0N/A }
0N/A default:
0N/A assert(0, "Unknown Statistic Type");
0N/A }
0N/A return false;
0N/AJVM_END
0N/A
0N/A// Returns the fast estimate of CPU time consumed by
0N/A// a given thread (in nanoseconds).
0N/A// If thread_id == 0, return CPU time for the current thread.
0N/AJVM_ENTRY(jlong, jmm_GetThreadCpuTime(JNIEnv *env, jlong thread_id))
0N/A if (!os::is_thread_cpu_time_supported()) {
0N/A return -1;
0N/A }
0N/A
0N/A if (thread_id < 0) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Invalid thread ID", -1);
0N/A }
0N/A
0N/A JavaThread* java_thread = NULL;
0N/A if (thread_id == 0) {
0N/A // current thread
0N/A return os::current_thread_cpu_time();
0N/A } else {
0N/A MutexLockerEx ml(Threads_lock);
0N/A java_thread = find_java_thread_from_id(thread_id);
0N/A if (java_thread != NULL) {
0N/A return os::thread_cpu_time((Thread*) java_thread);
0N/A }
0N/A }
0N/A return -1;
0N/AJVM_END
0N/A
0N/A// Returns the CPU time consumed by a given thread (in nanoseconds).
0N/A// If thread_id == 0, CPU time for the current thread is returned.
0N/A// If user_sys_cpu_time = true, user level and system CPU time of
0N/A// a given thread is returned; otherwise, only user level CPU time
0N/A// is returned.
0N/AJVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time))
0N/A if (!os::is_thread_cpu_time_supported()) {
0N/A return -1;
0N/A }
0N/A
0N/A if (thread_id < 0) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Invalid thread ID", -1);
0N/A }
0N/A
0N/A JavaThread* java_thread = NULL;
0N/A if (thread_id == 0) {
0N/A // current thread
0N/A return os::current_thread_cpu_time(user_sys_cpu_time != 0);
0N/A } else {
0N/A MutexLockerEx ml(Threads_lock);
0N/A java_thread = find_java_thread_from_id(thread_id);
0N/A if (java_thread != NULL) {
0N/A return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0);
0N/A }
0N/A }
0N/A return -1;
0N/AJVM_END
0N/A
1988N/A// Gets an array containing the CPU times consumed by a set of threads
1988N/A// (in nanoseconds). Each element of the array is the CPU time for the
1988N/A// thread ID specified in the corresponding entry in the given array
1988N/A// of thread IDs; or -1 if the thread does not exist or has terminated.
1988N/A// If user_sys_cpu_time = true, the sum of user level and system CPU time
1988N/A// for the given thread is returned; otherwise, only user level CPU time
1988N/A// is returned.
1988N/AJVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids,
1988N/A jlongArray timeArray,
1988N/A jboolean user_sys_cpu_time))
1988N/A // Check if threads is null
1988N/A if (ids == NULL || timeArray == NULL) {
1988N/A THROW(vmSymbols::java_lang_NullPointerException());
1988N/A }
1988N/A
1988N/A ResourceMark rm(THREAD);
1988N/A typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
1988N/A typeArrayHandle ids_ah(THREAD, ta);
1988N/A
1988N/A typeArrayOop tia = typeArrayOop(JNIHandles::resolve_non_null(timeArray));
1988N/A typeArrayHandle timeArray_h(THREAD, tia);
1988N/A
1988N/A // validate the thread id array
1988N/A validate_thread_id_array(ids_ah, CHECK);
1988N/A
1988N/A // timeArray must be of the same length as the given array of thread IDs
1988N/A int num_threads = ids_ah->length();
1988N/A if (num_threads != timeArray_h->length()) {
1988N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1988N/A "The length of the given long array does not match the length of "
1988N/A "the given array of thread IDs");
1988N/A }
1988N/A
1988N/A MutexLockerEx ml(Threads_lock);
1988N/A for (int i = 0; i < num_threads; i++) {
1988N/A JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i));
1988N/A if (java_thread != NULL) {
1988N/A timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread,
1988N/A user_sys_cpu_time != 0));
1988N/A }
1988N/A }
1988N/AJVM_END
1988N/A
0N/A// Returns a String array of all VM global flag names
0N/AJVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
0N/A // last flag entry is always NULL, so subtract 1
0N/A int nFlags = (int) Flag::numFlags - 1;
0N/A // allocate a temp array
1142N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
0N/A nFlags, CHECK_0);
0N/A objArrayHandle flags_ah(THREAD, r);
0N/A int num_entries = 0;
0N/A for (int i = 0; i < nFlags; i++) {
0N/A Flag* flag = &Flag::flags[i];
350N/A // Exclude the locked (experimental, diagnostic) flags
0N/A if (flag->is_unlocked() || flag->is_unlocker()) {
0N/A Handle s = java_lang_String::create_from_str(flag->name, CHECK_0);
0N/A flags_ah->obj_at_put(num_entries, s());
0N/A num_entries++;
0N/A }
0N/A }
0N/A
0N/A if (num_entries < nFlags) {
0N/A // Return array of right length
1142N/A objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0);
0N/A for(int i = 0; i < num_entries; i++) {
0N/A res->obj_at_put(i, flags_ah->obj_at(i));
0N/A }
0N/A return (jobjectArray)JNIHandles::make_local(env, res);
0N/A }
0N/A
0N/A return (jobjectArray)JNIHandles::make_local(env, flags_ah());
0N/AJVM_END
0N/A
1067N/A// Utility function used by jmm_GetVMGlobals. Returns false if flag type
1067N/A// can't be determined, true otherwise. If false is returned, then *global
1067N/A// will be incomplete and invalid.
1067N/Abool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) {
0N/A Handle flag_name;
0N/A if (name() == NULL) {
1067N/A flag_name = java_lang_String::create_from_str(flag->name, CHECK_false);
0N/A } else {
0N/A flag_name = name;
0N/A }
0N/A global->name = (jstring)JNIHandles::make_local(env, flag_name());
0N/A
0N/A if (flag->is_bool()) {
0N/A global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
0N/A global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
0N/A } else if (flag->is_intx()) {
0N/A global->value.j = (jlong)flag->get_intx();
0N/A global->type = JMM_VMGLOBAL_TYPE_JLONG;
0N/A } else if (flag->is_uintx()) {
0N/A global->value.j = (jlong)flag->get_uintx();
0N/A global->type = JMM_VMGLOBAL_TYPE_JLONG;
1067N/A } else if (flag->is_uint64_t()) {
1067N/A global->value.j = (jlong)flag->get_uint64_t();
1067N/A global->type = JMM_VMGLOBAL_TYPE_JLONG;
0N/A } else if (flag->is_ccstr()) {
1067N/A Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
0N/A global->value.l = (jobject)JNIHandles::make_local(env, str());
0N/A global->type = JMM_VMGLOBAL_TYPE_JSTRING;
1067N/A } else {
1067N/A global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
1067N/A return false;
0N/A }
0N/A
0N/A global->writeable = flag->is_writeable();
0N/A global->external = flag->is_external();
0N/A switch (flag->origin) {
0N/A case DEFAULT:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
0N/A break;
0N/A case COMMAND_LINE:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
0N/A break;
0N/A case ENVIRON_VAR:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
0N/A break;
0N/A case CONFIG_FILE:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
0N/A break;
0N/A case MANAGEMENT:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT;
0N/A break;
0N/A case ERGONOMIC:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC;
0N/A break;
0N/A default:
0N/A global->origin = JMM_VMGLOBAL_ORIGIN_OTHER;
0N/A }
1067N/A
1067N/A return true;
0N/A}
0N/A
0N/A// Fill globals array of count length with jmmVMGlobal entries
0N/A// specified by names. If names == NULL, fill globals array
0N/A// with all Flags. Return value is number of entries
0N/A// created in globals.
0N/A// If a Flag with a given name in an array element does not
0N/A// exist, globals[i].name will be set to NULL.
0N/AJVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env,
0N/A jobjectArray names,
0N/A jmmVMGlobal *globals,
0N/A jint count))
0N/A
0N/A
0N/A if (globals == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), 0);
0N/A }
0N/A
0N/A ResourceMark rm(THREAD);
0N/A
0N/A if (names != NULL) {
0N/A // return the requested globals
0N/A objArrayOop ta = objArrayOop(JNIHandles::resolve_non_null(names));
0N/A objArrayHandle names_ah(THREAD, ta);
0N/A // Make sure we have a String array
0N/A klassOop element_klass = objArrayKlass::cast(names_ah->klass())->element_klass();
1142N/A if (element_klass != SystemDictionary::String_klass()) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Array element type is not String class", 0);
0N/A }
0N/A
0N/A int names_length = names_ah->length();
0N/A int num_entries = 0;
0N/A for (int i = 0; i < names_length && i < count; i++) {
0N/A oop s = names_ah->obj_at(i);
0N/A if (s == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), 0);
0N/A }
0N/A
0N/A Handle sh(THREAD, s);
0N/A char* str = java_lang_String::as_utf8_string(s);
0N/A Flag* flag = Flag::find_flag(str, strlen(str));
1067N/A if (flag != NULL &&
1067N/A add_global_entry(env, sh, &globals[i], flag, THREAD)) {
0N/A num_entries++;
0N/A } else {
0N/A globals[i].name = NULL;
0N/A }
0N/A }
0N/A return num_entries;
0N/A } else {
0N/A // return all globals if names == NULL
0N/A
0N/A // last flag entry is always NULL, so subtract 1
0N/A int nFlags = (int) Flag::numFlags - 1;
0N/A Handle null_h;
0N/A int num_entries = 0;
0N/A for (int i = 0; i < nFlags && num_entries < count; i++) {
0N/A Flag* flag = &Flag::flags[i];
350N/A // Exclude the locked (diagnostic, experimental) flags
1067N/A if ((flag->is_unlocked() || flag->is_unlocker()) &&
1067N/A add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
0N/A num_entries++;
0N/A }
0N/A }
0N/A return num_entries;
0N/A }
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A oop fn = JNIHandles::resolve_external_guard(flag_name);
0N/A if (fn == NULL) {
0N/A THROW_MSG(vmSymbols::java_lang_NullPointerException(),
0N/A "The flag name cannot be null.");
0N/A }
0N/A char* name = java_lang_String::as_utf8_string(fn);
0N/A Flag* flag = Flag::find_flag(name, strlen(name));
0N/A if (flag == NULL) {
0N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Flag does not exist.");
0N/A }
0N/A if (!flag->is_writeable()) {
0N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "This flag is not writeable.");
0N/A }
0N/A
0N/A bool succeed;
0N/A if (flag->is_bool()) {
0N/A bool bvalue = (new_value.z == JNI_TRUE ? true : false);
0N/A succeed = CommandLineFlags::boolAtPut(name, &bvalue, MANAGEMENT);
0N/A } else if (flag->is_intx()) {
1067N/A intx ivalue = (intx)new_value.j;
0N/A succeed = CommandLineFlags::intxAtPut(name, &ivalue, MANAGEMENT);
0N/A } else if (flag->is_uintx()) {
1067N/A uintx uvalue = (uintx)new_value.j;
0N/A succeed = CommandLineFlags::uintxAtPut(name, &uvalue, MANAGEMENT);
1067N/A } else if (flag->is_uint64_t()) {
1067N/A uint64_t uvalue = (uint64_t)new_value.j;
1067N/A succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, MANAGEMENT);
0N/A } else if (flag->is_ccstr()) {
0N/A oop str = JNIHandles::resolve_external_guard(new_value.l);
0N/A if (str == NULL) {
0N/A THROW(vmSymbols::java_lang_NullPointerException());
0N/A }
0N/A ccstr svalue = java_lang_String::as_utf8_string(str);
0N/A succeed = CommandLineFlags::ccstrAtPut(name, &svalue, MANAGEMENT);
0N/A }
0N/A assert(succeed, "Setting flag should succeed");
0N/AJVM_END
0N/A
0N/Aclass ThreadTimesClosure: public ThreadClosure {
0N/A private:
4088N/A objArrayHandle _names_strings;
4088N/A char **_names_chars;
0N/A typeArrayOop _times;
0N/A int _names_len;
0N/A int _times_len;
0N/A int _count;
0N/A
0N/A public:
4088N/A ThreadTimesClosure(objArrayHandle names, typeArrayOop times);
4088N/A ~ThreadTimesClosure();
0N/A virtual void do_thread(Thread* thread);
4088N/A void do_unlocked();
0N/A int count() { return _count; }
0N/A};
0N/A
4088N/AThreadTimesClosure::ThreadTimesClosure(objArrayHandle names,
0N/A typeArrayOop times) {
4088N/A assert(names() != NULL, "names was NULL");
0N/A assert(times != NULL, "times was NULL");
4088N/A _names_strings = names;
0N/A _names_len = names->length();
4088N/A _names_chars = NEW_C_HEAP_ARRAY(char*, _names_len, mtInternal);
0N/A _times = times;
0N/A _times_len = times->length();
0N/A _count = 0;
0N/A}
0N/A
4088N/A//
4088N/A// Called with Threads_lock held
4088N/A//
0N/Avoid ThreadTimesClosure::do_thread(Thread* thread) {
0N/A assert(thread != NULL, "thread was NULL");
0N/A
0N/A // exclude externally visible JavaThreads
0N/A if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
0N/A return;
0N/A }
0N/A
0N/A if (_count >= _names_len || _count >= _times_len) {
0N/A // skip if the result array is not big enough
0N/A return;
0N/A }
0N/A
0N/A EXCEPTION_MARK;
4088N/A ResourceMark rm(THREAD); // thread->name() uses ResourceArea
0N/A
0N/A assert(thread->name() != NULL, "All threads should have a name");
4088N/A _names_chars[_count] = strdup(thread->name());
0N/A _times->long_at_put(_count, os::is_thread_cpu_time_supported() ?
0N/A os::thread_cpu_time(thread) : -1);
0N/A _count++;
0N/A}
0N/A
4088N/A// Called without Threads_lock, we can allocate String objects.
4088N/Avoid ThreadTimesClosure::do_unlocked() {
4088N/A
4088N/A EXCEPTION_MARK;
4088N/A for (int i = 0; i < _count; i++) {
4088N/A Handle s = java_lang_String::create_from_str(_names_chars[i], CHECK);
4088N/A _names_strings->obj_at_put(i, s());
4088N/A }
4088N/A}
4088N/A
4088N/AThreadTimesClosure::~ThreadTimesClosure() {
4088N/A for (int i = 0; i < _count; i++) {
4088N/A free(_names_chars[i]);
4088N/A }
4088N/A FREE_C_HEAP_ARRAY(char *, _names_chars, mtInternal);
4088N/A}
4088N/A
0N/A// Fills names with VM internal thread names and times with the corresponding
0N/A// CPU times. If names or times is NULL, a NullPointerException is thrown.
0N/A// If the element type of names is not String, an IllegalArgumentException is
0N/A// thrown.
0N/A// If an array is not large enough to hold all the entries, only the entries
0N/A// that fit will be returned. Return value is the number of VM internal
0N/A// threads entries.
0N/AJVM_ENTRY(jint, jmm_GetInternalThreadTimes(JNIEnv *env,
0N/A jobjectArray names,
0N/A jlongArray times))
0N/A if (names == NULL || times == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), 0);
0N/A }
0N/A objArrayOop na = objArrayOop(JNIHandles::resolve_non_null(names));
0N/A objArrayHandle names_ah(THREAD, na);
0N/A
0N/A // Make sure we have a String array
0N/A klassOop element_klass = objArrayKlass::cast(names_ah->klass())->element_klass();
1142N/A if (element_klass != SystemDictionary::String_klass()) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "Array element type is not String class", 0);
0N/A }
0N/A
0N/A typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(times));
0N/A typeArrayHandle times_ah(THREAD, ta);
0N/A
4088N/A ThreadTimesClosure ttc(names_ah, times_ah());
0N/A {
0N/A MutexLockerEx ml(Threads_lock);
0N/A Threads::threads_do(&ttc);
0N/A }
4088N/A ttc.do_unlocked();
0N/A return ttc.count();
0N/AJVM_END
0N/A
0N/Astatic Handle find_deadlocks(bool object_monitors_only, TRAPS) {
0N/A ResourceMark rm(THREAD);
0N/A
0N/A VM_FindDeadlocks op(!object_monitors_only /* also check concurrent locks? */);
0N/A VMThread::execute(&op);
0N/A
0N/A DeadlockCycle* deadlocks = op.result();
0N/A if (deadlocks == NULL) {
0N/A // no deadlock found and return
0N/A return Handle();
0N/A }
0N/A
0N/A int num_threads = 0;
0N/A DeadlockCycle* cycle;
0N/A for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) {
0N/A num_threads += cycle->num_threads();
0N/A }
0N/A
1142N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NH);
0N/A objArrayHandle threads_ah(THREAD, r);
0N/A
0N/A int index = 0;
0N/A for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) {
0N/A GrowableArray<JavaThread*>* deadlock_threads = cycle->threads();
0N/A int len = deadlock_threads->length();
0N/A for (int i = 0; i < len; i++) {
0N/A threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj());
0N/A index++;
0N/A }
0N/A }
0N/A return threads_ah;
0N/A}
0N/A
0N/A// Finds cycles of threads that are deadlocked involved in object monitors
0N/A// and JSR-166 synchronizers.
0N/A// Returns an array of Thread objects which are in deadlock, if any.
0N/A// Otherwise, returns NULL.
0N/A//
0N/A// Input parameter:
0N/A// object_monitors_only - if true, only check object monitors
0N/A//
0N/AJVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only))
0N/A Handle result = find_deadlocks(object_monitors_only != 0, CHECK_0);
0N/A return (jobjectArray) JNIHandles::make_local(env, result());
0N/AJVM_END
0N/A
0N/A// Finds cycles of threads that are deadlocked on monitor locks
0N/A// Returns an array of Thread objects which are in deadlock, if any.
0N/A// Otherwise, returns NULL.
0N/AJVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env))
0N/A Handle result = find_deadlocks(true, CHECK_0);
0N/A return (jobjectArray) JNIHandles::make_local(env, result());
0N/AJVM_END
0N/A
0N/A// Gets the information about GC extension attributes including
0N/A// the name of the attribute, its type, and a short description.
0N/A//
0N/A// Input parameters:
0N/A// mgr - GC memory manager
0N/A// info - caller allocated array of jmmExtAttributeInfo
0N/A// count - number of elements of the info array
0N/A//
0N/A// Returns the number of GC extension attributes filled in the info array; or
0N/A// -1 if info is not big enough
0N/A//
0N/AJVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count))
0N/A // All GC memory managers have 1 attribute (number of GC threads)
0N/A if (count == 0) {
0N/A return 0;
0N/A }
0N/A
0N/A if (info == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), 0);
0N/A }
0N/A
0N/A info[0].name = "GcThreadCount";
0N/A info[0].type = 'I';
0N/A info[0].description = "Number of GC threads";
0N/A return 1;
0N/AJVM_END
0N/A
0N/A// verify the given array is an array of java/lang/management/MemoryUsage objects
0N/A// of a given length and return the objArrayOop
0N/Astatic objArrayOop get_memory_usage_objArray(jobjectArray array, int length, TRAPS) {
0N/A if (array == NULL) {
0N/A THROW_(vmSymbols::java_lang_NullPointerException(), 0);
0N/A }
0N/A
0N/A objArrayOop oa = objArrayOop(JNIHandles::resolve_non_null(array));
0N/A objArrayHandle array_h(THREAD, oa);
0N/A
0N/A // array must be of the given length
0N/A if (length != array_h->length()) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "The length of the given MemoryUsage array does not match the number of memory pools.", 0);
0N/A }
0N/A
0N/A // check if the element of array is of type MemoryUsage class
0N/A klassOop usage_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_0);
0N/A klassOop element_klass = objArrayKlass::cast(array_h->klass())->element_klass();
0N/A if (element_klass != usage_klass) {
0N/A THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
0N/A "The element type is not MemoryUsage class", 0);
0N/A }
0N/A
0N/A return array_h();
0N/A}
0N/A
0N/A// Gets the statistics of the last GC of a given GC memory manager.
0N/A// Input parameters:
0N/A// obj - GarbageCollectorMXBean object
0N/A// gc_stat - caller allocated jmmGCStat where:
0N/A// a. before_gc_usage - array of MemoryUsage objects
0N/A// b. after_gc_usage - array of MemoryUsage objects
0N/A// c. gc_ext_attributes_values_size is set to the
0N/A// gc_ext_attribute_values array allocated
0N/A// d. gc_ext_attribute_values is a caller allocated array of jvalue.
0N/A//
0N/A// On return,
0N/A// gc_index == 0 indicates no GC statistics available
0N/A//
0N/A// before_gc_usage and after_gc_usage - filled with per memory pool
0N/A// before and after GC usage in the same order as the memory pools
0N/A// returned by GetMemoryPools for a given GC memory manager.
0N/A// num_gc_ext_attributes indicates the number of elements in
0N/A// the gc_ext_attribute_values array is filled; or
0N/A// -1 if the gc_ext_attributes_values array is not big enough
0N/A//
0N/AJVM_ENTRY(void, jmm_GetLastGCStat(JNIEnv *env, jobject obj, jmmGCStat *gc_stat))
0N/A ResourceMark rm(THREAD);
0N/A
0N/A if (gc_stat->gc_ext_attribute_values_size > 0 && gc_stat->gc_ext_attribute_values == NULL) {
0N/A THROW(vmSymbols::java_lang_NullPointerException());
0N/A }
0N/A
0N/A // Get the GCMemoryManager
0N/A GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK);
0N/A
0N/A // Make a copy of the last GC statistics
0N/A // GC may occur while constructing the last GC information
0N/A int num_pools = MemoryService::num_memory_pools();
3127N/A GCStatInfo stat(num_pools);
3127N/A if (mgr->get_last_gc_stat(&stat) == 0) {
1623N/A gc_stat->gc_index = 0;
1623N/A return;
1623N/A }
0N/A
3127N/A gc_stat->gc_index = stat.gc_index();
3127N/A gc_stat->start_time = Management::ticks_to_ms(stat.start_time());
3127N/A gc_stat->end_time = Management::ticks_to_ms(stat.end_time());
0N/A
0N/A // Current implementation does not have GC extension attributes
0N/A gc_stat->num_gc_ext_attributes = 0;
0N/A
0N/A // Fill the arrays of MemoryUsage objects with before and after GC
0N/A // per pool memory usage
0N/A objArrayOop bu = get_memory_usage_objArray(gc_stat->usage_before_gc,
0N/A num_pools,
0N/A CHECK);
0N/A objArrayHandle usage_before_gc_ah(THREAD, bu);
0N/A
0N/A objArrayOop au = get_memory_usage_objArray(gc_stat->usage_after_gc,
0N/A num_pools,
0N/A CHECK);
0N/A objArrayHandle usage_after_gc_ah(THREAD, au);
0N/A
0N/A for (int i = 0; i < num_pools; i++) {
3127N/A Handle before_usage = MemoryService::create_MemoryUsage_obj(stat.before_gc_usage_for_pool(i), CHECK);
0N/A Handle after_usage;
0N/A
3127N/A MemoryUsage u = stat.after_gc_usage_for_pool(i);
0N/A if (u.max_size() == 0 && u.used() > 0) {
0N/A // If max size == 0, this pool is a survivor space.
0N/A // Set max size = -1 since the pools will be swapped after GC.
0N/A MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1);
0N/A after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK);
0N/A } else {
3127N/A after_usage = MemoryService::create_MemoryUsage_obj(stat.after_gc_usage_for_pool(i), CHECK);
0N/A }
0N/A usage_before_gc_ah->obj_at_put(i, before_usage());
0N/A usage_after_gc_ah->obj_at_put(i, after_usage());
0N/A }
0N/A
0N/A if (gc_stat->gc_ext_attribute_values_size > 0) {
0N/A // Current implementation only has 1 attribute (number of GC threads)
0N/A // The type is 'I'
0N/A gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads();
0N/A }
0N/AJVM_END
0N/A
2453N/AJVM_ENTRY(void, jmm_SetGCNotificationEnabled(JNIEnv *env, jobject obj, jboolean enabled))
2453N/A ResourceMark rm(THREAD);
2453N/A // Get the GCMemoryManager
2453N/A GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK);
2453N/A mgr->set_notification_enabled(enabled?true:false);
2453N/AJVM_END
2453N/A
0N/A// Dump heap - Returns 0 if succeeds.
0N/AJVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live))
0N/A ResourceMark rm(THREAD);
0N/A oop on = JNIHandles::resolve_external_guard(outputfile);
0N/A if (on == NULL) {
0N/A THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
0N/A "Output file name cannot be null.", -1);
0N/A }
0N/A char* name = java_lang_String::as_utf8_string(on);
0N/A if (name == NULL) {
0N/A THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
0N/A "Output file name cannot be null.", -1);
0N/A }
0N/A HeapDumper dumper(live ? true : false);
0N/A if (dumper.dump(name) != 0) {
0N/A const char* errmsg = dumper.error_as_C_string();
0N/A THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
0N/A }
0N/A return 0;
0N/AJVM_END
0N/A
2976N/AJVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
2976N/A ResourceMark rm(THREAD);
2976N/A GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list();
2976N/A objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
2976N/A dcmd_list->length(), CHECK_NULL);
2976N/A objArrayHandle cmd_array(THREAD, cmd_array_oop);
2976N/A for (int i = 0; i < dcmd_list->length(); i++) {
2976N/A oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
2976N/A cmd_array->obj_at_put(i, cmd_name);
2976N/A }
2976N/A return (jobjectArray) JNIHandles::make_local(env, cmd_array());
2976N/AJVM_END
2976N/A
2976N/AJVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
2976N/A dcmdInfo* infoArray))
2976N/A if (cmds == NULL || infoArray == NULL) {
2976N/A THROW(vmSymbols::java_lang_NullPointerException());
2976N/A }
2976N/A
2976N/A ResourceMark rm(THREAD);
2976N/A
2976N/A objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
2976N/A objArrayHandle cmds_ah(THREAD, ca);
2976N/A
2976N/A // Make sure we have a String array
2976N/A klassOop element_klass = objArrayKlass::cast(cmds_ah->klass())->element_klass();
2976N/A if (element_klass != SystemDictionary::String_klass()) {
2976N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2976N/A "Array element type is not String class");
2976N/A }
2976N/A
2976N/A GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list();
2976N/A
2976N/A int num_cmds = cmds_ah->length();
2976N/A for (int i = 0; i < num_cmds; i++) {
2976N/A oop cmd = cmds_ah->obj_at(i);
2976N/A if (cmd == NULL) {
2976N/A THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2976N/A "Command name cannot be null.");
2976N/A }
2976N/A char* cmd_name = java_lang_String::as_utf8_string(cmd);
2976N/A if (cmd_name == NULL) {
2976N/A THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2976N/A "Command name cannot be null.");
2976N/A }
2976N/A int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name);
2976N/A if (pos == -1) {
2976N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2976N/A "Unknown diagnostic command");
2976N/A }
2976N/A DCmdInfo* info = info_list->at(pos);
2976N/A infoArray[i].name = info->name();
2976N/A infoArray[i].description = info->description();
2976N/A infoArray[i].impact = info->impact();
2976N/A infoArray[i].num_arguments = info->num_arguments();
2976N/A infoArray[i].enabled = info->is_enabled();
2976N/A }
2976N/AJVM_END
2976N/A
2976N/AJVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
2976N/A jstring command, dcmdArgInfo* infoArray))
2976N/A ResourceMark rm(THREAD);
2976N/A oop cmd = JNIHandles::resolve_external_guard(command);
2976N/A if (cmd == NULL) {
2976N/A THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2976N/A "Command line cannot be null.");
2976N/A }
2976N/A char* cmd_name = java_lang_String::as_utf8_string(cmd);
2976N/A if (cmd_name == NULL) {
2976N/A THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2976N/A "Command line content cannot be null.");
2976N/A }
2976N/A DCmd* dcmd = NULL;
2976N/A DCmdFactory*factory = DCmdFactory::factory(cmd_name, strlen(cmd_name));
2976N/A if (factory != NULL) {
2976N/A dcmd = factory->create_resource_instance(NULL);
2976N/A }
2976N/A if (dcmd == NULL) {
2976N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2976N/A "Unknown diagnostic command");
2976N/A }
2976N/A DCmdMark mark(dcmd);
2976N/A GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array();
2976N/A if (array->length() == 0) {
2976N/A return;
2976N/A }
2976N/A for (int i = 0; i < array->length(); i++) {
2976N/A infoArray[i].name = array->at(i)->name();
2976N/A infoArray[i].description = array->at(i)->description();
2976N/A infoArray[i].type = array->at(i)->type();
2976N/A infoArray[i].default_string = array->at(i)->default_string();
2976N/A infoArray[i].mandatory = array->at(i)->is_mandatory();
2976N/A infoArray[i].option = array->at(i)->is_option();
2976N/A infoArray[i].position = array->at(i)->position();
2976N/A }
2976N/A return;
2976N/AJVM_END
2976N/A
2976N/AJVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2976N/A ResourceMark rm(THREAD);
2976N/A oop cmd = JNIHandles::resolve_external_guard(commandline);
2976N/A if (cmd == NULL) {
2976N/A THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2976N/A "Command line cannot be null.");
2976N/A }
2976N/A char* cmdline = java_lang_String::as_utf8_string(cmd);
2976N/A if (cmdline == NULL) {
2976N/A THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2976N/A "Command line content cannot be null.");
2976N/A }
2976N/A bufferedStream output;
2976N/A DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL);
2976N/A oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2976N/A return (jstring) JNIHandles::make_local(env, result);
2976N/AJVM_END
2976N/A
0N/Ajlong Management::ticks_to_ms(jlong ticks) {
0N/A assert(os::elapsed_frequency() > 0, "Must be non-zero");
0N/A return (jlong)(((double)ticks / (double)os::elapsed_frequency())
0N/A * (double)1000.0);
0N/A}
0N/A
0N/Aconst struct jmmInterface_1_ jmm_interface = {
0N/A NULL,
0N/A NULL,
0N/A jmm_GetVersion,
0N/A jmm_GetOptionalSupport,
0N/A jmm_GetInputArguments,
0N/A jmm_GetThreadInfo,
0N/A jmm_GetInputArgumentArray,
0N/A jmm_GetMemoryPools,
0N/A jmm_GetMemoryManagers,
0N/A jmm_GetMemoryPoolUsage,
0N/A jmm_GetPeakMemoryPoolUsage,
1988N/A jmm_GetThreadAllocatedMemory,
0N/A jmm_GetMemoryUsage,
0N/A jmm_GetLongAttribute,
0N/A jmm_GetBoolAttribute,
0N/A jmm_SetBoolAttribute,
0N/A jmm_GetLongAttributes,
0N/A jmm_FindMonitorDeadlockedThreads,
0N/A jmm_GetThreadCpuTime,
0N/A jmm_GetVMGlobalNames,
0N/A jmm_GetVMGlobals,
0N/A jmm_GetInternalThreadTimes,
0N/A jmm_ResetStatistic,
0N/A jmm_SetPoolSensor,
0N/A jmm_SetPoolThreshold,
0N/A jmm_GetPoolCollectionUsage,
0N/A jmm_GetGCExtAttributeInfo,
0N/A jmm_GetLastGCStat,
0N/A jmm_GetThreadCpuTimeWithKind,
1988N/A jmm_GetThreadCpuTimesWithKind,
0N/A jmm_DumpHeap0,
0N/A jmm_FindDeadlockedThreads,
0N/A jmm_SetVMGlobal,
0N/A NULL,
2453N/A jmm_DumpThreads,
2976N/A jmm_SetGCNotificationEnabled,
2976N/A jmm_GetDiagnosticCommands,
2976N/A jmm_GetDiagnosticCommandInfo,
2976N/A jmm_GetDiagnosticCommandArgumentsInfo,
2976N/A jmm_ExecuteDiagnosticCommand
0N/A};
0N/A
0N/Avoid* Management::get_jmm_interface(int version) {
0N/A if (version == JMM_VERSION_1_0) {
0N/A return (void*) &jmm_interface;
0N/A }
0N/A return NULL;
0N/A}