src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp
author tschatzl
Fri, 22 Nov 2019 10:03:38 +0100
changeset 59221 cc3a82fc7bcb
parent 54659 62d6baca22fc
permissions -rw-r--r--
8233702: Introduce helper function to clamp value to range Reviewed-by: sjohanss, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54659
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4636
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4636
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4636
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
52124
c64384f414bc 8211955: GC abstraction for LAB reserve
rkennke
parents: 51817
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
    27
#include "gc/shared/threadLocalAllocBuffer.inline.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    28
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/resourceArea.hpp"
49359
59f6547e151f 8199264: Remove universe.inline.hpp to simplify include dependencies
stefank
parents: 48105
diff changeset
    30
#include "memory/universe.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.inline.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 10565
diff changeset
    32
#include "runtime/thread.inline.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 48005
diff changeset
    33
#include "runtime/threadSMR.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/copy.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    36
size_t       ThreadLocalAllocBuffer::_max_size = 0;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    37
int          ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    38
unsigned int ThreadLocalAllocBuffer::_target_refills = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    40
size_t ThreadLocalAllocBuffer::remaining() {
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    41
  if (end() == NULL) {
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    42
    return 0;
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    43
  }
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    44
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    45
  return pointer_delta(hard_end(), top());
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    46
}
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
    47
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    48
void ThreadLocalAllocBuffer::accumulate_and_reset_statistics(ThreadLocalAllocStats* stats) {
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
    49
  Thread* thr     = thread();
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
    50
  size_t capacity = Universe::heap()->tlab_capacity(thr);
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
    51
  size_t used     = Universe::heap()->tlab_used(thr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _gc_waste += (unsigned)remaining();
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
    54
  size_t total_allocated = thr->allocated_bytes();
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    55
  size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    56
  _allocated_before_last_gc = total_allocated;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    58
  print_stats("gc");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (_number_of_refills > 0) {
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    61
    // Update allocation history if a reasonable amount of eden was allocated.
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    62
    bool update_allocation_history = used > 0.5 * capacity;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    if (update_allocation_history) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      // Average the fraction of eden allocated in a tlab by this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      // thread for use in the next resize operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      // _gc_waste is not subtracted because it's included in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      // "used".
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    69
      // The result can be larger than 1.0 due to direct to old allocations.
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    70
      // These allocations should ideally not be counted but since it is not possible
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    71
      // to filter them out here we just cap the fraction to be at most 1.0.
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
    72
      double alloc_frac = MIN2(1.0, (double) allocated_since_last_gc / used);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      _allocation_fraction.sample(alloc_frac);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    76
    stats->update_fast_allocations(_number_of_refills,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    77
                                   _allocated_size,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    78
                                   _gc_waste,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    79
                                   _fast_refill_waste,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    80
                                   _slow_refill_waste);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    assert(_number_of_refills == 0 && _fast_refill_waste == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
           _slow_refill_waste == 0 && _gc_waste          == 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
           "tlab stats == 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    86
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    87
  stats->update_slow_allocations(_slow_allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    88
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    89
  reset_statistics();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    92
void ThreadLocalAllocBuffer::insert_filler() {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    93
  assert(end() != NULL, "Must not be retired");
53414
fe8991950105 8214235: arm32: assertion in collectedHeap.cpp: attempt to clean empty remainder
bulasevich
parents: 52854
diff changeset
    94
  if (top() < hard_end()) {
fe8991950105 8214235: arm32: assertion in collectedHeap.cpp: attempt to clean empty remainder
bulasevich
parents: 52854
diff changeset
    95
    Universe::heap()->fill_with_dummy_object(top(), hard_end(), true);
fe8991950105 8214235: arm32: assertion in collectedHeap.cpp: attempt to clean empty remainder
bulasevich
parents: 52854
diff changeset
    96
  }
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    97
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    98
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
    99
void ThreadLocalAllocBuffer::make_parsable() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  if (end() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    invariants();
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   102
    if (ZeroTLAB) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   103
      retire();
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   104
    } else {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   105
      insert_filler();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   108
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   109
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   110
void ThreadLocalAllocBuffer::retire(ThreadLocalAllocStats* stats) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   111
  if (stats != NULL) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   112
    accumulate_and_reset_statistics(stats);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   113
  }
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   114
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   115
  if (end() != NULL) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   116
    invariants();
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   117
    thread()->incr_allocated_bytes(used_bytes());
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   118
    insert_filler();
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   119
    initialize(NULL, NULL, NULL);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   120
  }
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   121
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   122
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   123
void ThreadLocalAllocBuffer::retire_before_allocation() {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   124
  _slow_refill_waste += (unsigned int)remaining();
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   125
  retire();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void ThreadLocalAllocBuffer::resize() {
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   129
  // Compute the next tlab size using expected allocation amount
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   130
  assert(ResizeTLAB, "Should not call this otherwise");
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   131
  size_t alloc = (size_t)(_allocation_fraction.average() *
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   132
                          (Universe::heap()->tlab_capacity(thread()) / HeapWordSize));
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   133
  size_t new_size = alloc / _target_refills;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
59221
cc3a82fc7bcb 8233702: Introduce helper function to clamp value to range
tschatzl
parents: 54659
diff changeset
   135
  new_size = clamp(new_size, min_size(), max_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   137
  size_t aligned_new_size = align_object_size(new_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   139
  log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   140
                      " refills %d  alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   141
                      p2i(thread()), thread()->osthread()->thread_id(),
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   142
                      _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   143
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   144
  set_desired_size(aligned_new_size);
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   145
  set_refill_waste_limit(initial_refill_waste_limit());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   148
void ThreadLocalAllocBuffer::reset_statistics() {
49946
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   149
  _number_of_refills = 0;
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   150
  _fast_refill_waste = 0;
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   151
  _slow_refill_waste = 0;
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   152
  _gc_waste          = 0;
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   153
  _slow_allocations  = 0;
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   154
  _allocated_size    = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
void ThreadLocalAllocBuffer::fill(HeapWord* start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                                  HeapWord* top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
                                  size_t    new_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  _number_of_refills++;
49946
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   161
  _allocated_size += new_size;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   162
  print_stats("fill");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  assert(top <= start + new_size - alignment_reserve(), "size too small");
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   164
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  initialize(start, top, start + new_size - alignment_reserve());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Reset amount of internal fragmentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  set_refill_waste_limit(initial_refill_waste_limit());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void ThreadLocalAllocBuffer::initialize(HeapWord* start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
                                        HeapWord* top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
                                        HeapWord* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  set_start(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  set_top(top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  set_pf_top(top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  set_end(end);
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   178
  set_allocation_end(end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
void ThreadLocalAllocBuffer::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  initialize(NULL,                    // start
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
             NULL,                    // top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
             NULL);                   // end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  set_desired_size(initial_desired_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   189
  size_t capacity = Universe::heap()->tlab_capacity(thread()) / HeapWordSize;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   190
  double alloc_frac = desired_size() * target_refills() / (double) capacity;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   191
  _allocation_fraction.sample(alloc_frac);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  set_refill_waste_limit(initial_refill_waste_limit());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   195
  reset_statistics();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
void ThreadLocalAllocBuffer::startup_initialization() {
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   199
  ThreadLocalAllocStats::initialize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // Assuming each thread's active tlab is, on average,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // 1/2 full at a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  _target_refills = 100 / (2 * TLABWasteTargetPercent);
51385
be775229d3b3 8200365: TestOptionsWithRanges.java of '-XX:TLABWasteTargetPercent=100' fails intermittently
tschatzl
parents: 51268
diff changeset
   204
  // We need to set initial target refills to 2 to avoid a GC which causes VM
be775229d3b3 8200365: TestOptionsWithRanges.java of '-XX:TLABWasteTargetPercent=100' fails intermittently
tschatzl
parents: 51268
diff changeset
   205
  // abort during VM initialization.
be775229d3b3 8200365: TestOptionsWithRanges.java of '-XX:TLABWasteTargetPercent=100' fails intermittently
tschatzl
parents: 51268
diff changeset
   206
  _target_refills = MAX2(_target_refills, 2U);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
38651
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   208
#ifdef COMPILER2
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   209
  // If the C2 compiler is present, extra space is needed at the end of
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   210
  // TLABs, otherwise prefetching instructions generated by the C2
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   211
  // compiler will fault (due to accessing memory outside of heap).
38220
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   212
  // The amount of space is the max of the number of lines to
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   213
  // prefetch for array and for instance allocations. (Extra space must be
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   214
  // reserved to accommodate both types of allocations.)
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   215
  //
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   216
  // Only SPARC-specific BIS instructions are known to fault. (Those
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   217
  // instructions are generated if AllocatePrefetchStyle==3 and
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   218
  // AllocatePrefetchInstr==1). To be on the safe side, however,
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   219
  // extra space is reserved for all combinations of
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   220
  // AllocatePrefetchStyle and AllocatePrefetchInstr.
38651
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   221
  //
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   222
  // If the C2 compiler is not present, no space is reserved.
38220
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   223
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   224
  // +1 for rounding up to next cache line, +1 to be safe
43455
96560cffef4d 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 38651
diff changeset
   225
  if (is_server_compilation_mode_vm()) {
96560cffef4d 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 38651
diff changeset
   226
    int lines =  MAX2(AllocatePrefetchLines, AllocateInstancePrefetchLines) + 2;
96560cffef4d 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 38651
diff changeset
   227
    _reserve_for_allocation_prefetch = (AllocatePrefetchDistance + AllocatePrefetchStepSize * lines) /
96560cffef4d 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 38651
diff changeset
   228
                                       (int)HeapWordSize;
96560cffef4d 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 38651
diff changeset
   229
  }
38651
c86a9e9079fb 8157560: Reserve space for allocation prefetch only in builds that support allocation prefetching
zmajo
parents: 38220
diff changeset
   230
#endif
38220
8d86b82e0ac7 8153340: Disallow misconfiguration and improve the consistency of allocation prefetching
zmajo
parents: 37242
diff changeset
   231
48005
9fd89aabb6cd 8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
dholmes
parents: 47679
diff changeset
   232
  // During jvm startup, the main thread is initialized
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // before the heap is initialized.  So reinitialize it now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  Thread::current()->tlab().initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   237
  log_develop_trace(gc, tlab)("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   238
                               min_size(), Thread::current()->tlab().initial_desired_size(), max_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
size_t ThreadLocalAllocBuffer::initial_desired_size() {
28511
3de39f0478f8 8055479: TLAB stability
mgerdin
parents: 24424
diff changeset
   242
  size_t init_sz = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  if (TLABSize > 0) {
28511
3de39f0478f8 8055479: TLAB stability
mgerdin
parents: 24424
diff changeset
   245
    init_sz = TLABSize / HeapWordSize;
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   246
  } else {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    // Initial size is a function of the average number of allocating threads.
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   248
    unsigned int nof_threads = ThreadLocalAllocStats::allocating_threads_avg();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   250
    init_sz  = (Universe::heap()->tlab_capacity(thread()) / HeapWordSize) /
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                      (nof_threads * target_refills());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    init_sz = align_object_size(init_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
59221
cc3a82fc7bcb 8233702: Introduce helper function to clamp value to range
tschatzl
parents: 54659
diff changeset
   254
  // We can't use clamp() between min_size() and max_size() here because some
cc3a82fc7bcb 8233702: Introduce helper function to clamp value to range
tschatzl
parents: 54659
diff changeset
   255
  // options based on them may still be inconsistent and so it may assert;
cc3a82fc7bcb 8233702: Introduce helper function to clamp value to range
tschatzl
parents: 54659
diff changeset
   256
  // inconsistencies between those will be caught by following AfterMemoryInit
cc3a82fc7bcb 8233702: Introduce helper function to clamp value to range
tschatzl
parents: 54659
diff changeset
   257
  // constraint checking.
28511
3de39f0478f8 8055479: TLAB stability
mgerdin
parents: 24424
diff changeset
   258
  init_sz = MIN2(MAX2(init_sz, min_size()), max_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  return init_sz;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
void ThreadLocalAllocBuffer::print_stats(const char* tag) {
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 35548
diff changeset
   263
  Log(gc, tlab) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   264
  if (!log.is_trace()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   265
    return;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   266
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   267
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   268
  Thread* thrd = thread();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste;
49946
2143feab681a 8202140: TLAB logging is not correct for G1
sjohanss
parents: 49734
diff changeset
   270
  double waste_percent = percent_of(waste, _allocated_size);
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 14583
diff changeset
   271
  size_t tlab_used  = Universe::heap()->tlab_used(thrd);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   272
  log.trace("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   273
            " desired_size: " SIZE_FORMAT "KB"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   274
            " slow allocs: %d  refill waste: " SIZE_FORMAT "B"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   275
            " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   276
            " slow: %dB fast: %dB",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   277
            tag, p2i(thrd), thrd->osthread()->thread_id(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   278
            _desired_size / (K / HeapWordSize),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   279
            _slow_allocations, _refill_waste_limit * HeapWordSize,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   280
            _allocation_fraction.average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   281
            _allocation_fraction.average() * tlab_used / K,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   282
            _number_of_refills, waste_percent,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   283
            _gc_waste * HeapWordSize,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   284
            _slow_refill_waste * HeapWordSize,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   285
            _fast_refill_waste * HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
54659
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   288
void ThreadLocalAllocBuffer::set_sample_end(bool reset_byte_accumulation) {
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   289
  size_t heap_words_remaining = pointer_delta(_end, _top);
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   290
  size_t bytes_until_sample = thread()->heap_sampler().bytes_until_sample();
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents: 50578
diff changeset
   291
  size_t words_until_sample = bytes_until_sample / HeapWordSize;
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   292
54659
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   293
  if (reset_byte_accumulation) {
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   294
    _bytes_since_last_sample_point = 0;
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   295
  }
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   296
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   297
  if (heap_words_remaining > words_until_sample) {
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   298
    HeapWord* new_end = _top + words_until_sample;
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   299
    set_end(new_end);
54659
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   300
    _bytes_since_last_sample_point += bytes_until_sample;
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   301
  } else {
54659
62d6baca22fc 8215113: Sampling interval not always correct
jcbeyler
parents: 53414
diff changeset
   302
    _bytes_since_last_sample_point += heap_words_remaining * HeapWordSize;
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   303
  }
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   304
}
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   305
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   306
Thread* ThreadLocalAllocBuffer::thread() {
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 51385
diff changeset
   307
  return (Thread*)(((char*)this) + in_bytes(start_offset()) - in_bytes(Thread::tlab_start_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
50578
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   310
void ThreadLocalAllocBuffer::set_back_allocation_end() {
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   311
  _end = _allocation_end;
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   312
}
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   313
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   314
HeapWord* ThreadLocalAllocBuffer::hard_end() {
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   315
  return _allocation_end + alignment_reserve();
e2a7f431f65c 8203394: Implementation of JEP 331: Low-Overhead Heap Profiling
jcbeyler
parents: 50537
diff changeset
   316
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   318
PerfVariable* ThreadLocalAllocStats::_perf_allocating_threads;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   319
PerfVariable* ThreadLocalAllocStats::_perf_total_refills;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   320
PerfVariable* ThreadLocalAllocStats::_perf_max_refills;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   321
PerfVariable* ThreadLocalAllocStats::_perf_total_allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   322
PerfVariable* ThreadLocalAllocStats::_perf_total_gc_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   323
PerfVariable* ThreadLocalAllocStats::_perf_max_gc_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   324
PerfVariable* ThreadLocalAllocStats::_perf_total_slow_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   325
PerfVariable* ThreadLocalAllocStats::_perf_max_slow_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   326
PerfVariable* ThreadLocalAllocStats::_perf_total_fast_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   327
PerfVariable* ThreadLocalAllocStats::_perf_max_fast_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   328
PerfVariable* ThreadLocalAllocStats::_perf_total_slow_allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   329
PerfVariable* ThreadLocalAllocStats::_perf_max_slow_allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   330
AdaptiveWeightedAverage ThreadLocalAllocStats::_allocating_threads_avg(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   332
static PerfVariable* create_perf_variable(const char* name, PerfData::Units unit, TRAPS) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   333
  ResourceMark rm;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   334
  return PerfDataManager::create_variable(SUN_GC, PerfDataManager::counter_name("tlab", name), unit, THREAD);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   335
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   337
void ThreadLocalAllocStats::initialize() {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   338
  _allocating_threads_avg = AdaptiveWeightedAverage(TLABAllocationWeight);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  _allocating_threads_avg.sample(1); // One allocating thread at startup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    EXCEPTION_MARK;
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   343
    _perf_allocating_threads      = create_perf_variable("allocThreads", PerfData::U_None,  CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   344
    _perf_total_refills           = create_perf_variable("fills",        PerfData::U_None,  CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   345
    _perf_max_refills             = create_perf_variable("maxFills",     PerfData::U_None,  CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   346
    _perf_total_allocations       = create_perf_variable("alloc",        PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   347
    _perf_total_gc_waste          = create_perf_variable("gcWaste",      PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   348
    _perf_max_gc_waste            = create_perf_variable("maxGcWaste",   PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   349
    _perf_total_slow_refill_waste = create_perf_variable("slowWaste",    PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   350
    _perf_max_slow_refill_waste   = create_perf_variable("maxSlowWaste", PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   351
    _perf_total_fast_refill_waste = create_perf_variable("fastWaste",    PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   352
    _perf_max_fast_refill_waste   = create_perf_variable("maxFastWaste", PerfData::U_Bytes, CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   353
    _perf_total_slow_allocations  = create_perf_variable("slowAlloc",    PerfData::U_None,  CHECK);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   354
    _perf_max_slow_allocations    = create_perf_variable("maxSlowAlloc", PerfData::U_None,  CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   358
ThreadLocalAllocStats::ThreadLocalAllocStats() :
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   359
    _allocating_threads(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   360
    _total_refills(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   361
    _max_refills(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   362
    _total_allocations(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   363
    _total_gc_waste(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   364
    _max_gc_waste(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   365
    _total_fast_refill_waste(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   366
    _max_fast_refill_waste(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   367
    _total_slow_refill_waste(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   368
    _max_slow_refill_waste(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   369
    _total_slow_allocations(0),
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   370
    _max_slow_allocations(0) {}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   371
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   372
unsigned int ThreadLocalAllocStats::allocating_threads_avg() {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   373
  return MAX2((unsigned int)(_allocating_threads_avg.average() + 0.5), 1U);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   374
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   375
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   376
void ThreadLocalAllocStats::update_fast_allocations(unsigned int refills,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   377
                                       size_t allocations,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   378
                                       size_t gc_waste,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   379
                                       size_t fast_refill_waste,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   380
                                       size_t slow_refill_waste) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   381
  _allocating_threads      += 1;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   382
  _total_refills           += refills;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   383
  _max_refills              = MAX2(_max_refills, refills);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   384
  _total_allocations       += allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   385
  _total_gc_waste          += gc_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   386
  _max_gc_waste             = MAX2(_max_gc_waste, gc_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   387
  _total_fast_refill_waste += fast_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   388
  _max_fast_refill_waste    = MAX2(_max_fast_refill_waste, fast_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   389
  _total_slow_refill_waste += slow_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   390
  _max_slow_refill_waste    = MAX2(_max_slow_refill_waste, slow_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   391
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   392
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   393
void ThreadLocalAllocStats::update_slow_allocations(unsigned int allocations) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   394
  _total_slow_allocations += allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   395
  _max_slow_allocations    = MAX2(_max_slow_allocations, allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   396
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   397
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   398
void ThreadLocalAllocStats::update(const ThreadLocalAllocStats& other) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   399
  _allocating_threads      += other._allocating_threads;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   400
  _total_refills           += other._total_refills;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   401
  _max_refills              = MAX2(_max_refills, other._max_refills);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   402
  _total_allocations       += other._total_allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   403
  _total_gc_waste          += other._total_gc_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   404
  _max_gc_waste             = MAX2(_max_gc_waste, other._max_gc_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   405
  _total_fast_refill_waste += other._total_fast_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   406
  _max_fast_refill_waste    = MAX2(_max_fast_refill_waste, other._max_fast_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   407
  _total_slow_refill_waste += other._total_slow_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   408
  _max_slow_refill_waste    = MAX2(_max_slow_refill_waste, other._max_slow_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   409
  _total_slow_allocations  += other._total_slow_allocations;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   410
  _max_slow_allocations     = MAX2(_max_slow_allocations, other._max_slow_allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   411
}
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   412
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   413
void ThreadLocalAllocStats::reset() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  _allocating_threads      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  _total_refills           = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  _max_refills             = 0;
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   417
  _total_allocations       = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  _total_gc_waste          = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  _max_gc_waste            = 0;
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   420
  _total_fast_refill_waste = 0;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   421
  _max_fast_refill_waste   = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  _total_slow_refill_waste = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  _max_slow_refill_waste   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  _total_slow_allocations  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  _max_slow_allocations    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   428
void ThreadLocalAllocStats::publish() {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   429
  if (_total_allocations == 0) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   430
    return;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   431
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   432
51817
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   433
  _allocating_threads_avg.sample(_allocating_threads);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   434
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   435
  const size_t waste = _total_gc_waste + _total_slow_refill_waste + _total_fast_refill_waste;
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   436
  const double waste_percent = percent_of(waste, _total_allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   437
  log_debug(gc, tlab)("TLAB totals: thrds: %d  refills: %d max: %d"
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   438
                      " slow allocs: %d max %d waste: %4.1f%%"
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   439
                      " gc: " SIZE_FORMAT "B max: " SIZE_FORMAT "B"
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   440
                      " slow: " SIZE_FORMAT "B max: " SIZE_FORMAT "B"
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   441
                      " fast: " SIZE_FORMAT "B max: " SIZE_FORMAT "B",
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   442
                      _allocating_threads, _total_refills, _max_refills,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   443
                      _total_slow_allocations, _max_slow_allocations, waste_percent,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   444
                      _total_gc_waste * HeapWordSize, _max_gc_waste * HeapWordSize,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   445
                      _total_slow_refill_waste * HeapWordSize, _max_slow_refill_waste * HeapWordSize,
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   446
                      _total_fast_refill_waste * HeapWordSize, _max_fast_refill_waste * HeapWordSize);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   447
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   448
  if (UsePerfData) {
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   449
    _perf_allocating_threads      ->set_value(_allocating_threads);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   450
    _perf_total_refills           ->set_value(_total_refills);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   451
    _perf_max_refills             ->set_value(_max_refills);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   452
    _perf_total_allocations       ->set_value(_total_allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   453
    _perf_total_gc_waste          ->set_value(_total_gc_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   454
    _perf_max_gc_waste            ->set_value(_max_gc_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   455
    _perf_total_slow_refill_waste ->set_value(_total_slow_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   456
    _perf_max_slow_refill_waste   ->set_value(_max_slow_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   457
    _perf_total_fast_refill_waste ->set_value(_total_fast_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   458
    _perf_max_fast_refill_waste   ->set_value(_max_fast_refill_waste);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   459
    _perf_total_slow_allocations  ->set_value(_total_slow_allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   460
    _perf_max_slow_allocations    ->set_value(_max_slow_allocations);
46eac084082d 8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents: 51794
diff changeset
   461
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
}
52124
c64384f414bc 8211955: GC abstraction for LAB reserve
rkennke
parents: 51817
diff changeset
   463
c64384f414bc 8211955: GC abstraction for LAB reserve
rkennke
parents: 51817
diff changeset
   464
size_t ThreadLocalAllocBuffer::end_reserve() {
c64384f414bc 8211955: GC abstraction for LAB reserve
rkennke
parents: 51817
diff changeset
   465
  size_t reserve_size = Universe::heap()->tlab_alloc_reserve();
c64384f414bc 8211955: GC abstraction for LAB reserve
rkennke
parents: 51817
diff changeset
   466
  return MAX2(reserve_size, (size_t)_reserve_for_allocation_prefetch);
c64384f414bc 8211955: GC abstraction for LAB reserve
rkennke
parents: 51817
diff changeset
   467
}