0N/A/*
4170N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_RUNTIME_FPROFILER_HPP
1879N/A#define SHARE_VM_RUNTIME_FPROFILER_HPP
1879N/A
1879N/A#include "runtime/timer.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "thread_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "thread_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "thread_windows.inline.hpp"
1879N/A#endif
2796N/A#ifdef TARGET_OS_FAMILY_bsd
2796N/A# include "thread_bsd.inline.hpp"
2796N/A#endif
1879N/A
0N/A// a simple flat profiler for Java
0N/A
0N/A
0N/A// Forward declaration of classes defined in this header file
0N/Aclass ThreadProfiler;
0N/Aclass ThreadProfilerMark;
0N/Aclass FlatProfiler;
0N/Aclass IntervalData;
0N/A
0N/A// Declarations of classes defined only in the implementation.
0N/Aclass ProfilerNode;
0N/Aclass FlatProfilerTask;
0N/A
0N/Aenum TickPosition {
0N/A tp_code,
0N/A tp_native
0N/A};
0N/A
0N/A// One of these guys is constructed as we enter interesting regions
0N/A// and destructed as we exit the region. While we are in the region
0N/A// ticks are allotted to the region.
0N/Aclass ThreadProfilerMark: public StackObj {
0N/Apublic:
0N/A // For now, the only thread-specific region is the class loader.
0N/A enum Region { noRegion, classLoaderRegion, extraRegion, maxRegion };
0N/A
4170N/A ThreadProfilerMark(Region);
4170N/A ~ThreadProfilerMark();
0N/A
0N/Aprivate:
0N/A ThreadProfiler* _pp;
0N/A Region _r;
0N/A};
0N/A
0N/A
0N/Aclass IntervalData VALUE_OBJ_CLASS_SPEC {
0N/A // Just to keep these things all together
0N/Aprivate:
0N/A int _interpreted;
0N/A int _compiled;
0N/A int _native;
0N/A int _compiling;
0N/Apublic:
0N/A int interpreted() {
0N/A return _interpreted;
0N/A }
0N/A int compiled() {
0N/A return _compiled;
0N/A }
0N/A int native() {
0N/A return _native;
0N/A }
0N/A int compiling() {
0N/A return _compiling;
0N/A }
0N/A int total() {
0N/A return (interpreted() + compiled() + native() + compiling());
0N/A }
0N/A void inc_interpreted() {
0N/A _interpreted += 1;
0N/A }
0N/A void inc_compiled() {
0N/A _compiled += 1;
0N/A }
0N/A void inc_native() {
0N/A _native += 1;
0N/A }
0N/A void inc_compiling() {
0N/A _compiling += 1;
0N/A }
0N/A void reset() {
0N/A _interpreted = 0;
0N/A _compiled = 0;
0N/A _native = 0;
0N/A _compiling = 0;
0N/A }
0N/A static void print_header(outputStream* st);
0N/A void print_data(outputStream* st);
0N/A};
0N/A
3863N/Aclass ThreadProfiler: public CHeapObj<mtInternal> {
0N/Apublic:
4170N/A ThreadProfiler();
4170N/A ~ThreadProfiler();
0N/A
0N/A // Resets the profiler
4170N/A void reset();
0N/A
0N/A // Activates the profiler for a certain thread
4170N/A void engage();
0N/A
0N/A // Deactivates the profiler
4170N/A void disengage();
0N/A
0N/A // Prints the collected profiling information
4170N/A void print(const char* thread_name);
0N/A
0N/A // Garbage Collection Support
4170N/A void oops_do(OopClosure* f);
0N/A
0N/Aprivate:
0N/A // for recording ticks.
0N/A friend class ProfilerNode;
0N/A char* area_bottom; // preallocated area for pnodes
0N/A char* area_top;
0N/A char* area_limit;
0N/A static int table_size;
0N/A ProfilerNode** table;
0N/A
0N/Aprivate:
107N/A void record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks);
0N/A void record_compiled_tick (JavaThread* thread, frame fr, TickPosition where);
0N/A void interpreted_update(methodOop method, TickPosition where);
0N/A void compiled_update (methodOop method, TickPosition where);
0N/A void stub_update (methodOop method, const char* name, TickPosition where);
0N/A void adapter_update (TickPosition where);
0N/A
0N/A void runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where);
0N/A void unknown_compiled_update (const CodeBlob* cb, TickPosition where);
0N/A
0N/A void vm_update (TickPosition where);
0N/A void vm_update (const char* name, TickPosition where);
0N/A
0N/A void record_tick_for_running_frame(JavaThread* thread, frame fr);
0N/A void record_tick_for_calling_frame(JavaThread* thread, frame fr);
0N/A
0N/A void initialize();
0N/A
0N/A static int entry(int value);
0N/A
0N/A
0N/Aprivate:
0N/A friend class FlatProfiler;
0N/A void record_tick(JavaThread* thread);
0N/A bool engaged;
0N/A // so we can do percentages for this thread, and quick checks for activity
0N/A int thread_ticks;
0N/A int compiler_ticks;
0N/A int interpreter_ticks;
0N/A
0N/Apublic:
0N/A void inc_thread_ticks() { thread_ticks += 1; }
0N/A
0N/Aprivate:
0N/A friend class ThreadProfilerMark;
0N/A // counters for thread-specific regions
0N/A bool region_flag[ThreadProfilerMark::maxRegion];
0N/A int class_loader_ticks;
0N/A int extra_ticks;
0N/A
0N/Aprivate:
0N/A // other thread-specific regions
0N/A int blocked_ticks;
0N/A enum UnknownTickSites {
0N/A ut_null_method,
0N/A ut_vtable_stubs,
0N/A ut_running_frame,
0N/A ut_calling_frame,
0N/A ut_no_pc,
0N/A ut_no_last_Java_frame,
0N/A ut_unknown_thread_state,
0N/A ut_end
0N/A };
0N/A int unknown_ticks_array[ut_end];
0N/A int unknown_ticks() {
0N/A int result = 0;
0N/A for (int ut = 0; ut < ut_end; ut += 1) {
0N/A result += unknown_ticks_array[ut];
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A elapsedTimer timer;
0N/A
0N/A // For interval timing
0N/Aprivate:
0N/A IntervalData _interval_data;
0N/A IntervalData interval_data() {
0N/A return _interval_data;
0N/A }
0N/A IntervalData* interval_data_ref() {
0N/A return &_interval_data;
0N/A }
0N/A};
0N/A
0N/Aclass FlatProfiler: AllStatic {
0N/Apublic:
4170N/A static void reset() ;
4170N/A static void engage(JavaThread* mainThread, bool fullProfile) ;
4170N/A static void disengage() ;
4170N/A static void print(int unused) ;
4170N/A static bool is_active();
0N/A
0N/A // This is NULL if each thread has its own thread profiler,
0N/A // else this is the single thread profiler used by all threads.
0N/A // In particular it makes a difference during garbage collection,
0N/A // where you only want to traverse each thread profiler once.
4170N/A static ThreadProfiler* get_thread_profiler();
0N/A
0N/A // Garbage Collection Support
4170N/A static void oops_do(OopClosure* f) ;
0N/A
0N/A // Support for disassembler to inspect the PCRecorder
0N/A
0N/A // Returns the start address for a given pc
0N/A // NULL is returned if the PCRecorder is inactive
4170N/A static address bucket_start_for(address pc);
0N/A
0N/A enum { MillisecsPerTick = 10 }; // ms per profiling ticks
0N/A
0N/A // Returns the number of ticks recorded for the bucket
0N/A // pc belongs to.
4170N/A static int bucket_count_for(address pc);
0N/A
0N/A
0N/A private:
0N/A static bool full_profile() {
0N/A return full_profile_flag;
0N/A }
0N/A
0N/A friend class ThreadProfiler;
0N/A // the following group of ticks cover everything that's not attributed to individual Java methods
0N/A static int received_gc_ticks; // ticks during which gc was active
0N/A static int vm_operation_ticks; // total ticks in vm_operations other than GC
0N/A static int threads_lock_ticks; // the number of times we couldn't get the Threads_lock without blocking
0N/A static int blocked_ticks; // ticks when the thread was blocked.
0N/A static int class_loader_ticks; // total ticks in class loader
0N/A static int extra_ticks; // total ticks an extra temporary measuring
0N/A static int compiler_ticks; // total ticks in compilation
0N/A static int interpreter_ticks; // ticks in unknown interpreted method
0N/A static int deopt_ticks; // ticks in deoptimization
0N/A static int unknown_ticks; // ticks that cannot be categorized
0N/A static int received_ticks; // ticks that were received by task
0N/A static int delivered_ticks; // ticks that were delivered by task
0N/A static int non_method_ticks() {
0N/A return
0N/A ( received_gc_ticks
0N/A + vm_operation_ticks
0N/A + deopt_ticks
0N/A + threads_lock_ticks
0N/A + blocked_ticks
0N/A + compiler_ticks
0N/A + interpreter_ticks
0N/A + unknown_ticks );
0N/A }
0N/A static elapsedTimer timer;
0N/A
0N/A // Counts of each of the byte codes
0N/A static int* bytecode_ticks;
0N/A static int* bytecode_ticks_stub;
0N/A static void print_byte_code_statistics();
0N/A
0N/A // the ticks below are for continuous profiling (to adjust recompilation, etc.)
0N/A static int all_ticks; // total count of ticks received so far
0N/A static int all_int_ticks; // ticks in interpreter
0N/A static int all_comp_ticks; // ticks in compiled code (+ native)
0N/A static bool full_profile_flag; // collecting full profile?
0N/A
0N/A // to accumulate thread-specific data
0N/A // if we aren't profiling individual threads.
0N/A static ThreadProfiler* thread_profiler;
0N/A static ThreadProfiler* vm_thread_profiler;
0N/A
0N/A static void allocate_table();
0N/A
0N/A // The task that periodically interrupts things.
0N/A friend class FlatProfilerTask;
0N/A static FlatProfilerTask* task;
0N/A static void record_vm_operation();
0N/A static void record_vm_tick();
0N/A static void record_thread_ticks();
0N/A
0N/A // For interval analysis
0N/A private:
0N/A static int interval_ticks_previous; // delivered_ticks from the last interval
0N/A static void interval_record_thread(ThreadProfiler* tp); // extract ticks from ThreadProfiler.
0N/A static void interval_print(); // print interval data.
0N/A static void interval_reset(); // reset interval data.
0N/A enum {interval_print_size = 10};
0N/A static IntervalData* interval_data;
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_RUNTIME_FPROFILER_HPP