src/share/vm/interpreter/bytecodeHistogram.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "interpreter/bytecodeHistogram.hpp"
aoqi@0 27 #include "memory/resourceArea.hpp"
aoqi@0 28 #include "runtime/os.hpp"
aoqi@0 29 #include "utilities/growableArray.hpp"
aoqi@0 30
aoqi@0 31 // ------------------------------------------------------------------------------------------------
aoqi@0 32 // Non-product code
aoqi@0 33 #ifndef PRODUCT
aoqi@0 34
aoqi@0 35 // Implementation of BytecodeCounter
aoqi@0 36
aoqi@0 37 int BytecodeCounter::_counter_value = 0;
aoqi@0 38 jlong BytecodeCounter::_reset_time = 0;
aoqi@0 39
aoqi@0 40
aoqi@0 41 void BytecodeCounter::reset() {
aoqi@0 42 _counter_value = 0;
aoqi@0 43 _reset_time = os::elapsed_counter();
aoqi@0 44 }
aoqi@0 45
aoqi@0 46
aoqi@0 47 double BytecodeCounter::elapsed_time() {
aoqi@0 48 return (double)(os::elapsed_counter() - _reset_time) / (double)os::elapsed_frequency();
aoqi@0 49 }
aoqi@0 50
aoqi@0 51
aoqi@0 52 double BytecodeCounter::frequency() {
aoqi@0 53 return (double)counter_value() / elapsed_time();
aoqi@0 54 }
aoqi@0 55
aoqi@0 56
aoqi@0 57 void BytecodeCounter::print() {
aoqi@0 58 tty->print_cr(
aoqi@0 59 "%d bytecodes executed in %.1fs (%.3fMHz)",
aoqi@0 60 counter_value(),
aoqi@0 61 elapsed_time(),
aoqi@0 62 frequency() / 1000000.0
aoqi@0 63 );
aoqi@0 64 }
aoqi@0 65
aoqi@0 66
aoqi@0 67 // Helper class for sorting
aoqi@0 68
aoqi@0 69 class HistoEntry: public ResourceObj {
aoqi@0 70 private:
aoqi@0 71 int _index;
aoqi@0 72 int _count;
aoqi@0 73
aoqi@0 74 public:
aoqi@0 75 HistoEntry(int index, int count) { _index = index; _count = count; }
aoqi@0 76 int index() const { return _index; }
aoqi@0 77 int count() const { return _count; }
aoqi@0 78
aoqi@0 79 static int compare(HistoEntry** x, HistoEntry** y) { return (*x)->count() - (*y)->count(); }
aoqi@0 80 };
aoqi@0 81
aoqi@0 82
aoqi@0 83 // Helper functions
aoqi@0 84
aoqi@0 85 static GrowableArray<HistoEntry*>* sorted_array(int* array, int length) {
aoqi@0 86 GrowableArray<HistoEntry*>* a = new GrowableArray<HistoEntry*>(length);
aoqi@0 87 int i = length;
aoqi@0 88 while (i-- > 0) a->append(new HistoEntry(i, array[i]));
aoqi@0 89 a->sort(HistoEntry::compare);
aoqi@0 90 return a;
aoqi@0 91 }
aoqi@0 92
aoqi@0 93
aoqi@0 94 static int total_count(GrowableArray<HistoEntry*>* profile) {
aoqi@0 95 int sum = 0;
aoqi@0 96 int i = profile->length();
aoqi@0 97 while (i-- > 0) sum += profile->at(i)->count();
aoqi@0 98 return sum;
aoqi@0 99 }
aoqi@0 100
aoqi@0 101
aoqi@0 102 static const char* name_for(int i) {
aoqi@0 103 return Bytecodes::is_defined(i) ? Bytecodes::name(Bytecodes::cast(i)) : "xxxunusedxxx";
aoqi@0 104 }
aoqi@0 105
aoqi@0 106
aoqi@0 107 // Implementation of BytecodeHistogram
aoqi@0 108
aoqi@0 109 int BytecodeHistogram::_counters[Bytecodes::number_of_codes];
aoqi@0 110
aoqi@0 111
aoqi@0 112 void BytecodeHistogram::reset() {
aoqi@0 113 int i = Bytecodes::number_of_codes;
aoqi@0 114 while (i-- > 0) _counters[i] = 0;
aoqi@0 115 }
aoqi@0 116
aoqi@0 117
aoqi@0 118 void BytecodeHistogram::print(float cutoff) {
aoqi@0 119 ResourceMark rm;
aoqi@0 120 GrowableArray<HistoEntry*>* profile = sorted_array(_counters, Bytecodes::number_of_codes);
aoqi@0 121 // print profile
aoqi@0 122 int tot = total_count(profile);
aoqi@0 123 int abs_sum = 0;
aoqi@0 124 tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789
aoqi@0 125 tty->print_cr("Histogram of %d executed bytecodes:", tot);
aoqi@0 126 tty->cr();
aoqi@0 127 tty->print_cr(" absolute relative code name");
aoqi@0 128 tty->print_cr("----------------------------------------------------------------------");
aoqi@0 129 int i = profile->length();
aoqi@0 130 while (i-- > 0) {
aoqi@0 131 HistoEntry* e = profile->at(i);
aoqi@0 132 int abs = e->count();
aoqi@0 133 float rel = abs * 100.0F / tot;
aoqi@0 134 if (cutoff <= rel) {
aoqi@0 135 tty->print_cr("%10d %7.2f%% %02x %s", abs, rel, e->index(), name_for(e->index()));
aoqi@0 136 abs_sum += abs;
aoqi@0 137 }
aoqi@0 138 }
aoqi@0 139 tty->print_cr("----------------------------------------------------------------------");
aoqi@0 140 float rel_sum = abs_sum * 100.0F / tot;
aoqi@0 141 tty->print_cr("%10d %7.2f%% (cutoff = %.2f%%)", abs_sum, rel_sum, cutoff);
aoqi@0 142 tty->cr();
aoqi@0 143 }
aoqi@0 144
aoqi@0 145
aoqi@0 146 // Implementation of BytecodePairHistogram
aoqi@0 147
aoqi@0 148 int BytecodePairHistogram::_index;
aoqi@0 149 int BytecodePairHistogram::_counters[BytecodePairHistogram::number_of_pairs];
aoqi@0 150
aoqi@0 151
aoqi@0 152 void BytecodePairHistogram::reset() {
aoqi@0 153 _index = Bytecodes::_nop << log2_number_of_codes;
aoqi@0 154
aoqi@0 155 int i = number_of_pairs;
aoqi@0 156 while (i-- > 0) _counters[i] = 0;
aoqi@0 157 }
aoqi@0 158
aoqi@0 159
aoqi@0 160 void BytecodePairHistogram::print(float cutoff) {
aoqi@0 161 ResourceMark rm;
aoqi@0 162 GrowableArray<HistoEntry*>* profile = sorted_array(_counters, number_of_pairs);
aoqi@0 163 // print profile
aoqi@0 164 int tot = total_count(profile);
aoqi@0 165 int abs_sum = 0;
aoqi@0 166 tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789
aoqi@0 167 tty->print_cr("Histogram of %d executed bytecode pairs:", tot);
aoqi@0 168 tty->cr();
aoqi@0 169 tty->print_cr(" absolute relative codes 1st bytecode 2nd bytecode");
aoqi@0 170 tty->print_cr("----------------------------------------------------------------------");
aoqi@0 171 int i = profile->length();
aoqi@0 172 while (i-- > 0) {
aoqi@0 173 HistoEntry* e = profile->at(i);
aoqi@0 174 int abs = e->count();
aoqi@0 175 float rel = abs * 100.0F / tot;
aoqi@0 176 if (cutoff <= rel) {
aoqi@0 177 int c1 = e->index() % number_of_codes;
aoqi@0 178 int c2 = e->index() / number_of_codes;
aoqi@0 179 tty->print_cr("%10d %6.3f%% %02x %02x %-19s %s", abs, rel, c1, c2, name_for(c1), name_for(c2));
aoqi@0 180 abs_sum += abs;
aoqi@0 181 }
aoqi@0 182 }
aoqi@0 183 tty->print_cr("----------------------------------------------------------------------");
aoqi@0 184 float rel_sum = abs_sum * 100.0F / tot;
aoqi@0 185 tty->print_cr("%10d %6.3f%% (cutoff = %.3f%%)", abs_sum, rel_sum, cutoff);
aoqi@0 186 tty->cr();
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 #endif

mercurial