hotspot/src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp
author johnc
Mon, 28 Mar 2011 10:58:54 -0700
changeset 8926 717a49db1743
parent 8683 9d31cebc0f6e
child 8929 33175c0c6b9b
permissions -rw-r--r--
7026932: G1: No need to abort VM when card count cache expansion fails Summary: Manage allocation/freeing of the card cache counts and epochs arrays directly so that an allocation failure while attempting to expand these arrays does not abort the JVM. Failure to expand these arrays is not fatal. Reviewed-by: iveresov, tonyp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
8103
65eafe3fb3c7 6923430: G1: assert(res != 0,"This should have worked.")
johnc
parents: 7397
diff changeset
     2
 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5033
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5033
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: 5033
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    26
#include "gc_implementation/g1/concurrentG1Refine.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    27
#include "gc_implementation/g1/concurrentG1RefineThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    28
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    29
#include "gc_implementation/g1/g1CollectorPolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    30
#include "gc_implementation/g1/g1RemSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    31
#include "gc_implementation/g1/heapRegionSeq.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    32
#include "memory/space.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    33
#include "runtime/atomic.hpp"
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    34
#include "runtime/java.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6247
diff changeset
    35
#include "utilities/copy.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    37
// Possible sizes for the card counts cache: odd primes that roughly double in size.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    38
// (See jvmtiTagMap.cpp).
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    39
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    40
#define MAX_SIZE ((size_t) -1)
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    41
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    42
size_t ConcurrentG1Refine::_cc_cache_sizes[] = {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    43
          16381,    32771,    76831,    150001,   307261,
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    44
         614563,  1228891,  2457733,   4915219,  9830479,
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    45
       19660831, 39321619, 78643219, 157286461,  MAX_SIZE
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    46
  };
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    47
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
ConcurrentG1Refine::ConcurrentG1Refine() :
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    49
  _card_counts(NULL), _card_epochs(NULL),
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    50
  _n_card_counts(0), _max_cards(0), _max_n_card_counts(0),
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    51
  _cache_size_index(0), _expand_card_counts(false),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
  _hot_cache(NULL),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
  _def_use_cache(false), _use_cache(false),
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    54
  _n_periods(0),
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
    55
  _threads(NULL), _n_threads(0)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    56
{
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    57
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    58
  // Ergomonically select initial concurrent refinement parameters
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    59
  if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    60
    FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, MAX2<int>(ParallelGCThreads, 1));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    61
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    62
  set_green_zone(G1ConcRefinementGreenZone);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    63
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    64
  if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    65
    FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    66
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    67
  set_yellow_zone(MAX2<int>(G1ConcRefinementYellowZone, green_zone()));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    68
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    69
  if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    70
    FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    71
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    72
  set_red_zone(MAX2<int>(G1ConcRefinementRedZone, yellow_zone()));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    73
  _n_worker_threads = thread_num();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    74
  // We need one extra thread to do the young gen rset size sampling.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    75
  _n_threads = _n_worker_threads + 1;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    76
  reset_threshold_step();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    77
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    78
  _threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    79
  int worker_id_offset = (int)DirtyCardQueueSet::num_par_ids();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    80
  ConcurrentG1RefineThread *next = NULL;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    81
  for (int i = _n_threads - 1; i >= 0; i--) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    82
    ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, worker_id_offset, i);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    83
    assert(t != NULL, "Conc refine should have been created");
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    84
    assert(t->cg1r() == this, "Conc refine thread should refer to this");
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    85
    _threads[i] = t;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    86
    next = t;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    90
void ConcurrentG1Refine::reset_threshold_step() {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    91
  if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    92
    _thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    93
  } else {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    94
    _thread_threshold_step = G1ConcRefinementThresholdStep;
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    95
  }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    96
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    97
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    98
int ConcurrentG1Refine::thread_num() {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    99
  return MAX2<int>((G1ConcRefinementThreads > 0) ? G1ConcRefinementThreads : ParallelGCThreads, 1);
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
   100
}
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
   101
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
void ConcurrentG1Refine::init() {
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   103
  if (G1ConcRSLogCacheSize > 0) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   104
    _g1h = G1CollectedHeap::heap();
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   105
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   106
    _max_cards = _g1h->max_capacity() >> CardTableModRefBS::card_shift;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   107
    _max_n_card_counts = _max_cards * G1MaxHotCardCountSizePercent / 100;
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   108
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   109
    size_t max_card_num = ((size_t)1 << (sizeof(unsigned)*BitsPerByte-1)) - 1;
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   110
    guarantee(_max_cards < max_card_num, "card_num representation");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   111
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   112
    // We need _n_card_counts to be less than _max_n_card_counts here
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   113
    // so that the expansion call (below) actually allocates the
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   114
    // _counts and _epochs arrays.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   115
    assert(_n_card_counts == 0, "pre-condition");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   116
    assert(_max_n_card_counts > 0, "pre-condition");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   117
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   118
    // Find the index into cache size array that is of a size that's
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   119
    // large enough to hold desired_sz.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   120
    size_t desired_sz = _max_cards / InitialCacheFraction;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   121
    int desired_sz_index = 0;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   122
    while (_cc_cache_sizes[desired_sz_index] < desired_sz) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   123
      desired_sz_index += 1;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   124
      assert(desired_sz_index <  MAX_CC_CACHE_INDEX, "invariant");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   125
    }
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   126
    assert(desired_sz_index <  MAX_CC_CACHE_INDEX, "invariant");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   127
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   128
    // If the desired_sz value is between two sizes then
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   129
    // _cc_cache_sizes[desired_sz_index-1] < desired_sz <= _cc_cache_sizes[desired_sz_index]
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   130
    // we will start with the lower size in the optimistic expectation that
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   131
    // we will not need to expand up. Note desired_sz_index could also be 0.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   132
    if (desired_sz_index > 0 &&
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   133
        _cc_cache_sizes[desired_sz_index] > desired_sz) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   134
      desired_sz_index -= 1;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   135
    }
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   136
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   137
    if (!expand_card_count_cache(desired_sz_index)) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   138
      // Allocation was unsuccessful - exit
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   139
      vm_exit_during_initialization("Could not reserve enough space for card count cache");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   140
    }
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   141
    assert(_n_card_counts > 0, "post-condition");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   142
    assert(_cache_size_index == desired_sz_index, "post-condition");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   143
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   144
    Copy::fill_to_bytes(&_card_counts[0],
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   145
                        _n_card_counts * sizeof(CardCountCacheEntry));
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   146
    Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry));
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   147
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   148
    ModRefBarrierSet* bs = _g1h->mr_bs();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   149
    guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   150
    _ct_bs = (CardTableModRefBS*)bs;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   151
    _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start());
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   152
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
    _def_use_cache = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   154
    _use_cache = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   155
    _hot_cache_size = (1 << G1ConcRSLogCacheSize);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
    _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   157
    _n_hot = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
    _hot_cache_idx = 0;
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   159
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   160
    // For refining the cards in the hot cache in parallel
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   161
    int n_workers = (ParallelGCThreads > 0 ?
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   162
                        _g1h->workers()->total_workers() : 1);
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   163
    _hot_cache_par_chunk_size = MAX2(1, _hot_cache_size / n_workers);
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   164
    _hot_cache_par_claimed_idx = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   168
void ConcurrentG1Refine::stop() {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   169
  if (_threads != NULL) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   170
    for (int i = 0; i < _n_threads; i++) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   171
      _threads[i]->stop();
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   172
    }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   173
  }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   174
}
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   175
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   176
void ConcurrentG1Refine::reinitialize_threads() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   177
  reset_threshold_step();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   178
  if (_threads != NULL) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   179
    for (int i = 0; i < _n_threads; i++) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   180
      _threads[i]->initialize();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   181
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   182
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   183
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   184
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   185
ConcurrentG1Refine::~ConcurrentG1Refine() {
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   186
  if (G1ConcRSLogCacheSize > 0) {
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   187
    // Please see the comment in allocate_card_count_cache
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   188
    // for why we call os::malloc() and os::free() directly.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
    assert(_card_counts != NULL, "Logic");
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   190
    os::free(_card_counts);
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   191
    assert(_card_epochs != NULL, "Logic");
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   192
    os::free(_card_epochs);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   193
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   194
    assert(_hot_cache != NULL, "Logic");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   195
    FREE_C_HEAP_ARRAY(jbyte*, _hot_cache);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   196
  }
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   197
  if (_threads != NULL) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   198
    for (int i = 0; i < _n_threads; i++) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   199
      delete _threads[i];
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   200
    }
2886
70bf7d429eba 6849122: G1: Typo introduced during implementation of the parallel refinement
iveresov
parents: 2882
diff changeset
   201
    FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   202
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   205
void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   206
  if (_threads != NULL) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   207
    for (int i = 0; i < _n_threads; i++) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   208
      tc->do_thread(_threads[i]);
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   209
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   213
bool ConcurrentG1Refine::is_young_card(jbyte* card_ptr) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   214
  HeapWord* start = _ct_bs->addr_for(card_ptr);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   215
  HeapRegion* r = _g1h->heap_region_containing(start);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   216
  if (r != NULL && r->is_young()) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   217
    return true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   218
  }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   219
  // This card is not associated with a heap region
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   220
  // so can't be young.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   221
  return false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   223
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   224
jbyte* ConcurrentG1Refine::add_card_count(jbyte* card_ptr, int* count, bool* defer) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   225
  unsigned new_card_num = ptr_2_card_num(card_ptr);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   226
  unsigned bucket = hash(new_card_num);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   227
  assert(0 <= bucket && bucket < _n_card_counts, "Bounds");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   228
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   229
  CardCountCacheEntry* count_ptr = &_card_counts[bucket];
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   230
  CardEpochCacheEntry* epoch_ptr = &_card_epochs[bucket];
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   231
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   232
  // We have to construct a new entry if we haven't updated the counts
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   233
  // during the current period, or if the count was updated for a
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   234
  // different card number.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   235
  unsigned int new_epoch = (unsigned int) _n_periods;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   236
  julong new_epoch_entry = make_epoch_entry(new_card_num, new_epoch);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   237
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   238
  while (true) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   239
    // Fetch the previous epoch value
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   240
    julong prev_epoch_entry = epoch_ptr->_value;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   241
    julong cas_res;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   242
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   243
    if (extract_epoch(prev_epoch_entry) != new_epoch) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   244
      // This entry has not yet been updated during this period.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   245
      // Note: we update the epoch value atomically to ensure
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   246
      // that there is only one winner that updates the cached
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   247
      // card_ptr value even though all the refine threads share
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   248
      // the same epoch value.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   249
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   250
      cas_res = (julong) Atomic::cmpxchg((jlong) new_epoch_entry,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   251
                                         (volatile jlong*)&epoch_ptr->_value,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   252
                                         (jlong) prev_epoch_entry);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   253
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   254
      if (cas_res == prev_epoch_entry) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   255
        // We have successfully won the race to update the
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   256
        // epoch and card_num value. Make it look like the
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   257
        // count and eviction count were previously cleared.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   258
        count_ptr->_count = 1;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   259
        count_ptr->_evict_count = 0;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   260
        *count = 0;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   261
        // We can defer the processing of card_ptr
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   262
        *defer = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   263
        return card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   264
      }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   265
      // We did not win the race to update the epoch field, so some other
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   266
      // thread must have done it. The value that gets returned by CAS
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   267
      // should be the new epoch value.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   268
      assert(extract_epoch(cas_res) == new_epoch, "unexpected epoch");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   269
      // We could 'continue' here or just re-read the previous epoch value
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   270
      prev_epoch_entry = epoch_ptr->_value;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   271
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   272
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   273
    // The epoch entry for card_ptr has been updated during this period.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   274
    unsigned old_card_num = extract_card_num(prev_epoch_entry);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   275
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   276
    // The card count that will be returned to caller
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   277
    *count = count_ptr->_count;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   278
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   279
    // Are we updating the count for the same card?
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   280
    if (new_card_num == old_card_num) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   281
      // Same card - just update the count. We could have more than one
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   282
      // thread racing to update count for the current card. It should be
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   283
      // OK not to use a CAS as the only penalty should be some missed
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   284
      // increments of the count which delays identifying the card as "hot".
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   285
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   286
      if (*count < max_jubyte) count_ptr->_count++;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   287
      // We can defer the processing of card_ptr
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   288
      *defer = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   289
      return card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   290
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   291
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   292
    // Different card - evict old card info
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   293
    if (count_ptr->_evict_count < max_jubyte) count_ptr->_evict_count++;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   294
    if (count_ptr->_evict_count > G1CardCountCacheExpandThreshold) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   295
      // Trigger a resize the next time we clear
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   296
      _expand_card_counts = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   297
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   298
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   299
    cas_res = (julong) Atomic::cmpxchg((jlong) new_epoch_entry,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   300
                                       (volatile jlong*)&epoch_ptr->_value,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   301
                                       (jlong) prev_epoch_entry);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   302
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   303
    if (cas_res == prev_epoch_entry) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   304
      // We successfully updated the card num value in the epoch entry
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   305
      count_ptr->_count = 0; // initialize counter for new card num
6068
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   306
      jbyte* old_card_ptr = card_num_2_ptr(old_card_num);
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   307
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   308
      // Even though the region containg the card at old_card_num was not
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   309
      // in the young list when old_card_num was recorded in the epoch
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   310
      // cache it could have been added to the free list and subsequently
6068
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   311
      // added to the young list in the intervening time. See CR 6817995.
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   312
      // We do not deal with this case here - it will be handled in
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   313
      // HeapRegion::oops_on_card_seq_iterate_careful after it has been
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   314
      // determined that the region containing the card has been allocated
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   315
      // to, and it's safe to check the young type of the region.
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   316
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   317
      // We do not want to defer processing of card_ptr in this case
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   318
      // (we need to refine old_card_ptr and card_ptr)
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   319
      *defer = false;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   320
      return old_card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   321
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   322
    // Someone else beat us - try again.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   323
  }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   324
}
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   325
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   326
jbyte* ConcurrentG1Refine::cache_insert(jbyte* card_ptr, bool* defer) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   327
  int count;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   328
  jbyte* cached_ptr = add_card_count(card_ptr, &count, defer);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   329
  assert(cached_ptr != NULL, "bad cached card ptr");
4887
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   330
6068
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   331
  // We've just inserted a card pointer into the card count cache
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   332
  // and got back the card that we just inserted or (evicted) the
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   333
  // previous contents of that count slot.
4887
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   334
6068
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   335
  // The card we got back could be in a young region. When the
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   336
  // returned card (if evicted) was originally inserted, we had
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   337
  // determined that its containing region was not young. However
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   338
  // it is possible for the region to be freed during a cleanup
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   339
  // pause, then reallocated and tagged as young which will result
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   340
  // in the returned card residing in a young region.
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   341
  //
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   342
  // We do not deal with this case here - the change from non-young
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   343
  // to young could be observed at any time - it will be handled in
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   344
  // HeapRegion::oops_on_card_seq_iterate_careful after it has been
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   345
  // determined that the region containing the card has been allocated
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   346
  // to.
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   347
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   348
  // The card pointer we obtained from card count cache is not hot
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   349
  // so do not store it in the cache; return it for immediate
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   350
  // refining.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   351
  if (count < G1ConcRSHotCardLimit) {
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   352
    return cached_ptr;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
  }
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   354
6068
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   355
  // Otherwise, the pointer we got from the _card_counts cache is hot.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
  jbyte* res = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
  MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   358
  if (_n_hot == _hot_cache_size) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
    res = _hot_cache[_hot_cache_idx];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
    _n_hot--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
  // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx.
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   363
  _hot_cache[_hot_cache_idx] = cached_ptr;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   364
  _hot_cache_idx++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   365
  if (_hot_cache_idx == _hot_cache_size) _hot_cache_idx = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   366
  _n_hot++;
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   367
6068
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   368
  // The card obtained from the hot card cache could be in a young
80ef41e75a2d 6956639: G1: assert(cached_ptr != card_ptr) failed: shouldn't be, concurrentG1Refine.cpp:307
johnc
parents: 5547
diff changeset
   369
  // region. See above on how this can happen.
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   370
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   371
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   372
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   374
void ConcurrentG1Refine::clean_up_cache(int worker_i,
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   375
                                        G1RemSet* g1rs,
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   376
                                        DirtyCardQueue* into_cset_dcq) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   377
  assert(!use_cache(), "cache should be disabled");
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   378
  int start_idx;
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   379
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   380
  while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   381
    int end_idx = start_idx + _hot_cache_par_chunk_size;
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   382
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   383
    if (start_idx ==
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   384
        Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) {
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   385
      // The current worker has successfully claimed the chunk [start_idx..end_idx)
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   386
      end_idx = MIN2(end_idx, _n_hot);
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   387
      for (int i = start_idx; i < end_idx; i++) {
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   388
        jbyte* entry = _hot_cache[i];
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   389
        if (entry != NULL) {
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   390
          if (g1rs->concurrentRefineOneCard(entry, worker_i, true)) {
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   391
            // 'entry' contains references that point into the current
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   392
            // collection set. We need to record 'entry' in the DCQS
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   393
            // that's used for that purpose.
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   394
            //
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   395
            // The only time we care about recording cards that contain
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   396
            // references that point into the collection set is during
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   397
            // RSet updating while within an evacuation pause.
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   398
            // In this case worker_i should be the id of a GC worker thread
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   399
            assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
8683
9d31cebc0f6e 7023747: G1: too strict assert in RefineRecordRefsIntoCSCardTableEntryClosure::do_card_ptr in g1RemSet.cpp
brutisso
parents: 8103
diff changeset
   400
            assert(worker_i < (int) (ParallelGCThreads == 0 ? 1 : ParallelGCThreads), "incorrect worker id");
6247
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   401
            into_cset_dcq->enqueue(entry);
00e5cc407d03 6814437: G1: remove the _new_refs array
johnc
parents: 6068
diff changeset
   402
          }
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   403
        }
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   404
      }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   405
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   406
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   407
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   408
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   409
// The arrays used to hold the card counts and the epochs must have
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   410
// a 1:1 correspondence. Hence they are allocated and freed together
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   411
// Returns true if the allocations of both the counts and epochs
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   412
// were successful; false otherwise.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   413
bool ConcurrentG1Refine::allocate_card_count_cache(size_t n,
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   414
                                                   CardCountCacheEntry** counts,
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   415
                                                   CardEpochCacheEntry** epochs) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   416
  // We call the allocation/free routines directly for the counts
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   417
  // and epochs arrays. The NEW_C_HEAP_ARRAY/FREE_C_HEAP_ARRAY
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   418
  // macros call AllocateHeap and FreeHeap respectively.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   419
  // AllocateHeap will call vm_exit_out_of_memory in the event
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   420
  // of an allocation failure and abort the JVM. With the
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   421
  // _counts/epochs arrays we only need to abort the JVM if the
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   422
  // initial allocation of these arrays fails.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   423
  //
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   424
  // Additionally AllocateHeap/FreeHeap do some tracing of
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   425
  // allocate/free calls so calling one without calling the
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   426
  // other can cause inconsistencies in the tracing. So we
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   427
  // call neither.
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   428
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   429
  assert(*counts == NULL, "out param");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   430
  assert(*epochs == NULL, "out param");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   431
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   432
  size_t counts_size = n * sizeof(CardCountCacheEntry);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   433
  size_t epochs_size = n * sizeof(CardEpochCacheEntry);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   434
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   435
  *counts = (CardCountCacheEntry*) os::malloc(counts_size);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   436
  if (*counts == NULL) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   437
    // allocation was unsuccessful
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   438
    return false;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   439
  }
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   440
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   441
  *epochs = (CardEpochCacheEntry*) os::malloc(epochs_size);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   442
  if (*epochs == NULL) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   443
    // allocation was unsuccessful - free counts array
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   444
    assert(*counts != NULL, "must be");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   445
    os::free(*counts);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   446
    *counts = NULL;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   447
    return false;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   448
  }
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   449
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   450
  // We successfully allocated both counts and epochs
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   451
  return true;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   452
}
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   453
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   454
// Returns true if the card counts/epochs cache was
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   455
// successfully expanded; false otherwise.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   456
bool ConcurrentG1Refine::expand_card_count_cache(int cache_size_idx) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   457
  // Can we expand the card count and epoch tables?
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   458
  if (_n_card_counts < _max_n_card_counts) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   459
    assert(cache_size_idx >= 0 && cache_size_idx  < MAX_CC_CACHE_INDEX, "oob");
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   460
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   461
    size_t cache_size = _cc_cache_sizes[cache_size_idx];
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   462
    // Make sure we don't go bigger than we will ever need
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   463
    cache_size = MIN2(cache_size, _max_n_card_counts);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   464
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   465
    // Should we expand the card count and card epoch tables?
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   466
    if (cache_size > _n_card_counts) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   467
      // We have been asked to allocate new, larger, arrays for
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   468
      // the card counts and the epochs. Attempt the allocation
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   469
      // of both before we free the existing arrays in case
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   470
      // the allocation is unsuccessful...
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   471
      CardCountCacheEntry* counts = NULL;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   472
      CardEpochCacheEntry* epochs = NULL;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   473
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   474
      if (allocate_card_count_cache(cache_size, &counts, &epochs)) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   475
        // Allocation was successful.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   476
        // We can just free the old arrays; we're
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   477
        // not interested in preserving the contents
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   478
        if (_card_counts != NULL) os::free(_card_counts);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   479
        if (_card_epochs != NULL) os::free(_card_epochs);
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   480
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   481
        // Cache the size of the arrays and the index that got us there.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   482
        _n_card_counts = cache_size;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   483
        _cache_size_index = cache_size_idx;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   484
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   485
        _card_counts = counts;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   486
        _card_epochs = epochs;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   487
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   488
        // We successfully allocated/expanded the caches.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   489
        return true;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   490
      }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   491
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   492
  }
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   493
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   494
  // We did not successfully expand the caches.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   495
  return false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   496
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   497
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   498
void ConcurrentG1Refine::clear_and_record_card_counts() {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   499
  if (G1ConcRSLogCacheSize == 0) return;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   500
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   501
#ifndef PRODUCT
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   502
  double start = os::elapsedTime();
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   503
#endif
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   504
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   505
  if (_expand_card_counts) {
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   506
    int new_idx = _cache_size_index + 1;
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   507
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   508
    if (expand_card_count_cache(new_idx)) {
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   509
      // Allocation was successful and  _n_card_counts has
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   510
      // been updated to the new size. We only need to clear
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   511
      // the epochs so we don't read a bogus epoch value
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   512
      // when inserting a card into the hot card cache.
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   513
      Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry));
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
   514
    }
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   515
    _expand_card_counts = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   516
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   517
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   518
  int this_epoch = (int) _n_periods;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   519
  assert((this_epoch+1) <= max_jint, "to many periods");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   520
  // Update epoch
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   521
  _n_periods++;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   522
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   523
#ifndef PRODUCT
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   524
  double elapsed = os::elapsedTime() - start;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   525
  _g1h->g1_policy()->record_cc_clear_time(elapsed * 1000.0);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   526
#endif
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   527
}
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   528
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   529
void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   530
  for (int i = 0; i < _n_threads; ++i) {
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   531
    _threads[i]->print_on(st);
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   532
    st->cr();
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   533
  }
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   534
}