hotspot/src/share/vm/services/memRecorder.hpp
author zgu
Fri, 19 Oct 2012 21:40:07 -0400
changeset 14120 7d298141c258
parent 13478 85fe611440e5
child 15104 f5d78994619f
permissions -rw-r--r--
7199092: NMT: NMT needs to deal overlapped virtual memory ranges Summary: Enhanced virtual memory tracking to track committed regions as well as reserved regions, so NMT now can generate virtual memory map. Reviewed-by: acorn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     1
/*
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     4
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     8
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    13
 * accompanied this code).
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    14
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    18
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    21
 * questions.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    22
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    23
 */
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    24
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    25
#ifndef SHARE_VM_SERVICES_MEM_RECORDER_HPP
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    26
#define SHARE_VM_SERVICES_MEM_RECORDER_HPP
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    27
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    28
#include "memory/allocation.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    29
#include "runtime/os.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    30
#include "services/memPtrArray.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    31
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    32
class MemSnapshot;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    33
class MemTracker;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    34
class MemTrackWorker;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    35
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    36
// Fixed size memory pointer array implementation
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    37
template <class E, int SIZE> class FixedSizeMemPointerArray :
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    38
  public MemPointerArray {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    39
  // This implementation is for memory recorder only
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    40
  friend class MemRecorder;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    41
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    42
 private:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    43
  E      _data[SIZE];
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    44
  int    _size;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    45
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    46
 protected:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    47
  FixedSizeMemPointerArray(bool init_elements = false):
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    48
   _size(0){
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    49
    if (init_elements) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    50
      for (int index = 0; index < SIZE; index ++) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    51
        ::new ((void*)&_data[index]) E();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    52
      }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    53
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    54
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    55
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    56
  void* operator new(size_t size, const std::nothrow_t& nothrow_constant) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    57
    // the instance is part of memRecorder, needs to be tagged with 'otNMTRecorder'
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    58
    // to avoid recursion
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    59
    return os::malloc(size, (mtNMT | otNMTRecorder));
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    60
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    61
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    62
  void* operator new(size_t size) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    63
    assert(false, "use nothrow version");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    64
    return NULL;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    65
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    66
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    67
  void operator delete(void* p) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    68
    os::free(p, (mtNMT | otNMTRecorder));
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    69
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    70
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    71
  // instance size
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    72
  inline size_t instance_size() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    73
    return sizeof(FixedSizeMemPointerArray<E, SIZE>);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    74
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    75
13478
85fe611440e5 7191124: Optimized build is broken due to inconsistent use of DEBUG_ONLY and NOT_PRODUCT macros in NMT
zgu
parents: 13300
diff changeset
    76
  NOT_PRODUCT(int capacity() const { return SIZE; })
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    77
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    78
 public:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    79
  // implementation of public interface
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    80
  bool out_of_memory() const { return false; }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    81
  bool is_empty()      const { return _size == 0; }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    82
  bool is_full()             { return length() >= SIZE; }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    83
  int  length()        const { return _size; }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    84
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    85
  void clear() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    86
    _size = 0;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    87
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    88
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    89
  bool append(MemPointer* ptr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    90
    if (is_full()) return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    91
    _data[_size ++] = *(E*)ptr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    92
    return true;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    93
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    94
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    95
  virtual bool insert_at(MemPointer* p, int pos) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    96
    assert(false, "append only");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    97
    return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    98
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    99
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   100
  virtual bool remove_at(int pos) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   101
    assert(false, "not supported");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   102
    return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   103
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   104
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   105
  MemPointer* at(int index) const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   106
    assert(index >= 0 && index < length(),
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   107
      "parameter check");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   108
    return ((E*)&_data[index]);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   109
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   110
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   111
  void sort(FN_SORT fn) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   112
    qsort((void*)_data, _size, sizeof(E), fn);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   113
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   114
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   115
  bool shrink() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   116
    return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   117
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   118
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   119
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   120
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   121
// This iterator requires pre-sorted MemPointerArray, which is sorted by:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   122
//  1. address
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   123
//  2. allocation type
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   124
//  3. sequence number
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   125
// During the array walking, iterator collapses pointers with the same
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   126
// address and allocation type, and only returns the one with highest
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   127
// sequence number.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   128
//
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   129
// This is read-only iterator, update methods are asserted.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   130
class SequencedRecordIterator : public MemPointerArrayIterator {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   131
 private:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   132
   MemPointerArrayIteratorImpl _itr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   133
   MemPointer*                 _cur;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   134
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   135
 public:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   136
  SequencedRecordIterator(const MemPointerArray* arr):
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   137
    _itr(const_cast<MemPointerArray*>(arr)) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   138
    _cur = next_record();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   139
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   140
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   141
  SequencedRecordIterator(const SequencedRecordIterator& itr):
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   142
    _itr(itr._itr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   143
    _cur = next_record();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   144
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   145
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   146
  // return the pointer at current position
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   147
  virtual MemPointer* current() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   148
    return _cur;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   149
  };
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   150
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   151
  // return the next pointer and advance current position
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   152
  virtual MemPointer* next() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   153
    _cur = next_record();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   154
    return _cur;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   155
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   156
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   157
  // return the next pointer without advancing current position
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   158
  virtual MemPointer* peek_next() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   159
    assert(false, "not implemented");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   160
    return NULL;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   161
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   162
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   163
  // return the previous pointer without changing current position
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   164
  virtual MemPointer* peek_prev() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   165
    assert(false, "not implemented");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   166
    return NULL;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   167
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   168
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   169
  // remove the pointer at current position
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   170
  virtual void remove() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   171
    assert(false, "read-only iterator");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   172
  };
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   173
  // insert the pointer at current position
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   174
  virtual bool insert(MemPointer* ptr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   175
    assert(false, "read-only iterator");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   176
    return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   177
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   178
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   179
  virtual bool insert_after(MemPointer* ptr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   180
    assert(false, "read-only iterator");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   181
    return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   182
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   183
 private:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   184
  // collapse the 'same kind' of records, and return this 'kind' of
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   185
  // record with highest sequence number
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   186
  MemPointer* next_record();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   187
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   188
  // Test if the two records are the same kind: the same memory block and allocation
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   189
  // type.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   190
  inline bool same_kind(const MemPointerRecord* p1, const MemPointerRecord* p2) const {
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13478
diff changeset
   191
    assert(!p1->is_vm_pointer() && !p2->is_vm_pointer(), "malloc pointer only");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   192
    return (p1->addr() == p2->addr() &&
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   193
      (p1->flags() &MemPointerRecord::tag_masks) ==
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   194
      (p2->flags() & MemPointerRecord::tag_masks));
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   195
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   196
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   197
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   198
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   199
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   200
#define DEFAULT_RECORDER_PTR_ARRAY_SIZE 512
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   201
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   202
class MemRecorder : public CHeapObj<mtNMT|otNMTRecorder> {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   203
  friend class MemSnapshot;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   204
  friend class MemTracker;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   205
  friend class MemTrackWorker;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   206
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   207
 protected:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   208
  // the array that holds memory records
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   209
  MemPointerArray*         _pointer_records;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   210
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   211
 private:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   212
  // used for linked list
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   213
  MemRecorder*             _next;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   214
  // active recorder can only record a certain generation data
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   215
  debug_only(unsigned long _generation;)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   216
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   217
 protected:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   218
  _NOINLINE_ MemRecorder();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   219
  ~MemRecorder();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   220
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   221
  // record a memory operation
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   222
  bool record(address addr, MEMFLAGS flags, size_t size, address caller_pc = 0);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   223
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   224
  // linked list support
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   225
  inline void set_next(MemRecorder* rec) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   226
    _next = rec;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   227
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   228
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   229
  inline MemRecorder* next() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   230
    return _next;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   231
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   232
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   233
  // if the recorder is full
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   234
  inline bool is_full() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   235
    assert(_pointer_records != NULL, "just check");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   236
    return _pointer_records->is_full();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   237
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   238
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   239
  // if running out of memory when initializing recorder's internal
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   240
  // data
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   241
  inline bool out_of_memory() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   242
    return (_pointer_records == NULL ||
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   243
      _pointer_records->out_of_memory());
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   244
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   245
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   246
  inline void clear() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   247
    assert(_pointer_records != NULL, "Just check");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   248
    _pointer_records->clear();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   249
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   250
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   251
  SequencedRecordIterator pointer_itr();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   252
13300
38485c548c9f 7182543: NMT ON: Aggregate a few NMT related bugs
zgu
parents: 13195
diff changeset
   253
 protected:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   254
  // number of MemRecorder instance
13300
38485c548c9f 7182543: NMT ON: Aggregate a few NMT related bugs
zgu
parents: 13195
diff changeset
   255
  static volatile jint _instance_count;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   256
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   257
 private:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   258
  // sorting function, sort records into following order
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   259
  // 1. memory address
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   260
  // 2. allocation type
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   261
  // 3. sequence number
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   262
  static int sort_record_fn(const void* e1, const void* e2);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   263
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   264
  debug_only(void check_dup_seq(jint seq) const;)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   265
  debug_only(void set_generation();)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   266
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   267
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   268
#endif // SHARE_VM_SERVICES_MEM_RECORDER_HPP