src/hotspot/share/gc/shared/threadLocalAllocBuffer.inline.hpp
author eosterlund
Tue, 16 Oct 2018 13:18:22 +0200
changeset 52142 ca0c25e01c5b
parent 51742 3dd95a83791b
child 53244 9807daeb47c4
permissions -rw-r--r--
8210498: nmethod entry barriers Reviewed-by: kvn, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
50866
cb4b07d61aac 8205679: Remove unused ThreadLocalAllocBuffer::undo_allocate()
pliden
parents: 50101
diff changeset
     2
 * Copyright (c) 1999, 2018, 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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    26
#define SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    29
#include "gc/shared/threadLocalAllocBuffer.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    30
#include "logging/log.hpp"
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
    31
#include "runtime/thread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    32
#include "utilities/copy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  if (pointer_delta(end(), obj) >= size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    // successful thread-local allocation
4636
90e004691873 6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents: 1
diff changeset
    39
#ifdef ASSERT
90e004691873 6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents: 1
diff changeset
    40
    // Skip mangling the space corresponding to the object header to
90e004691873 6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents: 1
diff changeset
    41
    // ensure that the returned space is not considered parsable by
90e004691873 6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents: 1
diff changeset
    42
    // any concurrent GC thread.
5694
1e0532a6abff 6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents: 4636
diff changeset
    43
    size_t hdr_size = oopDesc::header_size();
4636
90e004691873 6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents: 1
diff changeset
    44
    Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal);
90e004691873 6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents: 1
diff changeset
    45
#endif // ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    // This addition is safe because we know that top is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    // at least size below end, so the add can't wrap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    set_top(obj + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Compute the size for the new TLAB.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // The "last" tlab may be smaller to reduce fragmentation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // unsafe_max_tlab_alloc is just a hint.
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 50866
diff changeset
    60
  const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(thread()) / HeapWordSize;
49945
9425445633cf 8191471: Elastic TLABs for G1
sjohanss
parents: 47216
diff changeset
    61
  size_t new_tlab_size = MIN3(available_size, desired_size() + align_object_size(obj_size), max_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Make sure there's enough room for object and filler int[].
49945
9425445633cf 8191471: Elastic TLABs for G1
sjohanss
parents: 47216
diff changeset
    64
  if (new_tlab_size < compute_min_size(obj_size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    // If there isn't enough room for the allocation, return failure.
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    66
    log_trace(gc, tlab)("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ") returns failure",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    67
                        obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    70
  log_trace(gc, tlab)("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ") returns " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    71
                      obj_size, new_tlab_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  return new_tlab_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
49945
9425445633cf 8191471: Elastic TLABs for G1
sjohanss
parents: 47216
diff changeset
    75
inline size_t ThreadLocalAllocBuffer::compute_min_size(size_t obj_size) {
9425445633cf 8191471: Elastic TLABs for G1
sjohanss
parents: 47216
diff changeset
    76
  const size_t aligned_obj_size = align_object_size(obj_size);
9425445633cf 8191471: Elastic TLABs for G1
sjohanss
parents: 47216
diff changeset
    77
  const size_t size_with_reserve = aligned_obj_size + alignment_reserve();
50070
c036b84c6bbf 8202662: JFR tests fails: Could not find leak with class
sjohanss
parents: 49945
diff changeset
    78
  return MAX2(size_with_reserve, heap_word_size(MinTLABSize));
49945
9425445633cf 8191471: Elastic TLABs for G1
sjohanss
parents: 47216
diff changeset
    79
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Raise size required to bypass TLAB next time. Why? Else there's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // a risk that a thread that repeatedly allocates objects of one
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // size will get stuck on this slow path.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  _slow_allocations++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    90
  log_develop_trace(gc, tlab)("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    91
                              " obj: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    92
                              " free: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    93
                              " waste: " SIZE_FORMAT,
51742
3dd95a83791b 8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents: 50866
diff changeset
    94
                              "slow", p2i(thread()), thread()->osthread()->thread_id(),
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31592
diff changeset
    95
                              obj_size, free(), refill_waste_limit());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    97
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25351
diff changeset
    98
#endif // SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP