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