hotspot/src/share/vm/runtime/fprofiler.cpp
author hseigel
Tue, 08 Aug 2017 09:53:52 -0400
changeset 46773 fb17cc9a6847
parent 38133 78b95467b9f1
permissions -rw-r--r--
8185717: Make ModuleEntry->module() return an oop not a jobject Summary: Change ModuleEntry::module() to return an oop and add a ModuleEntry::module_handle() that returns a jobject Reviewed-by: shade, coleenp, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
36357
953ab5f53cff 8150506: Remove unused locks
dholmes
parents: 33148
diff changeset
     2
 * Copyright (c) 1997, 2016, 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: 2131
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
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: 2131
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 "classfile/classLoader.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    27
#include "code/codeCache.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "code/vtableStubs.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    29
#include "gc/shared/collectedHeap.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 36357
diff changeset
    32
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "memory/universe.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "oops/oop.inline.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    35
#include "oops/symbol.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/deoptimization.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/fprofiler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "runtime/stubRoutines.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
#include "runtime/task.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 19699
diff changeset
    42
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    43
#include "runtime/vframe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    44
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Static fields of FlatProfiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
int               FlatProfiler::received_gc_ticks   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
int               FlatProfiler::vm_operation_ticks  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
int               FlatProfiler::threads_lock_ticks  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
int               FlatProfiler::class_loader_ticks  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
int               FlatProfiler::extra_ticks         = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
int               FlatProfiler::blocked_ticks       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
int               FlatProfiler::deopt_ticks         = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
int               FlatProfiler::unknown_ticks       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
int               FlatProfiler::interpreter_ticks   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
int               FlatProfiler::compiler_ticks      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
int               FlatProfiler::received_ticks      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
int               FlatProfiler::delivered_ticks     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
int*              FlatProfiler::bytecode_ticks      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
int*              FlatProfiler::bytecode_ticks_stub = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
int               FlatProfiler::all_int_ticks       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
int               FlatProfiler::all_comp_ticks      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
int               FlatProfiler::all_ticks           = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
bool              FlatProfiler::full_profile_flag   = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
ThreadProfiler*   FlatProfiler::thread_profiler     = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
ThreadProfiler*   FlatProfiler::vm_thread_profiler  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
FlatProfilerTask* FlatProfiler::task                = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
elapsedTimer      FlatProfiler::timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
int               FlatProfiler::interval_ticks_previous = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
IntervalData*     FlatProfiler::interval_data       = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
ThreadProfiler::ThreadProfiler() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Space for the ProfilerNodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  const int area_size = 1 * ProfilerNodeSize * 1024;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    75
  area_bottom = AllocateHeap(area_size, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  area_top    = area_bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  area_limit  = area_bottom + area_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // ProfilerNode pointer table
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    80
  table = NEW_C_HEAP_ARRAY(ProfilerNode*, table_size, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  engaged = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
ThreadProfiler::~ThreadProfiler() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  FreeHeap(area_bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  area_bottom = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  area_top = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  area_limit = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  FreeHeap(table);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  table = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// Statics for ThreadProfiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
int ThreadProfiler::table_size = 1024;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
int ThreadProfiler::entry(int  value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  value = (value > 0) ? value : -value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  return value % table_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
ThreadProfilerMark::ThreadProfilerMark(ThreadProfilerMark::Region r) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _r = r;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _pp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  assert(((r > ThreadProfilerMark::noRegion) && (r < ThreadProfilerMark::maxRegion)), "ThreadProfilerMark::Region out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  Thread* tp = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  if (tp != NULL && tp->is_Java_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    JavaThread* jtp = (JavaThread*) tp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    ThreadProfiler* pp = jtp->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    _pp = pp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    if (pp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      pp->region_flag[r] = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
ThreadProfilerMark::~ThreadProfilerMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  if (_pp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _pp->region_flag[_r] = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  _pp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// Random other statics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
static const int col1 = 2;      // position of output column 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
static const int col2 = 11;     // position of output column 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
static const int col3 = 25;     // position of output column 3
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
static const int col4 = 55;     // position of output column 4
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// Used for detailed profiling of nmethods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
class PCRecorder : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static int*    counters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static address base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
   bucket_size = 16
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static int     index_for(address pc) { return (pc - base)/bucket_size;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static address pc_for(int index)     { return base + (index * bucket_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static int     size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return ((int)CodeCache::max_capacity())/bucket_size * BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static address bucket_start_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    if (counters == NULL) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    return pc_for(index_for(pc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  static int bucket_count_for(address pc)  { return counters[index_for(pc)]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  static void init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  static void record(address pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  static void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static void print_blobs(CodeBlob* cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
int*    PCRecorder::counters = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
address PCRecorder::base     = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
void PCRecorder::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  MutexLockerEx lm(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  int s = size();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   162
  counters = NEW_C_HEAP_ARRAY(int, s, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  for (int index = 0; index < s; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    counters[index] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25949
diff changeset
   166
  base = CodeCache::low_bound();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
void PCRecorder::record(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if (counters == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  assert(CodeCache::contains(pc), "must be in CodeCache");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  counters[index_for(pc)]++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
address FlatProfiler::bucket_start_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  return PCRecorder::bucket_start_for(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
int FlatProfiler::bucket_count_for(address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  return PCRecorder::bucket_count_for(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
void PCRecorder::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  if (counters == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  tty->cr();
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 30764
diff changeset
   188
  tty->print_cr("Printing compiled methods with PC buckets having more than " INTX_FORMAT " ticks", ProfilerPCTickThreshold);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  tty->print_cr("===================================================================");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  GrowableArray<CodeBlob*>* candidates = new GrowableArray<CodeBlob*>(20);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  int s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    MutexLockerEx lm(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    s = size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  for (int index = 0; index < s; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    int count = counters[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    if (count > ProfilerPCTickThreshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      address pc = pc_for(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      if (cb != NULL && candidates->find(cb) < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        candidates->push(cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  for (int i = 0; i < candidates->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    print_blobs(candidates->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void PCRecorder::print_blobs(CodeBlob* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (cb != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    cb->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    if (cb->is_nmethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      ((nmethod*)cb)->print_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    tty->print_cr("stub code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
class tick_counter {            // holds tick info for one node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  int ticks_in_code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  int ticks_in_native;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  tick_counter()                     {  ticks_in_code = ticks_in_native = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  tick_counter(int code, int native) {  ticks_in_code = code; ticks_in_native = native; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  int total() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    return (ticks_in_code + ticks_in_native);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  void add(tick_counter* a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    ticks_in_code += a->ticks_in_code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    ticks_in_native += a->ticks_in_native;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  void update(TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    switch(where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      case tp_code:     ticks_in_code++;       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      case tp_native:   ticks_in_native++;      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  void print_code(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    st->print("%5.1f%% %5d ", total() * 100.0 / total_ticks, ticks_in_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  void print_native(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    st->print(" + %5d ", ticks_in_native);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
class ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  ProfilerNode* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  tick_counter ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17000
diff changeset
   269
  void* operator new(size_t size, ThreadProfiler* tp) throw();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  void  operator delete(void* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  ProfilerNode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    _next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  virtual ~ProfilerNode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    if (_next)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      delete _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  void set_next(ProfilerNode* n) { _next = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  ProfilerNode* next()           { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  void update(TickPosition where) { ticks.update(where);}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  int total_ticks() { return ticks.total(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  virtual bool is_interpreted() const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  virtual bool is_compiled()    const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  virtual bool is_stub()        const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  virtual bool is_runtime_stub() const{ return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  virtual void oops_do(OopClosure* f) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   293
  virtual bool interpreted_match(Method* m) const { return false; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   294
  virtual bool compiled_match(Method* m ) const { return false; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   295
  virtual bool stub_match(Method* m, const char* name) const { return false; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  virtual bool adapter_match() const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  virtual bool runtimeStub_match(const CodeBlob* stub, const char* name) const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  virtual bool unknown_compiled_match(const CodeBlob* cb) const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  static void print_title(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    st->print(" + native");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    st->fill_to(col3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    st->print("Method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    st->fill_to(col4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  static void print_total(outputStream* st, tick_counter* t, int total, const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    t->print_code(st, total);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    st->fill_to(col2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    t->print_native(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    st->fill_to(col3);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
   313
    st->print("%s", msg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   317
  virtual Method* method()         = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  virtual void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    int limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    int i;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   322
    Method* m = method();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   323
    Symbol* k = m->klass_name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // Print the class name with dots instead of slashes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    limit = k->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    for (i = 0 ; i < limit ; i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      char c = (char) k->byte_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      if (c == '/') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
        c = '.';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      st->print("%c", c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    if (limit > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      st->print(".");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   336
    Symbol* n = m->name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    limit = n->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    for (i = 0 ; i < limit ; i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      char c = (char) n->byte_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      st->print("%c", c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   342
    if (Verbose || WizardMode) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      // Disambiguate overloaded methods
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   344
      Symbol* sig = m->signature();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      sig->print_symbol_on(st);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   346
    } else if (MethodHandles::is_signature_polymorphic(m->intrinsic_id()))
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   347
      // compare with Method::print_short_name
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   348
      MethodHandles::print_as_basic_type_signature_on(st, m->signature(), true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  virtual void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    ticks.print_code(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    st->fill_to(col2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    ticks.print_native(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    st->fill_to(col3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    print_method_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  // for hashing into the table
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   361
  static int hash(Method* method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      // The point here is to try to make something fairly unique
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      // out of the fields we can read without grabbing any locks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      // since the method may be locked when we need the hash.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      return (
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
          method->code_size() ^
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
          method->max_stack() ^
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
          method->max_locals() ^
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
          method->size_of_parameters());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // for sorting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  static int compare(ProfilerNode** a, ProfilerNode** b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    return (*b)->total_ticks() - (*a)->total_ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 17000
diff changeset
   378
void* ProfilerNode::operator new(size_t size, ThreadProfiler* tp) throw() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  void* result = (void*) tp->area_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  tp->area_top += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  if (tp->area_top > tp->area_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    fatal("flat profiler buffer overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
void ProfilerNode::operator delete(void* p){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
class interpretedNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   393
   Method* _method;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   394
   oop       _class_loader;  // needed to keep metadata for the method alive
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   396
   interpretedNode(Method* method, TickPosition where) : ProfilerNode() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
     _method = method;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   398
     _class_loader = method->method_holder()->class_loader();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
     update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
   bool is_interpreted() const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   404
   bool interpreted_match(Method* m) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      return _method == m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
   void oops_do(OopClosure* f) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   409
     f->do_oop(&_class_loader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   412
   Method* method() { return _method; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
   static void print_title(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
     st->fill_to(col1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
     st->print("%11s", "Interpreted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
     ProfilerNode::print_title(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
   void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
     ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
   void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
     ProfilerNode::print_method_on(st);
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 13728
diff changeset
   426
     MethodCounters* mcs = method()->method_counters();
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 13728
diff changeset
   427
     if (Verbose && mcs != NULL) mcs->invocation_counter()->print_short();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
class compiledNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   433
   Method* _method;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   434
   oop       _class_loader;  // needed to keep metadata for the method alive
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   436
   compiledNode(Method* method, TickPosition where) : ProfilerNode() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
     _method = method;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   438
     _class_loader = method->method_holder()->class_loader();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
     update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  bool is_compiled()    const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   443
  bool compiled_match(Method* m) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    return _method == m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   447
  Method* method()         { return _method; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  void oops_do(OopClosure* f) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   450
    f->do_oop(&_class_loader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  static void print_title(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    st->fill_to(col1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    st->print("%11s", "Compiled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    ProfilerNode::print_title(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    ProfilerNode::print_method_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
class stubNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   470
  Method* _method;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   471
  oop       _class_loader;  // needed to keep metadata for the method alive
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  const char* _symbol;   // The name of the nearest VM symbol (for +ProfileVM). Points to a unique string
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   474
   stubNode(Method* method, const char* name, TickPosition where) : ProfilerNode() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
     _method = method;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   476
     _class_loader = method->method_holder()->class_loader();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
     _symbol = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
     update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
   bool is_stub() const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   483
   void oops_do(OopClosure* f) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   484
     f->do_oop(&_class_loader);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   485
   }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   486
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   487
   bool stub_match(Method* m, const char* name) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
     return (_method == m) && (_symbol == name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   491
   Method* method() { return _method; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
   static void print_title(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
     st->fill_to(col1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
     st->print("%11s", "Stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
     ProfilerNode::print_title(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
   void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
     ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
   void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
     ProfilerNode::print_method_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
     print_symbol_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  void print_symbol_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    if(_symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
      st->print("  (%s)", _symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
class adapterNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
   adapterNode(TickPosition where) : ProfilerNode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
     update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  bool is_compiled()    const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  bool adapter_match() const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   524
  Method* method()         { return NULL; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  void oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    st->print("%s", "adapters");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
class runtimeStubNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
 private:
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   541
  const RuntimeStub* _stub;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  const char* _symbol;     // The name of the nearest VM symbol when ProfileVM is on. Points to a unique string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
 public:
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   544
   runtimeStubNode(const CodeBlob* stub, const char* name, TickPosition where) : ProfilerNode(), _stub(NULL),  _symbol(name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
     assert(stub->is_runtime_stub(), "wrong code blob");
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   546
     _stub = (RuntimeStub*) stub;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
     update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  bool is_runtime_stub() const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  bool runtimeStub_match(const CodeBlob* stub, const char* name) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    assert(stub->is_runtime_stub(), "wrong code blob");
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   554
    return _stub->entry_point() == ((RuntimeStub*)stub)->entry_point() &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
            (_symbol == name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   558
  Method* method() { return NULL; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  static void print_title(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    st->fill_to(col1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    st->print("%11s", "Runtime stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    ProfilerNode::print_title(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  void oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  void print_method_on(outputStream* st) {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   575
    st->print("%s", _stub->name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    print_symbol_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  void print_symbol_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    if(_symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      st->print("  (%s)", _symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
class unknown_compiledNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
 const char *_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
   unknown_compiledNode(const CodeBlob* cb, TickPosition where) : ProfilerNode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
     if ( cb->is_buffer_blob() )
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   592
       _name = ((const BufferBlob*)cb)->name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
     else
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   594
       _name = ((const SingletonBlob*)cb)->name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
     update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  bool is_compiled()    const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  bool unknown_compiled_match(const CodeBlob* cb) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
     if ( cb->is_buffer_blob() )
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   601
       return !strcmp(((const BufferBlob*)cb)->name(), _name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
     else
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   603
       return !strcmp(((const SingletonBlob*)cb)->name(), _name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   606
  Method* method()         { return NULL; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  void oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    st->print("%s", _name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
class vmNode : public ProfilerNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  const char* _name; // "optional" name obtained by os means such as dll lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  vmNode(const TickPosition where) : ProfilerNode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    _name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  vmNode(const char* name, const TickPosition where) : ProfilerNode() {
25949
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   631
    _name = os::strdup(name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
25949
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   635
  ~vmNode() {
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   636
    if (_name != NULL) {
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   637
      os::free((void*)_name);
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   638
    }
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   639
  }
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   640
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  const char *name()    const { return _name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  bool is_compiled()    const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  bool vm_match(const char* name) const { return strcmp(name, _name) == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   646
  Method* method()          { return NULL; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  static int hash(const char* name){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    // Compute a simple hash
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    const char* cp = name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    int h = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    if(name != NULL){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      while(*cp != '\0'){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
        h = (h << 1) ^ *cp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
        cp++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    return h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  void oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  void print(outputStream* st, int total_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    ProfilerNode::print(st, total_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  void print_method_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    if(_name==NULL){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
      st->print("%s", "unknown code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
      st->print("%s", _name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   680
void ThreadProfiler::interpreted_update(Method* method, TickPosition where) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  int index = entry(ProfilerNode::hash(method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  if (!table[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    table[index] = new (this) interpretedNode(method, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
      if (node->interpreted_match(method)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    prev->set_next(new (this) interpretedNode(method, where));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   697
void ThreadProfiler::compiled_update(Method* method, TickPosition where) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  int index = entry(ProfilerNode::hash(method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  if (!table[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    table[index] = new (this) compiledNode(method, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
      if (node->compiled_match(method)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    prev->set_next(new (this) compiledNode(method, where));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   714
void ThreadProfiler::stub_update(Method* method, const char* name, TickPosition where) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  int index = entry(ProfilerNode::hash(method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  if (!table[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
    table[index] = new (this) stubNode(method, name, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
      if (node->stub_match(method, name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    prev->set_next(new (this) stubNode(method, name, where));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
void ThreadProfiler::adapter_update(TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  if (!table[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
    table[index] = new (this) adapterNode(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
      if (node->adapter_match()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    prev->set_next(new (this) adapterNode(where));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
void ThreadProfiler::runtime_stub_update(const CodeBlob* stub, const char* name, TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  if (!table[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    table[index] = new (this) runtimeStubNode(stub, name, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
      if (node->runtimeStub_match(stub, name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    prev->set_next(new (this) runtimeStubNode(stub, name, where));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
void ThreadProfiler::unknown_compiled_update(const CodeBlob* cb, TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  if (!table[index]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    table[index] = new (this) unknown_compiledNode(cb, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      if (node->unknown_compiled_match(cb)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    prev->set_next(new (this) unknown_compiledNode(cb, where));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
void ThreadProfiler::vm_update(TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  vm_update(NULL, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
void ThreadProfiler::vm_update(const char* name, TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  int index = entry(vmNode::hash(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  assert(index >= 0, "Must be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  // Note that we call strdup below since the symbol may be resource allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  if (!table[index]) {
25949
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   792
    table[index] = new (this) vmNode(name, where);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    ProfilerNode* prev = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    for(ProfilerNode* node = prev; node; node = node->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      if (((vmNode *)node)->vm_match(name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
        node->update(where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
      prev = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    }
25949
34557722059b 6424123: JVM crashes on failed 'strdup' call
zgu
parents: 25715
diff changeset
   802
    prev->set_next(new (this) vmNode(name, where));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
class FlatProfilerTask : public PeriodicTask {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  FlatProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  void task();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
void FlatProfiler::record_vm_operation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  if (Universe::heap()->is_gc_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    FlatProfiler::received_gc_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  if (DeoptimizationMarker::is_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    FlatProfiler::deopt_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  FlatProfiler::vm_operation_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
void FlatProfiler::record_vm_tick() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  // Profile the VM Thread itself if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  // This is done without getting the Threads_lock and we can go deep
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  // inside Safepoint, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  if( ProfileVM  ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    ExtendedPC epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    const char *name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    char buf[256];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    buf[0] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    vm_thread_profiler->inc_thread_ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    // Get a snapshot of a current VMThread pc (and leave it running!)
36357
953ab5f53cff 8150506: Remove unused locks
dholmes
parents: 33148
diff changeset
   841
    // The call may fail in some circumstances
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    epc = os::get_thread_pc(VMThread::vm_thread());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    if(epc.pc() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
      if (os::dll_address_to_function_name(epc.pc(), buf, sizeof(buf), NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
         name = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    if (name != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
      vm_thread_profiler->vm_update(name, tp_native);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
void FlatProfiler::record_thread_ticks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  int maxthreads, suspendedthreadcount;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  JavaThread** threadsList;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  bool interval_expired = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  if (ProfileIntervals &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
      (FlatProfiler::received_ticks >= interval_ticks_previous + ProfileIntervalsTicks)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    interval_expired = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    interval_ticks_previous = FlatProfiler::received_ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  // Try not to wait for the Threads_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  if (Threads_lock->try_lock()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    {  // Threads_lock scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      maxthreads = Threads::number_of_threads();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   870
      threadsList = NEW_C_HEAP_ARRAY(JavaThread *, maxthreads, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
      suspendedthreadcount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
      for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
        if (tp->is_Compiler_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
          // Only record ticks for active compiler threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
          CompilerThread* cthread = (CompilerThread*)tp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
          if (cthread->task() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
            // The compiler is active.  If we need to access any of the fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
            // of the compiler task we should suspend the CompilerThread first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
            FlatProfiler::compiler_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
        // First externally suspend all threads by marking each for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
        // external suspension - so it will stop at its next transition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
        // Then do a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
        ThreadProfiler* pp = tp->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
        if (pp != NULL && pp->engaged) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
          MutexLockerEx ml(tp->SR_lock(), Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
          if (!tp->is_external_suspend() && !tp->is_exiting()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
            tp->set_external_suspend();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
            threadsList[suspendedthreadcount++] = tp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      Threads_lock->unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    // Suspend each thread. This call should just return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    // for any threads that have already self-suspended
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    // Net result should be one safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    for (int j = 0; j < suspendedthreadcount; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
      JavaThread *tp = threadsList[j];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
      if (tp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
        tp->java_suspend();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    // We are responsible for resuming any thread on this list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    for (int i = 0; i < suspendedthreadcount; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      JavaThread *tp = threadsList[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      if (tp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
        ThreadProfiler* pp = tp->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
        if (pp != NULL && pp->engaged) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
          HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
          FlatProfiler::delivered_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
          if (interval_expired) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
          FlatProfiler::interval_record_thread(pp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
          // This is the place where we check to see if a user thread is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
          // blocked waiting for compilation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
          if (tp->blocked_on_compilation()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
            pp->compiler_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
            pp->interval_data_ref()->inc_compiling();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
            pp->record_tick(tp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
        MutexLocker ml(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
        tp->java_resume();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
    if (interval_expired) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
      FlatProfiler::interval_print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
      FlatProfiler::interval_reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    }
19698
fd7f14977192 6991327: using -Xprof trigger native memory leak
zgu
parents: 17000
diff changeset
   936
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26796
diff changeset
   937
    FREE_C_HEAP_ARRAY(JavaThread *, threadsList);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    // Couldn't get the threads lock, just record that rather than blocking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    FlatProfiler::threads_lock_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
void FlatProfilerTask::task() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  FlatProfiler::received_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  if (ProfileVM) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    FlatProfiler::record_vm_tick();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  VM_Operation* op = VMThread::vm_operation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  if (op != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    FlatProfiler::record_vm_operation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    if (SafepointSynchronize::is_at_safepoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  FlatProfiler::record_thread_ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
354
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
   962
void ThreadProfiler::record_interpreted_tick(JavaThread* thread, frame fr, TickPosition where, int* ticks) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  FlatProfiler::all_int_ticks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  if (!FlatProfiler::full_profile()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
354
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
   968
  if (!fr.is_interpreted_frame_valid(thread)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    // tick came at a bad time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    interpreter_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    FlatProfiler::interpreter_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
354
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
   975
  // The frame has been fully validated so we can trust the method and bci
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
   976
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   977
  Method* method = *fr.interpreter_frame_method_addr();
354
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
   978
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  interpreted_update(method, where);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  // update byte code table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  InterpreterCodelet* desc = Interpreter::codelet_containing(fr.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  if (desc != NULL && desc->bytecode() >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    ticks[desc->bytecode()]++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
void ThreadProfiler::record_compiled_tick(JavaThread* thread, frame fr, TickPosition where) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  const char *name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  TickPosition localwhere = where;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  FlatProfiler::all_comp_ticks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  if (!FlatProfiler::full_profile()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  CodeBlob* cb = fr.cb();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   997
  // For runtime stubs, record as native rather than as compiled
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   998
  if (cb->is_runtime_stub()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
   999
    RegisterMap map(thread, false);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
  1000
    fr = fr.sender(&map);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
  1001
    cb = fr.cb();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
  1002
    localwhere = tp_native;
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
  1003
 }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37248
diff changeset
  1005
  Method* method = cb->is_compiled() ? cb->as_compiled_method()->method() : (Method*) NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  if (method == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    if (cb->is_runtime_stub())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      runtime_stub_update(cb, name, localwhere);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
      unknown_compiled_update(cb, localwhere);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
    if (method->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      stub_update(method, name, localwhere);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
      compiled_update(method, localwhere);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
extern "C" void find(int x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
void ThreadProfiler::record_tick_for_running_frame(JavaThread* thread, frame fr) {
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 670
diff changeset
  1025
  // The tick happened in real code -> non VM code
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  if (fr.is_interpreted_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    interval_data_ref()->inc_interpreted();
354
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
  1028
    record_interpreted_tick(thread, fr, tp_code, FlatProfiler::bytecode_ticks);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  if (CodeCache::contains(fr.pc())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    interval_data_ref()->inc_compiled();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    PCRecorder::record(fr.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    record_compiled_tick(thread, fr, tp_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  if (VtableStubs::stub_containing(fr.pc()) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    unknown_ticks_array[ut_vtable_stubs] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  frame caller = fr.profile_find_Java_sender_frame(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  if (caller.sp() != NULL && caller.pc() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    record_tick_for_calling_frame(thread, caller);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  unknown_ticks_array[ut_running_frame] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
  FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
void ThreadProfiler::record_tick_for_calling_frame(JavaThread* thread, frame fr) {
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 670
diff changeset
  1056
  // The tick happened in VM code
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  interval_data_ref()->inc_native();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  if (fr.is_interpreted_frame()) {
354
3b42d6fdcb82 6603919: Stackwalking crash on x86 -server with Sun Studio's collect -j on
sgoldman
parents: 1
diff changeset
  1059
    record_interpreted_tick(thread, fr, tp_native, FlatProfiler::bytecode_ticks_stub);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  if (CodeCache::contains(fr.pc())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    record_compiled_tick(thread, fr, tp_native);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  frame caller = fr.profile_find_Java_sender_frame(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
  if (caller.sp() != NULL && caller.pc() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    record_tick_for_calling_frame(thread, caller);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  unknown_ticks_array[ut_calling_frame] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
void ThreadProfiler::record_tick(JavaThread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  FlatProfiler::all_ticks++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  thread_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  // Here's another way to track global state changes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  // When the class loader starts it marks the ThreadProfiler to tell it it is in the class loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  // and we check that here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  // This is more direct, and more than one thread can be in the class loader at a time,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  // but it does mean the class loader has to know about the profiler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  if (region_flag[ThreadProfilerMark::classLoaderRegion]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
    class_loader_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
    FlatProfiler::class_loader_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  } else if (region_flag[ThreadProfilerMark::extraRegion]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
    extra_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    FlatProfiler::extra_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  // Note that the WatcherThread can now stop for safepoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
  uint32_t debug_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  if (!thread->wait_for_ext_suspend_completion(SuspendRetryCount,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
      SuspendRetryDelay, &debug_bits)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
    unknown_ticks_array[ut_unknown_thread_state] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
    FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  frame fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  switch (thread->thread_state()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  case _thread_in_native:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  case _thread_in_native_trans:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  case _thread_in_vm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  case _thread_in_vm_trans:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
    if (thread->profile_last_Java_frame(&fr)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
      if (fr.is_runtime_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
        RegisterMap map(thread, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
        fr = fr.sender(&map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
      record_tick_for_calling_frame(thread, fr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
      unknown_ticks_array[ut_no_last_Java_frame] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
      FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  // handle_special_runtime_exit_condition self-suspends threads in Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  case _thread_in_Java:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  case _thread_in_Java_trans:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    if (thread->profile_last_Java_frame(&fr)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
      if (fr.is_safepoint_blob_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
        RegisterMap map(thread, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
        fr = fr.sender(&map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
      record_tick_for_running_frame(thread, fr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
      unknown_ticks_array[ut_no_last_Java_frame] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  case _thread_blocked:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  case _thread_blocked_trans:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    if (thread->osthread() && thread->osthread()->get_state() == RUNNABLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
        if (thread->profile_last_Java_frame(&fr)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
          if (fr.is_safepoint_blob_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
            RegisterMap map(thread, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
            fr = fr.sender(&map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
            record_tick_for_running_frame(thread, fr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
            record_tick_for_calling_frame(thread, fr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
          unknown_ticks_array[ut_no_last_Java_frame] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
          FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
          blocked_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
          FlatProfiler::blocked_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  case _thread_uninitialized:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  case _thread_new:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  // not used, included for completeness
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
  case _thread_new_trans:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
     unknown_ticks_array[ut_no_last_Java_frame] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
     FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    unknown_ticks_array[ut_unknown_thread_state] += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    FlatProfiler::unknown_ticks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
void ThreadProfiler::engage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
  engaged = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
void ThreadProfiler::disengage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  engaged = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
void ThreadProfiler::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  for (int index = 0; index < table_size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    table[index] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
  thread_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  blocked_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  compiler_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  interpreter_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  for (int ut = 0; ut < ut_end; ut += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    unknown_ticks_array[ut] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  region_flag[ThreadProfilerMark::classLoaderRegion] = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  class_loader_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  region_flag[ThreadProfilerMark::extraRegion] = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  extra_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
  interval_data_ref()->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
void ThreadProfiler::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  if (table != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    for (int index = 0; index < table_size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
      ProfilerNode* n = table[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
      if (n != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
        delete n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
void FlatProfiler::allocate_table() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  { // Bytecode table
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
  1216
    bytecode_ticks      = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
  1217
    bytecode_ticks_stub = NEW_C_HEAP_ARRAY(int, Bytecodes::number_of_codes, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    for(int index = 0; index < Bytecodes::number_of_codes; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
      bytecode_ticks[index]      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
      bytecode_ticks_stub[index] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  if (ProfilerRecordPC) PCRecorder::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
  1226
  interval_data         = NEW_C_HEAP_ARRAY(IntervalData, interval_print_size, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  FlatProfiler::interval_reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
void FlatProfiler::engage(JavaThread* mainThread, bool fullProfile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  full_profile_flag = fullProfile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
  if (bytecode_ticks == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    allocate_table();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
  if(ProfileVM && (vm_thread_profiler == NULL)){
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    vm_thread_profiler = new ThreadProfiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  if (task == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    task = new FlatProfilerTask(WatcherThread::delay_interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
    task->enroll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
  timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  if (mainThread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    // When mainThread was created, it might not have a ThreadProfiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    ThreadProfiler* pp = mainThread->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
    if (pp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
      mainThread->set_thread_profiler(new ThreadProfiler());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
      pp->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    mainThread->get_thread_profiler()->engage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  // This is where we would assign thread_profiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
  // if we wanted only one thread_profiler for all threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  thread_profiler = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
void FlatProfiler::disengage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  if (!task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  task->disenroll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  delete task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  task = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
  if (thread_profiler != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    thread_profiler->disengage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    MutexLocker tl(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
    for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
      ThreadProfiler* pp = tp->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
      if (pp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
        pp->disengage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
void FlatProfiler::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
  if (task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
    disengage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
  class_loader_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  extra_ticks        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  received_gc_ticks  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  vm_operation_ticks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
  compiler_ticks     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
  deopt_ticks        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  interpreter_ticks  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
  blocked_ticks      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
  unknown_ticks      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  received_ticks     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  delivered_ticks    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
bool FlatProfiler::is_active() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  return task != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
void FlatProfiler::print_byte_code_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  tty->print_cr(" Bytecode ticks:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  for (int index = 0; index < Bytecodes::number_of_codes; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
    if (FlatProfiler::bytecode_ticks[index] > 0 || FlatProfiler::bytecode_ticks_stub[index] > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
      tty->print_cr("  %4d %4d = %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
        FlatProfiler::bytecode_ticks[index],
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
        FlatProfiler::bytecode_ticks_stub[index],
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
        Bytecodes::name( (Bytecodes::Code) index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
void print_ticks(const char* title, int ticks, int total) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
  if (ticks > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
    tty->print("%5.1f%% %5d", ticks * 100.0 / total, ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    tty->fill_to(col3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
    tty->print("%s", title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
void ThreadProfiler::print(const char* thread_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  MutexLocker ppl(ProfilePrint_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
  int index = 0; // Declared outside for loops for portability
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  if (table == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  if (thread_ticks <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
  const char* title = "too soon to tell";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
  double secs = timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
  GrowableArray <ProfilerNode*>* array = new GrowableArray<ProfilerNode*>(200);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
  for(index = 0; index < table_size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
    for(ProfilerNode* node = table[index]; node; node = node->next())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
      array->append(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
  array->sort(&ProfilerNode::compare);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
  // compute total (sanity check)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
  int active =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
    class_loader_ticks +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
    compiler_ticks +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
    interpreter_ticks +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    unknown_ticks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  for (index = 0; index < array->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
    active += array->at(index)->ticks.total();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  int total = active + blocked_ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  tty->print_cr("Flat profile of %3.2f secs (%d total ticks): %s", secs, total, thread_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  if (total != thread_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
    print_ticks("Lost ticks", thread_ticks-total, thread_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  // print interpreted methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  tick_counter interpreted_ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  bool has_interpreted_ticks = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
  int print_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  for (index = 0; index < array->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
    ProfilerNode* n = array->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
    if (n->is_interpreted()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
      interpreted_ticks.add(&n->ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
      if (!has_interpreted_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
        interpretedNode::print_title(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
        has_interpreted_ticks = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      if (print_count++ < ProfilerNumberOfInterpretedMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
        n->print(tty, active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
  if (has_interpreted_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    if (print_count <= ProfilerNumberOfInterpretedMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
      title = "Total interpreted";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
      title = "Total interpreted (including elided)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    interpretedNode::print_total(tty, &interpreted_ticks, active, title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  // print compiled methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
  tick_counter compiled_ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  bool has_compiled_ticks = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  print_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
  for (index = 0; index < array->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
    ProfilerNode* n = array->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
    if (n->is_compiled()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
      compiled_ticks.add(&n->ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
      if (!has_compiled_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
        compiledNode::print_title(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
        has_compiled_ticks = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
      if (print_count++ < ProfilerNumberOfCompiledMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
        n->print(tty, active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
  if (has_compiled_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
    if (print_count <= ProfilerNumberOfCompiledMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
      title = "Total compiled";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
      title = "Total compiled (including elided)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
    compiledNode::print_total(tty, &compiled_ticks, active, title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
  // print stub methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
  tick_counter stub_ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
  bool has_stub_ticks = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
  print_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
  for (index = 0; index < array->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
    ProfilerNode* n = array->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
    if (n->is_stub()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
      stub_ticks.add(&n->ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
      if (!has_stub_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
        stubNode::print_title(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
        has_stub_ticks = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
      if (print_count++ < ProfilerNumberOfStubMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
        n->print(tty, active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
  if (has_stub_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
    if (print_count <= ProfilerNumberOfStubMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
      title = "Total stub";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
      title = "Total stub (including elided)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
    stubNode::print_total(tty, &stub_ticks, active, title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
  // print runtime stubs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
  tick_counter runtime_stub_ticks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  bool has_runtime_stub_ticks = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  print_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  for (index = 0; index < array->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    ProfilerNode* n = array->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
    if (n->is_runtime_stub()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
      runtime_stub_ticks.add(&n->ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
      if (!has_runtime_stub_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
        runtimeStubNode::print_title(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
        has_runtime_stub_ticks = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
      if (print_count++ < ProfilerNumberOfRuntimeStubNodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
        n->print(tty, active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  if (has_runtime_stub_ticks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
    if (print_count <= ProfilerNumberOfRuntimeStubNodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
      title = "Total runtime stubs";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
      title = "Total runtime stubs (including elided)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
    runtimeStubNode::print_total(tty, &runtime_stub_ticks, active, title);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
  if (blocked_ticks + class_loader_ticks + interpreter_ticks + compiler_ticks + unknown_ticks() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
    tty->fill_to(col1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
    tty->print_cr("Thread-local ticks:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
    print_ticks("Blocked (of total)",  blocked_ticks,      total);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
    print_ticks("Class loader",        class_loader_ticks, active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    print_ticks("Extra",               extra_ticks,        active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
    print_ticks("Interpreter",         interpreter_ticks,  active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
    print_ticks("Compilation",         compiler_ticks,     active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
    print_ticks("Unknown: vtable stubs",  unknown_ticks_array[ut_vtable_stubs],         active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
    print_ticks("Unknown: null method",   unknown_ticks_array[ut_null_method],          active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
    print_ticks("Unknown: running frame", unknown_ticks_array[ut_running_frame],        active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
    print_ticks("Unknown: calling frame", unknown_ticks_array[ut_calling_frame],        active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
    print_ticks("Unknown: no pc",         unknown_ticks_array[ut_no_pc],                active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
    print_ticks("Unknown: no last frame", unknown_ticks_array[ut_no_last_Java_frame],   active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
    print_ticks("Unknown: thread_state",  unknown_ticks_array[ut_unknown_thread_state], active);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
  if (WizardMode) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 30764
diff changeset
  1495
    tty->print_cr("Node area used: " INTX_FORMAT " Kb", (area_top - area_bottom) / 1024);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
  reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
ThreadProfiler::print_unknown(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
  if (table == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
  if (thread_ticks <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
} */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
void FlatProfiler::print(int unused) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
  if (thread_profiler != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
    thread_profiler->print("All threads");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
    MutexLocker tl(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
      ThreadProfiler* pp = tp->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
      if (pp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
        pp->print(tp->get_thread_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
  if (ProfilerPrintByteCodeStatistics) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    print_byte_code_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
  if (non_method_ticks() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
    tty->print_cr("Global summary of %3.2f seconds:", timer.seconds());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
    print_ticks("Received ticks",      received_ticks,     received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    print_ticks("Received GC ticks",   received_gc_ticks,  received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
    print_ticks("Compilation",         compiler_ticks,     received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
    print_ticks("Deoptimization",      deopt_ticks,        received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
    print_ticks("Other VM operations", vm_operation_ticks, received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
    print_ticks("Blocked ticks",       blocked_ticks,      received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
    print_ticks("Threads_lock blocks", threads_lock_ticks, received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
    print_ticks("Delivered ticks",     delivered_ticks,    received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
    print_ticks("All ticks",           all_ticks,          received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
    print_ticks("Class loader",        class_loader_ticks, received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
    print_ticks("Extra       ",        extra_ticks,        received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
    print_ticks("Interpreter",         interpreter_ticks,  received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    print_ticks("Unknown code",        unknown_ticks,      received_ticks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
  PCRecorder::print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
  if(ProfileVM){
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
    vm_thread_profiler->print("VM Thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
void IntervalData::print_header(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
  st->print("i/c/n/g");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
void IntervalData::print_data(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
  st->print("%d/%d/%d/%d", interpreted(), compiled(), native(), compiling());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
void FlatProfiler::interval_record_thread(ThreadProfiler* tp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  IntervalData id = tp->interval_data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
  int total = id.total();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
  tp->interval_data_ref()->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
  // Insertion sort the data, if it's relevant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  for (int i = 0; i < interval_print_size; i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
    if (total > interval_data[i].total()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
      for (int j = interval_print_size - 1; j > i; j -= 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
        interval_data[j] = interval_data[j-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
      interval_data[i] = id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
void FlatProfiler::interval_print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  if ((interval_data[0].total() > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
    tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
    tty->print("\t");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
    IntervalData::print_header(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
    for (int i = 0; i < interval_print_size; i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
      if (interval_data[i].total() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
        tty->print("\t");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
        interval_data[i].print_data(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
void FlatProfiler::interval_reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  for (int i = 0; i < interval_print_size; i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
    interval_data[i].reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
void ThreadProfiler::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  if (table == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  for(int index = 0; index < table_size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    for(ProfilerNode* node = table[index]; node; node = node->next())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
      node->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
void FlatProfiler::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
  if (thread_profiler != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    thread_profiler->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
    for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
      ThreadProfiler* pp = tp->get_thread_profiler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
      if (pp != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
        pp->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
}