Path: blob/master/src/hotspot/share/services/management.hpp
41144 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_SERVICES_MANAGEMENT_HPP25#define SHARE_SERVICES_MANAGEMENT_HPP2627#include "jmm.h"28#include "memory/allocation.hpp"29#include "runtime/handles.hpp"30#include "runtime/os.hpp"31#include "runtime/perfData.hpp"32#include "runtime/timer.hpp"3334class OopClosure;35class ThreadSnapshot;3637class Management : public AllStatic {38private:39static PerfVariable* _begin_vm_creation_time;40static PerfVariable* _end_vm_creation_time;41static PerfVariable* _vm_init_done_time;42static jmmOptionalSupport _optional_support;43static TimeStamp _stamp; // Timestamp since vm init done time4445// Management klasses46static InstanceKlass* _diagnosticCommandImpl_klass;47static InstanceKlass* _garbageCollectorExtImpl_klass;48static InstanceKlass* _garbageCollectorMXBean_klass;49static InstanceKlass* _gcInfo_klass;50static InstanceKlass* _managementFactoryHelper_klass;51static InstanceKlass* _memoryManagerMXBean_klass;52static InstanceKlass* _memoryPoolMXBean_klass;53static InstanceKlass* _memoryUsage_klass;54static InstanceKlass* _sensor_klass;55static InstanceKlass* _threadInfo_klass;56static InstanceKlass* load_and_initialize_klass(Symbol* sh, TRAPS);57static InstanceKlass* load_and_initialize_klass_or_null(Symbol* sh, TRAPS);58static InstanceKlass* initialize_klass(Klass* k, TRAPS);5960public:61static void init();62static void initialize(TRAPS);6364static jlong ticks_to_ms(jlong ticks) NOT_MANAGEMENT_RETURN_(0L);65static jlong timestamp() NOT_MANAGEMENT_RETURN_(0L);6667static void* get_jmm_interface(int version);68static void get_optional_support(jmmOptionalSupport* support);6970static void record_vm_startup_time(jlong begin, jlong duration)71NOT_MANAGEMENT_RETURN;72static void record_vm_init_completed() {73// Initialize the timestamp to get the current time74_vm_init_done_time->set_value(os::javaTimeMillis());7576// Update the timestamp to the vm init done time77_stamp.update();78}7980static jlong begin_vm_creation_time() {81return _begin_vm_creation_time->get_value();82}83static jlong vm_init_done_time() {84return _vm_init_done_time->get_value();85}8687// methods to return a Klass*.88static InstanceKlass* java_lang_management_ThreadInfo_klass(TRAPS);89static InstanceKlass* java_lang_management_MemoryUsage_klass(TRAPS)90NOT_MANAGEMENT_RETURN_(NULL);91static InstanceKlass* java_lang_management_MemoryPoolMXBean_klass(TRAPS);92static InstanceKlass* java_lang_management_MemoryManagerMXBean_klass(TRAPS);93static InstanceKlass* java_lang_management_GarbageCollectorMXBean_klass(TRAPS);94static InstanceKlass* sun_management_ManagementFactoryHelper_klass(TRAPS)95NOT_MANAGEMENT_RETURN_(NULL);96static InstanceKlass* sun_management_Sensor_klass(TRAPS)97NOT_MANAGEMENT_RETURN_(NULL);98static InstanceKlass* com_sun_management_internal_GarbageCollectorExtImpl_klass(TRAPS)99NOT_MANAGEMENT_RETURN_(NULL);100static InstanceKlass* com_sun_management_GcInfo_klass(TRAPS)101NOT_MANAGEMENT_RETURN_(NULL);102static InstanceKlass* com_sun_management_internal_DiagnosticCommandImpl_klass(TRAPS)103NOT_MANAGEMENT_RETURN_(NULL);104105static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS);106static instanceOop create_thread_info_instance(ThreadSnapshot* snapshot, objArrayHandle monitors_array, typeArrayHandle depths_array, objArrayHandle synchronizers_array, TRAPS);107};108109class TraceVmCreationTime : public StackObj {110private:111TimeStamp _timer;112jlong _begin_time;113114public:115TraceVmCreationTime() {}116~TraceVmCreationTime() {}117118void start()119{ _timer.update_to(0); _begin_time = os::javaTimeMillis(); }120121jlong begin_time() const {122return _begin_time;123}124125/**126* Only call this if initialization completes successfully; it will127* crash if PerfMemory_exit() has already been called (usually by128* os::shutdown() when there was an initialization failure).129*/130void end()131{ Management::record_vm_startup_time(_begin_time, _timer.milliseconds()); }132133};134135#endif // SHARE_SERVICES_MANAGEMENT_HPP136137138