Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/jfr/periodic/jfrPeriodic.cpp
48785 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/**61* JfrPeriodic class62* Implementation of declarations in63* xsl generated traceRequestables.hpp64*/65#define TRACE_REQUEST_FUNC(id) void JfrPeriodicEventSet::request##id(void)6667TRACE_REQUEST_FUNC(JVMInformation) {68ResourceMark rm;69EventJVMInformation event;70event.set_jvmName(VM_Version::vm_name());71event.set_jvmVersion(VM_Version::internal_vm_info_string());72event.set_javaArguments(Arguments::java_command());73event.set_jvmArguments(Arguments::jvm_args());74event.set_jvmFlags(Arguments::jvm_flags());75event.set_jvmStartTime(Management::vm_init_done_time());76event.set_pid(os::current_process_id());77event.commit();78}7980TRACE_REQUEST_FUNC(OSInformation) {81ResourceMark rm;82char* os_name = NEW_RESOURCE_ARRAY(char, 2048);83JfrOSInterface::os_version(&os_name);84EventOSInformation event;85event.set_osVersion(os_name);86event.commit();87}8889/*90* This is left empty on purpose, having ExecutionSample as a requestable91* is a way of getting the period. The period is passed to ThreadSampling::update_period.92* Implementation in jfrSamples.cpp93*/94TRACE_REQUEST_FUNC(ExecutionSample) {95}96TRACE_REQUEST_FUNC(NativeMethodSample) {97}9899TRACE_REQUEST_FUNC(ThreadDump) {100ResourceMark rm;101EventThreadDump event;102event.set_result(JfrDcmdEvent::thread_dump());103event.commit();104}105106static int _native_library_callback(const char* name, address base, address top, void *param) {107EventNativeLibrary event(UNTIMED);108event.set_name(name);109event.set_baseAddress((u8)base);110event.set_topAddress((u8)top);111event.set_endtime(*(JfrTicks*) param);112event.commit();113return 0;114}115116TRACE_REQUEST_FUNC(NativeLibrary) {117JfrTicks ts= JfrTicks::now();118os::get_loaded_modules_info(&_native_library_callback, (void *)&ts);119}120121TRACE_REQUEST_FUNC(InitialEnvironmentVariable) {122JfrOSInterface::generate_initial_environment_variable_events();123}124125TRACE_REQUEST_FUNC(CPUInformation) {126CPUInformation cpu_info;127int ret_val = JfrOSInterface::cpu_information(cpu_info);128if (ret_val == OS_ERR) {129if (LogJFR) tty->print_cr( "Unable to generate requestable event CPUInformation");130return;131}132if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {133return;134}135if (ret_val == OS_OK) {136EventCPUInformation event;137event.set_cpu(cpu_info.cpu_name());138event.set_description(cpu_info.cpu_description());139event.set_sockets(cpu_info.number_of_sockets());140event.set_cores(cpu_info.number_of_cores());141event.set_hwThreads(cpu_info.number_of_hardware_threads());142event.commit();143}144}145146TRACE_REQUEST_FUNC(CPULoad) {147double u = 0; // user time148double s = 0; // kernel time149double t = 0; // total time150int ret_val = JfrOSInterface::cpu_loads_process(&u, &s, &t);151if (ret_val == OS_ERR) {152if (LogJFR) tty->print_cr( "Unable to generate requestable event CPULoad");153return;154}155if (ret_val == OS_OK) {156EventCPULoad event;157event.set_jvmUser((float)u);158event.set_jvmSystem((float)s);159event.set_machineTotal((float)t);160event.commit();161}162}163164TRACE_REQUEST_FUNC(ThreadCPULoad) {165JfrThreadCPULoadEvent::send_events();166}167168TRACE_REQUEST_FUNC(NetworkUtilization) {169JfrNetworkUtilization::send_events();170}171172TRACE_REQUEST_FUNC(CPUTimeStampCounter) {173EventCPUTimeStampCounter event;174event.set_fastTimeEnabled(JfrTime::is_ft_enabled());175event.set_fastTimeAutoEnabled(JfrTime::is_ft_supported());176event.set_osFrequency(os::elapsed_frequency());177event.set_fastTimeFrequency(JfrTime::frequency());178event.commit();179}180181TRACE_REQUEST_FUNC(SystemProcess) {182char pid_buf[16];183SystemProcess* processes = NULL;184int num_of_processes = 0;185JfrTicks start_time = JfrTicks::now();186int ret_val = JfrOSInterface::system_processes(&processes, &num_of_processes);187if (ret_val == OS_ERR) {188if (LogJFR) tty->print_cr( "Unable to generate requestable event SystemProcesses");189return;190}191JfrTicks end_time = JfrTicks::now();192if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {193return;194}195if (ret_val == OS_OK) {196// feature is implemented, write real event197while (processes != NULL) {198SystemProcess* tmp = processes;199const char* info = processes->command_line();200if (info == NULL) {201info = processes->path();202}203if (info == NULL) {204info = processes->name();205}206if (info == NULL) {207info = "?";208}209jio_snprintf(pid_buf, sizeof(pid_buf), "%d", processes->pid());210EventSystemProcess event(UNTIMED);211event.set_pid(pid_buf);212event.set_commandLine(info);213event.set_starttime(start_time);214event.set_endtime(end_time);215event.commit();216processes = processes->next();217delete tmp;218}219}220}221222TRACE_REQUEST_FUNC(ThreadContextSwitchRate) {223double rate = 0.0;224int ret_val = JfrOSInterface::context_switch_rate(&rate);225if (ret_val == OS_ERR) {226if (LogJFR) tty->print_cr( "Unable to generate requestable event ThreadContextSwitchRate");227return;228}229if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {230return;231}232if (ret_val == OS_OK) {233EventThreadContextSwitchRate event;234event.set_switchRate((float)rate + 0.0f);235event.commit();236}237}238239#define SEND_FLAGS_OF_TYPE(eventType, flagType) \240do { \241Flag *flag = Flag::flags; \242while (flag->_name != NULL) { \243if (flag->is_ ## flagType()) { \244if (flag->is_unlocked()) { \245Event ## eventType event; \246event.set_name(flag->_name); \247event.set_value(flag->get_ ## flagType()); \248event.set_origin(flag->get_origin()); \249event.commit(); \250} \251} \252++flag; \253} \254} while (0)255256TRACE_REQUEST_FUNC(IntFlag) {257SEND_FLAGS_OF_TYPE(IntFlag, intx);258}259260TRACE_REQUEST_FUNC(UnsignedIntFlag) {261SEND_FLAGS_OF_TYPE(UnsignedIntFlag, uintx);262}263264TRACE_REQUEST_FUNC(LongFlag) {265SEND_FLAGS_OF_TYPE(LongFlag, intx);266}267268TRACE_REQUEST_FUNC(UnsignedLongFlag) {269SEND_FLAGS_OF_TYPE(UnsignedLongFlag, uintx);270SEND_FLAGS_OF_TYPE(UnsignedLongFlag, uint64_t);271}272273TRACE_REQUEST_FUNC(DoubleFlag) {274SEND_FLAGS_OF_TYPE(DoubleFlag, double);275}276277TRACE_REQUEST_FUNC(BooleanFlag) {278SEND_FLAGS_OF_TYPE(BooleanFlag, bool);279}280281TRACE_REQUEST_FUNC(StringFlag) {282SEND_FLAGS_OF_TYPE(StringFlag, ccstr);283}284285class VM_GC_SendObjectCountEvent : public VM_GC_HeapInspection {286public:287VM_GC_SendObjectCountEvent() : VM_GC_HeapInspection(NULL, true) {}288virtual void doit() {289ObjectCountEventSender::enable_requestable_event();290collect();291ObjectCountEventSender::disable_requestable_event();292}293};294295TRACE_REQUEST_FUNC(ObjectCount) {296VM_GC_SendObjectCountEvent op;297VMThread::execute(&op);298}299300class VM_G1SendHeapRegionInfoEvents : public VM_Operation {301virtual void doit() {302G1HeapRegionEventSender::send_events();303}304virtual VMOp_Type type() const { return VMOp_HeapIterateOperation; }305};306307TRACE_REQUEST_FUNC(G1HeapRegionInformation) {308if (UseG1GC) {309VM_G1SendHeapRegionInfoEvents op;310VMThread::execute(&op);311}312}313314// Java Mission Control (JMC) uses (Java) Long.MIN_VALUE to describe that a315// long value is undefined.316static jlong jmc_undefined_long = min_jlong;317318TRACE_REQUEST_FUNC(GCConfiguration) {319GCConfiguration conf;320jlong pause_target = conf.has_pause_target_default_value() ? jmc_undefined_long : conf.pause_target();321EventGCConfiguration event;322event.set_youngCollector(conf.young_collector());323event.set_oldCollector(conf.old_collector());324event.set_parallelGCThreads(conf.num_parallel_gc_threads());325event.set_concurrentGCThreads(conf.num_concurrent_gc_threads());326event.set_usesDynamicGCThreads(conf.uses_dynamic_gc_threads());327event.set_isExplicitGCConcurrent(conf.is_explicit_gc_concurrent());328event.set_isExplicitGCDisabled(conf.is_explicit_gc_disabled());329event.set_gcTimeRatio(conf.gc_time_ratio());330event.set_pauseTarget((s8)pause_target);331event.commit();332}333334TRACE_REQUEST_FUNC(GCTLABConfiguration) {335GCTLABConfiguration conf;336EventGCTLABConfiguration event;337event.set_usesTLABs(conf.uses_tlabs());338event.set_minTLABSize(conf.min_tlab_size());339event.set_tlabRefillWasteLimit(conf.tlab_refill_waste_limit());340event.commit();341}342343TRACE_REQUEST_FUNC(GCSurvivorConfiguration) {344GCSurvivorConfiguration conf;345EventGCSurvivorConfiguration event;346event.set_maxTenuringThreshold(conf.max_tenuring_threshold());347event.set_initialTenuringThreshold(conf.initial_tenuring_threshold());348event.commit();349}350351TRACE_REQUEST_FUNC(GCHeapConfiguration) {352GCHeapConfiguration conf;353EventGCHeapConfiguration event;354event.set_minSize(conf.min_size());355event.set_maxSize(conf.max_size());356event.set_initialSize(conf.initial_size());357event.set_usesCompressedOops(conf.uses_compressed_oops());358event.set_compressedOopsMode(conf.narrow_oop_mode());359event.set_objectAlignment(conf.object_alignment_in_bytes());360event.set_heapAddressBits(conf.heap_address_size_in_bits());361event.commit();362}363364TRACE_REQUEST_FUNC(YoungGenerationConfiguration) {365GCYoungGenerationConfiguration conf;366jlong max_size = conf.has_max_size_default_value() ? jmc_undefined_long : conf.max_size();367EventYoungGenerationConfiguration event;368event.set_maxSize((u8)max_size);369event.set_minSize(conf.min_size());370event.set_newRatio(conf.new_ratio());371event.commit();372}373374TRACE_REQUEST_FUNC(InitialSystemProperty) {375SystemProperty* p = Arguments::system_properties();376JfrTicks time_stamp = JfrTicks::now();377while (p != NULL) {378if (true/* XXX fix me if you want !p->internal()*/) {379EventInitialSystemProperty event(UNTIMED);380event.set_key(p->key());381event.set_value(p->value());382event.set_endtime(time_stamp);383event.commit();384}385p = p->next();386}387}388389TRACE_REQUEST_FUNC(ThreadAllocationStatistics) {390ResourceMark rm;391int initial_size = Threads::number_of_threads();392GrowableArray<jlong> allocated(initial_size);393GrowableArray<traceid> thread_ids(initial_size);394JfrTicks time_stamp = JfrTicks::now();395{396// Collect allocation statistics while holding threads lock397MutexLockerEx ml(Threads_lock);398for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {399allocated.append(thread->cooked_allocated_bytes());400thread_ids.append(JFR_THREAD_ID(thread));401}402}403404// Write allocation statistics to buffer.405for(int i = 0; i < thread_ids.length(); i++) {406EventThreadAllocationStatistics event(UNTIMED);407event.set_allocated(allocated.at(i));408event.set_thread(thread_ids.at(i));409event.set_endtime(time_stamp);410event.commit();411}412}413414/**415* PhysicalMemory event represents:416*417* @totalSize == The amount of physical memory (hw) installed and reported by the OS, in bytes.418* @usedSize == The amount of physical memory currently in use in the system (reserved/committed), in bytes.419*420* Both fields are systemwide, i.e. represents the entire OS/HW environment.421* These fields do not include virtual memory.422*423* If running inside a guest OS on top of a hypervisor in a virtualized environment,424* the total memory reported is the amount of memory configured for the guest OS by the hypervisor.425*/426TRACE_REQUEST_FUNC(PhysicalMemory) {427u8 totalPhysicalMemory = os::physical_memory();428EventPhysicalMemory event;429event.set_totalSize(totalPhysicalMemory);430event.set_usedSize(totalPhysicalMemory - os::available_memory());431event.commit();432}433434TRACE_REQUEST_FUNC(JavaThreadStatistics) {435EventJavaThreadStatistics event;436event.set_activeCount(ThreadService::get_live_thread_count());437event.set_daemonCount(ThreadService::get_daemon_thread_count());438event.set_accumulatedCount(ThreadService::get_total_thread_count());439event.set_peakCount(ThreadService::get_peak_thread_count());440event.commit();441}442443TRACE_REQUEST_FUNC(ClassLoadingStatistics) {444EventClassLoadingStatistics event;445event.set_loadedClassCount(ClassLoadingService::loaded_class_count());446event.set_unloadedClassCount(ClassLoadingService::unloaded_class_count());447event.commit();448}449450class JfrClassLoaderStatsClosure : public ClassLoaderStatsClosure {451public:452JfrClassLoaderStatsClosure() : ClassLoaderStatsClosure(NULL) {}453454bool do_entry(oop const& key, ClassLoaderStats* const& cls) {455const ClassLoaderData* this_cld = cls->_class_loader != NULL ?456java_lang_ClassLoader::loader_data(cls->_class_loader) : (ClassLoaderData*)NULL;457const ClassLoaderData* parent_cld = cls->_parent != NULL ?458java_lang_ClassLoader::loader_data(cls->_parent) : (ClassLoaderData*)NULL;459EventClassLoaderStatistics event;460event.set_classLoader(this_cld);461event.set_parentClassLoader(parent_cld);462event.set_classLoaderData((intptr_t)cls->_cld);463event.set_classCount(cls->_classes_count);464event.set_chunkSize(cls->_chunk_sz);465event.set_blockSize(cls->_block_sz);466event.set_anonymousClassCount(cls->_anon_classes_count);467event.set_anonymousChunkSize(cls->_anon_chunk_sz);468event.set_anonymousBlockSize(cls->_anon_block_sz);469event.commit();470return true;471}472473void createEvents(void) {474_stats->iterate(this);475}476};477478class JfrClassLoaderStatsVMOperation : public ClassLoaderStatsVMOperation {479public:480JfrClassLoaderStatsVMOperation() : ClassLoaderStatsVMOperation(NULL) { }481482void doit() {483JfrClassLoaderStatsClosure clsc;484ClassLoaderDataGraph::cld_do(&clsc);485clsc.createEvents();486}487};488489TRACE_REQUEST_FUNC(ClassLoaderStatistics) {490JfrClassLoaderStatsVMOperation op;491VMThread::execute(&op);492}493494TRACE_REQUEST_FUNC(CompilerStatistics) {495EventCompilerStatistics event;496event.set_compileCount(CompileBroker::get_total_compile_count());497event.set_bailoutCount(CompileBroker::get_total_bailout_count());498event.set_invalidatedCount(CompileBroker::get_total_invalidated_count());499event.set_osrCompileCount(CompileBroker::get_total_osr_compile_count());500event.set_standardCompileCount(CompileBroker::get_total_standard_compile_count());501event.set_osrBytesCompiled(CompileBroker::get_sum_osr_bytes_compiled());502event.set_standardBytesCompiled(CompileBroker::get_sum_standard_bytes_compiled());503event.set_nmetodsSize(CompileBroker::get_sum_nmethod_size());504event.set_nmetodCodeSize(CompileBroker::get_sum_nmethod_code_size());505event.set_peakTimeSpent(CompileBroker::get_peak_compilation_time());506event.set_totalTimeSpent(CompileBroker::get_total_compilation_time());507event.commit();508}509510TRACE_REQUEST_FUNC(CompilerConfiguration) {511EventCompilerConfiguration event;512event.set_threadCount(CICompilerCount);513event.set_tieredCompilation(TieredCompilation);514event.commit();515}516517TRACE_REQUEST_FUNC(CodeCacheStatistics) {518EventCodeCacheStatistics event;519event.set_codeBlobType((u1)0/*bt*/); // XXX520event.set_startAddress((u8)CodeCache::low_bound());521event.set_reservedTopAddress((u8)CodeCache::high_bound());522event.set_entryCount(CodeCache::nof_blobs());523event.set_methodCount(CodeCache::nof_nmethods());524event.set_adaptorCount(CodeCache::nof_adapters());525event.set_unallocatedCapacity(CodeCache::unallocated_capacity());526event.set_fullCount(CodeCache::get_codemem_full_count());527event.commit();528}529530TRACE_REQUEST_FUNC(CodeCacheConfiguration) {531EventCodeCacheConfiguration event;532event.set_initialSize(InitialCodeCacheSize);533event.set_reservedSize(ReservedCodeCacheSize);534event.set_nonNMethodSize(0/*NonNMethodCodeHeapSize*/); // XXX535event.set_profiledSize(0/*ProfiledCodeHeapSize*/); // XXX536event.set_nonProfiledSize(0/*NonProfiledCodeHeapSize*/); // XXX537event.set_expansionSize(CodeCacheExpansionSize);538event.set_minBlockLength(CodeCacheMinBlockLength);539event.set_startAddress((u8)CodeCache::low_bound());540event.set_reservedTopAddress((u8)CodeCache::high_bound());541event.commit();542}543544TRACE_REQUEST_FUNC(CodeSweeperStatistics) {545EventCodeSweeperStatistics event;546event.set_sweepCount(NMethodSweeper::traversal_count());547event.set_methodReclaimedCount(NMethodSweeper::total_nof_methods_reclaimed());548event.set_totalSweepTime(NMethodSweeper::total_time_sweeping());549event.set_peakFractionTime(NMethodSweeper::peak_sweep_fraction_time());550event.set_peakSweepTime(NMethodSweeper::peak_sweep_time());551event.commit();552}553554TRACE_REQUEST_FUNC(CodeSweeperConfiguration) {555EventCodeSweeperConfiguration event;556event.set_sweeperEnabled(MethodFlushing);557event.set_flushingEnabled(UseCodeCacheFlushing);558event.commit();559}560561562