hotspot/src/share/vm/gc/g1/workerDataArray.inline.hpp
author mgerdin
Mon, 07 Mar 2016 17:23:59 +0100
changeset 37039 79f62b89a7a6
parent 36374 613f27cc37b9
child 37214 bc4e0e0995e6
permissions -rw-r--r--
8151178: Move the collection set out of the G1 collector policy Summary: Create a G1CollectionSet class Reviewed-by: jwilhelm, tbenson, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33623
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     1
/*
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     4
 *
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     8
 *
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    13
 * accompanied this code).
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    14
 *
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    18
 *
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    21
 * questions.
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    22
 *
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    23
 */
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    24
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
    25
#ifndef SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
    26
#define SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
    27
33623
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    28
#include "gc/g1/workerDataArray.hpp"
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    29
#include "memory/allocation.inline.hpp"
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
    30
#include "utilities/ostream.hpp"
33623
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    31
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    32
template <typename T>
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
    33
WorkerDataArray<T>::WorkerDataArray(uint length, const char* title) :
33623
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    34
 _title(title),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    35
 _length(0),
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
    36
 _thread_work_items(NULL) {
33623
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    37
  assert(length > 0, "Must have some workers to store data for");
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    38
  _length = length;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    39
  _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    40
  reset();
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    41
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    42
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    43
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    44
void WorkerDataArray<T>::set(uint worker_i, T value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    45
  assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    46
  assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    47
  _data[worker_i] = value;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    48
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    49
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    50
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    51
T WorkerDataArray<T>::get(uint worker_i) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    52
  assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    53
  assert(_data[worker_i] != uninitialized(), "No data added for worker %d", worker_i);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    54
  return _data[worker_i];
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    55
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    56
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    57
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    58
WorkerDataArray<T>::~WorkerDataArray() {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    59
  FREE_C_HEAP_ARRAY(T, _data);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    60
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    61
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    62
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    63
void WorkerDataArray<T>::link_thread_work_items(WorkerDataArray<size_t>* thread_work_items) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    64
  _thread_work_items = thread_work_items;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    65
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    66
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    67
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    68
void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    69
  assert(_thread_work_items != NULL, "No sub count");
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    70
  _thread_work_items->set(worker_i, value);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    71
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    72
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    73
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    74
void WorkerDataArray<T>::add(uint worker_i, T value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    75
  assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    76
  assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    77
  _data[worker_i] += value;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    78
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    79
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    80
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    81
double WorkerDataArray<T>::average(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    82
  return sum(active_threads) / (double) active_threads;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    83
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    84
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    85
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    86
T WorkerDataArray<T>::sum(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    87
  T s = get(0);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    88
  for (uint i = 1; i < active_threads; ++i) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    89
    s += get(i);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    90
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    91
  return s;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    92
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    93
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    94
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    95
void WorkerDataArray<T>::clear() {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    96
  set_all(0);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    97
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    98
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    99
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   100
void WorkerDataArray<T>::set_all(T value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   101
  for (uint i = 0; i < _length; i++) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   102
    _data[i] = value;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   103
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   104
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   105
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   106
template <class T>
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   107
void WorkerDataArray<T>::print_summary_on(outputStream* out, uint active_threads, bool print_sum) const {
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   108
  T max = get(0);
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   109
  T min = max;
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   110
  T sum = 0;
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   111
  for (uint i = 1; i < active_threads; ++i) {
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   112
    T value = get(i);
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   113
    max = MAX2(max, value);
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   114
    min = MIN2(min, value);
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   115
    sum += value;
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   116
  }
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   117
  T diff = max - min;
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   118
  double avg = sum / (double) active_threads;
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   119
  WDAPrinter::summary(out, title(), min, avg, max, diff, sum, print_sum);
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   120
}
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   121
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   122
template <class T>
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   123
void WorkerDataArray<T>::print_details_on(outputStream* out, uint active_threads) const {
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   124
  WDAPrinter::details(this, out, active_threads);
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   125
}
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   126
33623
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   127
#ifndef PRODUCT
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   128
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   129
void WorkerDataArray<T>::reset() {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   130
  set_all(uninitialized());
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   131
  if (_thread_work_items != NULL) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   132
    _thread_work_items->reset();
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   133
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   134
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   135
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   136
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   137
void WorkerDataArray<T>::verify(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   138
  assert(active_threads <= _length, "Wrong number of active threads");
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   139
  for (uint i = 0; i < active_threads; i++) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   140
    assert(_data[i] != uninitialized(),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   141
           "Invalid data for worker %u in '%s'", i, _title);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   142
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   143
  if (_thread_work_items != NULL) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   144
    _thread_work_items->verify(active_threads);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   145
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   146
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   147
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   148
template <>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   149
inline size_t WorkerDataArray<size_t>::uninitialized() const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   150
  return (size_t)-1;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   151
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   152
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   153
template <>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   154
inline double WorkerDataArray<double>::uninitialized() const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   155
  return -1.0;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   156
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   157
#endif
36374
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   158
613f27cc37b9 8150068: Log the main G1 phases at info level
brutisso
parents: 35061
diff changeset
   159
#endif // SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP