Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/periodic/jfrPeriodic.cpp
38920 views
/*1* Copyright (c) 2012, 2018, 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#include "precompiled.hpp"25#include "jvm.h"26#include "classfile/classLoaderStats.hpp"27#include "classfile/javaClasses.hpp"28#include "code/codeCache.hpp"29#include "compiler/compileBroker.hpp"30#include "gc_implementation/g1/g1HeapRegionEventSender.hpp"31#include "gc_implementation/shared/gcConfiguration.hpp"32#include "gc_implementation/shared/gcTrace.hpp"33#include "gc_implementation/shared/objectCountEventSender.hpp"34#include "gc_implementation/shared/vmGCOperations.hpp"35#include "jfr/jfrEvents.hpp"36#include "jfr/periodic/jfrOSInterface.hpp"37#include "jfr/periodic/jfrThreadCPULoadEvent.hpp"38#include "jfr/periodic/jfrThreadDumpEvent.hpp"39#include "jfr/periodic/jfrNetworkUtilization.hpp"40#include "jfr/recorder/jfrRecorder.hpp"41#include "jfr/support/jfrThreadId.hpp"42#include "jfr/utilities/jfrTime.hpp"43#include "jfrfiles/jfrPeriodic.hpp"44#include "memory/heapInspection.hpp"45#include "memory/resourceArea.hpp"46#include "oops/oop.inline.hpp"47#include "runtime/arguments.hpp"48#include "runtime/globals.hpp"49#include "runtime/os.hpp"50#include "runtime/os_perf.hpp"51#include "runtime/thread.inline.hpp"52#include "runtime/sweeper.hpp"53#include "runtime/vmThread.hpp"54#include "services/classLoadingService.hpp"55#include "services/management.hpp"56#include "services/threadService.hpp"57#include "utilities/exceptions.hpp"58#include "utilities/globalDefinitions.hpp"5960#if INCLUDE_ALL_GCS61#include "gc_implementation/shenandoah/shenandoahJfrSupport.hpp"62#endif6364/**65* JfrPeriodic class66* Implementation of declarations in67* xsl generated traceRequestables.hpp68*/69#define TRACE_REQUEST_FUNC(id) void JfrPeriodicEventSet::request##id(void)7071TRACE_REQUEST_FUNC(JVMInformation) {72ResourceMark rm;73EventJVMInformation event;74event.set_jvmName(VM_Version::vm_name());75event.set_jvmVersion(VM_Version::internal_vm_info_string());76event.set_javaArguments(Arguments::java_command());77event.set_jvmArguments(Arguments::jvm_args());78event.set_jvmFlags(Arguments::jvm_flags());79event.set_jvmStartTime(Management::vm_init_done_time());80event.set_pid(os::current_process_id());81event.commit();82}8384TRACE_REQUEST_FUNC(OSInformation) {85ResourceMark rm;86char* os_name = NEW_RESOURCE_ARRAY(char, 2048);87JfrOSInterface::os_version(&os_name);88EventOSInformation event;89event.set_osVersion(os_name);90event.commit();91}9293/*94* This is left empty on purpose, having ExecutionSample as a requestable95* is a way of getting the period. The period is passed to ThreadSampling::update_period.96* Implementation in jfrSamples.cpp97*/98TRACE_REQUEST_FUNC(ExecutionSample) {99}100TRACE_REQUEST_FUNC(NativeMethodSample) {101}102103TRACE_REQUEST_FUNC(ThreadDump) {104ResourceMark rm;105EventThreadDump event;106event.set_result(JfrDcmdEvent::thread_dump());107event.commit();108}109110static int _native_library_callback(const char* name, address base, address top, void *param) {111EventNativeLibrary event(UNTIMED);112event.set_name(name);113event.set_baseAddress((u8)base);114event.set_topAddress((u8)top);115event.set_endtime(*(JfrTicks*) param);116event.commit();117return 0;118}119120TRACE_REQUEST_FUNC(NativeLibrary) {121JfrTicks ts= JfrTicks::now();122os::get_loaded_modules_info(&_native_library_callback, (void *)&ts);123}124125TRACE_REQUEST_FUNC(InitialEnvironmentVariable) {126JfrOSInterface::generate_initial_environment_variable_events();127}128129TRACE_REQUEST_FUNC(CPUInformation) {130CPUInformation cpu_info;131int ret_val = JfrOSInterface::cpu_information(cpu_info);132if (ret_val == OS_ERR) {133if (LogJFR) tty->print_cr( "Unable to generate requestable event CPUInformation");134return;135}136if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {137return;138}139if (ret_val == OS_OK) {140EventCPUInformation event;141event.set_cpu(cpu_info.cpu_name());142event.set_description(cpu_info.cpu_description());143event.set_sockets(cpu_info.number_of_sockets());144event.set_cores(cpu_info.number_of_cores());145event.set_hwThreads(cpu_info.number_of_hardware_threads());146event.commit();147}148}149150TRACE_REQUEST_FUNC(CPULoad) {151double u = 0; // user time152double s = 0; // kernel time153double t = 0; // total time154int ret_val = JfrOSInterface::cpu_loads_process(&u, &s, &t);155if (ret_val == OS_ERR) {156if (LogJFR) tty->print_cr( "Unable to generate requestable event CPULoad");157return;158}159if (ret_val == OS_OK) {160EventCPULoad event;161event.set_jvmUser((float)u);162event.set_jvmSystem((float)s);163event.set_machineTotal((float)t);164event.commit();165}166}167168TRACE_REQUEST_FUNC(ThreadCPULoad) {169JfrThreadCPULoadEvent::send_events();170}171172TRACE_REQUEST_FUNC(NetworkUtilization) {173JfrNetworkUtilization::send_events();174}175176TRACE_REQUEST_FUNC(CPUTimeStampCounter) {177EventCPUTimeStampCounter event;178event.set_fastTimeEnabled(JfrTime::is_ft_enabled());179event.set_fastTimeAutoEnabled(JfrTime::is_ft_supported());180event.set_osFrequency(os::elapsed_frequency());181event.set_fastTimeFrequency(JfrTime::frequency());182event.commit();183}184185TRACE_REQUEST_FUNC(SystemProcess) {186char pid_buf[16];187SystemProcess* processes = NULL;188int num_of_processes = 0;189JfrTicks start_time = JfrTicks::now();190int ret_val = JfrOSInterface::system_processes(&processes, &num_of_processes);191if (ret_val == OS_ERR) {192if (LogJFR) tty->print_cr( "Unable to generate requestable event SystemProcesses");193return;194}195JfrTicks end_time = JfrTicks::now();196if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {197return;198}199if (ret_val == OS_OK) {200// feature is implemented, write real event201while (processes != NULL) {202SystemProcess* tmp = processes;203const char* info = processes->command_line();204if (info == NULL) {205info = processes->path();206}207if (info == NULL) {208info = processes->name();209}210if (info == NULL) {211info = "?";212}213jio_snprintf(pid_buf, sizeof(pid_buf), "%d", processes->pid());214EventSystemProcess event(UNTIMED);215event.set_pid(pid_buf);216event.set_commandLine(info);217event.set_starttime(start_time);218event.set_endtime(end_time);219event.commit();220processes = processes->next();221delete tmp;222}223}224}225226TRACE_REQUEST_FUNC(ThreadContextSwitchRate) {227double rate = 0.0;228int ret_val = JfrOSInterface::context_switch_rate(&rate);229if (ret_val == OS_ERR) {230if (LogJFR) tty->print_cr( "Unable to generate requestable event ThreadContextSwitchRate");231return;232}233if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {234return;235}236if (ret_val == OS_OK) {237EventThreadContextSwitchRate event;238event.set_switchRate((float)rate + 0.0f);239event.commit();240}241}242243#define SEND_FLAGS_OF_TYPE(eventType, flagType) \244do { \245Flag *flag = Flag::flags; \246while (flag->_name != NULL) { \247if (flag->is_ ## flagType()) { \248if (flag->is_unlocked()) { \249Event ## eventType event; \250event.set_name(flag->_name); \251event.set_value(flag->get_ ## flagType()); \252event.set_origin(flag->get_origin()); \253event.commit(); \254} \255} \256++flag; \257} \258} while (0)259260TRACE_REQUEST_FUNC(IntFlag) {261SEND_FLAGS_OF_TYPE(IntFlag, intx);262}263264TRACE_REQUEST_FUNC(UnsignedIntFlag) {265SEND_FLAGS_OF_TYPE(UnsignedIntFlag, uintx);266}267268TRACE_REQUEST_FUNC(LongFlag) {269SEND_FLAGS_OF_TYPE(LongFlag, intx);270}271272TRACE_REQUEST_FUNC(UnsignedLongFlag) {273SEND_FLAGS_OF_TYPE(UnsignedLongFlag, uintx);274SEND_FLAGS_OF_TYPE(UnsignedLongFlag, uint64_t);275}276277TRACE_REQUEST_FUNC(DoubleFlag) {278SEND_FLAGS_OF_TYPE(DoubleFlag, double);279}280281TRACE_REQUEST_FUNC(BooleanFlag) {282SEND_FLAGS_OF_TYPE(BooleanFlag, bool);283}284285TRACE_REQUEST_FUNC(StringFlag) {286SEND_FLAGS_OF_TYPE(StringFlag, ccstr);287}288289class VM_GC_SendObjectCountEvent : public VM_GC_HeapInspection {290public:291VM_GC_SendObjectCountEvent() : VM_GC_HeapInspection(NULL, true) {}292virtual void doit() {293ObjectCountEventSender::enable_requestable_event();294collect();295ObjectCountEventSender::disable_requestable_event();296}297};298299TRACE_REQUEST_FUNC(ObjectCount) {300VM_GC_SendObjectCountEvent op;301VMThread::execute(&op);302}303304class VM_G1SendHeapRegionInfoEvents : public VM_Operation {305virtual void doit() {306G1HeapRegionEventSender::send_events();307}308virtual VMOp_Type type() const { return VMOp_HeapIterateOperation; }309};310311TRACE_REQUEST_FUNC(G1HeapRegionInformation) {312if (UseG1GC) {313VM_G1SendHeapRegionInfoEvents op;314VMThread::execute(&op);315}316}317318// Java Mission Control (JMC) uses (Java) Long.MIN_VALUE to describe that a319// long value is undefined.320static jlong jmc_undefined_long = min_jlong;321322TRACE_REQUEST_FUNC(GCConfiguration) {323GCConfiguration conf;324jlong pause_target = conf.has_pause_target_default_value() ? jmc_undefined_long : conf.pause_target();325EventGCConfiguration event;326event.set_youngCollector(conf.young_collector());327event.set_oldCollector(conf.old_collector());328event.set_parallelGCThreads(conf.num_parallel_gc_threads());329event.set_concurrentGCThreads(conf.num_concurrent_gc_threads());330event.set_usesDynamicGCThreads(conf.uses_dynamic_gc_threads());331event.set_isExplicitGCConcurrent(conf.is_explicit_gc_concurrent());332event.set_isExplicitGCDisabled(conf.is_explicit_gc_disabled());333event.set_gcTimeRatio(conf.gc_time_ratio());334event.set_pauseTarget((s8)pause_target);335event.commit();336}337338TRACE_REQUEST_FUNC(GCTLABConfiguration) {339GCTLABConfiguration conf;340EventGCTLABConfiguration event;341event.set_usesTLABs(conf.uses_tlabs());342event.set_minTLABSize(conf.min_tlab_size());343event.set_tlabRefillWasteLimit(conf.tlab_refill_waste_limit());344event.commit();345}346347TRACE_REQUEST_FUNC(GCSurvivorConfiguration) {348GCSurvivorConfiguration conf;349EventGCSurvivorConfiguration event;350event.set_maxTenuringThreshold(conf.max_tenuring_threshold());351event.set_initialTenuringThreshold(conf.initial_tenuring_threshold());352event.commit();353}354355TRACE_REQUEST_FUNC(GCHeapConfiguration) {356GCHeapConfiguration conf;357EventGCHeapConfiguration event;358event.set_minSize(conf.min_size());359event.set_maxSize(conf.max_size());360event.set_initialSize(conf.initial_size());361event.set_usesCompressedOops(conf.uses_compressed_oops());362event.set_compressedOopsMode(conf.narrow_oop_mode());363event.set_objectAlignment(conf.object_alignment_in_bytes());364event.set_heapAddressBits(conf.heap_address_size_in_bits());365event.commit();366}367368TRACE_REQUEST_FUNC(YoungGenerationConfiguration) {369GCYoungGenerationConfiguration conf;370jlong max_size = conf.has_max_size_default_value() ? jmc_undefined_long : conf.max_size();371EventYoungGenerationConfiguration event;372event.set_maxSize((u8)max_size);373event.set_minSize(conf.min_size());374event.set_newRatio(conf.new_ratio());375event.commit();376}377378TRACE_REQUEST_FUNC(InitialSystemProperty) {379SystemProperty* p = Arguments::system_properties();380JfrTicks time_stamp = JfrTicks::now();381while (p != NULL) {382if (true/* XXX fix me if you want !p->internal()*/) {383EventInitialSystemProperty event(UNTIMED);384event.set_key(p->key());385event.set_value(p->value());386event.set_endtime(time_stamp);387event.commit();388}389p = p->next();390}391}392393TRACE_REQUEST_FUNC(ThreadAllocationStatistics) {394ResourceMark rm;395int initial_size = Threads::number_of_threads();396GrowableArray<jlong> allocated(initial_size);397GrowableArray<traceid> thread_ids(initial_size);398JfrTicks time_stamp = JfrTicks::now();399{400// Collect allocation statistics while holding threads lock401MutexLockerEx ml(Threads_lock);402for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {403allocated.append(thread->cooked_allocated_bytes());404thread_ids.append(JFR_THREAD_ID(thread));405}406}407408// Write allocation statistics to buffer.409for(int i = 0; i < thread_ids.length(); i++) {410EventThreadAllocationStatistics event(UNTIMED);411event.set_allocated(allocated.at(i));412event.set_thread(thread_ids.at(i));413event.set_endtime(time_stamp);414event.commit();415}416}417418/**419* PhysicalMemory event represents:420*421* @totalSize == The amount of physical memory (hw) installed and reported by the OS, in bytes.422* @usedSize == The amount of physical memory currently in use in the system (reserved/committed), in bytes.423*424* Both fields are systemwide, i.e. represents the entire OS/HW environment.425* These fields do not include virtual memory.426*427* If running inside a guest OS on top of a hypervisor in a virtualized environment,428* the total memory reported is the amount of memory configured for the guest OS by the hypervisor.429*/430TRACE_REQUEST_FUNC(PhysicalMemory) {431u8 totalPhysicalMemory = os::physical_memory();432EventPhysicalMemory event;433event.set_totalSize(totalPhysicalMemory);434event.set_usedSize(totalPhysicalMemory - os::available_memory());435event.commit();436}437438TRACE_REQUEST_FUNC(JavaThreadStatistics) {439EventJavaThreadStatistics event;440event.set_activeCount(ThreadService::get_live_thread_count());441event.set_daemonCount(ThreadService::get_daemon_thread_count());442event.set_accumulatedCount(ThreadService::get_total_thread_count());443event.set_peakCount(ThreadService::get_peak_thread_count());444event.commit();445}446447TRACE_REQUEST_FUNC(ClassLoadingStatistics) {448EventClassLoadingStatistics event;449event.set_loadedClassCount(ClassLoadingService::loaded_class_count());450event.set_unloadedClassCount(ClassLoadingService::unloaded_class_count());451event.commit();452}453454class JfrClassLoaderStatsClosure : public ClassLoaderStatsClosure {455public:456JfrClassLoaderStatsClosure() : ClassLoaderStatsClosure(NULL) {}457458bool do_entry(oop const& key, ClassLoaderStats* const& cls) {459const ClassLoaderData* this_cld = cls->_class_loader != NULL ?460java_lang_ClassLoader::loader_data(cls->_class_loader) : (ClassLoaderData*)NULL;461const ClassLoaderData* parent_cld = cls->_parent != NULL ?462java_lang_ClassLoader::loader_data(cls->_parent) : (ClassLoaderData*)NULL;463EventClassLoaderStatistics event;464event.set_classLoader(this_cld);465event.set_parentClassLoader(parent_cld);466event.set_classLoaderData((intptr_t)cls->_cld);467event.set_classCount(cls->_classes_count);468event.set_chunkSize(cls->_chunk_sz);469event.set_blockSize(cls->_block_sz);470event.set_anonymousClassCount(cls->_anon_classes_count);471event.set_anonymousChunkSize(cls->_anon_chunk_sz);472event.set_anonymousBlockSize(cls->_anon_block_sz);473event.commit();474return true;475}476477void createEvents(void) {478_stats->iterate(this);479}480};481482class JfrClassLoaderStatsVMOperation : public ClassLoaderStatsVMOperation {483public:484JfrClassLoaderStatsVMOperation() : ClassLoaderStatsVMOperation(NULL) { }485486void doit() {487JfrClassLoaderStatsClosure clsc;488ClassLoaderDataGraph::cld_do(&clsc);489clsc.createEvents();490}491};492493TRACE_REQUEST_FUNC(ClassLoaderStatistics) {494JfrClassLoaderStatsVMOperation op;495VMThread::execute(&op);496}497498TRACE_REQUEST_FUNC(CompilerStatistics) {499EventCompilerStatistics event;500event.set_compileCount(CompileBroker::get_total_compile_count());501event.set_bailoutCount(CompileBroker::get_total_bailout_count());502event.set_invalidatedCount(CompileBroker::get_total_invalidated_count());503event.set_osrCompileCount(CompileBroker::get_total_osr_compile_count());504event.set_standardCompileCount(CompileBroker::get_total_standard_compile_count());505event.set_osrBytesCompiled(CompileBroker::get_sum_osr_bytes_compiled());506event.set_standardBytesCompiled(CompileBroker::get_sum_standard_bytes_compiled());507event.set_nmetodsSize(CompileBroker::get_sum_nmethod_size());508event.set_nmetodCodeSize(CompileBroker::get_sum_nmethod_code_size());509event.set_peakTimeSpent(CompileBroker::get_peak_compilation_time());510event.set_totalTimeSpent(CompileBroker::get_total_compilation_time());511event.commit();512}513514TRACE_REQUEST_FUNC(CompilerConfiguration) {515EventCompilerConfiguration event;516event.set_threadCount(CICompilerCount);517event.set_tieredCompilation(TieredCompilation);518event.commit();519}520521TRACE_REQUEST_FUNC(CodeCacheStatistics) {522EventCodeCacheStatistics event;523event.set_codeBlobType((u1)0/*bt*/); // XXX524event.set_startAddress((u8)CodeCache::low_bound());525event.set_reservedTopAddress((u8)CodeCache::high_bound());526event.set_entryCount(CodeCache::nof_blobs());527event.set_methodCount(CodeCache::nof_nmethods());528event.set_adaptorCount(CodeCache::nof_adapters());529event.set_unallocatedCapacity(CodeCache::unallocated_capacity());530event.set_fullCount(CodeCache::get_codemem_full_count());531event.commit();532}533534TRACE_REQUEST_FUNC(CodeCacheConfiguration) {535EventCodeCacheConfiguration event;536event.set_initialSize(InitialCodeCacheSize);537event.set_reservedSize(ReservedCodeCacheSize);538event.set_nonNMethodSize(0/*NonNMethodCodeHeapSize*/); // XXX539event.set_profiledSize(0/*ProfiledCodeHeapSize*/); // XXX540event.set_nonProfiledSize(0/*NonProfiledCodeHeapSize*/); // XXX541event.set_expansionSize(CodeCacheExpansionSize);542event.set_minBlockLength(CodeCacheMinBlockLength);543event.set_startAddress((u8)CodeCache::low_bound());544event.set_reservedTopAddress((u8)CodeCache::high_bound());545event.commit();546}547548TRACE_REQUEST_FUNC(CodeSweeperStatistics) {549EventCodeSweeperStatistics event;550event.set_sweepCount(NMethodSweeper::traversal_count());551event.set_methodReclaimedCount(NMethodSweeper::total_nof_methods_reclaimed());552event.set_totalSweepTime(NMethodSweeper::total_time_sweeping());553event.set_peakFractionTime(NMethodSweeper::peak_sweep_fraction_time());554event.set_peakSweepTime(NMethodSweeper::peak_sweep_time());555event.commit();556}557558TRACE_REQUEST_FUNC(CodeSweeperConfiguration) {559EventCodeSweeperConfiguration event;560event.set_sweeperEnabled(MethodFlushing);561event.set_flushingEnabled(UseCodeCacheFlushing);562event.commit();563}564565566TRACE_REQUEST_FUNC(ShenandoahHeapRegionInformation) {567#if INCLUDE_ALL_GCS568if (UseShenandoahGC) {569VM_ShenandoahSendHeapRegionInfoEvents op;570VMThread::execute(&op);571}572#endif573}574575576577