src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp
author stefank
Thu, 08 Mar 2018 09:56:29 +0100
changeset 49360 886acec3b4c6
parent 47216 71c04702a3d5
child 50729 7755c93d3923
permissions -rw-r--r--
8199275: Fix inclusions of allocation.inline.hpp Reviewed-by: coleenp, kbarrett, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, 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: 4894
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4894
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: 4894
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: 6418
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    26
#include "code/codeBlob.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    27
#include "code/codeCache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    28
#include "code/scopeDesc.hpp"
22747
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
    29
#include "code/vtableStubs.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 47216
diff changeset
    30
#include "memory/allocation.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    31
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    32
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    33
#include "prims/jvmtiCodeBlobEvents.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    34
#include "prims/jvmtiExport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    35
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    36
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    37
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Support class to collect a list of the non-nmethod CodeBlobs in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// the CodeCache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// This class actually creates a list of JvmtiCodeBlobDesc - each JvmtiCodeBlobDesc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// describes a single CodeBlob in the CodeCache. Note that collection is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// done to a static list - this is because CodeCache::blobs_do is defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// as void CodeCache::blobs_do(void f(CodeBlob* nm)) and hence requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// a C or static method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Usage :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// CodeBlobCollector collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// collector.collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// JvmtiCodeBlobDesc* blob = collector.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// while (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//   blob = collector.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
class CodeBlobCollector : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs;   // collected blobs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  int _pos;                                         // iterator position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // used during a collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static GrowableArray<JvmtiCodeBlobDesc*>* _global_code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static void do_blob(CodeBlob* cb);
22747
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
    68
  static void do_vtable_stub(VtableStub* vs);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  CodeBlobCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    _code_blobs = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _pos = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  ~CodeBlobCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    if (_code_blobs != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      for (int i=0; i<_code_blobs->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        FreeHeap(_code_blobs->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      delete _code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // collect list of code blobs in the cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  void collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // iteration support - return first code blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  JvmtiCodeBlobDesc* first() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    assert(_code_blobs != NULL, "not collected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (_code_blobs->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    _pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    return _code_blobs->at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // iteration support - return next code blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  JvmtiCodeBlobDesc* next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    assert(_pos >= 0, "iteration not started");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if (_pos+1 >= _code_blobs->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    return _code_blobs->at(++_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
// used during collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
GrowableArray<JvmtiCodeBlobDesc*>* CodeBlobCollector::_global_code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
// called for each CodeBlob in the CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// This function filters out nmethods as it is only interested in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// other CodeBlobs. This function also filters out CodeBlobs that have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// a duplicate starting address as previous blobs. This is needed to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// handle the case where multiple stubs are generated into a single
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// BufferBlob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
void CodeBlobCollector::do_blob(CodeBlob* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // ignore nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  if (cb->is_nmethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
22747
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   125
  // exclude VtableStubs, which are processed separately
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   126
  if (cb->is_buffer_blob() && strcmp(cb->name(), "vtable chunks") == 0) {
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   127
    return;
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   128
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // check if this starting address has been seen already - the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // assumption is that stubs are inserted into the list before the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // enclosing BufferBlobs.
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5929
diff changeset
   133
  address addr = cb->code_begin();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  for (int i=0; i<_global_code_blobs->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    JvmtiCodeBlobDesc* scb = _global_code_blobs->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    if (addr == scb->code_begin()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // record the CodeBlob details as a JvmtiCodeBlobDesc
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5929
diff changeset
   142
  JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(cb->name(), cb->code_begin(), cb->code_end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  _global_code_blobs->append(scb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
22747
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   146
// called for each VtableStub in VtableStubs
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   147
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   148
void CodeBlobCollector::do_vtable_stub(VtableStub* vs) {
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   149
    JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(vs->is_vtable_stub() ? "vtable stub" : "itable stub",
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   150
                                                   vs->code_begin(), vs->code_end());
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   151
    _global_code_blobs->append(scb);
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   152
}
1
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   174
  _global_code_blobs = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JvmtiCodeBlobDesc*>(50,true);
1
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.
36301
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 33160
diff changeset
   177
  for (StubCodeDesc* desc = StubCodeDesc::first(); desc != NULL; desc = StubCodeDesc::next(desc)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    _global_code_blobs->append(new JvmtiCodeBlobDesc(desc->name(), desc->begin(), desc->end()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
22747
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   181
  // Vtable stubs are not described with StubCodeDesc,
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   182
  // process them separately
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   183
  VtableStubs::vtable_stub_do(do_vtable_stub);
f467c14746f5 8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents: 13963
diff changeset
   184
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // next iterate over all the non-nmethod code blobs and add them to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // the list - as noted above this will filter out duplicates and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // enclosing blobs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  CodeCache::blobs_do(do_blob);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // make the global list the instance list so that it can be used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // for other iterations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  _code_blobs = _global_code_blobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  _global_code_blobs = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
// Generate a DYNAMIC_CODE_GENERATED event for each non-nmethod code blob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
jvmtiError JvmtiCodeBlobEvents::generate_dynamic_code_events(JvmtiEnv* env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  CodeBlobCollector collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
5913
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   202
  // First collect all the code blobs.  This has to be done in a
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   203
  // single pass over the code cache with CodeCache_lock held because
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   204
  // there isn't any safe way to iterate over regular CodeBlobs since
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   205
  // they can be freed at any point.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    collector.collect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // iterate over the collected list and post an event for each blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  JvmtiCodeBlobDesc* blob = collector.first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  while (blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    JvmtiExport::post_dynamic_code_generated(env, blob->name(), blob->code_begin(), blob->code_end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    blob = collector.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// Generate a COMPILED_METHOD_LOAD event for each nnmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
5913
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   225
  // Walk the CodeCache notifying for live nmethods.  The code cache
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   226
  // may be changing while this is happening which is ok since newly
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   227
  // created nmethod will notify normally and nmethods which are freed
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   228
  // can be safely skipped.
9dbc3381245b 6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents: 5896
diff changeset
   229
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   230
  // Iterate over non-profiled and profiled nmethods
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   231
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   232
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   233
    nmethod* current = iter.method();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   234
    // Lock the nmethod so it can't be freed
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   235
    nmethodLocker nml(current);
5929
279fd26a4b68 6968336: VM crash guarantee(!nm->is_zombie()) failed: cannot lock a zombie method
never
parents: 5913
diff changeset
   236
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   237
    // Don't hold the lock over the notify or jmethodID creation
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   238
    MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   239
    current->get_and_cache_jmethod_id();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 22747
diff changeset
   240
    JvmtiExport::post_compiled_method_load(current);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// create a C-heap allocated address location map for an nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
                                                        jvmtiAddrLocationMap** map_ptr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                                                        jint *map_length_ptr)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  jvmtiAddrLocationMap* map = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  jint map_length = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // Generate line numbers using PcDesc and ScopeDesc info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  methodHandle mh(nm->method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (!mh->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    PcDesc *pcd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    int pcds_in_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    pcds_in_method = (nm->scopes_pcs_end() - nm->scopes_pcs_begin());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   264
    map = NEW_C_HEAP_ARRAY(jvmtiAddrLocationMap, pcds_in_method, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    address scopes_data = nm->scopes_data_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    for( pcd = nm->scopes_pcs_begin(); pcd < nm->scopes_pcs_end(); ++pcd ) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 26796
diff changeset
   268
      ScopeDesc sc0(nm, pcd->scope_decode_offset(), pcd->should_reexecute(), pcd->rethrow_exception(), pcd->return_oop());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      ScopeDesc *sd  = &sc0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      while( !sd->is_top() ) { sd = sd->sender(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      int bci = sd->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      if (bci != InvocationEntryBci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        assert(map_length < pcds_in_method, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
        map[map_length].start_address = (const void*)pcd->real_pc(nm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        map[map_length].location = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        ++map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      }
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
  *map_ptr = map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  *map_length_ptr = map_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
}