hotspot/src/share/vm/services/memTrackWorker.cpp
author jlaskey
Tue, 23 Jul 2013 12:00:29 -0300
changeset 19089 51cfdcf21d35
parent 16991 aa4978a77e1f
child 19696 bd5a0131bde1
permissions -rw-r--r--
8021130: Comments need to be tokens Reviewed-by: lagergren, attila Contributed-by: james.laskey@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
#include "precompiled.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    26
#include "runtime/threadCritical.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    27
#include "services/memTracker.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    28
#include "services/memTrackWorker.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    29
#include "utilities/decoder.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    30
#include "utilities/vmError.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    31
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    32
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    33
void GenerationData::reset() {
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    34
  _number_of_classes = 0;
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    35
  while (_recorder_list != NULL) {
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    36
    MemRecorder* tmp = _recorder_list;
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    37
    _recorder_list = _recorder_list->next();
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    38
    MemTracker::release_thread_recorder(tmp);
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    39
  }
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    40
}
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    41
16991
aa4978a77e1f 8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents: 15452
diff changeset
    42
MemTrackWorker::MemTrackWorker(MemSnapshot* snapshot): _snapshot(snapshot) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    43
  // create thread uses cgc thread type for now. We should revisit
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    44
  // the option, or create new thread type.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    45
  _has_error = !os::create_thread(this, os::cgc_thread);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    46
  set_name("MemTrackWorker", 0);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    47
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    48
  // initial generation circuit buffer
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    49
  if (!has_error()) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    50
    _head = _tail = 0;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    51
    for(int index = 0; index < MAX_GENERATIONS; index ++) {
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    52
      ::new ((void*)&_gen[index]) GenerationData();
13195
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
  NOT_PRODUCT(_sync_point_count = 0;)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    56
  NOT_PRODUCT(_merge_count = 0;)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    57
  NOT_PRODUCT(_last_gen_in_use = 0;)
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
MemTrackWorker::~MemTrackWorker() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    61
  for (int index = 0; index < MAX_GENERATIONS; index ++) {
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
    62
    _gen[index].reset();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    63
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    64
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    65
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    66
void* MemTrackWorker::operator new(size_t size) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    67
  assert(false, "use nothrow version");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    68
  return NULL;
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
void* MemTrackWorker::operator new(size_t size, const std::nothrow_t& nothrow_constant) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    72
  return allocate(size, false, mtNMT);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    73
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    74
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    75
void MemTrackWorker::start() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    76
  os::start_thread(this);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    77
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    78
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    79
/*
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    80
 * Native memory tracking worker thread loop:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    81
 *   1. merge one generation of memory recorders to staging area
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    82
 *   2. promote staging data to memory snapshot
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    83
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    84
 * This thread can run through safepoint.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    85
 */
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    86
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    87
void MemTrackWorker::run() {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    88
  assert(MemTracker::is_on(), "native memory tracking is off");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    89
  this->initialize_thread_local_storage();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    90
  this->record_stack_base_and_size();
16991
aa4978a77e1f 8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents: 15452
diff changeset
    91
  assert(_snapshot != NULL, "Worker should not be started");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    92
  MemRecorder* rec;
15452
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
    93
  unsigned long processing_generation = 0;
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
    94
  bool          worker_idle = false;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    95
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    96
  while (!MemTracker::shutdown_in_progress()) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    97
    NOT_PRODUCT(_last_gen_in_use = generations_in_use();)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    98
    {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    99
      // take a recorder from earliest generation in buffer
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   100
      ThreadCritical tc;
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   101
      rec = _gen[_head].next_recorder();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   102
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   103
    if (rec != NULL) {
15452
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   104
      if (rec->get_generation() != processing_generation || worker_idle) {
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   105
        processing_generation = rec->get_generation();
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   106
        worker_idle = false;
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   107
        MemTracker::set_current_processing_generation(processing_generation);
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   108
      }
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   109
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   110
      // merge the recorder into staging area
16991
aa4978a77e1f 8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents: 15452
diff changeset
   111
      if (!_snapshot->merge(rec)) {
13470
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
   112
        MemTracker::shutdown(MemTracker::NMT_out_of_memory);
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
   113
      } else {
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
   114
        NOT_PRODUCT(_merge_count ++;)
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
   115
      }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   116
      MemTracker::release_thread_recorder(rec);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   117
    } else {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   118
      // no more recorder to merge, promote staging area
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   119
      // to snapshot
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   120
      if (_head != _tail) {
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   121
        long number_of_classes;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   122
        {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   123
          ThreadCritical tc;
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   124
          if (_gen[_head].has_more_recorder() || _head == _tail) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   125
            continue;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   126
          }
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   127
          number_of_classes = _gen[_head].number_of_classes();
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   128
          _gen[_head].reset();
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   129
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   130
          // done with this generation, increment _head pointer
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   131
          _head = (_head + 1) % MAX_GENERATIONS;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   132
        }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   133
        // promote this generation data to snapshot
16991
aa4978a77e1f 8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents: 15452
diff changeset
   134
        if (!_snapshot->promote(number_of_classes)) {
13744
631fe815def5 7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents: 13470
diff changeset
   135
          // failed to promote, means 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
   136
          MemTracker::shutdown(MemTracker::NMT_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
   137
        }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   138
      } else {
15452
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   139
        // worker thread is idle
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   140
        worker_idle = true;
3bfde2dea09d 8005012: Add WB APIs to better support NMT testing
ctornqvi
parents: 15104
diff changeset
   141
        MemTracker::report_worker_idle();
16991
aa4978a77e1f 8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents: 15452
diff changeset
   142
        _snapshot->wait(1000);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   143
        ThreadCritical tc;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   144
        // check if more data arrived
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   145
        if (!_gen[_head].has_more_recorder()) {
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   146
          _gen[_head].add_recorders(MemTracker::get_pending_recorders());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   147
        }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   148
      }
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
  assert(MemTracker::shutdown_in_progress(), "just check");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   152
13470
a99b4dc12f9b 7185614: NMT ON: "check by caller" assertion failed on nsk ThreadMXBean test
zgu
parents: 13195
diff changeset
   153
  // transits to final shutdown
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   154
  MemTracker::final_shutdown();
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
// at synchronization point, where 'safepoint visible' Java threads are blocked
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   158
// at a safepoint, and the rest of threads are blocked on ThreadCritical lock.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   159
// The caller MemTracker::sync() already takes ThreadCritical before calling this
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   160
// method.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   161
//
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   162
// Following tasks are performed:
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   163
//   1. add all recorders in pending queue to current generation
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   164
//   2. increase generation
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   165
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   166
void MemTrackWorker::at_sync_point(MemRecorder* rec, int number_of_classes) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   167
  NOT_PRODUCT(_sync_point_count ++;)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   168
  assert(count_recorder(rec) <= MemRecorder::_instance_count,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   169
    "pending queue has infinite loop");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   170
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   171
  bool out_of_generation_buffer = false;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   172
  // check shutdown state inside ThreadCritical
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   173
  if (MemTracker::shutdown_in_progress()) return;
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   174
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   175
  _gen[_tail].set_number_of_classes(number_of_classes);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   176
  // append the recorders to the end of the generation
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   177
  _gen[_tail].add_recorders(rec);
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   178
  assert(count_recorder(_gen[_tail].peek()) <= MemRecorder::_instance_count,
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   179
    "after add to current generation has infinite loop");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   180
  // we have collected all recorders for this generation. If there is data,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   181
  // we need to increment _tail to start a new generation.
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   182
  if (_gen[_tail].has_more_recorder()  || _head == _tail) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   183
    _tail = (_tail + 1) % MAX_GENERATIONS;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   184
    out_of_generation_buffer = (_tail == _head);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   185
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   186
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   187
  if (out_of_generation_buffer) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   188
    MemTracker::shutdown(MemTracker::NMT_out_of_generation);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   189
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   190
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   191
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   192
#ifndef PRODUCT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   193
int MemTrackWorker::count_recorder(const MemRecorder* head) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   194
  int count = 0;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   195
  while(head != NULL) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   196
    count ++;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   197
    head = head->next();
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   198
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   199
  return count;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   200
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   201
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   202
int MemTrackWorker::count_pending_recorders() const {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   203
  int count = 0;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   204
  for (int index = 0; index < MAX_GENERATIONS; index ++) {
15104
f5d78994619f 8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents: 13744
diff changeset
   205
    MemRecorder* head = _gen[index].peek();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   206
    if (head != NULL) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   207
      count += count_recorder(head);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   208
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   209
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   210
  return count;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   211
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   212
#endif