Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/fprofiler.hpp
32285 views
/*1* Copyright (c) 1997, 2013, 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_VM_RUNTIME_FPROFILER_HPP25#define SHARE_VM_RUNTIME_FPROFILER_HPP2627#include "utilities/macros.hpp"28#include "runtime/timer.hpp"2930// a simple flat profiler for Java313233// Forward declaration of classes defined in this header file34class ThreadProfiler;35class ThreadProfilerMark;36class FlatProfiler;37class IntervalData;3839// Declarations of classes defined only in the implementation.40class ProfilerNode;41class FlatProfilerTask;4243enum TickPosition {44tp_code,45tp_native46};4748// One of these guys is constructed as we enter interesting regions49// and destructed as we exit the region. While we are in the region50// ticks are allotted to the region.51class ThreadProfilerMark: public StackObj {52public:53// For now, the only thread-specific region is the class loader.54enum Region { noRegion, classLoaderRegion, extraRegion, maxRegion };5556ThreadProfilerMark(Region) NOT_FPROF_RETURN;57~ThreadProfilerMark() NOT_FPROF_RETURN;5859private:60ThreadProfiler* _pp;61Region _r;62};6364#if INCLUDE_FPROF6566class IntervalData VALUE_OBJ_CLASS_SPEC {67// Just to keep these things all together68private:69int _interpreted;70int _compiled;71int _native;72int _compiling;73public:74int interpreted() {75return _interpreted;76}77int compiled() {78return _compiled;79}80int native() {81return _native;82}83int compiling() {84return _compiling;85}86int total() {87return (interpreted() + compiled() + native() + compiling());88}89void inc_interpreted() {90_interpreted += 1;91}92void inc_compiled() {93_compiled += 1;94}95void inc_native() {96_native += 1;97}98void inc_compiling() {99_compiling += 1;100}101void reset() {102_interpreted = 0;103_compiled = 0;104_native = 0;105_compiling = 0;106}107static void print_header(outputStream* st);108void print_data(outputStream* st);109};110#endif // INCLUDE_FPROF111112class ThreadProfiler: public CHeapObj<mtInternal> {113public:114ThreadProfiler() NOT_FPROF_RETURN;115~ThreadProfiler() NOT_FPROF_RETURN;116117// Resets the profiler118void reset() NOT_FPROF_RETURN;119120// Activates the profiler for a certain thread121void engage() NOT_FPROF_RETURN;122123// Deactivates the profiler124void disengage() NOT_FPROF_RETURN;125126// Prints the collected profiling information127void print(const char* thread_name) NOT_FPROF_RETURN;128129// Garbage Collection Support130void oops_do(OopClosure* f) NOT_FPROF_RETURN;131132#if INCLUDE_FPROF133private:134// for recording ticks.135friend class ProfilerNode;136char* area_bottom; // preallocated area for pnodes137char* area_top;138char* area_limit;139static int table_size;140ProfilerNode** table;141142private:143void record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks);144void record_compiled_tick (JavaThread* thread, frame fr, TickPosition where);145void interpreted_update(Method* method, TickPosition where);146void compiled_update (Method* method, TickPosition where);147void stub_update (Method* method, const char* name, TickPosition where);148void adapter_update (TickPosition where);149150void runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where);151void unknown_compiled_update (const CodeBlob* cb, TickPosition where);152153void vm_update (TickPosition where);154void vm_update (const char* name, TickPosition where);155156void record_tick_for_running_frame(JavaThread* thread, frame fr);157void record_tick_for_calling_frame(JavaThread* thread, frame fr);158159void initialize();160161static int entry(int value);162163164private:165friend class FlatProfiler;166void record_tick(JavaThread* thread);167bool engaged;168// so we can do percentages for this thread, and quick checks for activity169int thread_ticks;170int compiler_ticks;171int interpreter_ticks;172173public:174void inc_thread_ticks() { thread_ticks += 1; }175176private:177friend class ThreadProfilerMark;178// counters for thread-specific regions179bool region_flag[ThreadProfilerMark::maxRegion];180int class_loader_ticks;181int extra_ticks;182183private:184// other thread-specific regions185int blocked_ticks;186enum UnknownTickSites {187ut_null_method,188ut_vtable_stubs,189ut_running_frame,190ut_calling_frame,191ut_no_pc,192ut_no_last_Java_frame,193ut_unknown_thread_state,194ut_end195};196int unknown_ticks_array[ut_end];197int unknown_ticks() {198int result = 0;199for (int ut = 0; ut < ut_end; ut += 1) {200result += unknown_ticks_array[ut];201}202return result;203}204205elapsedTimer timer;206207// For interval timing208private:209IntervalData _interval_data;210IntervalData interval_data() {211return _interval_data;212}213IntervalData* interval_data_ref() {214return &_interval_data;215}216#endif // INCLUDE_FPROF217};218219class FlatProfiler: AllStatic {220public:221static void reset() NOT_FPROF_RETURN ;222static void engage(JavaThread* mainThread, bool fullProfile) NOT_FPROF_RETURN ;223static void disengage() NOT_FPROF_RETURN ;224static void print(int unused) NOT_FPROF_RETURN ;225static bool is_active() NOT_FPROF_RETURN_(false) ;226227// This is NULL if each thread has its own thread profiler,228// else this is the single thread profiler used by all threads.229// In particular it makes a difference during garbage collection,230// where you only want to traverse each thread profiler once.231static ThreadProfiler* get_thread_profiler() NOT_FPROF_RETURN_(NULL);232233// Garbage Collection Support234static void oops_do(OopClosure* f) NOT_FPROF_RETURN ;235236// Support for disassembler to inspect the PCRecorder237238// Returns the start address for a given pc239// NULL is returned if the PCRecorder is inactive240static address bucket_start_for(address pc) NOT_FPROF_RETURN_(NULL);241242enum { MillisecsPerTick = 10 }; // ms per profiling ticks243244// Returns the number of ticks recorded for the bucket245// pc belongs to.246static int bucket_count_for(address pc) NOT_FPROF_RETURN_(0);247248#if INCLUDE_FPROF249250private:251static bool full_profile() {252return full_profile_flag;253}254255friend class ThreadProfiler;256// the following group of ticks cover everything that's not attributed to individual Java methods257static int received_gc_ticks; // ticks during which gc was active258static int vm_operation_ticks; // total ticks in vm_operations other than GC259static int threads_lock_ticks; // the number of times we couldn't get the Threads_lock without blocking260static int blocked_ticks; // ticks when the thread was blocked.261static int class_loader_ticks; // total ticks in class loader262static int extra_ticks; // total ticks an extra temporary measuring263static int compiler_ticks; // total ticks in compilation264static int interpreter_ticks; // ticks in unknown interpreted method265static int deopt_ticks; // ticks in deoptimization266static int unknown_ticks; // ticks that cannot be categorized267static int received_ticks; // ticks that were received by task268static int delivered_ticks; // ticks that were delivered by task269static int non_method_ticks() {270return271( received_gc_ticks272+ vm_operation_ticks273+ deopt_ticks274+ threads_lock_ticks275+ blocked_ticks276+ compiler_ticks277+ interpreter_ticks278+ unknown_ticks );279}280static elapsedTimer timer;281282// Counts of each of the byte codes283static int* bytecode_ticks;284static int* bytecode_ticks_stub;285static void print_byte_code_statistics();286287// the ticks below are for continuous profiling (to adjust recompilation, etc.)288static int all_ticks; // total count of ticks received so far289static int all_int_ticks; // ticks in interpreter290static int all_comp_ticks; // ticks in compiled code (+ native)291static bool full_profile_flag; // collecting full profile?292293// to accumulate thread-specific data294// if we aren't profiling individual threads.295static ThreadProfiler* thread_profiler;296static ThreadProfiler* vm_thread_profiler;297298static void allocate_table();299300// The task that periodically interrupts things.301friend class FlatProfilerTask;302static FlatProfilerTask* task;303static void record_vm_operation();304static void record_vm_tick();305static void record_thread_ticks();306307// For interval analysis308private:309static int interval_ticks_previous; // delivered_ticks from the last interval310static void interval_record_thread(ThreadProfiler* tp); // extract ticks from ThreadProfiler.311static void interval_print(); // print interval data.312static void interval_reset(); // reset interval data.313enum {interval_print_size = 10};314static IntervalData* interval_data;315#endif // INCLUDE_FPROF316};317318#endif // SHARE_VM_RUNTIME_FPROFILER_HPP319320321