1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/services/management.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,135 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_SERVICES_MANAGEMENT_HPP 1.29 +#define SHARE_VM_SERVICES_MANAGEMENT_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "runtime/handles.hpp" 1.33 +#include "runtime/timer.hpp" 1.34 +#include "services/jmm.h" 1.35 + 1.36 +class OopClosure; 1.37 +class ThreadSnapshot; 1.38 + 1.39 +class Management : public AllStatic { 1.40 +private: 1.41 + static PerfVariable* _begin_vm_creation_time; 1.42 + static PerfVariable* _end_vm_creation_time; 1.43 + static PerfVariable* _vm_init_done_time; 1.44 + static jmmOptionalSupport _optional_support; 1.45 + static TimeStamp _stamp; // Timestamp since vm init done time 1.46 + 1.47 + // Management klasses 1.48 + static Klass* _sensor_klass; 1.49 + static Klass* _threadInfo_klass; 1.50 + static Klass* _memoryUsage_klass; 1.51 + static Klass* _memoryPoolMXBean_klass; 1.52 + static Klass* _memoryManagerMXBean_klass; 1.53 + static Klass* _garbageCollectorMXBean_klass; 1.54 + static Klass* _managementFactory_klass; 1.55 + static Klass* _garbageCollectorImpl_klass; 1.56 + static Klass* _diagnosticCommandImpl_klass; 1.57 + static Klass* _managementFactoryHelper_klass; 1.58 + static Klass* _gcInfo_klass; 1.59 + 1.60 + static Klass* load_and_initialize_klass(Symbol* sh, TRAPS); 1.61 + 1.62 +public: 1.63 + static void init(); 1.64 + static void initialize(TRAPS); 1.65 + 1.66 + static jlong ticks_to_ms(jlong ticks) NOT_MANAGEMENT_RETURN_(0L); 1.67 + static jlong timestamp() NOT_MANAGEMENT_RETURN_(0L); 1.68 + 1.69 + static void oops_do(OopClosure* f) NOT_MANAGEMENT_RETURN; 1.70 + static void* get_jmm_interface(int version); 1.71 + static void get_optional_support(jmmOptionalSupport* support); 1.72 + 1.73 + static void get_loaded_classes(JavaThread* cur_thread, GrowableArray<KlassHandle>* klass_handle_array); 1.74 + 1.75 + static void record_vm_startup_time(jlong begin, jlong duration) 1.76 + NOT_MANAGEMENT_RETURN; 1.77 + static void record_vm_init_completed() { 1.78 + // Initialize the timestamp to get the current time 1.79 + _vm_init_done_time->set_value(os::javaTimeMillis()); 1.80 + 1.81 + // Update the timestamp to the vm init done time 1.82 + _stamp.update(); 1.83 + } 1.84 + 1.85 + static jlong begin_vm_creation_time() { 1.86 + return _begin_vm_creation_time->get_value(); 1.87 + } 1.88 + static jlong vm_init_done_time() { 1.89 + return _vm_init_done_time->get_value(); 1.90 + } 1.91 + 1.92 + // methods to return a Klass*. 1.93 + static Klass* java_lang_management_ThreadInfo_klass(TRAPS); 1.94 + static Klass* java_lang_management_MemoryUsage_klass(TRAPS) 1.95 + NOT_MANAGEMENT_RETURN_(NULL); 1.96 + static Klass* java_lang_management_MemoryPoolMXBean_klass(TRAPS); 1.97 + static Klass* java_lang_management_MemoryManagerMXBean_klass(TRAPS); 1.98 + static Klass* java_lang_management_GarbageCollectorMXBean_klass(TRAPS); 1.99 + static Klass* sun_management_Sensor_klass(TRAPS) 1.100 + NOT_MANAGEMENT_RETURN_(NULL); 1.101 + static Klass* sun_management_ManagementFactory_klass(TRAPS) 1.102 + NOT_MANAGEMENT_RETURN_(NULL); 1.103 + static Klass* sun_management_GarbageCollectorImpl_klass(TRAPS) 1.104 + NOT_MANAGEMENT_RETURN_(NULL); 1.105 + static Klass* com_sun_management_GcInfo_klass(TRAPS) 1.106 + NOT_MANAGEMENT_RETURN_(NULL); 1.107 + static Klass* sun_management_DiagnosticCommandImpl_klass(TRAPS) 1.108 + NOT_MANAGEMENT_RETURN_(NULL); 1.109 + static Klass* sun_management_ManagementFactoryHelper_klass(TRAPS) 1.110 + NOT_MANAGEMENT_RETURN_(NULL); 1.111 + 1.112 + static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS); 1.113 + static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, objArrayHandle monitors_array, typeArrayHandle depths_array, objArrayHandle synchronizers_array, TRAPS); 1.114 +}; 1.115 + 1.116 +class TraceVmCreationTime : public StackObj { 1.117 +private: 1.118 + TimeStamp _timer; 1.119 + jlong _begin_time; 1.120 + 1.121 +public: 1.122 + TraceVmCreationTime() {} 1.123 + ~TraceVmCreationTime() {} 1.124 + 1.125 + void start() 1.126 + { _timer.update_to(0); _begin_time = os::javaTimeMillis(); } 1.127 + 1.128 + /** 1.129 + * Only call this if initialization completes successfully; it will 1.130 + * crash if PerfMemory_exit() has already been called (usually by 1.131 + * os::shutdown() when there was an initialization failure). 1.132 + */ 1.133 + void end() 1.134 + { Management::record_vm_startup_time(_begin_time, _timer.milliseconds()); } 1.135 + 1.136 +}; 1.137 + 1.138 +#endif // SHARE_VM_SERVICES_MANAGEMENT_HPP