hotspot/src/share/vm/gc/g1/workerDataArray.inline.hpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 33623 8b6afaf25abd
child 35061 be6025ebffea
permissions -rw-r--r--
8136679: JFR event for adaptive IHOP Reviewed-by: tbenson, mgerdin, sangheki, ehelin
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
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    25
#include "gc/g1/workerDataArray.hpp"
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    26
#include "memory/allocation.inline.hpp"
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    27
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    28
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    29
WorkerDataArray<T>::WorkerDataArray(uint length,
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    30
                                    const char* title,
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    31
                                    bool print_sum,
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    32
                                    int log_level,
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    33
                                    uint indent_level) :
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),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    36
 _print_sum(print_sum),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    37
 _log_level(log_level),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    38
 _indent_level(indent_level),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    39
 _thread_work_items(NULL),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    40
 _enabled(true) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    41
  assert(length > 0, "Must have some workers to store data for");
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    42
  _length = length;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    43
  _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    44
  reset();
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    45
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    46
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    47
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    48
void WorkerDataArray<T>::set(uint worker_i, T value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    49
  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
    50
  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
    51
  _data[worker_i] = value;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    52
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    53
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    54
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    55
T WorkerDataArray<T>::get(uint worker_i) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    56
  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
    57
  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
    58
  return _data[worker_i];
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    59
}
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
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    62
WorkerDataArray<T>::~WorkerDataArray() {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    63
  FREE_C_HEAP_ARRAY(T, _data);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    64
}
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
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    67
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
    68
  _thread_work_items = thread_work_items;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    69
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    70
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    71
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    72
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
    73
  assert(_thread_work_items != NULL, "No sub count");
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    74
  _thread_work_items->set(worker_i, value);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    75
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    76
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    77
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    78
void WorkerDataArray<T>::add(uint worker_i, T value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    79
  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
    80
  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
    81
  _data[worker_i] += value;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    82
}
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
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    85
double WorkerDataArray<T>::average(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    86
  return sum(active_threads) / (double) active_threads;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    87
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    88
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    89
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    90
T WorkerDataArray<T>::sum(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    91
  T s = get(0);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    92
  for (uint i = 1; i < active_threads; ++i) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    93
    s += get(i);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    94
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    95
  return s;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    96
}
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
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
    99
T WorkerDataArray<T>::minimum(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   100
  T min = get(0);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   101
  for (uint i = 1; i < active_threads; ++i) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   102
    min = MIN2(min, get(i));
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
  return min;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   105
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   106
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   107
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   108
T WorkerDataArray<T>::maximum(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   109
  T max = get(0);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   110
  for (uint i = 1; i < active_threads; ++i) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   111
    max = MAX2(max, get(i));
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   112
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   113
  return max;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   114
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   115
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   116
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   117
T WorkerDataArray<T>::diff(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   118
  return maximum(active_threads) - minimum(active_threads);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   119
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   120
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   121
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   122
void WorkerDataArray<T>::clear() {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   123
  set_all(0);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   124
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   125
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   126
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   127
void WorkerDataArray<T>::set_all(T value) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   128
  for (uint i = 0; i < _length; i++) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   129
    _data[i] = value;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   130
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   131
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   132
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   133
#ifndef PRODUCT
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   134
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   135
void WorkerDataArray<T>::reset() {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   136
  set_all(uninitialized());
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   137
  if (_thread_work_items != NULL) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   138
    _thread_work_items->reset();
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   139
  }
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   140
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   141
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   142
template <typename T>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   143
void WorkerDataArray<T>::verify(uint active_threads) const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   144
  if (!_enabled) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   145
    return;
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
  assert(active_threads <= _length, "Wrong number of active threads");
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   149
  for (uint i = 0; i < active_threads; i++) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   150
    assert(_data[i] != uninitialized(),
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   151
           "Invalid data for worker %u in '%s'", i, _title);
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
  if (_thread_work_items != NULL) {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   154
    _thread_work_items->verify(active_threads);
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   155
  }
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
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   158
template <>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   159
inline size_t WorkerDataArray<size_t>::uninitialized() const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   160
  return (size_t)-1;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   161
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   162
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   163
template <>
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   164
inline double WorkerDataArray<double>::uninitialized() const {
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   165
  return -1.0;
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   166
}
8b6afaf25abd 8140393: Move WorkerDataArray to its own file
ehelin
parents:
diff changeset
   167
#endif