Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_SERVICES_MANAGEMENT_HPP |
aoqi@0 | 26 | #define SHARE_VM_SERVICES_MANAGEMENT_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "memory/allocation.hpp" |
aoqi@0 | 29 | #include "runtime/handles.hpp" |
aoqi@0 | 30 | #include "runtime/timer.hpp" |
aoqi@0 | 31 | #include "services/jmm.h" |
aoqi@0 | 32 | |
aoqi@0 | 33 | class OopClosure; |
aoqi@0 | 34 | class ThreadSnapshot; |
aoqi@0 | 35 | |
aoqi@0 | 36 | class Management : public AllStatic { |
aoqi@0 | 37 | private: |
aoqi@0 | 38 | static PerfVariable* _begin_vm_creation_time; |
aoqi@0 | 39 | static PerfVariable* _end_vm_creation_time; |
aoqi@0 | 40 | static PerfVariable* _vm_init_done_time; |
aoqi@0 | 41 | static jmmOptionalSupport _optional_support; |
aoqi@0 | 42 | static TimeStamp _stamp; // Timestamp since vm init done time |
aoqi@0 | 43 | |
aoqi@0 | 44 | // Management klasses |
aoqi@0 | 45 | static Klass* _sensor_klass; |
aoqi@0 | 46 | static Klass* _threadInfo_klass; |
aoqi@0 | 47 | static Klass* _memoryUsage_klass; |
aoqi@0 | 48 | static Klass* _memoryPoolMXBean_klass; |
aoqi@0 | 49 | static Klass* _memoryManagerMXBean_klass; |
aoqi@0 | 50 | static Klass* _garbageCollectorMXBean_klass; |
aoqi@0 | 51 | static Klass* _managementFactory_klass; |
aoqi@0 | 52 | static Klass* _garbageCollectorImpl_klass; |
aoqi@0 | 53 | static Klass* _diagnosticCommandImpl_klass; |
aoqi@0 | 54 | static Klass* _managementFactoryHelper_klass; |
aoqi@0 | 55 | static Klass* _gcInfo_klass; |
aoqi@0 | 56 | |
aoqi@0 | 57 | static Klass* load_and_initialize_klass(Symbol* sh, TRAPS); |
aoqi@0 | 58 | |
aoqi@0 | 59 | public: |
aoqi@0 | 60 | static void init(); |
aoqi@0 | 61 | static void initialize(TRAPS); |
aoqi@0 | 62 | |
aoqi@0 | 63 | static jlong ticks_to_ms(jlong ticks) NOT_MANAGEMENT_RETURN_(0L); |
aoqi@0 | 64 | static jlong timestamp() NOT_MANAGEMENT_RETURN_(0L); |
aoqi@0 | 65 | |
aoqi@0 | 66 | static void oops_do(OopClosure* f) NOT_MANAGEMENT_RETURN; |
aoqi@0 | 67 | static void* get_jmm_interface(int version); |
aoqi@0 | 68 | static void get_optional_support(jmmOptionalSupport* support); |
aoqi@0 | 69 | |
aoqi@0 | 70 | static void get_loaded_classes(JavaThread* cur_thread, GrowableArray<KlassHandle>* klass_handle_array); |
aoqi@0 | 71 | |
aoqi@0 | 72 | static void record_vm_startup_time(jlong begin, jlong duration) |
aoqi@0 | 73 | NOT_MANAGEMENT_RETURN; |
aoqi@0 | 74 | static void record_vm_init_completed() { |
aoqi@0 | 75 | // Initialize the timestamp to get the current time |
aoqi@0 | 76 | _vm_init_done_time->set_value(os::javaTimeMillis()); |
aoqi@0 | 77 | |
aoqi@0 | 78 | // Update the timestamp to the vm init done time |
aoqi@0 | 79 | _stamp.update(); |
aoqi@0 | 80 | } |
aoqi@0 | 81 | |
aoqi@0 | 82 | static jlong begin_vm_creation_time() { |
aoqi@0 | 83 | return _begin_vm_creation_time->get_value(); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | static jlong vm_init_done_time() { |
aoqi@0 | 86 | return _vm_init_done_time->get_value(); |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | // methods to return a Klass*. |
aoqi@0 | 90 | static Klass* java_lang_management_ThreadInfo_klass(TRAPS); |
aoqi@0 | 91 | static Klass* java_lang_management_MemoryUsage_klass(TRAPS) |
aoqi@0 | 92 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 93 | static Klass* java_lang_management_MemoryPoolMXBean_klass(TRAPS); |
aoqi@0 | 94 | static Klass* java_lang_management_MemoryManagerMXBean_klass(TRAPS); |
aoqi@0 | 95 | static Klass* java_lang_management_GarbageCollectorMXBean_klass(TRAPS); |
aoqi@0 | 96 | static Klass* sun_management_Sensor_klass(TRAPS) |
aoqi@0 | 97 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 98 | static Klass* sun_management_ManagementFactory_klass(TRAPS) |
aoqi@0 | 99 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 100 | static Klass* sun_management_GarbageCollectorImpl_klass(TRAPS) |
aoqi@0 | 101 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 102 | static Klass* com_sun_management_GcInfo_klass(TRAPS) |
aoqi@0 | 103 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 104 | static Klass* sun_management_DiagnosticCommandImpl_klass(TRAPS) |
aoqi@0 | 105 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 106 | static Klass* sun_management_ManagementFactoryHelper_klass(TRAPS) |
aoqi@0 | 107 | NOT_MANAGEMENT_RETURN_(NULL); |
aoqi@0 | 108 | |
aoqi@0 | 109 | static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS); |
aoqi@0 | 110 | static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, objArrayHandle monitors_array, typeArrayHandle depths_array, objArrayHandle synchronizers_array, TRAPS); |
aoqi@0 | 111 | }; |
aoqi@0 | 112 | |
aoqi@0 | 113 | class TraceVmCreationTime : public StackObj { |
aoqi@0 | 114 | private: |
aoqi@0 | 115 | TimeStamp _timer; |
aoqi@0 | 116 | jlong _begin_time; |
aoqi@0 | 117 | |
aoqi@0 | 118 | public: |
aoqi@0 | 119 | TraceVmCreationTime() {} |
aoqi@0 | 120 | ~TraceVmCreationTime() {} |
aoqi@0 | 121 | |
aoqi@0 | 122 | void start() |
aoqi@0 | 123 | { _timer.update_to(0); _begin_time = os::javaTimeMillis(); } |
aoqi@0 | 124 | |
aoqi@0 | 125 | /** |
aoqi@0 | 126 | * Only call this if initialization completes successfully; it will |
aoqi@0 | 127 | * crash if PerfMemory_exit() has already been called (usually by |
aoqi@0 | 128 | * os::shutdown() when there was an initialization failure). |
aoqi@0 | 129 | */ |
aoqi@0 | 130 | void end() |
aoqi@0 | 131 | { Management::record_vm_startup_time(_begin_time, _timer.milliseconds()); } |
aoqi@0 | 132 | |
aoqi@0 | 133 | }; |
aoqi@0 | 134 | |
aoqi@0 | 135 | #endif // SHARE_VM_SERVICES_MANAGEMENT_HPP |