hotspot/src/share/vm/gc/g1/g1AllocRegion.inline.hpp
author ehelin
Mon, 19 Oct 2015 15:47:36 +0200
changeset 34131 d5fc001452bb
parent 33105 294e48b4f704
permissions -rw-r--r--
8139883: Add virtual destructor G1ParScanThreadState Reviewed-by: tschatzl, mgerdin, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     4
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     8
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    13
 * accompanied this code).
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    14
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    18
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    21
 * questions.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    22
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    23
 */
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1ALLOCREGION_INLINE_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
    26
#define SHARE_VM_GC_G1_G1ALLOCREGION_INLINE_HPP
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
    28
#include "gc/g1/g1AllocRegion.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
    29
#include "gc/g1/heapRegion.inline.hpp"
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    30
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    31
#define assert_alloc_region(p, message)                                  \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    32
  do {                                                                   \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    33
    assert((p), "[%s] %s c: %u b: %s r: " PTR_FORMAT " u: " SIZE_FORMAT, \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    34
           _name, (message), _count, BOOL_TO_STR(_bot_updates),          \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    35
           p2i(_alloc_region), _used_bytes_before);                      \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    36
  } while (0)
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    37
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    38
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    39
inline HeapWord* G1AllocRegion::allocate(HeapRegion* alloc_region,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    40
                                         size_t word_size,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    41
                                         bool bot_updates) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    42
  assert(alloc_region != NULL, "pre-condition");
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    43
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    44
  if (!bot_updates) {
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    45
    return alloc_region->allocate_no_bot_updates(word_size);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    46
  } else {
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    47
    return alloc_region->allocate(word_size);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    48
  }
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    49
}
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    50
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    51
inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region, size_t word_size, bool bot_updates) {
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    52
  size_t temp;
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    53
  return par_allocate(alloc_region, word_size, word_size, &temp, bot_updates);
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    54
}
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    55
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    56
inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region,
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    57
                                             size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    58
                                             size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    59
                                             size_t* actual_word_size,
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    60
                                             bool bot_updates) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    61
  assert(alloc_region != NULL, "pre-condition");
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    62
  assert(!alloc_region->is_empty(), "pre-condition");
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    63
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    64
  if (!bot_updates) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    65
    return alloc_region->par_allocate_no_bot_updates(min_word_size, desired_word_size, actual_word_size);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    66
  } else {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    67
    return alloc_region->par_allocate(min_word_size, desired_word_size, actual_word_size);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    68
  }
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    69
}
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    70
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    71
inline HeapWord* G1AllocRegion::attempt_allocation(size_t word_size, bool bot_updates) {
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    72
  size_t temp;
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    73
  return attempt_allocation(word_size, word_size, &temp, bot_updates);
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    74
}
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    75
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    76
inline HeapWord* G1AllocRegion::attempt_allocation(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    77
                                                   size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    78
                                                   size_t* actual_word_size,
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    79
                                                   bool bot_updates) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    80
  assert_alloc_region(bot_updates == _bot_updates, "pre-condition");
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    81
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    82
  HeapRegion* alloc_region = _alloc_region;
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
    83
  assert_alloc_region(alloc_region != NULL, "not initialized properly");
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    84
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    85
  HeapWord* result = par_allocate(alloc_region, min_word_size, desired_word_size, actual_word_size, bot_updates);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    86
  if (result != NULL) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    87
    trace("alloc", min_word_size, desired_word_size, *actual_word_size, result);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    88
    return result;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    89
  }
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    90
  trace("alloc failed", min_word_size, desired_word_size);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    91
  return NULL;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    92
}
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    93
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    94
inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t word_size, bool bot_updates) {
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    95
  size_t temp;
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    96
  return attempt_allocation_locked(word_size, word_size, &temp, bot_updates);
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    97
}
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    98
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
    99
inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   100
                                                          size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   101
                                                          size_t* actual_word_size,
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   102
                                                          bool bot_updates) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 8928
diff changeset
   103
  // First we have to redo the allocation, assuming we're holding the
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   104
  // appropriate lock, in case another thread changed the region while
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   105
  // we were waiting to get the lock.
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   106
  HeapWord* result = attempt_allocation(min_word_size, desired_word_size, actual_word_size, bot_updates);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   107
  if (result != NULL) {
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   108
    return result;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   109
  }
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   110
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   111
  retire(true /* fill_up */);
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   112
  result = new_alloc_region_and_allocate(desired_word_size, false /* force */);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   113
  if (result != NULL) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   114
    *actual_word_size = desired_word_size;
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   115
    trace("alloc locked (second attempt)", min_word_size, desired_word_size, *actual_word_size, result);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   116
    return result;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   117
  }
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   118
  trace("alloc locked failed", min_word_size, desired_word_size);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   119
  return NULL;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   120
}
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   121
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   122
inline HeapWord* G1AllocRegion::attempt_allocation_force(size_t word_size,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   123
                                                         bool bot_updates) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
   124
  assert_alloc_region(bot_updates == _bot_updates, "pre-condition");
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
   125
  assert_alloc_region(_alloc_region != NULL, "not initialized properly");
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   126
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   127
  trace("forcing alloc", word_size, word_size);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   128
  HeapWord* result = new_alloc_region_and_allocate(word_size, true /* force */);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   129
  if (result != NULL) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   130
    trace("alloc forced", word_size, word_size, word_size, result);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   131
    return result;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   132
  }
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 30764
diff changeset
   133
  trace("alloc forced failed", word_size, word_size);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   134
  return NULL;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   135
}
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   136
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
   137
#endif // SHARE_VM_GC_G1_G1ALLOCREGION_INLINE_HPP