hotspot/src/share/vm/prims/jvmtiCodeBlobEvents.cpp
author ysr
Thu, 03 Dec 2009 15:01:57 -0800
changeset 4461 c17c526d36ef
parent 3686 69c1b5228547
child 4894 8a76fd3d098d
permissions -rw-r--r--
6906727: UseCompressedOops: some card-marking fixes related to object arrays Summary: Introduced a new write_ref_array(HeapWords* start, size_t count) method that does the requisite MemRegion range calculation so (some of the) clients of the erstwhile write_ref_array(MemRegion mr) do not need to worry. This removed all external uses of array_size(), which was also simplified and made private. Asserts were added to catch other possible issues. Further, less essential, fixes stemming from this investigation are deferred to CR 6904516 (to follow shortly in hs17). Reviewed-by: kvn, coleenp, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3686
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 1
diff changeset
     2
 * Copyright 2003-2009 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_jvmtiCodeBlobEvents.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Support class to collect a list of the non-nmethod CodeBlobs in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// the CodeCache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// This class actually creates a list of JvmtiCodeBlobDesc - each JvmtiCodeBlobDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// describes a single CodeBlob in the CodeCache. Note that collection is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// done to a static list - this is because CodeCache::blobs_do is defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// as void CodeCache::blobs_do(void f(CodeBlob* nm)) and hence requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// a C or static method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Usage :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// CodeBlobCollector collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// collector.collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// JvmtiCodeBlobDesc* blob = collector.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// while (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//   blob = collector.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class CodeBlobCollector : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs;   // collected blobs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  int _pos;                                         // iterator position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // used during a collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static GrowableArray<JvmtiCodeBlobDesc*>* _global_code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static void do_blob(CodeBlob* cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  CodeBlobCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _code_blobs = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _pos = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ~CodeBlobCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    if (_code_blobs != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      for (int i=0; i<_code_blobs->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
        FreeHeap(_code_blobs->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      delete _code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // collect list of code blobs in the cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // iteration support - return first code blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  JvmtiCodeBlobDesc* first() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    assert(_code_blobs != NULL, "not collected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    if (_code_blobs->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    _pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    return _code_blobs->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // iteration support - return next code blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  JvmtiCodeBlobDesc* next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    assert(_pos >= 0, "iteration not started");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    if (_pos+1 >= _code_blobs->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    return _code_blobs->at(++_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// used during collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
GrowableArray<JvmtiCodeBlobDesc*>* CodeBlobCollector::_global_code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
// called for each CodeBlob in the CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// This function filters out nmethods as it is only interested in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// other CodeBlobs. This function also filters out CodeBlobs that have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// a duplicate starting address as previous blobs. This is needed to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
// handle the case where multiple stubs are generated into a single
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
// BufferBlob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
void CodeBlobCollector::do_blob(CodeBlob* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // ignore nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  if (cb->is_nmethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // check if this starting address has been seen already - the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // assumption is that stubs are inserted into the list before the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // enclosing BufferBlobs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  address addr = cb->instructions_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  for (int i=0; i<_global_code_blobs->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    JvmtiCodeBlobDesc* scb = _global_code_blobs->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    if (addr == scb->code_begin()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // we must name the CodeBlob - some CodeBlobs already have names :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // - stubs used by compiled code to call a (static) C++ runtime routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // - non-relocatable machine code such as the interpreter, stubroutines, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // - various singleton blobs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // others are unnamed so we create a name :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // - OSR adapter (interpreter frame that has been on-stack replaced)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // - I2C and C2I adapters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  const char* name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  if (cb->is_runtime_stub()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    name = ((RuntimeStub*)cb)->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  if (cb->is_buffer_blob()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    name = ((BufferBlob*)cb)->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  if (cb->is_deoptimization_stub() || cb->is_safepoint_stub()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    name = ((SingletonBlob*)cb)->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (cb->is_uncommon_trap_stub() || cb->is_exception_stub()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    name = ((SingletonBlob*)cb)->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // record the CodeBlob details as a JvmtiCodeBlobDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(name, cb->instructions_begin(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
                                                 cb->instructions_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  _global_code_blobs->append(scb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// collects a list of CodeBlobs in the CodeCache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// The created list is growable array of JvmtiCodeBlobDesc - each one describes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// a CodeBlob. Note that the list is static - this is because CodeBlob::blobs_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// requires a a C or static function so we can't use an instance function. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// isn't a problem as the iteration is serial anyway as we need the CodeCache_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// to iterate over the code cache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
// Note that the CodeBlobs in the CodeCache will include BufferBlobs that may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
// contain multiple stubs. As a profiler is interested in the stubs rather than
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
// the enclosing container we first iterate over the stub code descriptors so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// that the stubs go into the list first. do_blob will then filter out the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// enclosing blobs if the starting address of the enclosing blobs matches the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// starting address of first stub generated in the enclosing blob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
void CodeBlobCollector::collect() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  assert_locked_or_safepoint(CodeCache_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  assert(_global_code_blobs == NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // create the global list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  _global_code_blobs = new (ResourceObj::C_HEAP) GrowableArray<JvmtiCodeBlobDesc*>(50,true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // iterate over the stub code descriptors and put them in the list first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  int index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  StubCodeDesc* desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  while ((desc = StubCodeDesc::desc_for_index(++index)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    _global_code_blobs->append(new JvmtiCodeBlobDesc(desc->name(), desc->begin(), desc->end()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // next iterate over all the non-nmethod code blobs and add them to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // the list - as noted above this will filter out duplicates and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // enclosing blobs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  CodeCache::blobs_do(do_blob);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // make the global list the instance list so that it can be used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // for other iterations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  _code_blobs = _global_code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  _global_code_blobs = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// Generate a DYNAMIC_CODE_GENERATED event for each non-nmethod code blob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
jvmtiError JvmtiCodeBlobEvents::generate_dynamic_code_events(JvmtiEnv* env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  CodeBlobCollector collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // first collect all the code blobs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    collector.collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // iterate over the collected list and post an event for each blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  JvmtiCodeBlobDesc* blob = collector.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  while (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    JvmtiExport::post_dynamic_code_generated(env, blob->name(), blob->code_begin(), blob->code_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    blob = collector.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  return JVMTI_ERROR_NONE;
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
// Support class to describe a nmethod in the CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
class nmethodDesc: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  methodHandle _method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  address _code_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  address _code_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  jvmtiAddrLocationMap* _map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  jint _map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  nmethodDesc(methodHandle method, address code_begin, address code_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
              jvmtiAddrLocationMap* map, jint map_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    _code_begin = code_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    _code_end = code_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    _map = map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    _map_length = map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  methodHandle method() const           { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  address code_begin() const            { return _code_begin; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  address code_end() const              { return _code_end; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  jvmtiAddrLocationMap* map() const     { return _map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  jint map_length() const               { return _map_length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// Support class to collect a list of the nmethod CodeBlobs in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// the CodeCache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// Usage :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// nmethodCollector collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
// collector.collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
// JvmtiCodeBlobDesc* blob = collector.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
// while (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
//   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
//   blob = collector.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
class nmethodCollector : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  GrowableArray<nmethodDesc*>* _nmethods;           // collect nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  int _pos;                                         // iteration support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // used during a collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  static GrowableArray<nmethodDesc*>* _global_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  static void do_nmethod(nmethod* nm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  nmethodCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    _nmethods = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    _pos = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  ~nmethodCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    if (_nmethods != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      for (int i=0; i<_nmethods->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        nmethodDesc* blob = _nmethods->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        if (blob->map()!= NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
          FREE_C_HEAP_ARRAY(jvmtiAddrLocationMap, blob->map());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      delete _nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  // collect list of nmethods in the cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  void collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // iteration support - return first code blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  nmethodDesc* first() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    assert(_nmethods != NULL, "not collected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    if (_nmethods->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    _pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    return _nmethods->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // iteration support - return next code blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  nmethodDesc* next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    assert(_pos >= 0, "iteration not started");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    if (_pos+1 >= _nmethods->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    return _nmethods->at(++_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// used during collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
GrowableArray<nmethodDesc*>* nmethodCollector::_global_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
// called for each nmethod in the CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
// This function simply adds a descriptor for each nmethod to the global list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
void nmethodCollector::do_nmethod(nmethod* nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // ignore zombies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (!nm->is_alive()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  assert(nm->method() != NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  // create the location map for the nmethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  jvmtiAddrLocationMap* map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  jint map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &map, &map_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // record the nmethod details
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  methodHandle mh(nm->method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  nmethodDesc* snm = new nmethodDesc(mh,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
                                     nm->code_begin(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
                                     nm->code_end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
                                     map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                                     map_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  _global_nmethods->append(snm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
// collects a list of nmethod in the CodeCache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
// The created list is growable array of nmethodDesc - each one describes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
// a nmethod and includs its JVMTI address location map.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
void nmethodCollector::collect() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  assert_locked_or_safepoint(CodeCache_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  assert(_global_nmethods == NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // create the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  _global_nmethods = new (ResourceObj::C_HEAP) GrowableArray<nmethodDesc*>(100,true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  // any a descriptor for each nmethod to the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  CodeCache::nmethods_do(do_nmethod);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // make the list the instance list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  _nmethods = _global_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  _global_nmethods = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
// Generate a COMPILED_METHOD_LOAD event for each nnmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  nmethodCollector collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  // first collect all nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    collector.collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // iterate over the  list and post an event for each nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  nmethodDesc* nm_desc = collector.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  while (nm_desc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    methodOop method = nm_desc->method()();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    jmethodID mid = method->jmethod_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    assert(mid != NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    JvmtiExport::post_compiled_method_load(env, mid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
                                           (jint)(nm_desc->code_end() - nm_desc->code_begin()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                                           nm_desc->code_begin(), nm_desc->map_length(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                                           nm_desc->map());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    nm_desc = collector.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
// create a C-heap allocated address location map for an nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
                                                        jvmtiAddrLocationMap** map_ptr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
                                                        jint *map_length_ptr)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  jvmtiAddrLocationMap* map = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  jint map_length = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  // Generate line numbers using PcDesc and ScopeDesc info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  methodHandle mh(nm->method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  if (!mh->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    PcDesc *pcd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    int pcds_in_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    pcds_in_method = (nm->scopes_pcs_end() - nm->scopes_pcs_begin());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    map = NEW_C_HEAP_ARRAY(jvmtiAddrLocationMap, pcds_in_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    address scopes_data = nm->scopes_data_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    for( pcd = nm->scopes_pcs_begin(); pcd < nm->scopes_pcs_end(); ++pcd ) {
3686
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 1
diff changeset
   405
      ScopeDesc sc0(nm, pcd->scope_decode_offset(), pcd->should_reexecute());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
      ScopeDesc *sd  = &sc0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
      while( !sd->is_top() ) { sd = sd->sender(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      int bci = sd->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      if (bci != InvocationEntryBci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        assert(map_length < pcds_in_method, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
        map[map_length].start_address = (const void*)pcd->real_pc(nm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
        map[map_length].location = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
        ++map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  *map_ptr = map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  *map_length_ptr = map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
}