src/hotspot/share/runtime/threadHeapSampler.cpp
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 50638 f9f2e6a6a7b2
child 50882 80abf702eed8
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50579
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     1
/*
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     2
 * Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     4
 *
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     8
 *
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    13
 * accompanied this code).
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    14
 *
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    18
 *
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    21
 * questions.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    22
 *
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    23
 */
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    24
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    25
#include "precompiled.hpp"
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    26
#include "runtime/handles.inline.hpp"
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    27
#include "runtime/orderAccess.hpp"
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    28
#include "runtime/sharedRuntime.hpp"
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    29
#include "runtime/threadHeapSampler.hpp"
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    30
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    31
// Cheap random number generator
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    32
uint64_t ThreadHeapSampler::_rnd;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    33
// Default is 512kb.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    34
int ThreadHeapSampler::_sampling_rate = 512 * 1024;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    35
int ThreadHeapSampler::_enabled;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    36
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    37
// Statics for the fast log
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    38
static const int FastLogNumBits = 10;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    39
static const int FastLogMask = (1 << FastLogNumBits) - 1;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    40
static double log_table[1<<FastLogNumBits];  // Constant
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    41
static bool log_table_initialized;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    42
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    43
// Returns the next prng value.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    44
// pRNG is: aX+b mod c with a = 0x5DEECE66D, b =  0xB, c = 1<<48
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    45
// This is the lrand64 generator.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    46
static uint64_t next_random(uint64_t rnd) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    47
  const uint64_t PrngMult = 0x5DEECE66DLL;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    48
  const uint64_t PrngAdd = 0xB;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    49
  const uint64_t PrngModPower = 48;
50638
f9f2e6a6a7b2 8205172: 32 bit build broken
mdoerr
parents: 50579
diff changeset
    50
  const uint64_t PrngModMask = ((uint64_t)1 << PrngModPower) - 1;
50579
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    51
  //assert(IS_SAFE_SIZE_MUL(PrngMult, rnd), "Overflow on multiplication.");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    52
  //assert(IS_SAFE_SIZE_ADD(PrngMult * rnd, PrngAdd), "Overflow on addition.");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    53
  return (PrngMult * rnd + PrngAdd) & PrngModMask;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    54
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    55
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    56
static double fast_log2(const double & d) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    57
  assert(d>0, "bad value passed to assert");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    58
  uint64_t x = 0;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    59
  assert(sizeof(d) == sizeof(x),
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    60
         "double and uint64_t do not have the same size");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    61
  x = *reinterpret_cast<const uint64_t*>(&d);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    62
  const uint32_t x_high = x >> 32;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    63
  assert(FastLogNumBits <= 20, "FastLogNumBits should be less than 20.");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    64
  const uint32_t y = x_high >> (20 - FastLogNumBits) & FastLogMask;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    65
  const int32_t exponent = ((x_high >> 20) & 0x7FF) - 1023;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    66
  return exponent + log_table[y];
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    67
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    68
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    69
// Generates a geometric variable with the specified mean (512K by default).
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    70
// This is done by generating a random number between 0 and 1 and applying
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    71
// the inverse cumulative distribution function for an exponential.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    72
// Specifically: Let m be the inverse of the sample rate, then
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    73
// the probability distribution function is m*exp(-mx) so the CDF is
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    74
// p = 1 - exp(-mx), so
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    75
// q = 1 - p = exp(-mx)
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    76
// log_e(q) = -mx
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    77
// -log_e(q)/m = x
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    78
// log_2(q) * (-log_e(2) * 1/m) = x
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    79
// In the code, q is actually in the range 1 to 2**26, hence the -26 below
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    80
void ThreadHeapSampler::pick_next_geometric_sample() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    81
  _rnd = next_random(_rnd);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    82
  // Take the top 26 bits as the random number
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    83
  // (This plus a 1<<58 sampling bound gives a max possible step of
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    84
  // 5194297183973780480 bytes.  In this case,
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    85
  // for sample_parameter = 1<<19, max possible step is
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    86
  // 9448372 bytes (24 bits).
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    87
  const uint64_t PrngModPower = 48;  // Number of bits in prng
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    88
  // The uint32_t cast is to prevent a (hard-to-reproduce) NAN
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    89
  // under piii debug for some binaries.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    90
  double q = static_cast<uint32_t>(_rnd >> (PrngModPower - 26)) + 1.0;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    91
  // Put the computed p-value through the CDF of a geometric.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    92
  // For faster performance (save ~1/20th exec time), replace
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    93
  // min(0.0, FastLog2(q) - 26)  by  (Fastlog2(q) - 26.000705)
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    94
  // The value 26.000705 is used rather than 26 to compensate
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    95
  // for inaccuracies in FastLog2 which otherwise result in a
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    96
  // negative answer.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    97
  double log_val = (fast_log2(q) - 26);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    98
  double result =
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
    99
      (0.0 < log_val ? 0.0 : log_val) * (-log(2.0) * (get_sampling_rate())) + 1;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   100
  assert(result > 0 && result < SIZE_MAX, "Result is not in an acceptable range.");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   101
  size_t rate = static_cast<size_t>(result);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   102
  _bytes_until_sample = rate;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   103
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   104
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   105
void ThreadHeapSampler::pick_next_sample(size_t overflowed_bytes) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   106
  if (get_sampling_rate() == 1) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   107
    _bytes_until_sample = 1;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   108
    return;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   109
  }
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   110
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   111
  pick_next_geometric_sample();
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   112
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   113
  // Try to correct sample size by removing extra space from last allocation.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   114
  if (overflowed_bytes > 0 && _bytes_until_sample > overflowed_bytes) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   115
    _bytes_until_sample -= overflowed_bytes;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   116
  }
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   117
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   118
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   119
void ThreadHeapSampler::check_for_sampling(HeapWord* ptr, size_t allocation_size, size_t bytes_since_allocation) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   120
  oopDesc* oop = reinterpret_cast<oopDesc*>(ptr);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   121
  size_t total_allocated_bytes = bytes_since_allocation + allocation_size;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   122
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   123
  // If not yet time for a sample, skip it.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   124
  if (total_allocated_bytes < _bytes_until_sample) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   125
    _bytes_until_sample -= total_allocated_bytes;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   126
    return;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   127
  }
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   128
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   129
  JvmtiExport::sampled_object_alloc_event_collector(oop);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   130
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   131
  size_t overflow_bytes = total_allocated_bytes - _bytes_until_sample;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   132
  pick_next_sample(overflow_bytes);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   133
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   134
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   135
void ThreadHeapSampler::init_log_table() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   136
  MutexLockerEx mu(ThreadHeapSampler_lock, Mutex::_no_safepoint_check_flag);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   137
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   138
  if (log_table_initialized) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   139
    return;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   140
  }
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   141
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   142
  for (int i = 0; i < (1 << FastLogNumBits); i++) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   143
    log_table[i] = (log(1.0 + static_cast<double>(i+0.5) / (1 << FastLogNumBits))
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   144
                    / log(2.0));
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   145
  }
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   146
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   147
  log_table_initialized = true;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   148
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   149
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   150
void ThreadHeapSampler::enable() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   151
  // Done here to be done when things have settled. This adds a mutex lock but
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   152
  // presumably, users won't be enabling and disabling all the time.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   153
  init_log_table();
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   154
  OrderAccess::release_store(&_enabled, 1);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   155
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   156
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   157
int ThreadHeapSampler::enabled() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   158
  return OrderAccess::load_acquire(&_enabled);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   159
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   160
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   161
void ThreadHeapSampler::disable() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   162
  OrderAccess::release_store(&_enabled, 0);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   163
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   164
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   165
int ThreadHeapSampler::get_sampling_rate() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   166
  return OrderAccess::load_acquire(&_sampling_rate);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   167
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   168
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   169
void ThreadHeapSampler::set_sampling_rate(int sampling_rate) {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   170
  OrderAccess::release_store(&_sampling_rate, sampling_rate);
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   171
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   172
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   173
// Methods used in assertion mode to check if a collector is present or not at
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   174
// the moment of TLAB sampling, ie a slow allocation path.
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   175
bool ThreadHeapSampler::sampling_collector_present() const {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   176
  return _collectors_present > 0;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   177
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   178
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   179
bool ThreadHeapSampler::remove_sampling_collector() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   180
  assert(_collectors_present > 0, "Problem with collector counter.");
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   181
  _collectors_present--;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   182
  return true;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   183
}
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   184
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   185
bool ThreadHeapSampler::add_sampling_collector() {
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   186
  _collectors_present++;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   187
  return true;
1596f418ffe4 8205096: Add missing files for 8203394
jcbeyler
parents:
diff changeset
   188
}