hotspot/src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp
author tonyp
Tue, 23 Feb 2010 23:13:23 -0500
changeset 5033 55f476a32544
parent 4887 c6e9df29a2cf
child 5547 f4b087cbb361
permissions -rw-r--r--
6928059: G1: command line parameter renaming Summary: Rename G1 parameters to make them more consistent. Reviewed-by: jmasa, johnc
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
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 2886
diff changeset
     2
 * Copyright 2001-2009 Sun Microsystems, Inc.  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
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    21
 * have any questions.
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    26
#include "incls/_concurrentG1Refine.cpp.incl"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    27
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    28
// 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
    29
// (See jvmtiTagMap.cpp).
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    30
int ConcurrentG1Refine::_cc_cache_sizes[] = {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    31
        16381,    32771,    76831,    150001,   307261,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    32
       614563,  1228891,  2457733,   4915219,  9830479,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    33
     19660831, 39321619, 78643219, 157286461,       -1
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    34
  };
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    35
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
ConcurrentG1Refine::ConcurrentG1Refine() :
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    37
  _card_counts(NULL), _card_epochs(NULL),
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    38
  _n_card_counts(0), _max_n_card_counts(0),
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    39
  _cache_size_index(0), _expand_card_counts(false),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
  _hot_cache(NULL),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
  _def_use_cache(false), _use_cache(false),
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    42
  _n_periods(0),
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
    43
  _threads(NULL), _n_threads(0)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
{
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    45
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    46
  // Ergomonically select initial concurrent refinement parameters
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    47
  if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    48
    FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, MAX2<int>(ParallelGCThreads, 1));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    49
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    50
  set_green_zone(G1ConcRefinementGreenZone);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    51
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    52
  if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    53
    FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    54
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    55
  set_yellow_zone(MAX2<int>(G1ConcRefinementYellowZone, green_zone()));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    56
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    57
  if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    58
    FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    59
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    60
  set_red_zone(MAX2<int>(G1ConcRefinementRedZone, yellow_zone()));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    61
  _n_worker_threads = thread_num();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    62
  // We need one extra thread to do the young gen rset size sampling.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    63
  _n_threads = _n_worker_threads + 1;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    64
  reset_threshold_step();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    65
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    66
  _threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    67
  int worker_id_offset = (int)DirtyCardQueueSet::num_par_ids();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    68
  ConcurrentG1RefineThread *next = NULL;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    69
  for (int i = _n_threads - 1; i >= 0; i--) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    70
    ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, worker_id_offset, i);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    71
    assert(t != NULL, "Conc refine should have been created");
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    72
    assert(t->cg1r() == this, "Conc refine thread should refer to this");
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    73
    _threads[i] = t;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    74
    next = t;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    78
void ConcurrentG1Refine::reset_threshold_step() {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    79
  if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    80
    _thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    81
  } else {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    82
    _thread_threshold_step = G1ConcRefinementThresholdStep;
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    83
  }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    84
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    85
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    86
int ConcurrentG1Refine::thread_num() {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4887
diff changeset
    87
  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
    88
}
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    89
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
void ConcurrentG1Refine::init() {
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    91
  if (G1ConcRSLogCacheSize > 0) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    92
    _g1h = G1CollectedHeap::heap();
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    93
    _max_n_card_counts =
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    94
      (unsigned) (_g1h->g1_reserved_obj_bytes() >> CardTableModRefBS::card_shift);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    95
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    96
    size_t max_card_num = ((size_t)1 << (sizeof(unsigned)*BitsPerByte-1)) - 1;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    97
    guarantee(_max_n_card_counts < max_card_num, "card_num representation");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    98
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
    99
    int desired = _max_n_card_counts / InitialCacheFraction;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   100
    for (_cache_size_index = 0;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   101
              _cc_cache_sizes[_cache_size_index] >= 0; _cache_size_index++) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   102
      if (_cc_cache_sizes[_cache_size_index] >= desired) break;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   103
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   104
    _cache_size_index = MAX2(0, (_cache_size_index - 1));
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   105
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   106
    int initial_size = _cc_cache_sizes[_cache_size_index];
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   107
    if (initial_size < 0) initial_size = _max_n_card_counts;
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
    // Make sure we don't go bigger than we will ever need
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   110
    _n_card_counts = MIN2((unsigned) initial_size, _max_n_card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   111
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   112
    _card_counts = NEW_C_HEAP_ARRAY(CardCountCacheEntry, _n_card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   113
    _card_epochs = NEW_C_HEAP_ARRAY(CardEpochCacheEntry, _n_card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   114
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   115
    Copy::fill_to_bytes(&_card_counts[0],
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   116
                        _n_card_counts * sizeof(CardCountCacheEntry));
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   117
    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
   118
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   119
    ModRefBarrierSet* bs = _g1h->mr_bs();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
    guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   121
    _ct_bs = (CardTableModRefBS*)bs;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   122
    _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
   123
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
    _def_use_cache = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
    _use_cache = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
    _hot_cache_size = (1 << G1ConcRSLogCacheSize);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
    _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
    _n_hot = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
    _hot_cache_idx = 0;
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   130
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   131
    // For refining the cards in the hot cache in parallel
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   132
    int n_workers = (ParallelGCThreads > 0 ?
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   133
                        _g1h->workers()->total_workers() : 1);
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   134
    _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
   135
    _hot_cache_par_claimed_idx = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   136
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   139
void ConcurrentG1Refine::stop() {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   140
  if (_threads != NULL) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   141
    for (int i = 0; i < _n_threads; i++) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   142
      _threads[i]->stop();
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   143
    }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   144
  }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   145
}
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   146
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   147
void ConcurrentG1Refine::reinitialize_threads() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   148
  reset_threshold_step();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   149
  if (_threads != NULL) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   150
    for (int i = 0; i < _n_threads; i++) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   151
      _threads[i]->initialize();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   152
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   153
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   154
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   155
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
ConcurrentG1Refine::~ConcurrentG1Refine() {
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   157
  if (G1ConcRSLogCacheSize > 0) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
    assert(_card_counts != NULL, "Logic");
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   159
    FREE_C_HEAP_ARRAY(CardCountCacheEntry, _card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   160
    assert(_card_epochs != NULL, "Logic");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   161
    FREE_C_HEAP_ARRAY(CardEpochCacheEntry, _card_epochs);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
    assert(_hot_cache != NULL, "Logic");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
    FREE_C_HEAP_ARRAY(jbyte*, _hot_cache);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  }
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   165
  if (_threads != NULL) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   166
    for (int i = 0; i < _n_threads; i++) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   167
      delete _threads[i];
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   168
    }
2886
70bf7d429eba 6849122: G1: Typo introduced during implementation of the parallel refinement
iveresov
parents: 2882
diff changeset
   169
    FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   173
void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   174
  if (_threads != NULL) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   175
    for (int i = 0; i < _n_threads; i++) {
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   176
      tc->do_thread(_threads[i]);
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   177
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   179
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   180
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   181
bool ConcurrentG1Refine::is_young_card(jbyte* card_ptr) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   182
  HeapWord* start = _ct_bs->addr_for(card_ptr);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   183
  HeapRegion* r = _g1h->heap_region_containing(start);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   184
  if (r != NULL && r->is_young()) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   185
    return true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   186
  }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   187
  // 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
   188
  // so can't be young.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   189
  return false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   192
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
   193
  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
   194
  unsigned bucket = hash(new_card_num);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   195
  assert(0 <= bucket && bucket < _n_card_counts, "Bounds");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   196
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   197
  CardCountCacheEntry* count_ptr = &_card_counts[bucket];
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   198
  CardEpochCacheEntry* epoch_ptr = &_card_epochs[bucket];
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   199
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   200
  // 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
   201
  // 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
   202
  // different card number.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   203
  unsigned int new_epoch = (unsigned int) _n_periods;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   204
  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
   205
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   206
  while (true) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   207
    // Fetch the previous epoch value
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   208
    julong prev_epoch_entry = epoch_ptr->_value;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   209
    julong cas_res;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   210
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   211
    if (extract_epoch(prev_epoch_entry) != new_epoch) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   212
      // 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
   213
      // 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
   214
      // 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
   215
      // 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
   216
      // the same epoch value.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   217
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   218
      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
   219
                                         (volatile jlong*)&epoch_ptr->_value,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   220
                                         (jlong) prev_epoch_entry);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   221
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   222
      if (cas_res == prev_epoch_entry) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   223
        // 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
   224
        // 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
   225
        // count and eviction count were previously cleared.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   226
        count_ptr->_count = 1;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   227
        count_ptr->_evict_count = 0;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   228
        *count = 0;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   229
        // We can defer the processing of card_ptr
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   230
        *defer = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   231
        return card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   232
      }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   233
      // 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
   234
      // 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
   235
      // should be the new epoch value.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   236
      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
   237
      // 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
   238
      prev_epoch_entry = epoch_ptr->_value;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   239
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   240
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   241
    // 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
   242
    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
   243
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   244
    // 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
   245
    *count = count_ptr->_count;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   246
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   247
    // 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
   248
    if (new_card_num == old_card_num) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   249
      // 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
   250
      // 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
   251
      // 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
   252
      // 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
   253
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   254
      if (*count < max_jubyte) count_ptr->_count++;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   255
      // We can defer the processing of card_ptr
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   256
      *defer = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   257
      return card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   258
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   259
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   260
    // Different card - evict old card info
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   261
    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
   262
    if (count_ptr->_evict_count > G1CardCountCacheExpandThreshold) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   263
      // Trigger a resize the next time we clear
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   264
      _expand_card_counts = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   265
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   266
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   267
    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
   268
                                       (volatile jlong*)&epoch_ptr->_value,
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   269
                                       (jlong) prev_epoch_entry);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   270
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   271
    if (cas_res == prev_epoch_entry) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   272
      // 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
   273
      count_ptr->_count = 0; // initialize counter for new card num
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   274
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   275
      // 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
   276
      // 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
   277
      // cache it could have been added to the free list and subsequently
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   278
      // added to the young list in the intervening time. If the evicted
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   279
      // card is in a young region just return the card_ptr and the evicted
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   280
      // card will not be cleaned. See CR 6817995.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   281
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   282
      jbyte* old_card_ptr = card_num_2_ptr(old_card_num);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   283
      if (is_young_card(old_card_ptr)) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   284
        *count = 0;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   285
        // We can defer the processing of card_ptr
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   286
        *defer = true;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   287
        return card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   288
      }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   289
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   290
      // 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
   291
      // (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
   292
      *defer = false;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   293
      return old_card_ptr;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   294
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   295
    // Someone else beat us - try again.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   296
  }
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
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
   300
  int count;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   301
  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
   302
  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
   303
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   304
  if (is_young_card(cached_ptr)) {
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   305
    // The region containing cached_ptr has been freed during a clean up
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   306
    // pause, reallocated, and tagged as young.
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   307
    assert(cached_ptr != card_ptr, "shouldn't be");
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   308
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   309
    // We've just inserted a new old-gen card pointer into the card count
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   310
    // cache and evicted the previous contents of that count slot.
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   311
    // The evicted card pointer has been determined to be in a young region
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   312
    // and so cannot be the newly inserted card pointer (that will be
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   313
    // in an old region).
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   314
    // The count for newly inserted card will be set to zero during the
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   315
    // insertion, so we don't want to defer the cleaning of the newly
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   316
    // inserted card pointer.
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   317
    assert(*defer == false, "deferring non-hot card");
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   318
    return NULL;
c6e9df29a2cf 6914402: G1: assert(!is_young_card(cached_ptr),"shouldn't get a card in young region")
johnc
parents: 4481
diff changeset
   319
  }
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   320
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   321
  // 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
   322
  // 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
   323
  // refining.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
  if (count < G1ConcRSHotCardLimit) {
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   325
    return cached_ptr;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   326
  }
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   327
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   328
  // Otherwise, the pointer we got from the _card_counts is hot.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   329
  jbyte* res = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   330
  MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   331
  if (_n_hot == _hot_cache_size) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   332
    res = _hot_cache[_hot_cache_idx];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
    _n_hot--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   334
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   335
  // 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
   336
  _hot_cache[_hot_cache_idx] = cached_ptr;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   337
  _hot_cache_idx++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   338
  if (_hot_cache_idx == _hot_cache_size) _hot_cache_idx = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
  _n_hot++;
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   340
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   341
  if (res != NULL) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   342
    // Even though the region containg res was not in the young list
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   343
    // when it was recorded in the hot cache it could have been added
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   344
    // to the free list and subsequently added to the young list in
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   345
    // the intervening time. If res is in a young region, return NULL
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   346
    // so that res is not cleaned. See CR 6817995.
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
    if (is_young_card(res)) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   349
      res = NULL;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   350
    }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   351
  }
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   352
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   354
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
void ConcurrentG1Refine::clean_up_cache(int worker_i, G1RemSet* g1rs) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
  assert(!use_cache(), "cache should be disabled");
3589
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   358
  int start_idx;
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   359
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   360
  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
   361
    int end_idx = start_idx + _hot_cache_par_chunk_size;
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   362
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   363
    if (start_idx ==
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   364
        Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) {
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   365
      // 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
   366
      end_idx = MIN2(end_idx, _n_hot);
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   367
      for (int i = start_idx; i < end_idx; i++) {
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   368
        jbyte* entry = _hot_cache[i];
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   369
        if (entry != NULL) {
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   370
          g1rs->concurrentRefineOneCard(entry, worker_i);
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   371
        }
abdd970c243d 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 3261
diff changeset
   372
      }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   374
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   375
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   376
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   377
void ConcurrentG1Refine::expand_card_count_cache() {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   378
  if (_n_card_counts < _max_n_card_counts) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   379
    int new_idx = _cache_size_index+1;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   380
    int new_size = _cc_cache_sizes[new_idx];
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   381
    if (new_size < 0) new_size = _max_n_card_counts;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   382
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   383
    // Make sure we don't go bigger than we will ever need
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   384
    new_size = MIN2((unsigned) new_size, _max_n_card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   385
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   386
    // Expand the card count and card epoch tables
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   387
    if (new_size > (int)_n_card_counts) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   388
      // We can just free and allocate a new array as we're
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   389
      // not interested in preserving the contents
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   390
      assert(_card_counts != NULL, "Logic!");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   391
      assert(_card_epochs != NULL, "Logic!");
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   392
      FREE_C_HEAP_ARRAY(CardCountCacheEntry, _card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   393
      FREE_C_HEAP_ARRAY(CardEpochCacheEntry, _card_epochs);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   394
      _n_card_counts = new_size;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   395
      _card_counts = NEW_C_HEAP_ARRAY(CardCountCacheEntry, _n_card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   396
      _card_epochs = NEW_C_HEAP_ARRAY(CardEpochCacheEntry, _n_card_counts);
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   397
      _cache_size_index = new_idx;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   398
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   399
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   400
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   401
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   402
void ConcurrentG1Refine::clear_and_record_card_counts() {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   403
  if (G1ConcRSLogCacheSize == 0) return;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   404
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   405
#ifndef PRODUCT
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   406
  double start = os::elapsedTime();
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   407
#endif
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   408
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   409
  if (_expand_card_counts) {
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   410
    expand_card_count_cache();
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   411
    _expand_card_counts = false;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   412
    // Only need to clear the epochs.
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   413
    Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   414
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   415
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   416
  int this_epoch = (int) _n_periods;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   417
  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
   418
  // Update epoch
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   419
  _n_periods++;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   420
3590
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   421
#ifndef PRODUCT
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   422
  double elapsed = os::elapsedTime() - start;
a268fa66d7fb 6819077: G1: first GC thread coming late into the GC.
johnc
parents: 3589
diff changeset
   423
  _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
   424
#endif
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   425
}
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   426
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   427
void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   428
  for (int i = 0; i < _n_threads; ++i) {
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   429
    _threads[i]->print_on(st);
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   430
    st->cr();
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   431
  }
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   432
}