0N/A/*
2273N/A * Copyright (c) 1997, 2011, 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#include "precompiled.hpp"
1879N/A#include "classfile/classLoader.hpp"
1879N/A#include "code/vtableStubs.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "oops/oop.inline2.hpp"
2062N/A#include "oops/symbol.hpp"
1879N/A#include "runtime/deoptimization.hpp"
1879N/A#include "runtime/fprofiler.hpp"
1879N/A#include "runtime/mutexLocker.hpp"
1879N/A#include "runtime/stubCodeGenerator.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "runtime/task.hpp"
1879N/A#include "runtime/vframe.hpp"
1879N/A#include "utilities/macros.hpp"
0N/A
0N/A// Static fields of FlatProfiler
0N/Aint FlatProfiler::received_gc_ticks = 0;
0N/Aint FlatProfiler::vm_operation_ticks = 0;
0N/Aint FlatProfiler::threads_lock_ticks = 0;
0N/Aint FlatProfiler::class_loader_ticks = 0;
0N/Aint FlatProfiler::extra_ticks = 0;
0N/Aint FlatProfiler::blocked_ticks = 0;
0N/Aint FlatProfiler::deopt_ticks = 0;
0N/Aint FlatProfiler::unknown_ticks = 0;
0N/Aint FlatProfiler::interpreter_ticks = 0;
0N/Aint FlatProfiler::compiler_ticks = 0;
0N/Aint FlatProfiler::received_ticks = 0;
0N/Aint FlatProfiler::delivered_ticks = 0;
0N/Aint* FlatProfiler::bytecode_ticks = NULL;
0N/Aint* FlatProfiler::bytecode_ticks_stub = NULL;
0N/Aint FlatProfiler::all_int_ticks = 0;
0N/Aint FlatProfiler::all_comp_ticks = 0;
0N/Aint FlatProfiler::all_ticks = 0;
0N/Abool FlatProfiler::full_profile_flag = false;
0N/AThreadProfiler* FlatProfiler::thread_profiler = NULL;
0N/AThreadProfiler* FlatProfiler::vm_thread_profiler = NULL;
0N/AFlatProfilerTask* FlatProfiler::task = NULL;
0N/AelapsedTimer FlatProfiler::timer;
0N/Aint FlatProfiler::interval_ticks_previous = 0;
0N/AIntervalData* FlatProfiler::interval_data = NULL;
0N/A
0N/AThreadProfiler::ThreadProfiler() {
0N/A // Space for the ProfilerNodes
0N/A const int area_size = 1 * ProfilerNodeSize * 1024;
3863N/A area_bottom = AllocateHeap(area_size, mtInternal);
0N/A area_top = area_bottom;
0N/A area_limit = area_bottom + area_size;
0N/A
0N/A // ProfilerNode pointer table
3863N/A table = NEW_C_HEAP_ARRAY(ProfilerNode*, table_size, mtInternal);
0N/A initialize();
0N/A engaged = false;
0N/A}
0N/A
0N/AThreadProfiler::~ThreadProfiler() {
0N/A FreeHeap(area_bottom);
0N/A area_bottom = NULL;
0N/A area_top = NULL;
0N/A area_limit = NULL;
0N/A FreeHeap(table);
0N/A table = NULL;
0N/A}
0N/A
0N/A// Statics for ThreadProfiler
0N/Aint ThreadProfiler::table_size = 1024;
0N/A
0N/Aint ThreadProfiler::entry(int value) {
0N/A value = (value > 0) ? value : -value;
0N/A return value % table_size;
0N/A}
0N/A
0N/AThreadProfilerMark::ThreadProfilerMark(ThreadProfilerMark::Region r) {
0N/A _r = r;
0N/A _pp = NULL;
0N/A assert(((r > ThreadProfilerMark::noRegion) && (r < ThreadProfilerMark::maxRegion)), "ThreadProfilerMark::Region out of bounds");
0N/A Thread* tp = Thread::current();
0N/A if (tp != NULL && tp->is_Java_thread()) {
0N/A JavaThread* jtp = (JavaThread*) tp;
0N/A ThreadProfiler* pp = jtp->get_thread_profiler();
0N/A _pp = pp;
0N/A if (pp != NULL) {
0N/A pp->region_flag[r] = true;
0N/A }
0N/A }
0N/A}
0N/A
0N/AThreadProfilerMark::~ThreadProfilerMark() {
0N/A if (_pp != NULL) {
0N/A _pp->region_flag[_r] = false;
0N/A }
0N/A _pp = NULL;
0N/A}
0N/A
0N/A// Random other statics
0N/Astatic const int col1 = 2; // position of output column 1
0N/Astatic const int col2 = 11; // position of output column 2
0N/Astatic const int col3 = 25; // position of output column 3
0N/Astatic const int col4 = 55; // position of output column 4
0N/A
0N/A
0N/A// Used for detailed profiling of nmethods.
0N/Aclass PCRecorder : AllStatic {
0N/A private:
0N/A static int* counters;
0N/A static address base;
0N/A enum {
0N/A bucket_size = 16
0N/A };
0N/A static int index_for(address pc) { return (pc - base)/bucket_size; }
0N/A static address pc_for(int index) { return base + (index * bucket_size); }
0N/A static int size() {
0N/A return ((int)CodeCache::max_capacity())/bucket_size * BytesPerWord;
0N/A }
0N/A public:
0N/A static address bucket_start_for(address pc) {
0N/A if (counters == NULL) return NULL;
0N/A return pc_for(index_for(pc));
0N/A }
0N/A static int bucket_count_for(address pc) { return counters[index_for(pc)]; }
0N/A static void init();
0N/A static void record(address pc);
0N/A static void print();
0N/A static void print_blobs(CodeBlob* cb);
0N/A};
0N/A
0N/Aint* PCRecorder::counters = NULL;
0N/Aaddress PCRecorder::base = NULL;
0N/A
0N/Avoid PCRecorder::init() {
0N/A MutexLockerEx lm(CodeCache_lock, Mutex::_no_safepoint_check_flag);
0N/A int s = size();
3863N/A counters = NEW_C_HEAP_ARRAY(int, s, mtInternal);
0N/A for (int index = 0; index < s; index++) {
0N/A counters[index] = 0;
0N/A }
0N/A base = CodeCache::first_address();
0N/A}
0N/A
0N/Avoid PCRecorder::record(address pc) {
0N/A if (counters == NULL) return;
0N/A assert(CodeCache::contains(pc), "must be in CodeCache");
0N/A counters[index_for(pc)]++;
0N/A}
0N/A
0N/A
0N/Aaddress FlatProfiler::bucket_start_for(address pc) {
0N/A return PCRecorder::bucket_start_for(pc);
0N/A}
0N/A
0N/Aint FlatProfiler::bucket_count_for(address pc) {
0N/A return PCRecorder::bucket_count_for(pc);
0N/A}
0N/A
0N/Avoid PCRecorder::print() {
0N/A if (counters == NULL) return;
0N/A
0N/A tty->cr();
0N/A tty->print_cr("Printing compiled methods with PC buckets having more than %d ticks", ProfilerPCTickThreshold);
0N/A tty->print_cr("===================================================================");
0N/A tty->cr();
0N/A
0N/A GrowableArray<CodeBlob*>* candidates = new GrowableArray<CodeBlob*>(20);
0N/A
0N/A
0N/A int s;
0N/A {
0N/A MutexLockerEx lm(CodeCache_lock, Mutex::_no_safepoint_check_flag);
0N/A s = size();
0N/A }
0N/A
0N/A for (int index = 0; index < s; index++) {
0N/A int count = counters[index];
0N/A if (count > ProfilerPCTickThreshold) {
0N/A address pc = pc_for(index);
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
0N/A if (cb != NULL && candidates->find(cb) < 0) {
0N/A candidates->push(cb);
0N/A }
0N/A }
0N/A }
0N/A for (int i = 0; i < candidates->length(); i++) {
0N/A print_blobs(candidates->at(i));
0N/A }
0N/A}
0N/A
0N/Avoid PCRecorder::print_blobs(CodeBlob* cb) {
0N/A if (cb != NULL) {
0N/A cb->print();
0N/A if (cb->is_nmethod()) {
0N/A ((nmethod*)cb)->print_code();
0N/A }
0N/A tty->cr();
0N/A } else {
0N/A tty->print_cr("stub code");
0N/A }
0N/A}
0N/A
0N/Aclass tick_counter { // holds tick info for one node
0N/A public:
0N/A int ticks_in_code;
0N/A int ticks_in_native;
0N/A
0N/A tick_counter() { ticks_in_code = ticks_in_native = 0; }
0N/A tick_counter(int code, int native) { ticks_in_code = code; ticks_in_native = native; }
0N/A
0N/A int total() const {
0N/A return (ticks_in_code + ticks_in_native);
0N/A }
0N/A
0N/A void add(tick_counter* a) {
0N/A ticks_in_code += a->ticks_in_code;
0N/A ticks_in_native += a->ticks_in_native;
0N/A }
0N/A
0N/A void update(TickPosition where) {
0N/A switch(where) {
0N/A case tp_code: ticks_in_code++; break;
0N/A case tp_native: ticks_in_native++; break;
0N/A }
0N/A }
0N/A
0N/A void print_code(outputStream* st, int total_ticks) {
0N/A st->print("%5.1f%% %5d ", total() * 100.0 / total_ticks, ticks_in_code);
0N/A }
0N/A
0N/A void print_native(outputStream* st) {
0N/A st->print(" + %5d ", ticks_in_native);
0N/A }
0N/A};
0N/A
0N/Aclass ProfilerNode {
0N/A private:
0N/A ProfilerNode* _next;
0N/A public:
0N/A tick_counter ticks;
0N/A
0N/A public:
0N/A
0N/A void* operator new(size_t size, ThreadProfiler* tp);
0N/A void operator delete(void* p);
0N/A
0N/A ProfilerNode() {
0N/A _next = NULL;
0N/A }
0N/A
0N/A virtual ~ProfilerNode() {
0N/A if (_next)
0N/A delete _next;
0N/A }
0N/A
0N/A void set_next(ProfilerNode* n) { _next = n; }
0N/A ProfilerNode* next() { return _next; }
0N/A
0N/A void update(TickPosition where) { ticks.update(where);}
0N/A int total_ticks() { return ticks.total(); }
0N/A
0N/A virtual bool is_interpreted() const { return false; }
0N/A virtual bool is_compiled() const { return false; }
0N/A virtual bool is_stub() const { return false; }
0N/A virtual bool is_runtime_stub() const{ return false; }
0N/A virtual void oops_do(OopClosure* f) = 0;
0N/A
0N/A virtual bool interpreted_match(methodOop m) const { return false; }
0N/A virtual bool compiled_match(methodOop m ) const { return false; }
0N/A virtual bool stub_match(methodOop m, const char* name) const { return false; }
0N/A virtual bool adapter_match() const { return false; }
0N/A virtual bool runtimeStub_match(const CodeBlob* stub, const char* name) const { return false; }
0N/A virtual bool unknown_compiled_match(const CodeBlob* cb) const { return false; }
0N/A
0N/A static void print_title(outputStream* st) {
0N/A st->print(" + native");
0N/A st->fill_to(col3);
0N/A st->print("Method");
0N/A st->fill_to(col4);
0N/A st->cr();
0N/A }
0N/A
0N/A static void print_total(outputStream* st, tick_counter* t, int total, const char* msg) {
0N/A t->print_code(st, total);
0N/A st->fill_to(col2);
0N/A t->print_native(st);
0N/A st->fill_to(col3);
0N/A st->print(msg);
0N/A st->cr();
0N/A }
0N/A
0N/A virtual methodOop method() = 0;
0N/A
0N/A virtual void print_method_on(outputStream* st) {
0N/A int limit;
0N/A int i;
0N/A methodOop m = method();
2062N/A Symbol* k = m->klass_name();
0N/A // Print the class name with dots instead of slashes
0N/A limit = k->utf8_length();
0N/A for (i = 0 ; i < limit ; i += 1) {
0N/A char c = (char) k->byte_at(i);
0N/A if (c == '/') {
0N/A c = '.';
0N/A }
0N/A st->print("%c", c);
0N/A }
0N/A if (limit > 0) {
0N/A st->print(".");
0N/A }
2062N/A Symbol* n = m->name();
0N/A limit = n->utf8_length();
0N/A for (i = 0 ; i < limit ; i += 1) {
0N/A char c = (char) n->byte_at(i);
0N/A st->print("%c", c);
0N/A }
3932N/A if (Verbose || WizardMode) {
0N/A // Disambiguate overloaded methods
2062N/A Symbol* sig = m->signature();
0N/A sig->print_symbol_on(st);
3932N/A } else if (MethodHandles::is_signature_polymorphic(m->intrinsic_id()))
3932N/A // compare with methodOopDesc::print_short_name
3932N/A MethodHandles::print_as_basic_type_signature_on(st, m->signature(), true);
0N/A }
0N/A
0N/A virtual void print(outputStream* st, int total_ticks) {
0N/A ticks.print_code(st, total_ticks);
0N/A st->fill_to(col2);
0N/A ticks.print_native(st);
0N/A st->fill_to(col3);
0N/A print_method_on(st);
0N/A st->cr();
0N/A }
0N/A
0N/A // for hashing into the table
0N/A static int hash(methodOop method) {
0N/A // The point here is to try to make something fairly unique
0N/A // out of the fields we can read without grabbing any locks
0N/A // since the method may be locked when we need the hash.
0N/A return (
0N/A method->code_size() ^
0N/A method->max_stack() ^
0N/A method->max_locals() ^
0N/A method->size_of_parameters());
0N/A }
0N/A
0N/A // for sorting
0N/A static int compare(ProfilerNode** a, ProfilerNode** b) {
0N/A return (*b)->total_ticks() - (*a)->total_ticks();
0N/A }
0N/A};
0N/A
0N/Avoid* ProfilerNode::operator new(size_t size, ThreadProfiler* tp){
0N/A void* result = (void*) tp->area_top;
0N/A tp->area_top += size;
0N/A
0N/A if (tp->area_top > tp->area_limit) {
0N/A fatal("flat profiler buffer overflow");
0N/A }
0N/A return result;
0N/A}
0N/A
0N/Avoid ProfilerNode::operator delete(void* p){
0N/A}
0N/A
0N/Aclass interpretedNode : public ProfilerNode {
0N/A private:
0N/A methodOop _method;
0N/A public:
0N/A interpretedNode(methodOop method, TickPosition where) : ProfilerNode() {
0N/A _method = method;
0N/A update(where);
0N/A }
0N/A
0N/A bool is_interpreted() const { return true; }
0N/A
0N/A bool interpreted_match(methodOop m) const {
0N/A return _method == m;
0N/A }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A f->do_oop((oop*)&_method);
0N/A }
0N/A
0N/A methodOop method() { return _method; }
0N/A
0N/A static void print_title(outputStream* st) {
0N/A st->fill_to(col1);
0N/A st->print("%11s", "Interpreted");
0N/A ProfilerNode::print_title(st);
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A ProfilerNode::print_method_on(st);
0N/A if (Verbose) method()->invocation_counter()->print_short();
0N/A }
0N/A};
0N/A
0N/Aclass compiledNode : public ProfilerNode {
0N/A private:
0N/A methodOop _method;
0N/A public:
0N/A compiledNode(methodOop method, TickPosition where) : ProfilerNode() {
0N/A _method = method;
0N/A update(where);
0N/A }
0N/A bool is_compiled() const { return true; }
0N/A
0N/A bool compiled_match(methodOop m) const {
0N/A return _method == m;
0N/A }
0N/A
0N/A methodOop method() { return _method; }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A f->do_oop((oop*)&_method);
0N/A }
0N/A
0N/A static void print_title(outputStream* st) {
0N/A st->fill_to(col1);
0N/A st->print("%11s", "Compiled");
0N/A ProfilerNode::print_title(st);
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A ProfilerNode::print_method_on(st);
0N/A }
0N/A};
0N/A
0N/Aclass stubNode : public ProfilerNode {
0N/A private:
0N/A methodOop _method;
0N/A const char* _symbol; // The name of the nearest VM symbol (for +ProfileVM). Points to a unique string
0N/A public:
0N/A stubNode(methodOop method, const char* name, TickPosition where) : ProfilerNode() {
0N/A _method = method;
0N/A _symbol = name;
0N/A update(where);
0N/A }
0N/A
0N/A bool is_stub() const { return true; }
0N/A
0N/A bool stub_match(methodOop m, const char* name) const {
0N/A return (_method == m) && (_symbol == name);
0N/A }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A f->do_oop((oop*)&_method);
0N/A }
0N/A
0N/A methodOop method() { return _method; }
0N/A
0N/A static void print_title(outputStream* st) {
0N/A st->fill_to(col1);
0N/A st->print("%11s", "Stub");
0N/A ProfilerNode::print_title(st);
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A ProfilerNode::print_method_on(st);
0N/A print_symbol_on(st);
0N/A }
0N/A
0N/A void print_symbol_on(outputStream* st) {
0N/A if(_symbol) {
0N/A st->print(" (%s)", _symbol);
0N/A }
0N/A }
0N/A};
0N/A
0N/Aclass adapterNode : public ProfilerNode {
0N/A public:
0N/A adapterNode(TickPosition where) : ProfilerNode() {
0N/A update(where);
0N/A }
0N/A bool is_compiled() const { return true; }
0N/A
0N/A bool adapter_match() const { return true; }
0N/A
0N/A methodOop method() { return NULL; }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A ;
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A st->print("%s", "adapters");
0N/A }
0N/A};
0N/A
0N/Aclass runtimeStubNode : public ProfilerNode {
0N/A private:
0N/A const CodeBlob* _stub;
0N/A const char* _symbol; // The name of the nearest VM symbol when ProfileVM is on. Points to a unique string.
0N/A public:
0N/A runtimeStubNode(const CodeBlob* stub, const char* name, TickPosition where) : ProfilerNode(), _stub(stub), _symbol(name) {
0N/A assert(stub->is_runtime_stub(), "wrong code blob");
0N/A update(where);
0N/A }
0N/A
0N/A bool is_runtime_stub() const { return true; }
0N/A
0N/A bool runtimeStub_match(const CodeBlob* stub, const char* name) const {
0N/A assert(stub->is_runtime_stub(), "wrong code blob");
0N/A return ((RuntimeStub*)_stub)->entry_point() == ((RuntimeStub*)stub)->entry_point() &&
0N/A (_symbol == name);
0N/A }
0N/A
0N/A methodOop method() { return NULL; }
0N/A
0N/A static void print_title(outputStream* st) {
0N/A st->fill_to(col1);
0N/A st->print("%11s", "Runtime stub");
0N/A ProfilerNode::print_title(st);
0N/A }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A ;
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A st->print("%s", ((RuntimeStub*)_stub)->name());
0N/A print_symbol_on(st);
0N/A }
0N/A
0N/A void print_symbol_on(outputStream* st) {
0N/A if(_symbol) {
0N/A st->print(" (%s)", _symbol);
0N/A }
0N/A }
0N/A};
0N/A
0N/A
0N/Aclass unknown_compiledNode : public ProfilerNode {
0N/A const char *_name;
0N/A public:
0N/A unknown_compiledNode(const CodeBlob* cb, TickPosition where) : ProfilerNode() {
0N/A if ( cb->is_buffer_blob() )
0N/A _name = ((BufferBlob*)cb)->name();
0N/A else
0N/A _name = ((SingletonBlob*)cb)->name();
0N/A update(where);
0N/A }
0N/A bool is_compiled() const { return true; }
0N/A
0N/A bool unknown_compiled_match(const CodeBlob* cb) const {
0N/A if ( cb->is_buffer_blob() )
0N/A return !strcmp(((BufferBlob*)cb)->name(), _name);
0N/A else
0N/A return !strcmp(((SingletonBlob*)cb)->name(), _name);
0N/A }
0N/A
0N/A methodOop method() { return NULL; }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A ;
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A st->print("%s", _name);
0N/A }
0N/A};
0N/A
0N/Aclass vmNode : public ProfilerNode {
0N/A private:
0N/A const char* _name; // "optional" name obtained by os means such as dll lookup
0N/A public:
0N/A vmNode(const TickPosition where) : ProfilerNode() {
0N/A _name = NULL;
0N/A update(where);
0N/A }
0N/A
0N/A vmNode(const char* name, const TickPosition where) : ProfilerNode() {
0N/A _name = name;
0N/A update(where);
0N/A }
0N/A
0N/A const char *name() const { return _name; }
0N/A bool is_compiled() const { return true; }
0N/A
0N/A bool vm_match(const char* name) const { return strcmp(name, _name) == 0; }
0N/A
0N/A methodOop method() { return NULL; }
0N/A
0N/A static int hash(const char* name){
0N/A // Compute a simple hash
0N/A const char* cp = name;
0N/A int h = 0;
0N/A
0N/A if(name != NULL){
0N/A while(*cp != '\0'){
0N/A h = (h << 1) ^ *cp;
0N/A cp++;
0N/A }
0N/A }
0N/A return h;
0N/A }
0N/A
0N/A void oops_do(OopClosure* f) {
0N/A ;
0N/A }
0N/A
0N/A void print(outputStream* st, int total_ticks) {
0N/A ProfilerNode::print(st, total_ticks);
0N/A }
0N/A
0N/A void print_method_on(outputStream* st) {
0N/A if(_name==NULL){
0N/A st->print("%s", "unknown code");
0N/A }
0N/A else {
0N/A st->print("%s", _name);
0N/A }
0N/A }
0N/A};
0N/A
0N/Avoid ThreadProfiler::interpreted_update(methodOop method, TickPosition where) {
0N/A int index = entry(ProfilerNode::hash(method));
0N/A if (!table[index]) {
0N/A table[index] = new (this) interpretedNode(method, where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (node->interpreted_match(method)) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) interpretedNode(method, where));
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::compiled_update(methodOop method, TickPosition where) {
0N/A int index = entry(ProfilerNode::hash(method));
0N/A if (!table[index]) {
0N/A table[index] = new (this) compiledNode(method, where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (node->compiled_match(method)) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) compiledNode(method, where));
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::stub_update(methodOop method, const char* name, TickPosition where) {
0N/A int index = entry(ProfilerNode::hash(method));
0N/A if (!table[index]) {
0N/A table[index] = new (this) stubNode(method, name, where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (node->stub_match(method, name)) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) stubNode(method, name, where));
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::adapter_update(TickPosition where) {
0N/A int index = 0;
0N/A if (!table[index]) {
0N/A table[index] = new (this) adapterNode(where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (node->adapter_match()) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) adapterNode(where));
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where) {
0N/A int index = 0;
0N/A if (!table[index]) {
0N/A table[index] = new (this) runtimeStubNode(stub, name, where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (node->runtimeStub_match(stub, name)) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) runtimeStubNode(stub, name, where));
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid ThreadProfiler::unknown_compiled_update(const CodeBlob* cb, TickPosition where) {
0N/A int index = 0;
0N/A if (!table[index]) {
0N/A table[index] = new (this) unknown_compiledNode(cb, where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (node->unknown_compiled_match(cb)) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) unknown_compiledNode(cb, where));
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::vm_update(TickPosition where) {
0N/A vm_update(NULL, where);
0N/A}
0N/A
0N/Avoid ThreadProfiler::vm_update(const char* name, TickPosition where) {
0N/A int index = entry(vmNode::hash(name));
0N/A assert(index >= 0, "Must be positive");
0N/A // Note that we call strdup below since the symbol may be resource allocated
0N/A if (!table[index]) {
0N/A table[index] = new (this) vmNode(os::strdup(name), where);
0N/A } else {
0N/A ProfilerNode* prev = table[index];
0N/A for(ProfilerNode* node = prev; node; node = node->next()) {
0N/A if (((vmNode *)node)->vm_match(name)) {
0N/A node->update(where);
0N/A return;
0N/A }
0N/A prev = node;
0N/A }
0N/A prev->set_next(new (this) vmNode(os::strdup(name), where));
0N/A }
0N/A}
0N/A
0N/A
0N/Aclass FlatProfilerTask : public PeriodicTask {
0N/Apublic:
0N/A FlatProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
0N/A void task();
0N/A};
0N/A
0N/Avoid FlatProfiler::record_vm_operation() {
0N/A if (Universe::heap()->is_gc_active()) {
0N/A FlatProfiler::received_gc_ticks += 1;
0N/A return;
0N/A }
0N/A
0N/A if (DeoptimizationMarker::is_active()) {
0N/A FlatProfiler::deopt_ticks += 1;
0N/A return;
0N/A }
0N/A
0N/A FlatProfiler::vm_operation_ticks += 1;
0N/A}
0N/A
0N/Avoid FlatProfiler::record_vm_tick() {
0N/A // Profile the VM Thread itself if needed
0N/A // This is done without getting the Threads_lock and we can go deep
0N/A // inside Safepoint, etc.
0N/A if( ProfileVM ) {
0N/A ResourceMark rm;
0N/A ExtendedPC epc;
0N/A const char *name = NULL;
0N/A char buf[256];
0N/A buf[0] = '\0';
0N/A
0N/A vm_thread_profiler->inc_thread_ticks();
0N/A
0N/A // Get a snapshot of a current VMThread pc (and leave it running!)
0N/A // The call may fail if, for instance the VM thread is interrupted while
0N/A // holding the Interrupt_lock or for other reasons.
0N/A epc = os::get_thread_pc(VMThread::vm_thread());
0N/A if(epc.pc() != NULL) {
0N/A if (os::dll_address_to_function_name(epc.pc(), buf, sizeof(buf), NULL)) {
0N/A name = buf;
0N/A }
0N/A }
0N/A if (name != NULL) {
0N/A vm_thread_profiler->vm_update(name, tp_native);
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid FlatProfiler::record_thread_ticks() {
0N/A
0N/A int maxthreads, suspendedthreadcount;
0N/A JavaThread** threadsList;
0N/A bool interval_expired = false;
0N/A
0N/A if (ProfileIntervals &&
0N/A (FlatProfiler::received_ticks >= interval_ticks_previous + ProfileIntervalsTicks)) {
0N/A interval_expired = true;
0N/A interval_ticks_previous = FlatProfiler::received_ticks;
0N/A }
0N/A
0N/A // Try not to wait for the Threads_lock
0N/A if (Threads_lock->try_lock()) {
0N/A { // Threads_lock scope
0N/A maxthreads = Threads::number_of_threads();
3863N/A threadsList = NEW_C_HEAP_ARRAY(JavaThread *, maxthreads, mtInternal);
0N/A suspendedthreadcount = 0;
0N/A for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
0N/A if (tp->is_Compiler_thread()) {
0N/A // Only record ticks for active compiler threads
0N/A CompilerThread* cthread = (CompilerThread*)tp;
0N/A if (cthread->task() != NULL) {
0N/A // The compiler is active. If we need to access any of the fields
0N/A // of the compiler task we should suspend the CompilerThread first.
0N/A FlatProfiler::compiler_ticks += 1;
0N/A continue;
0N/A }
0N/A }
0N/A
0N/A // First externally suspend all threads by marking each for
0N/A // external suspension - so it will stop at its next transition
0N/A // Then do a safepoint
0N/A ThreadProfiler* pp = tp->get_thread_profiler();
0N/A if (pp != NULL && pp->engaged) {
0N/A MutexLockerEx ml(tp->SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A if (!tp->is_external_suspend() && !tp->is_exiting()) {
0N/A tp->set_external_suspend();
0N/A threadsList[suspendedthreadcount++] = tp;
0N/A }
0N/A }
0N/A }
0N/A Threads_lock->unlock();
0N/A }
0N/A // Suspend each thread. This call should just return
0N/A // for any threads that have already self-suspended
0N/A // Net result should be one safepoint
0N/A for (int j = 0; j < suspendedthreadcount; j++) {
0N/A JavaThread *tp = threadsList[j];
0N/A if (tp) {
0N/A tp->java_suspend();
0N/A }
0N/A }
0N/A
0N/A // We are responsible for resuming any thread on this list
0N/A for (int i = 0; i < suspendedthreadcount; i++) {
0N/A JavaThread *tp = threadsList[i];
0N/A if (tp) {
0N/A ThreadProfiler* pp = tp->get_thread_profiler();
0N/A if (pp != NULL && pp->engaged) {
0N/A HandleMark hm;
0N/A FlatProfiler::delivered_ticks += 1;
0N/A if (interval_expired) {
0N/A FlatProfiler::interval_record_thread(pp);
0N/A }
0N/A // This is the place where we check to see if a user thread is
0N/A // blocked waiting for compilation.
0N/A if (tp->blocked_on_compilation()) {
0N/A pp->compiler_ticks += 1;
0N/A pp->interval_data_ref()->inc_compiling();
0N/A } else {
0N/A pp->record_tick(tp);
0N/A }
0N/A }
0N/A MutexLocker ml(Threads_lock);
0N/A tp->java_resume();
0N/A }
0N/A }
0N/A if (interval_expired) {
0N/A FlatProfiler::interval_print();
0N/A FlatProfiler::interval_reset();
0N/A }
0N/A } else {
0N/A // Couldn't get the threads lock, just record that rather than blocking
0N/A FlatProfiler::threads_lock_ticks += 1;
0N/A }
0N/A
0N/A}
0N/A
0N/Avoid FlatProfilerTask::task() {
0N/A FlatProfiler::received_ticks += 1;
0N/A
0N/A if (ProfileVM) {
0N/A FlatProfiler::record_vm_tick();
0N/A }
0N/A
0N/A VM_Operation* op = VMThread::vm_operation();
0N/A if (op != NULL) {
0N/A FlatProfiler::record_vm_operation();
0N/A if (SafepointSynchronize::is_at_safepoint()) {
0N/A return;
0N/A }
0N/A }
0N/A FlatProfiler::record_thread_ticks();
0N/A}
0N/A
107N/Avoid ThreadProfiler::record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks) {
0N/A FlatProfiler::all_int_ticks++;
0N/A if (!FlatProfiler::full_profile()) {
0N/A return;
0N/A }
0N/A
107N/A if (!fr.is_interpreted_frame_valid(thread)) {
0N/A // tick came at a bad time
0N/A interpreter_ticks += 1;
0N/A FlatProfiler::interpreter_ticks += 1;
0N/A return;
0N/A }
0N/A
107N/A // The frame has been fully validated so we can trust the method and bci
107N/A
107N/A methodOop method = *fr.interpreter_frame_method_addr();
107N/A
0N/A interpreted_update(method, where);
0N/A
0N/A // update byte code table
0N/A InterpreterCodelet* desc = Interpreter::codelet_containing(fr.pc());
0N/A if (desc != NULL && desc->bytecode() >= 0) {
0N/A ticks[desc->bytecode()]++;
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::record_compiled_tick(JavaThread* thread, frame fr, TickPosition where) {
0N/A const char *name = NULL;
0N/A TickPosition localwhere = where;
0N/A
0N/A FlatProfiler::all_comp_ticks++;
0N/A if (!FlatProfiler::full_profile()) return;
0N/A
0N/A CodeBlob* cb = fr.cb();
0N/A
0N/A// For runtime stubs, record as native rather than as compiled
0N/A if (cb->is_runtime_stub()) {
0N/A RegisterMap map(thread, false);
0N/A fr = fr.sender(&map);
0N/A cb = fr.cb();
0N/A localwhere = tp_native;
0N/A }
0N/A methodOop method = (cb->is_nmethod()) ? ((nmethod *)cb)->method() :
0N/A (methodOop)NULL;
0N/A
0N/A if (method == NULL) {
0N/A if (cb->is_runtime_stub())
0N/A runtime_stub_update(cb, name, localwhere);
0N/A else
0N/A unknown_compiled_update(cb, localwhere);
0N/A }
0N/A else {
0N/A if (method->is_native()) {
0N/A stub_update(method, name, localwhere);
0N/A } else {
0N/A compiled_update(method, localwhere);
0N/A }
0N/A }
0N/A}
0N/A
0N/Aextern "C" void find(int x);
0N/A
0N/A
0N/Avoid ThreadProfiler::record_tick_for_running_frame(JavaThread* thread, frame fr) {
605N/A // The tick happened in real code -> non VM code
0N/A if (fr.is_interpreted_frame()) {
0N/A interval_data_ref()->inc_interpreted();
107N/A record_interpreted_tick(thread, fr, tp_code, FlatProfiler::bytecode_ticks);
0N/A return;
0N/A }
0N/A
0N/A if (CodeCache::contains(fr.pc())) {
0N/A interval_data_ref()->inc_compiled();
0N/A PCRecorder::record(fr.pc());
0N/A record_compiled_tick(thread, fr, tp_code);
0N/A return;
0N/A }
0N/A
0N/A if (VtableStubs::stub_containing(fr.pc()) != NULL) {
0N/A unknown_ticks_array[ut_vtable_stubs] += 1;
0N/A return;
0N/A }
0N/A
0N/A frame caller = fr.profile_find_Java_sender_frame(thread);
0N/A
0N/A if (caller.sp() != NULL && caller.pc() != NULL) {
0N/A record_tick_for_calling_frame(thread, caller);
0N/A return;
0N/A }
0N/A
0N/A unknown_ticks_array[ut_running_frame] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A}
0N/A
0N/Avoid ThreadProfiler::record_tick_for_calling_frame(JavaThread* thread, frame fr) {
605N/A // The tick happened in VM code
0N/A interval_data_ref()->inc_native();
0N/A if (fr.is_interpreted_frame()) {
107N/A record_interpreted_tick(thread, fr, tp_native, FlatProfiler::bytecode_ticks_stub);
0N/A return;
0N/A }
0N/A if (CodeCache::contains(fr.pc())) {
0N/A record_compiled_tick(thread, fr, tp_native);
0N/A return;
0N/A }
0N/A
0N/A frame caller = fr.profile_find_Java_sender_frame(thread);
0N/A
0N/A if (caller.sp() != NULL && caller.pc() != NULL) {
0N/A record_tick_for_calling_frame(thread, caller);
0N/A return;
0N/A }
0N/A
0N/A unknown_ticks_array[ut_calling_frame] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A}
0N/A
0N/Avoid ThreadProfiler::record_tick(JavaThread* thread) {
0N/A FlatProfiler::all_ticks++;
0N/A thread_ticks += 1;
0N/A
0N/A // Here's another way to track global state changes.
0N/A // When the class loader starts it marks the ThreadProfiler to tell it it is in the class loader
0N/A // and we check that here.
0N/A // This is more direct, and more than one thread can be in the class loader at a time,
0N/A // but it does mean the class loader has to know about the profiler.
0N/A if (region_flag[ThreadProfilerMark::classLoaderRegion]) {
0N/A class_loader_ticks += 1;
0N/A FlatProfiler::class_loader_ticks += 1;
0N/A return;
0N/A } else if (region_flag[ThreadProfilerMark::extraRegion]) {
0N/A extra_ticks += 1;
0N/A FlatProfiler::extra_ticks += 1;
0N/A return;
0N/A }
0N/A // Note that the WatcherThread can now stop for safepoints
0N/A uint32_t debug_bits = 0;
0N/A if (!thread->wait_for_ext_suspend_completion(SuspendRetryCount,
0N/A SuspendRetryDelay, &debug_bits)) {
0N/A unknown_ticks_array[ut_unknown_thread_state] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A return;
0N/A }
0N/A
0N/A frame fr;
0N/A
0N/A switch (thread->thread_state()) {
0N/A case _thread_in_native:
0N/A case _thread_in_native_trans:
0N/A case _thread_in_vm:
0N/A case _thread_in_vm_trans:
0N/A if (thread->profile_last_Java_frame(&fr)) {
0N/A if (fr.is_runtime_frame()) {
0N/A RegisterMap map(thread, false);
0N/A fr = fr.sender(&map);
0N/A }
0N/A record_tick_for_calling_frame(thread, fr);
0N/A } else {
0N/A unknown_ticks_array[ut_no_last_Java_frame] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A }
0N/A break;
0N/A // handle_special_runtime_exit_condition self-suspends threads in Java
0N/A case _thread_in_Java:
0N/A case _thread_in_Java_trans:
0N/A if (thread->profile_last_Java_frame(&fr)) {
0N/A if (fr.is_safepoint_blob_frame()) {
0N/A RegisterMap map(thread, false);
0N/A fr = fr.sender(&map);
0N/A }
0N/A record_tick_for_running_frame(thread, fr);
0N/A } else {
0N/A unknown_ticks_array[ut_no_last_Java_frame] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A }
0N/A break;
0N/A case _thread_blocked:
0N/A case _thread_blocked_trans:
0N/A if (thread->osthread() && thread->osthread()->get_state() == RUNNABLE) {
0N/A if (thread->profile_last_Java_frame(&fr)) {
0N/A if (fr.is_safepoint_blob_frame()) {
0N/A RegisterMap map(thread, false);
0N/A fr = fr.sender(&map);
0N/A record_tick_for_running_frame(thread, fr);
0N/A } else {
0N/A record_tick_for_calling_frame(thread, fr);
0N/A }
0N/A } else {
0N/A unknown_ticks_array[ut_no_last_Java_frame] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A }
0N/A } else {
0N/A blocked_ticks += 1;
0N/A FlatProfiler::blocked_ticks += 1;
0N/A }
0N/A break;
0N/A case _thread_uninitialized:
0N/A case _thread_new:
0N/A // not used, included for completeness
0N/A case _thread_new_trans:
0N/A unknown_ticks_array[ut_no_last_Java_frame] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A break;
0N/A default:
0N/A unknown_ticks_array[ut_unknown_thread_state] += 1;
0N/A FlatProfiler::unknown_ticks += 1;
0N/A break;
0N/A }
0N/A return;
0N/A}
0N/A
0N/Avoid ThreadProfiler::engage() {
0N/A engaged = true;
0N/A timer.start();
0N/A}
0N/A
0N/Avoid ThreadProfiler::disengage() {
0N/A engaged = false;
0N/A timer.stop();
0N/A}
0N/A
0N/Avoid ThreadProfiler::initialize() {
0N/A for (int index = 0; index < table_size; index++) {
0N/A table[index] = NULL;
0N/A }
0N/A thread_ticks = 0;
0N/A blocked_ticks = 0;
0N/A compiler_ticks = 0;
0N/A interpreter_ticks = 0;
0N/A for (int ut = 0; ut < ut_end; ut += 1) {
0N/A unknown_ticks_array[ut] = 0;
0N/A }
0N/A region_flag[ThreadProfilerMark::classLoaderRegion] = false;
0N/A class_loader_ticks = 0;
0N/A region_flag[ThreadProfilerMark::extraRegion] = false;
0N/A extra_ticks = 0;
0N/A timer.start();
0N/A interval_data_ref()->reset();
0N/A}
0N/A
0N/Avoid ThreadProfiler::reset() {
0N/A timer.stop();
0N/A if (table != NULL) {
0N/A for (int index = 0; index < table_size; index++) {
0N/A ProfilerNode* n = table[index];
0N/A if (n != NULL) {
0N/A delete n;
0N/A }
0N/A }
0N/A }
0N/A initialize();
0N/A}
0N/A
0N/Avoid FlatProfiler::allocate_table() {
0N/A { // Bytecode table
3863N/A bytecode_ticks = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
3863N/A bytecode_ticks_stub = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
0N/A for(int index = 0; index < Bytecodes::number_of_codes; index++) {
0N/A bytecode_ticks[index] = 0;
0N/A bytecode_ticks_stub[index] = 0;
0N/A }
0N/A }
0N/A
0N/A if (ProfilerRecordPC) PCRecorder::init();
0N/A
3863N/A interval_data = NEW_C_HEAP_ARRAY(IntervalData, interval_print_size, mtInternal);
0N/A FlatProfiler::interval_reset();
0N/A}
0N/A
0N/Avoid FlatProfiler::engage(JavaThread* mainThread, bool fullProfile) {
0N/A full_profile_flag = fullProfile;
0N/A if (bytecode_ticks == NULL) {
0N/A allocate_table();
0N/A }
0N/A if(ProfileVM && (vm_thread_profiler == NULL)){
0N/A vm_thread_profiler = new ThreadProfiler();
0N/A }
0N/A if (task == NULL) {
0N/A task = new FlatProfilerTask(WatcherThread::delay_interval);
0N/A task->enroll();
0N/A }
0N/A timer.start();
0N/A if (mainThread != NULL) {
0N/A // When mainThread was created, it might not have a ThreadProfiler
0N/A ThreadProfiler* pp = mainThread->get_thread_profiler();
0N/A if (pp == NULL) {
0N/A mainThread->set_thread_profiler(new ThreadProfiler());
0N/A } else {
0N/A pp->reset();
0N/A }
0N/A mainThread->get_thread_profiler()->engage();
0N/A }
0N/A // This is where we would assign thread_profiler
0N/A // if we wanted only one thread_profiler for all threads.
0N/A thread_profiler = NULL;
0N/A}
0N/A
0N/Avoid FlatProfiler::disengage() {
0N/A if (!task) {
0N/A return;
0N/A }
0N/A timer.stop();
0N/A task->disenroll();
0N/A delete task;
0N/A task = NULL;
0N/A if (thread_profiler != NULL) {
0N/A thread_profiler->disengage();
0N/A } else {
0N/A MutexLocker tl(Threads_lock);
0N/A for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
0N/A ThreadProfiler* pp = tp->get_thread_profiler();
0N/A if (pp != NULL) {
0N/A pp->disengage();
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid FlatProfiler::reset() {
0N/A if (task) {
0N/A disengage();
0N/A }
0N/A
0N/A class_loader_ticks = 0;
0N/A extra_ticks = 0;
0N/A received_gc_ticks = 0;
0N/A vm_operation_ticks = 0;
0N/A compiler_ticks = 0;
0N/A deopt_ticks = 0;
0N/A interpreter_ticks = 0;
0N/A blocked_ticks = 0;
0N/A unknown_ticks = 0;
0N/A received_ticks = 0;
0N/A delivered_ticks = 0;
0N/A timer.stop();
0N/A}
0N/A
0N/Abool FlatProfiler::is_active() {
0N/A return task != NULL;
0N/A}
0N/A
0N/Avoid FlatProfiler::print_byte_code_statistics() {
0N/A GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
0N/A
0N/A tty->print_cr(" Bytecode ticks:");
0N/A for (int index = 0; index < Bytecodes::number_of_codes; index++) {
0N/A if (FlatProfiler::bytecode_ticks[index] > 0 || FlatProfiler::bytecode_ticks_stub[index] > 0) {
0N/A tty->print_cr(" %4d %4d = %s",
0N/A FlatProfiler::bytecode_ticks[index],
0N/A FlatProfiler::bytecode_ticks_stub[index],
0N/A Bytecodes::name( (Bytecodes::Code) index));
0N/A }
0N/A }
0N/A tty->cr();
0N/A}
0N/A
0N/Avoid print_ticks(const char* title, int ticks, int total) {
0N/A if (ticks > 0) {
0N/A tty->print("%5.1f%% %5d", ticks * 100.0 / total, ticks);
0N/A tty->fill_to(col3);
0N/A tty->print("%s", title);
0N/A tty->cr();
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::print(const char* thread_name) {
0N/A ResourceMark rm;
0N/A MutexLocker ppl(ProfilePrint_lock);
0N/A int index = 0; // Declared outside for loops for portability
0N/A
0N/A if (table == NULL) {
0N/A return;
0N/A }
0N/A
0N/A if (thread_ticks <= 0) {
0N/A return;
0N/A }
0N/A
0N/A const char* title = "too soon to tell";
0N/A double secs = timer.seconds();
0N/A
0N/A GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
0N/A for(index = 0; index < table_size; index++) {
0N/A for(ProfilerNode* node = table[index]; node; node = node->next())
0N/A array->append(node);
0N/A }
0N/A
0N/A array->sort(&ProfilerNode::compare);
0N/A
0N/A // compute total (sanity check)
0N/A int active =
0N/A class_loader_ticks +
0N/A compiler_ticks +
0N/A interpreter_ticks +
0N/A unknown_ticks();
0N/A for (index = 0; index < array->length(); index++) {
0N/A active += array->at(index)->ticks.total();
0N/A }
0N/A int total = active + blocked_ticks;
0N/A
0N/A tty->cr();
0N/A tty->print_cr("Flat profile of %3.2f secs (%d total ticks): %s", secs, total, thread_name);
0N/A if (total != thread_ticks) {
0N/A print_ticks("Lost ticks", thread_ticks-total, thread_ticks);
0N/A }
0N/A tty->cr();
0N/A
0N/A // print interpreted methods
0N/A tick_counter interpreted_ticks;
0N/A bool has_interpreted_ticks = false;
0N/A int print_count = 0;
0N/A for (index = 0; index < array->length(); index++) {
0N/A ProfilerNode* n = array->at(index);
0N/A if (n->is_interpreted()) {
0N/A interpreted_ticks.add(&n->ticks);
0N/A if (!has_interpreted_ticks) {
0N/A interpretedNode::print_title(tty);
0N/A has_interpreted_ticks = true;
0N/A }
0N/A if (print_count++ < ProfilerNumberOfInterpretedMethods) {
0N/A n->print(tty, active);
0N/A }
0N/A }
0N/A }
0N/A if (has_interpreted_ticks) {
0N/A if (print_count <= ProfilerNumberOfInterpretedMethods) {
0N/A title = "Total interpreted";
0N/A } else {
0N/A title = "Total interpreted (including elided)";
0N/A }
0N/A interpretedNode::print_total(tty, &interpreted_ticks, active, title);
0N/A tty->cr();
0N/A }
0N/A
0N/A // print compiled methods
0N/A tick_counter compiled_ticks;
0N/A bool has_compiled_ticks = false;
0N/A print_count = 0;
0N/A for (index = 0; index < array->length(); index++) {
0N/A ProfilerNode* n = array->at(index);
0N/A if (n->is_compiled()) {
0N/A compiled_ticks.add(&n->ticks);
0N/A if (!has_compiled_ticks) {
0N/A compiledNode::print_title(tty);
0N/A has_compiled_ticks = true;
0N/A }
0N/A if (print_count++ < ProfilerNumberOfCompiledMethods) {
0N/A n->print(tty, active);
0N/A }
0N/A }
0N/A }
0N/A if (has_compiled_ticks) {
0N/A if (print_count <= ProfilerNumberOfCompiledMethods) {
0N/A title = "Total compiled";
0N/A } else {
0N/A title = "Total compiled (including elided)";
0N/A }
0N/A compiledNode::print_total(tty, &compiled_ticks, active, title);
0N/A tty->cr();
0N/A }
0N/A
0N/A // print stub methods
0N/A tick_counter stub_ticks;
0N/A bool has_stub_ticks = false;
0N/A print_count = 0;
0N/A for (index = 0; index < array->length(); index++) {
0N/A ProfilerNode* n = array->at(index);
0N/A if (n->is_stub()) {
0N/A stub_ticks.add(&n->ticks);
0N/A if (!has_stub_ticks) {
0N/A stubNode::print_title(tty);
0N/A has_stub_ticks = true;
0N/A }
0N/A if (print_count++ < ProfilerNumberOfStubMethods) {
0N/A n->print(tty, active);
0N/A }
0N/A }
0N/A }
0N/A if (has_stub_ticks) {
0N/A if (print_count <= ProfilerNumberOfStubMethods) {
0N/A title = "Total stub";
0N/A } else {
0N/A title = "Total stub (including elided)";
0N/A }
0N/A stubNode::print_total(tty, &stub_ticks, active, title);
0N/A tty->cr();
0N/A }
0N/A
0N/A // print runtime stubs
0N/A tick_counter runtime_stub_ticks;
0N/A bool has_runtime_stub_ticks = false;
0N/A print_count = 0;
0N/A for (index = 0; index < array->length(); index++) {
0N/A ProfilerNode* n = array->at(index);
0N/A if (n->is_runtime_stub()) {
0N/A runtime_stub_ticks.add(&n->ticks);
0N/A if (!has_runtime_stub_ticks) {
0N/A runtimeStubNode::print_title(tty);
0N/A has_runtime_stub_ticks = true;
0N/A }
0N/A if (print_count++ < ProfilerNumberOfRuntimeStubNodes) {
0N/A n->print(tty, active);
0N/A }
0N/A }
0N/A }
0N/A if (has_runtime_stub_ticks) {
0N/A if (print_count <= ProfilerNumberOfRuntimeStubNodes) {
0N/A title = "Total runtime stubs";
0N/A } else {
0N/A title = "Total runtime stubs (including elided)";
0N/A }
0N/A runtimeStubNode::print_total(tty, &runtime_stub_ticks, active, title);
0N/A tty->cr();
0N/A }
0N/A
0N/A if (blocked_ticks + class_loader_ticks + interpreter_ticks + compiler_ticks + unknown_ticks() != 0) {
0N/A tty->fill_to(col1);
0N/A tty->print_cr("Thread-local ticks:");
0N/A print_ticks("Blocked (of total)", blocked_ticks, total);
0N/A print_ticks("Class loader", class_loader_ticks, active);
0N/A print_ticks("Extra", extra_ticks, active);
0N/A print_ticks("Interpreter", interpreter_ticks, active);
0N/A print_ticks("Compilation", compiler_ticks, active);
0N/A print_ticks("Unknown: vtable stubs", unknown_ticks_array[ut_vtable_stubs], active);
0N/A print_ticks("Unknown: null method", unknown_ticks_array[ut_null_method], active);
0N/A print_ticks("Unknown: running frame", unknown_ticks_array[ut_running_frame], active);
0N/A print_ticks("Unknown: calling frame", unknown_ticks_array[ut_calling_frame], active);
0N/A print_ticks("Unknown: no pc", unknown_ticks_array[ut_no_pc], active);
0N/A print_ticks("Unknown: no last frame", unknown_ticks_array[ut_no_last_Java_frame], active);
0N/A print_ticks("Unknown: thread_state", unknown_ticks_array[ut_unknown_thread_state], active);
0N/A tty->cr();
0N/A }
0N/A
0N/A if (WizardMode) {
0N/A tty->print_cr("Node area used: %dKb", (area_top - area_bottom) / 1024);
0N/A }
0N/A reset();
0N/A}
0N/A
0N/A/*
0N/AThreadProfiler::print_unknown(){
0N/A if (table == NULL) {
0N/A return;
0N/A }
0N/A
0N/A if (thread_ticks <= 0) {
0N/A return;
0N/A }
0N/A} */
0N/A
0N/Avoid FlatProfiler::print(int unused) {
0N/A ResourceMark rm;
0N/A if (thread_profiler != NULL) {
0N/A thread_profiler->print("All threads");
0N/A } else {
0N/A MutexLocker tl(Threads_lock);
0N/A for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
0N/A ThreadProfiler* pp = tp->get_thread_profiler();
0N/A if (pp != NULL) {
0N/A pp->print(tp->get_thread_name());
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (ProfilerPrintByteCodeStatistics) {
0N/A print_byte_code_statistics();
0N/A }
0N/A
0N/A if (non_method_ticks() > 0) {
0N/A tty->cr();
0N/A tty->print_cr("Global summary of %3.2f seconds:", timer.seconds());
0N/A print_ticks("Received ticks", received_ticks, received_ticks);
0N/A print_ticks("Received GC ticks", received_gc_ticks, received_ticks);
0N/A print_ticks("Compilation", compiler_ticks, received_ticks);
0N/A print_ticks("Deoptimization", deopt_ticks, received_ticks);
0N/A print_ticks("Other VM operations", vm_operation_ticks, received_ticks);
0N/A#ifndef PRODUCT
0N/A print_ticks("Blocked ticks", blocked_ticks, received_ticks);
0N/A print_ticks("Threads_lock blocks", threads_lock_ticks, received_ticks);
0N/A print_ticks("Delivered ticks", delivered_ticks, received_ticks);
0N/A print_ticks("All ticks", all_ticks, received_ticks);
0N/A#endif
0N/A print_ticks("Class loader", class_loader_ticks, received_ticks);
0N/A print_ticks("Extra ", extra_ticks, received_ticks);
0N/A print_ticks("Interpreter", interpreter_ticks, received_ticks);
0N/A print_ticks("Unknown code", unknown_ticks, received_ticks);
0N/A }
0N/A
0N/A PCRecorder::print();
0N/A
0N/A if(ProfileVM){
0N/A tty->cr();
0N/A vm_thread_profiler->print("VM Thread");
0N/A }
0N/A}
0N/A
0N/Avoid IntervalData::print_header(outputStream* st) {
0N/A st->print("i/c/n/g");
0N/A}
0N/A
0N/Avoid IntervalData::print_data(outputStream* st) {
0N/A st->print("%d/%d/%d/%d", interpreted(), compiled(), native(), compiling());
0N/A}
0N/A
0N/Avoid FlatProfiler::interval_record_thread(ThreadProfiler* tp) {
0N/A IntervalData id = tp->interval_data();
0N/A int total = id.total();
0N/A tp->interval_data_ref()->reset();
0N/A
0N/A // Insertion sort the data, if it's relevant.
0N/A for (int i = 0; i < interval_print_size; i += 1) {
0N/A if (total > interval_data[i].total()) {
0N/A for (int j = interval_print_size - 1; j > i; j -= 1) {
0N/A interval_data[j] = interval_data[j-1];
0N/A }
0N/A interval_data[i] = id;
0N/A break;
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid FlatProfiler::interval_print() {
0N/A if ((interval_data[0].total() > 0)) {
0N/A tty->stamp();
0N/A tty->print("\t");
0N/A IntervalData::print_header(tty);
0N/A for (int i = 0; i < interval_print_size; i += 1) {
0N/A if (interval_data[i].total() > 0) {
0N/A tty->print("\t");
0N/A interval_data[i].print_data(tty);
0N/A }
0N/A }
0N/A tty->cr();
0N/A }
0N/A}
0N/A
0N/Avoid FlatProfiler::interval_reset() {
0N/A for (int i = 0; i < interval_print_size; i += 1) {
0N/A interval_data[i].reset();
0N/A }
0N/A}
0N/A
0N/Avoid ThreadProfiler::oops_do(OopClosure* f) {
0N/A if (table == NULL) return;
0N/A
0N/A for(int index = 0; index < table_size; index++) {
0N/A for(ProfilerNode* node = table[index]; node; node = node->next())
0N/A node->oops_do(f);
0N/A }
0N/A}
0N/A
0N/Avoid FlatProfiler::oops_do(OopClosure* f) {
0N/A if (thread_profiler != NULL) {
0N/A thread_profiler->oops_do(f);
0N/A } else {
0N/A for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
0N/A ThreadProfiler* pp = tp->get_thread_profiler();
0N/A if (pp != NULL) {
0N/A pp->oops_do(f);
0N/A }
0N/A }
0N/A }
0N/A}