hotspot/src/share/vm/services/memSnapshot.hpp
author hseigel
Fri, 11 Oct 2013 15:33:08 -0400
changeset 20679 7885e9e68382
parent 17023 aab2b408ebfe
child 22234 da823d78ad65
permissions -rw-r--r--
8026041: JVM crashes with assert "assert(is_updated()) failed: must not be clear" with -XX:+PrintGCApplicationConcurrentTime in -Xcomp mode Summary: Prior to printing the time interval in RuntimeService::record_safepoint_begin(), check first that VM initialization is complete. Reviewed-by: coleenp, dholmes, sla, ctornqvi Contributed-by: lois.foltan@oracle.com
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_SNAPSHOT_HPP
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    26
#define SHARE_VM_SERVICES_MEM_SNAPSHOT_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/mutex.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    30
#include "runtime/mutexLocker.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    31
#include "services/memBaseline.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    32
#include "services/memPtrArray.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    33
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    34
// Snapshot pointer array iterator
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    35
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    36
// The pointer array contains malloc-ed pointers
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    37
class MemPointerIterator : public MemPointerArrayIteratorImpl {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    38
 public:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    39
  MemPointerIterator(MemPointerArray* arr):
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    40
    MemPointerArrayIteratorImpl(arr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    41
    assert(arr != NULL, "null array");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    42
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    43
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    44
#ifdef ASSERT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    45
  virtual bool is_dup_pointer(const MemPointer* ptr1,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    46
    const MemPointer* ptr2) const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    47
    MemPointerRecord* p1 = (MemPointerRecord*)ptr1;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    48
    MemPointerRecord* p2 = (MemPointerRecord*)ptr2;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    49
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    50
    if (p1->addr() != p2->addr()) return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    51
    if ((p1->flags() & MemPointerRecord::tag_masks) !=
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    52
        (p2->flags() & MemPointerRecord::tag_masks)) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    53
      return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    54
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    55
    // we do see multiple commit/uncommit on the same memory, it is ok
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    56
    return (p1->flags() & MemPointerRecord::tag_masks) == MemPointerRecord::tag_alloc ||
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    57
           (p1->flags() & MemPointerRecord::tag_masks) == MemPointerRecord::tag_release;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    58
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    59
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    60
  virtual bool insert(MemPointer* ptr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    61
    if (_pos > 0) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    62
      MemPointer* p1 = (MemPointer*)ptr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    63
      MemPointer* p2 = (MemPointer*)_array->at(_pos - 1);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    64
      assert(!is_dup_pointer(p1, p2),
13470
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
    65
        err_msg("duplicated pointer, flag = [%x]", (unsigned int)((MemPointerRecord*)p1)->flags()));
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    66
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    67
     if (_pos < _array->length() -1) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    68
      MemPointer* p1 = (MemPointer*)ptr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    69
      MemPointer* p2 = (MemPointer*)_array->at(_pos + 1);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    70
      assert(!is_dup_pointer(p1, p2),
13470
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
    71
        err_msg("duplicated pointer, flag = [%x]", (unsigned int)((MemPointerRecord*)p1)->flags()));
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    72
     }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    73
    return _array->insert_at(ptr, _pos);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    74
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    75
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    76
  virtual bool insert_after(MemPointer* ptr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    77
    if (_pos > 0) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    78
      MemPointer* p1 = (MemPointer*)ptr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    79
      MemPointer* p2 = (MemPointer*)_array->at(_pos - 1);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    80
      assert(!is_dup_pointer(p1, p2),
13470
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
    81
        err_msg("duplicated pointer, flag = [%x]", (unsigned int)((MemPointerRecord*)p1)->flags()));
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    82
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    83
    if (_pos < _array->length() - 1) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    84
      MemPointer* p1 = (MemPointer*)ptr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    85
      MemPointer* p2 = (MemPointer*)_array->at(_pos + 1);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    86
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    87
      assert(!is_dup_pointer(p1, p2),
13470
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
    88
        err_msg("duplicated pointer, flag = [%x]", (unsigned int)((MemPointerRecord*)p1)->flags()));
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    89
     }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    90
    if (_array->insert_at(ptr, _pos + 1)) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    91
      _pos ++;
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
    return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    95
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    96
#endif
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    97
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    98
  virtual MemPointer* locate(address addr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    99
    MemPointer* cur = current();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   100
    while (cur != NULL && cur->addr() < addr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   101
      cur = next();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   102
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   103
    return cur;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   104
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   105
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   106
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   107
class VMMemPointerIterator : public MemPointerIterator {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   108
 public:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   109
  VMMemPointerIterator(MemPointerArray* arr):
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   110
      MemPointerIterator(arr) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   111
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   112
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   113
  // locate an existing reserved memory region that contains specified address,
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   114
  // or the reserved region just above this address, where the incoming
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   115
  // reserved region should be inserted.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   116
  virtual MemPointer* locate(address addr) {
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   117
    reset();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   118
    VMMemRegion* reg = (VMMemRegion*)current();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   119
    while (reg != NULL) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   120
      if (reg->is_reserved_region()) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   121
        if (reg->contains_address(addr) || addr < reg->base()) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   122
          return reg;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   123
      }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   124
    }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   125
      reg = (VMMemRegion*)next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   126
    }
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   127
      return NULL;
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   128
    }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   129
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   130
  // following methods update virtual memory in the context
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   131
  // of 'current' position, which is properly positioned by
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   132
  // callers via locate method.
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   133
  bool add_reserved_region(MemPointerRecord* rec);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   134
  bool add_committed_region(MemPointerRecord* rec);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   135
  bool remove_uncommitted_region(MemPointerRecord* rec);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   136
  bool remove_released_region(MemPointerRecord* rec);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   137
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   138
  // split a reserved region to create a new memory region with specified base and size
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   139
  bool split_reserved_region(VMMemRegion* rgn, address new_rgn_addr, size_t new_rgn_size);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   140
 private:
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   141
  bool insert_record(MemPointerRecord* rec);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   142
  bool insert_record_after(MemPointerRecord* rec);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   143
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   144
  bool insert_reserved_region(MemPointerRecord* rec);
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   145
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   146
  // reset current position
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   147
  inline void reset() { _pos = 0; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   148
#ifdef ASSERT
14569
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   149
  // check integrity of records on current reserved memory region.
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   150
  bool check_reserved_region() {
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   151
    VMMemRegion* reserved_region = (VMMemRegion*)current();
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   152
    assert(reserved_region != NULL && reserved_region->is_reserved_region(),
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   153
          "Sanity check");
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   154
    // all committed regions that follow current reserved region, should all
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   155
    // belong to the reserved region.
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   156
    VMMemRegion* next_region = (VMMemRegion*)next();
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   157
    for (; next_region != NULL && next_region->is_committed_region();
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   158
         next_region = (VMMemRegion*)next() ) {
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   159
      if(!reserved_region->contains_region(next_region)) {
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   160
        return false;
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   161
      }
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   162
    }
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   163
    return true;
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   164
  }
96937297368d 8003487: NMT: incorrect assertion in VMMemPointerIterator::remove_released_region method (memSnapshot.cpp)
zgu
parents: 14484
diff changeset
   165
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   166
  virtual bool is_dup_pointer(const MemPointer* ptr1,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   167
    const MemPointer* ptr2) const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   168
    VMMemRegion* p1 = (VMMemRegion*)ptr1;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   169
    VMMemRegion* p2 = (VMMemRegion*)ptr2;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   170
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   171
    if (p1->addr() != p2->addr()) return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   172
    if ((p1->flags() & MemPointerRecord::tag_masks) !=
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   173
        (p2->flags() & MemPointerRecord::tag_masks)) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   174
      return false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   175
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   176
    // we do see multiple commit/uncommit on the same memory, it is ok
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   177
    return (p1->flags() & MemPointerRecord::tag_masks) == MemPointerRecord::tag_alloc ||
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   178
           (p1->flags() & MemPointerRecord::tag_masks) == MemPointerRecord::tag_release;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   179
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   180
#endif
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   181
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   182
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   183
class MallocRecordIterator : public MemPointerArrayIterator {
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   184
 private:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   185
  MemPointerArrayIteratorImpl  _itr;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   186
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   187
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   188
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   189
 public:
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   190
  MallocRecordIterator(MemPointerArray* arr) : _itr(arr) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   191
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   192
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   193
  virtual MemPointer* current() const {
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   194
#ifdef ASSERT
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   195
    MemPointer* cur_rec = _itr.current();
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   196
    if (cur_rec != NULL) {
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   197
      MemPointer* prev_rec = _itr.peek_prev();
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   198
      MemPointer* next_rec = _itr.peek_next();
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   199
      assert(prev_rec == NULL || prev_rec->addr() < cur_rec->addr(), "Sorting order");
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   200
      assert(next_rec == NULL || next_rec->addr() > cur_rec->addr(), "Sorting order");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   201
    }
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   202
#endif
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   203
    return _itr.current();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   204
  }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   205
  virtual MemPointer* next() {
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   206
    MemPointerRecord* next_rec = (MemPointerRecord*)_itr.next();
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   207
    // arena memory record is a special case, which we have to compare
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   208
    // sequence number against its associated arena record.
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   209
    if (next_rec != NULL && next_rec->is_arena_memory_record()) {
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   210
      MemPointerRecord* prev_rec = (MemPointerRecord*)_itr.peek_prev();
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   211
      // if there is an associated arena record, it has to be previous
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   212
      // record because of sorting order (by address) - NMT generates a pseudo address
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   213
      // for arena's size record by offsetting arena's address, that guarantees
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   214
      // the order of arena record and it's size record.
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   215
      if (prev_rec != NULL && prev_rec->is_arena_record() &&
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   216
        next_rec->is_memory_record_of_arena(prev_rec)) {
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   217
        if (prev_rec->seq() > next_rec->seq()) {
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   218
          // Skip this arena memory record
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   219
          // Two scenarios:
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   220
          //   - if the arena record is an allocation record, this early
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   221
          //     size record must be leftover by previous arena,
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   222
          //     and the last size record should have size = 0.
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   223
          //   - if the arena record is a deallocation record, this
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   224
          //     size record should be its cleanup record, which should
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   225
          //     also have size = 0. In other world, arena alway reset
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   226
          //     its size before gone (see Arena's destructor)
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   227
          assert(next_rec->size() == 0, "size not reset");
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   228
          return _itr.next();
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   229
        } else {
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   230
          assert(prev_rec->is_allocation_record(),
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   231
            "Arena size record ahead of allocation record");
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   232
        }
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   233
      }
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   234
    }
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   235
    return next_rec;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   236
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   237
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   238
  MemPointer* peek_next() const      { ShouldNotReachHere(); return NULL; }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   239
  MemPointer* peek_prev() const      { ShouldNotReachHere(); return NULL; }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   240
  void remove()                      { ShouldNotReachHere(); }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   241
  bool insert(MemPointer* ptr)       { ShouldNotReachHere(); return false; }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   242
  bool insert_after(MemPointer* ptr) { ShouldNotReachHere(); return false; }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   243
};
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   244
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   245
// collapse duplicated records. Eliminating duplicated records here, is much
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   246
// cheaper than during promotion phase. However, it does have limitation - it
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   247
// can only eliminate duplicated records within the generation, there are
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   248
// still chances seeing duplicated records during promotion.
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   249
// We want to use the record with higher sequence number, because it has
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   250
// more accurate callsite pc.
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   251
class VMRecordIterator : public MemPointerArrayIterator {
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   252
 private:
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   253
  MemPointerArrayIteratorImpl  _itr;
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   254
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   255
 public:
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   256
  VMRecordIterator(MemPointerArray* arr) : _itr(arr) {
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   257
    MemPointerRecord* cur = (MemPointerRecord*)_itr.current();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   258
    MemPointerRecord* next = (MemPointerRecord*)_itr.peek_next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   259
    while (next != NULL) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   260
      assert(cur != NULL, "Sanity check");
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   261
      assert(((SeqMemPointerRecord*)next)->seq() > ((SeqMemPointerRecord*)cur)->seq(),
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   262
        "pre-sort order");
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   263
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   264
      if (is_duplicated_record(cur, next)) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   265
        _itr.next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   266
        next = (MemPointerRecord*)_itr.peek_next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   267
      } else {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   268
        break;
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   269
      }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   270
    }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   271
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   272
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   273
  virtual MemPointer* current() const {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   274
    return _itr.current();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   275
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   276
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   277
  // get next record, but skip the duplicated records
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   278
  virtual MemPointer* next() {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   279
    MemPointerRecord* cur = (MemPointerRecord*)_itr.next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   280
    MemPointerRecord* next = (MemPointerRecord*)_itr.peek_next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   281
    while (next != NULL) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   282
      assert(cur != NULL, "Sanity check");
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   283
      assert(((SeqMemPointerRecord*)next)->seq() > ((SeqMemPointerRecord*)cur)->seq(),
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   284
        "pre-sort order");
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   285
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   286
      if (is_duplicated_record(cur, next)) {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   287
        _itr.next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   288
        cur = next;
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   289
        next = (MemPointerRecord*)_itr.peek_next();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   290
      } else {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   291
        break;
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   292
      }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   293
    }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   294
    return cur;
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   295
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   296
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   297
  MemPointer* peek_next() const      { ShouldNotReachHere(); return NULL; }
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   298
  MemPointer* peek_prev() const      { ShouldNotReachHere(); return NULL; }
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   299
  void remove()                      { ShouldNotReachHere(); }
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   300
  bool insert(MemPointer* ptr)       { ShouldNotReachHere(); return false; }
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   301
  bool insert_after(MemPointer* ptr) { ShouldNotReachHere(); return false; }
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   302
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   303
 private:
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   304
  bool is_duplicated_record(MemPointerRecord* p1, MemPointerRecord* p2) const {
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   305
    bool ret = (p1->addr() == p2->addr() && p1->size() == p2->size() && p1->flags() == p2->flags());
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   306
    assert(!(ret && FLAGS_TO_MEMORY_TYPE(p1->flags()) == mtThreadStack), "dup on stack record");
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   307
    return ret;
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   308
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   309
};
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   310
17023
aab2b408ebfe 8012464: NMT: classes should not derive from _ValueObj, use VALUE_OBJ_CLASS_SPEC instead
zgu
parents: 15104
diff changeset
   311
class StagingArea VALUE_OBJ_CLASS_SPEC {
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   312
 private:
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   313
  MemPointerArray*   _malloc_data;
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   314
  MemPointerArray*   _vm_data;
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   315
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   316
 public:
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   317
  StagingArea() : _malloc_data(NULL), _vm_data(NULL) {
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   318
    init();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   319
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   320
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   321
  ~StagingArea() {
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   322
    if (_malloc_data != NULL) delete _malloc_data;
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   323
    if (_vm_data != NULL) delete _vm_data;
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   324
  }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   325
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   326
  MallocRecordIterator malloc_record_walker() {
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   327
    return MallocRecordIterator(malloc_data());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   328
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   329
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   330
  VMRecordIterator virtual_memory_record_walker();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   331
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   332
  bool init();
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   333
  void clear() {
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   334
    assert(_malloc_data != NULL && _vm_data != NULL, "Just check");
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   335
    _malloc_data->shrink();
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   336
    _malloc_data->clear();
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   337
    _vm_data->clear();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   338
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   339
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   340
  inline MemPointerArray* malloc_data() { return _malloc_data; }
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   341
  inline MemPointerArray* vm_data()     { return _vm_data; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   342
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   343
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   344
class MemBaseline;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   345
class MemSnapshot : public CHeapObj<mtNMT> {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   346
 private:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   347
  // the following two arrays contain records of all known lived memory blocks
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   348
  // live malloc-ed memory pointers
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   349
  MemPointerArray*      _alloc_ptrs;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   350
  // live virtual memory pointers
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   351
  MemPointerArray*      _vm_ptrs;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   352
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   353
  StagingArea           _staging_area;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   354
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   355
  // the lock to protect this snapshot
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   356
  Monitor*              _lock;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   357
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 14569
diff changeset
   358
  // the number of instance classes
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 14569
diff changeset
   359
  int                   _number_of_classes;
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 14569
diff changeset
   360
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   361
  NOT_PRODUCT(size_t    _untracked_count;)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   362
  friend class MemBaseline;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   363
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   364
 public:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   365
  MemSnapshot();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   366
  virtual ~MemSnapshot();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   367
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   368
  // if we are running out of native memory
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   369
  bool out_of_memory() {
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   370
    return (_alloc_ptrs == NULL ||
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   371
      _staging_area.malloc_data() == NULL ||
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   372
      _staging_area.vm_data() == NULL ||
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   373
      _vm_ptrs == NULL || _lock == NULL ||
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   374
      _alloc_ptrs->out_of_memory() ||
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   375
      _vm_ptrs->out_of_memory());
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   376
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   377
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   378
  // merge a per-thread memory recorder into staging area
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   379
  bool merge(MemRecorder* rec);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   380
  // promote staged data to snapshot
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 14569
diff changeset
   381
  bool promote(int number_of_classes);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   382
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 14569
diff changeset
   383
  int  number_of_classes() const { return _number_of_classes; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   384
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   385
  void wait(long timeout) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   386
    assert(_lock != NULL, "Just check");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   387
    MonitorLockerEx locker(_lock);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   388
    locker.wait(true, timeout);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   389
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   390
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   391
  NOT_PRODUCT(void print_snapshot_stats(outputStream* st);)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   392
  NOT_PRODUCT(void check_staging_data();)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   393
  NOT_PRODUCT(void check_malloc_pointers();)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   394
  NOT_PRODUCT(bool has_allocation_record(address addr);)
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   395
  // dump all virtual memory pointers in snapshot
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13744
diff changeset
   396
  DEBUG_ONLY( void dump_all_vm_pointers();)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   397
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   398
 private:
14484
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   399
   // copy sequenced pointer from src to dest
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   400
   void copy_seq_pointer(MemPointerRecord* dest, const MemPointerRecord* src);
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   401
   // assign a sequenced pointer to non-sequenced pointer
901d216b74bf 8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents: 14120
diff changeset
   402
   void assign_pointer(MemPointerRecord*dest, const MemPointerRecord* src);
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   403
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   404
   bool promote_malloc_records(MemPointerArrayIterator* itr);
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   405
   bool promote_virtual_memory_records(MemPointerArrayIterator* itr);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   406
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   407
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   408
#endif // SHARE_VM_SERVICES_MEM_SNAPSHOT_HPP