1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classLoaderStats.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/symbolTable.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "gc/g1/g1HeapRegionEventSender.hpp"
  35 #include "gc/shared/gcConfiguration.hpp"
  36 #include "gc/shared/gcTrace.hpp"
  37 #include "gc/shared/objectCountEventSender.hpp"
  38 #include "gc/shared/vmGCOperations.hpp"
  39 #include "jfr/jfrEvents.hpp"
  40 #include "jfr/periodic/jfrModuleEvent.hpp"
  41 #include "jfr/periodic/jfrOSInterface.hpp"
  42 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp"
  43 #include "jfr/periodic/jfrThreadDumpEvent.hpp"
  44 #include "jfr/periodic/jfrNetworkUtilization.hpp"
  45 #include "jfr/recorder/jfrRecorder.hpp"
  46 #include "jfr/support/jfrThreadId.hpp"
  47 #include "jfr/utilities/jfrTime.hpp"
  48 #include "jfrfiles/jfrPeriodic.hpp"
  49 #include "logging/log.hpp"
  50 #include "memory/heapInspection.hpp"
  51 #include "memory/resourceArea.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "runtime/arguments.hpp"
  54 #include "runtime/flags/jvmFlag.hpp"
  55 #include "runtime/globals.hpp"
  56 #include "runtime/os.hpp"
  57 #include "runtime/os_perf.hpp"
  58 #include "runtime/thread.inline.hpp"
  59 #include "runtime/threadSMR.hpp"
  60 #include "runtime/sweeper.hpp"
  61 #include "runtime/vmThread.hpp"
  62 #include "services/classLoadingService.hpp"
  63 #include "services/management.hpp"
  64 #include "services/threadService.hpp"
  65 #include "utilities/exceptions.hpp"
  66 #include "utilities/globalDefinitions.hpp"
  67 
  68 /**
  69  *  JfrPeriodic class
  70  *  Implementation of declarations in
  71  *  xsl generated traceRequestables.hpp
  72  */
  73 #define TRACE_REQUEST_FUNC(id)    void JfrPeriodicEventSet::request##id(void)
  74 
  75 TRACE_REQUEST_FUNC(JVMInformation) {
  76   ResourceMark rm;
  77   EventJVMInformation event;
  78   event.set_jvmName(VM_Version::vm_name());
  79   event.set_jvmVersion(VM_Version::internal_vm_info_string());
  80   event.set_javaArguments(Arguments::java_command());
  81   event.set_jvmArguments(Arguments::jvm_args());
  82   event.set_jvmFlags(Arguments::jvm_flags());
  83   event.set_jvmStartTime(Management::vm_init_done_time());
  84   event.set_pid(os::current_process_id());
  85   event.commit();
  86  }
  87 
  88 TRACE_REQUEST_FUNC(OSInformation) {
  89   ResourceMark rm;
  90   char* os_name = NEW_RESOURCE_ARRAY(char, 2048);
  91   JfrOSInterface::os_version(&os_name);
  92   EventOSInformation event;
  93   event.set_osVersion(os_name);
  94   event.commit();
  95 }
  96 
  97 TRACE_REQUEST_FUNC(VirtualizationInformation) {
  98   EventVirtualizationInformation event;
  99   event.set_name(JfrOSInterface::virtualization_name());
 100   event.commit();
 101 }
 102 
 103 TRACE_REQUEST_FUNC(ModuleRequire) {
 104   JfrModuleEvent::generate_module_dependency_events();
 105 }
 106 
 107 TRACE_REQUEST_FUNC(ModuleExport) {
 108   JfrModuleEvent::generate_module_export_events();
 109 }
 110 
 111 /*
 112  * This is left empty on purpose, having ExecutionSample as a requestable
 113  * is a way of getting the period. The period is passed to ThreadSampling::update_period.
 114  * Implementation in jfrSamples.cpp
 115  */
 116 TRACE_REQUEST_FUNC(ExecutionSample) {
 117 }
 118 TRACE_REQUEST_FUNC(NativeMethodSample) {
 119 }
 120 
 121 TRACE_REQUEST_FUNC(ThreadDump) {
 122   ResourceMark rm;
 123   EventThreadDump event;
 124   event.set_result(JfrDcmdEvent::thread_dump());
 125   event.commit();
 126 }
 127 
 128 static int _native_library_callback(const char* name, address base, address top, void *param) {
 129   EventNativeLibrary event(UNTIMED);
 130   event.set_name(name);
 131   event.set_baseAddress((u8)base);
 132   event.set_topAddress((u8)top);
 133   event.set_endtime(*(JfrTicks*) param);
 134   event.commit();
 135   return 0;
 136 }
 137 
 138 TRACE_REQUEST_FUNC(NativeLibrary) {
 139   JfrTicks ts= JfrTicks::now();
 140   os::get_loaded_modules_info(&_native_library_callback, (void *)&ts);
 141 }
 142 
 143 TRACE_REQUEST_FUNC(InitialEnvironmentVariable) {
 144   JfrOSInterface::generate_initial_environment_variable_events();
 145 }
 146 
 147 TRACE_REQUEST_FUNC(CPUInformation) {
 148   CPUInformation cpu_info;
 149   int ret_val = JfrOSInterface::cpu_information(cpu_info);
 150   if (ret_val == OS_ERR) {
 151     log_debug(jfr, system)( "Unable to generate requestable event CPUInformation");
 152     return;
 153   }
 154   if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {
 155      return;
 156   }
 157   if (ret_val == OS_OK) {
 158     EventCPUInformation event;
 159     event.set_cpu(cpu_info.cpu_name());
 160     event.set_description(cpu_info.cpu_description());
 161     event.set_sockets(cpu_info.number_of_sockets());
 162     event.set_cores(cpu_info.number_of_cores());
 163     event.set_hwThreads(cpu_info.number_of_hardware_threads());
 164     event.commit();
 165   }
 166 }
 167 
 168 TRACE_REQUEST_FUNC(CPULoad) {
 169   double u = 0; // user time
 170   double s = 0; // kernel time
 171   double t = 0; // total time
 172   int ret_val = JfrOSInterface::cpu_loads_process(&u, &s, &t);
 173   if (ret_val == OS_ERR) {
 174     log_debug(jfr, system)( "Unable to generate requestable event CPULoad");
 175     return;
 176   }
 177   if (ret_val == OS_OK) {
 178     EventCPULoad event;
 179     event.set_jvmUser((float)u);
 180     event.set_jvmSystem((float)s);
 181     event.set_machineTotal((float)t);
 182     event.commit();
 183   }
 184 }
 185 
 186 TRACE_REQUEST_FUNC(ThreadCPULoad) {
 187   JfrThreadCPULoadEvent::send_events();
 188 }
 189 
 190 TRACE_REQUEST_FUNC(NetworkUtilization) {
 191   JfrNetworkUtilization::send_events();
 192 }
 193 
 194 TRACE_REQUEST_FUNC(CPUTimeStampCounter) {
 195   EventCPUTimeStampCounter event;
 196   event.set_fastTimeEnabled(JfrTime::is_ft_enabled());
 197   event.set_fastTimeAutoEnabled(JfrTime::is_ft_supported());
 198   event.set_osFrequency(os::elapsed_frequency());
 199   event.set_fastTimeFrequency(JfrTime::frequency());
 200   event.commit();
 201 }
 202 
 203 TRACE_REQUEST_FUNC(SystemProcess) {
 204   char pid_buf[16];
 205   SystemProcess* processes = NULL;
 206   int num_of_processes = 0;
 207   JfrTicks start_time = JfrTicks::now();
 208   int ret_val = JfrOSInterface::system_processes(&processes, &num_of_processes);
 209   if (ret_val == OS_ERR) {
 210     log_debug(jfr, system)( "Unable to generate requestable event SystemProcesses");
 211     return;
 212   }
 213   JfrTicks end_time = JfrTicks::now();
 214   if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {
 215     return;
 216   }
 217   if (ret_val == OS_OK) {
 218     // feature is implemented, write real event
 219     while (processes != NULL) {
 220       SystemProcess* tmp = processes;
 221       const char* info = processes->command_line();
 222       if (info == NULL) {
 223          info = processes->path();
 224       }
 225       if (info == NULL) {
 226          info = processes->name();
 227       }
 228       if (info == NULL) {
 229          info = "?";
 230       }
 231       jio_snprintf(pid_buf, sizeof(pid_buf), "%d", processes->pid());
 232       EventSystemProcess event(UNTIMED);
 233       event.set_pid(pid_buf);
 234       event.set_commandLine(info);
 235       event.set_starttime(start_time);
 236       event.set_endtime(end_time);
 237       event.commit();
 238       processes = processes->next();
 239       delete tmp;
 240     }
 241   }
 242 }
 243 
 244 TRACE_REQUEST_FUNC(ThreadContextSwitchRate) {
 245   double rate = 0.0;
 246   int ret_val = JfrOSInterface::context_switch_rate(&rate);
 247   if (ret_val == OS_ERR) {
 248     log_debug(jfr, system)( "Unable to generate requestable event ThreadContextSwitchRate");
 249     return;
 250   }
 251   if (ret_val == FUNCTIONALITY_NOT_IMPLEMENTED) {
 252     return;
 253   }
 254   if (ret_val == OS_OK) {
 255     EventThreadContextSwitchRate event;
 256     event.set_switchRate((float)rate + 0.0f);
 257     event.commit();
 258   }
 259 }
 260 
 261 #define SEND_FLAGS_OF_TYPE(eventType, flagType)                   \
 262   do {                                                            \
 263     JVMFlag *flag = JVMFlag::flags;                               \
 264     while (flag->_name != NULL) {                                 \
 265       if (flag->is_ ## flagType()) {                              \
 266         if (flag->is_unlocked()) {                                \
 267           Event ## eventType event;                               \
 268           event.set_name(flag->_name);                            \
 269           event.set_value(flag->get_ ## flagType());              \
 270           event.set_origin(flag->get_origin());                   \
 271           event.commit();                                         \
 272         }                                                         \
 273       }                                                           \
 274       ++flag;                                                     \
 275     }                                                             \
 276   } while (0)
 277 
 278 TRACE_REQUEST_FUNC(IntFlag) {
 279   SEND_FLAGS_OF_TYPE(IntFlag, int);
 280 }
 281 
 282 TRACE_REQUEST_FUNC(UnsignedIntFlag) {
 283   SEND_FLAGS_OF_TYPE(UnsignedIntFlag, uint);
 284 }
 285 
 286 TRACE_REQUEST_FUNC(LongFlag) {
 287   SEND_FLAGS_OF_TYPE(LongFlag, intx);
 288 }
 289 
 290 TRACE_REQUEST_FUNC(UnsignedLongFlag) {
 291   SEND_FLAGS_OF_TYPE(UnsignedLongFlag, uintx);
 292   SEND_FLAGS_OF_TYPE(UnsignedLongFlag, uint64_t);
 293   SEND_FLAGS_OF_TYPE(UnsignedLongFlag, size_t);
 294 }
 295 
 296 TRACE_REQUEST_FUNC(DoubleFlag) {
 297   SEND_FLAGS_OF_TYPE(DoubleFlag, double);
 298 }
 299 
 300 TRACE_REQUEST_FUNC(BooleanFlag) {
 301   SEND_FLAGS_OF_TYPE(BooleanFlag, bool);
 302 }
 303 
 304 TRACE_REQUEST_FUNC(StringFlag) {
 305   SEND_FLAGS_OF_TYPE(StringFlag, ccstr);
 306 }
 307 
 308 class VM_GC_SendObjectCountEvent : public VM_GC_HeapInspection {
 309  public:
 310   VM_GC_SendObjectCountEvent() : VM_GC_HeapInspection(NULL, true) {}
 311   virtual void doit() {
 312     ObjectCountEventSender::enable_requestable_event();
 313     collect();
 314     ObjectCountEventSender::disable_requestable_event();
 315   }
 316 };
 317 
 318 TRACE_REQUEST_FUNC(ObjectCount) {
 319   VM_GC_SendObjectCountEvent op;
 320   VMThread::execute(&op);
 321 }
 322 
 323 class VM_G1SendHeapRegionInfoEvents : public VM_Operation {
 324   virtual void doit() {
 325     G1HeapRegionEventSender::send_events();
 326   }
 327   virtual VMOp_Type type() const { return VMOp_HeapIterateOperation; }
 328 };
 329 
 330 TRACE_REQUEST_FUNC(G1HeapRegionInformation) {
 331   if (UseG1GC) {
 332     VM_G1SendHeapRegionInfoEvents op;
 333     VMThread::execute(&op);
 334   }
 335 }
 336 
 337 // Java Mission Control (JMC) uses (Java) Long.MIN_VALUE to describe that a
 338 // long value is undefined.
 339 static jlong jmc_undefined_long = min_jlong;
 340 
 341 TRACE_REQUEST_FUNC(GCConfiguration) {
 342   GCConfiguration conf;
 343   jlong pause_target = conf.has_pause_target_default_value() ? jmc_undefined_long : conf.pause_target();
 344   EventGCConfiguration event;
 345   event.set_youngCollector(conf.young_collector());
 346   event.set_oldCollector(conf.old_collector());
 347   event.set_parallelGCThreads(conf.num_parallel_gc_threads());
 348   event.set_concurrentGCThreads(conf.num_concurrent_gc_threads());
 349   event.set_usesDynamicGCThreads(conf.uses_dynamic_gc_threads());
 350   event.set_isExplicitGCConcurrent(conf.is_explicit_gc_concurrent());
 351   event.set_isExplicitGCDisabled(conf.is_explicit_gc_disabled());
 352   event.set_gcTimeRatio(conf.gc_time_ratio());
 353   event.set_pauseTarget((s8)pause_target);
 354   event.commit();
 355 }
 356 
 357 TRACE_REQUEST_FUNC(GCTLABConfiguration) {
 358   GCTLABConfiguration conf;
 359   EventGCTLABConfiguration event;
 360   event.set_usesTLABs(conf.uses_tlabs());
 361   event.set_minTLABSize(conf.min_tlab_size());
 362   event.set_tlabRefillWasteLimit(conf.tlab_refill_waste_limit());
 363   event.commit();
 364 }
 365 
 366 TRACE_REQUEST_FUNC(GCSurvivorConfiguration) {
 367   GCSurvivorConfiguration conf;
 368   EventGCSurvivorConfiguration event;
 369   event.set_maxTenuringThreshold(conf.max_tenuring_threshold());
 370   event.set_initialTenuringThreshold(conf.initial_tenuring_threshold());
 371   event.commit();
 372 }
 373 
 374 TRACE_REQUEST_FUNC(GCHeapConfiguration) {
 375   GCHeapConfiguration conf;
 376   EventGCHeapConfiguration event;
 377   event.set_minSize(conf.min_size());
 378   event.set_maxSize(conf.max_size());
 379   event.set_initialSize(conf.initial_size());
 380   event.set_usesCompressedOops(conf.uses_compressed_oops());
 381   event.set_compressedOopsMode(conf.narrow_oop_mode());
 382   event.set_objectAlignment(conf.object_alignment_in_bytes());
 383   event.set_heapAddressBits(conf.heap_address_size_in_bits());
 384   event.commit();
 385 }
 386 
 387 TRACE_REQUEST_FUNC(YoungGenerationConfiguration) {
 388   GCYoungGenerationConfiguration conf;
 389   jlong max_size = conf.has_max_size_default_value() ? jmc_undefined_long : conf.max_size();
 390   EventYoungGenerationConfiguration event;
 391   event.set_maxSize((u8)max_size);
 392   event.set_minSize(conf.min_size());
 393   event.set_newRatio(conf.new_ratio());
 394   event.commit();
 395 }
 396 
 397 TRACE_REQUEST_FUNC(InitialSystemProperty) {
 398   SystemProperty* p = Arguments::system_properties();
 399   JfrTicks time_stamp = JfrTicks::now();
 400   while (p !=  NULL) {
 401     if (!p->internal()) {
 402       EventInitialSystemProperty event(UNTIMED);
 403       event.set_key(p->key());
 404       event.set_value(p->value());
 405       event.set_endtime(time_stamp);
 406       event.commit();
 407     }
 408     p = p->next();
 409   }
 410 }
 411 
 412 TRACE_REQUEST_FUNC(ThreadAllocationStatistics) {
 413   ResourceMark rm;
 414   int initial_size = Threads::number_of_threads();
 415   GrowableArray<jlong> allocated(initial_size);
 416   GrowableArray<traceid> thread_ids(initial_size);
 417   JfrTicks time_stamp = JfrTicks::now();
 418   {
 419     // Collect allocation statistics while holding threads lock
 420     MutexLockerEx ml(Threads_lock);
 421     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
 422       allocated.append(jt->cooked_allocated_bytes());
 423       thread_ids.append(JFR_THREAD_ID(jt));
 424     }
 425   }
 426 
 427   // Write allocation statistics to buffer.
 428   for(int i = 0; i < thread_ids.length(); i++) {
 429     EventThreadAllocationStatistics event(UNTIMED);
 430     event.set_allocated(allocated.at(i));
 431     event.set_thread(thread_ids.at(i));
 432     event.set_endtime(time_stamp);
 433     event.commit();
 434   }
 435 }
 436 
 437 /**
 438  *  PhysicalMemory event represents:
 439  *
 440  *  @totalSize == The amount of physical memory (hw) installed and reported by the OS, in bytes.
 441  *  @usedSize  == The amount of physical memory currently in use in the system (reserved/committed), in bytes.
 442  *
 443  *  Both fields are systemwide, i.e. represents the entire OS/HW environment.
 444  *  These fields do not include virtual memory.
 445  *
 446  *  If running inside a guest OS on top of a hypervisor in a virtualized environment,
 447  *  the total memory reported is the amount of memory configured for the guest OS by the hypervisor.
 448  */
 449 TRACE_REQUEST_FUNC(PhysicalMemory) {
 450   u8 totalPhysicalMemory = os::physical_memory();
 451   EventPhysicalMemory event;
 452   event.set_totalSize(totalPhysicalMemory);
 453   event.set_usedSize(totalPhysicalMemory - os::available_memory());
 454   event.commit();
 455 }
 456 
 457 TRACE_REQUEST_FUNC(JavaThreadStatistics) {
 458   EventJavaThreadStatistics event;
 459   event.set_activeCount(ThreadService::get_live_thread_count());
 460   event.set_daemonCount(ThreadService::get_daemon_thread_count());
 461   event.set_accumulatedCount(ThreadService::get_total_thread_count());
 462   event.set_peakCount(ThreadService::get_peak_thread_count());
 463   event.commit();
 464 }
 465 
 466 TRACE_REQUEST_FUNC(ClassLoadingStatistics) {
 467   EventClassLoadingStatistics event;
 468   event.set_loadedClassCount(ClassLoadingService::loaded_class_count());
 469   event.set_unloadedClassCount(ClassLoadingService::unloaded_class_count());
 470   event.commit();
 471 }
 472 
 473 class JfrClassLoaderStatsClosure : public ClassLoaderStatsClosure {
 474 public:
 475   JfrClassLoaderStatsClosure() : ClassLoaderStatsClosure(NULL) {}
 476 
 477   bool do_entry(oop const& key, ClassLoaderStats* const& cls) {
 478     const ClassLoaderData* this_cld = cls->_class_loader != NULL ?
 479       java_lang_ClassLoader::loader_data(cls->_class_loader) : (ClassLoaderData*)NULL;
 480     const ClassLoaderData* parent_cld = cls->_parent != NULL ?
 481       java_lang_ClassLoader::loader_data(cls->_parent) : (ClassLoaderData*)NULL;
 482     EventClassLoaderStatistics event;
 483     event.set_classLoader(this_cld);
 484     event.set_parentClassLoader(parent_cld);
 485     event.set_classLoaderData((intptr_t)cls->_cld);
 486     event.set_classCount(cls->_classes_count);
 487     event.set_chunkSize(cls->_chunk_sz);
 488     event.set_blockSize(cls->_block_sz);
 489     event.set_anonymousClassCount(cls->_anon_classes_count);
 490     event.set_anonymousChunkSize(cls->_anon_chunk_sz);
 491     event.set_anonymousBlockSize(cls->_anon_block_sz);
 492     event.commit();
 493     return true;
 494   }
 495 
 496   void createEvents(void) {
 497     _stats->iterate(this);
 498   }
 499 };
 500 
 501 class JfrClassLoaderStatsVMOperation : public ClassLoaderStatsVMOperation {
 502  public:
 503   JfrClassLoaderStatsVMOperation() : ClassLoaderStatsVMOperation(NULL) { }
 504 
 505   void doit() {
 506     JfrClassLoaderStatsClosure clsc;
 507     ClassLoaderDataGraph::cld_do(&clsc);
 508     clsc.createEvents();
 509   }
 510 };
 511 
 512 TRACE_REQUEST_FUNC(ClassLoaderStatistics) {
 513   JfrClassLoaderStatsVMOperation op;
 514   VMThread::execute(&op);
 515 }
 516 
 517 template<typename EVENT>
 518 static void emit_table_statistics(TableStatistics statistics) {
 519   EVENT event;
 520   event.set_bucketCount(statistics._number_of_buckets);
 521   event.set_entryCount(statistics._number_of_entries);
 522   event.set_totalFootprint(statistics._total_footprint);
 523   event.set_bucketCountMaximum(statistics._maximum_bucket_size);
 524   event.set_bucketCountAverage(statistics._average_bucket_size);
 525   event.set_bucketCountVariance(statistics._variance_of_bucket_size);
 526   event.set_bucketCountStandardDeviation(statistics._stddev_of_bucket_size);
 527   event.set_insertionRate(statistics._add_rate);
 528   event.set_removalRate(statistics._remove_rate);
 529   event.commit();
 530 }
 531 
 532 TRACE_REQUEST_FUNC(SymbolTableStatistics) {
 533   TableStatistics statistics = SymbolTable::the_table()->get_table_statistics();
 534   emit_table_statistics<EventSymbolTableStatistics>(statistics);
 535 }
 536 
 537 TRACE_REQUEST_FUNC(StringTableStatistics) {
 538   TableStatistics statistics = StringTable::the_table()->get_table_statistics();
 539   emit_table_statistics<EventStringTableStatistics>(statistics);
 540 }
 541 
 542 TRACE_REQUEST_FUNC(PlaceholderTableStatistics) {
 543   TableStatistics statistics = SystemDictionary::placeholders_statistics();
 544   emit_table_statistics<EventPlaceholderTableStatistics>(statistics);
 545 }
 546 
 547 TRACE_REQUEST_FUNC(LoaderConstraintsTableStatistics) {
 548   TableStatistics statistics = SystemDictionary::loader_constraints_statistics();
 549   emit_table_statistics<EventLoaderConstraintsTableStatistics>(statistics);
 550 }
 551 
 552 TRACE_REQUEST_FUNC(ProtectionDomainCacheTableStatistics) {
 553   TableStatistics statistics = SystemDictionary::protection_domain_cache_statistics();
 554   emit_table_statistics<EventProtectionDomainCacheTableStatistics>(statistics);
 555 }
 556 
 557 TRACE_REQUEST_FUNC(CompilerStatistics) {
 558   EventCompilerStatistics event;
 559   event.set_compileCount(CompileBroker::get_total_compile_count());
 560   event.set_bailoutCount(CompileBroker::get_total_bailout_count());
 561   event.set_invalidatedCount(CompileBroker::get_total_invalidated_count());
 562   event.set_osrCompileCount(CompileBroker::get_total_osr_compile_count());
 563   event.set_standardCompileCount(CompileBroker::get_total_standard_compile_count());
 564   event.set_osrBytesCompiled(CompileBroker::get_sum_osr_bytes_compiled());
 565   event.set_standardBytesCompiled(CompileBroker::get_sum_standard_bytes_compiled());
 566   event.set_nmetodsSize(CompileBroker::get_sum_nmethod_size());
 567   event.set_nmetodCodeSize(CompileBroker::get_sum_nmethod_code_size());
 568   event.set_peakTimeSpent(CompileBroker::get_peak_compilation_time());
 569   event.set_totalTimeSpent(CompileBroker::get_total_compilation_time());
 570   event.commit();
 571 }
 572 
 573 TRACE_REQUEST_FUNC(CompilerConfiguration) {
 574   EventCompilerConfiguration event;
 575   event.set_threadCount(CICompilerCount);
 576   event.set_tieredCompilation(TieredCompilation);
 577   event.commit();
 578 }
 579 
 580 TRACE_REQUEST_FUNC(CodeCacheStatistics) {
 581   // Emit stats for all available code heaps
 582   for (int bt = 0; bt < CodeBlobType::NumTypes; ++bt) {
 583     if (CodeCache::heap_available(bt)) {
 584       EventCodeCacheStatistics event;
 585       event.set_codeBlobType((u1)bt);
 586       event.set_startAddress((u8)CodeCache::low_bound(bt));
 587       event.set_reservedTopAddress((u8)CodeCache::high_bound(bt));
 588       event.set_entryCount(CodeCache::blob_count(bt));
 589       event.set_methodCount(CodeCache::nmethod_count(bt));
 590       event.set_adaptorCount(CodeCache::adapter_count(bt));
 591       event.set_unallocatedCapacity(CodeCache::unallocated_capacity(bt));
 592       event.set_fullCount(CodeCache::get_codemem_full_count(bt));
 593       event.commit();
 594     }
 595   }
 596 }
 597 
 598 TRACE_REQUEST_FUNC(CodeCacheConfiguration) {
 599   EventCodeCacheConfiguration event;
 600   event.set_initialSize(InitialCodeCacheSize);
 601   event.set_reservedSize(ReservedCodeCacheSize);
 602   event.set_nonNMethodSize(NonNMethodCodeHeapSize);
 603   event.set_profiledSize(ProfiledCodeHeapSize);
 604   event.set_nonProfiledSize(NonProfiledCodeHeapSize);
 605   event.set_expansionSize(CodeCacheExpansionSize);
 606   event.set_minBlockLength(CodeCacheMinBlockLength);
 607   event.set_startAddress((u8)CodeCache::low_bound());
 608   event.set_reservedTopAddress((u8)CodeCache::high_bound());
 609   event.commit();
 610 }
 611 
 612 TRACE_REQUEST_FUNC(CodeSweeperStatistics) {
 613   EventCodeSweeperStatistics event;
 614   event.set_sweepCount(NMethodSweeper::traversal_count());
 615   event.set_methodReclaimedCount(NMethodSweeper::total_nof_methods_reclaimed());
 616   event.set_totalSweepTime(NMethodSweeper::total_time_sweeping());
 617   event.set_peakFractionTime(NMethodSweeper::peak_sweep_fraction_time());
 618   event.set_peakSweepTime(NMethodSweeper::peak_sweep_time());
 619   event.commit();
 620 }
 621 
 622 TRACE_REQUEST_FUNC(CodeSweeperConfiguration) {
 623   EventCodeSweeperConfiguration event;
 624   event.set_sweeperEnabled(MethodFlushing);
 625   event.set_flushingEnabled(UseCodeCacheFlushing);
 626   event.commit();
 627 }