src/hotspot/share/gc/g1/g1RemSetTrackingPolicy.cpp
author tschatzl
Wed, 17 Jul 2019 16:33:19 +0200
changeset 55722 5ee183a90e65
parent 53704 ef72c85a0534
permissions -rw-r--r--
8227084: Add timing information for merge heap root preparation Reviewed-by: sangheki, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     1
/*
53704
ef72c85a0534 8217328: Rename CollectionSetChooser to G1CollectionSetChooser
tschatzl
parents: 51494
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     4
 *
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     8
 *
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    14
 *
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    18
 *
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    21
 * questions.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    22
 *
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    23
 */
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    24
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
53704
ef72c85a0534 8217328: Rename CollectionSetChooser to G1CollectionSetChooser
tschatzl
parents: 51494
diff changeset
    26
#include "gc/g1/g1CollectionSetChooser.hpp"
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    27
#include "gc/g1/g1RemSetTrackingPolicy.hpp"
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    28
#include "gc/g1/heapRegion.inline.hpp"
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    29
#include "gc/g1/heapRegionRemSet.hpp"
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    30
#include "runtime/safepoint.hpp"
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    31
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    32
bool G1RemSetTrackingPolicy::needs_scan_for_rebuild(HeapRegion* r) const {
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
    33
  // All non-free, non-young, non-closed archive regions need to be scanned for references;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    34
  // At every gc we gather references to other regions in young, and closed archive
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    35
  // regions by definition do not have references going outside the closed archive.
49634
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
    36
  // Free regions trivially do not need scanning because they do not contain live
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
    37
  // objects.
df9dcfff6628 8197932: Better split work in rebuild remembered sets phase
tschatzl
parents: 49632
diff changeset
    38
  return !(r->is_young() || r->is_closed_archive() || r->is_free());
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    39
}
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    40
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    41
void G1RemSetTrackingPolicy::update_at_allocate(HeapRegion* r) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    42
  if (r->is_young()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    43
    // Always collect remembered set for young regions.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    44
    r->rem_set()->set_state_complete();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    45
  } else if (r->is_humongous()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    46
    // Collect remembered sets for humongous regions by default to allow eager reclaim.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    47
    r->rem_set()->set_state_complete();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    48
  } else if (r->is_archive()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    49
    // Archive regions never move ever. So never build remembered sets for them.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    50
    r->rem_set()->set_state_empty();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    51
  } else if (r->is_old()) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    52
    // By default, do not create remembered set for new old regions.
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    53
    r->rem_set()->set_state_empty();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    54
  } else {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    55
    guarantee(false, "Unhandled region %u with heap region type %s", r->hrm_index(), r->get_type_str());
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    56
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    57
}
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    58
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    59
void G1RemSetTrackingPolicy::update_at_free(HeapRegion* r) {
49632
64f9ebc85e67 8197573: Remove concurrent cleanup and secondary free list handling
tschatzl
parents: 49607
diff changeset
    60
  /* nothing to do */
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    61
}
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
    62
51007
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    63
static void print_before_rebuild(HeapRegion* r, bool selected_for_rebuild, size_t total_live_bytes, size_t live_bytes) {
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    64
  log_trace(gc, remset, tracking)("Before rebuild region %u "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    65
                                  "(ntams: " PTR_FORMAT ") "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    66
                                  "total_live_bytes " SIZE_FORMAT " "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    67
                                  "selected %s "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    68
                                  "(live_bytes " SIZE_FORMAT " "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    69
                                  "next_marked " SIZE_FORMAT " "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    70
                                  "marked " SIZE_FORMAT " "
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    71
                                  "type %s)",
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    72
                                  r->hrm_index(),
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    73
                                  p2i(r->next_top_at_mark_start()),
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    74
                                  total_live_bytes,
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    75
                                  BOOL_TO_STR(selected_for_rebuild),
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    76
                                  live_bytes,
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    77
                                  r->next_marked_bytes(),
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    78
                                  r->marked_bytes(),
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    79
                                  r->get_type_str());
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    80
}
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    81
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    82
bool G1RemSetTrackingPolicy::update_humongous_before_rebuild(HeapRegion* r, bool is_live) {
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    83
  assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    84
  assert(r->is_humongous(), "Region %u should be humongous", r->hrm_index());
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    85
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    86
  if (r->is_archive()) {
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    87
    return false;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    88
  }
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    89
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    90
  assert(!r->rem_set()->is_updating(), "Remembered set of region %u is updating before rebuild", r->hrm_index());
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    91
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    92
  bool selected_for_rebuild = false;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    93
  // For humongous regions, to be of interest for rebuilding the remembered set the following must apply:
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    94
  // - We always try to update the remembered sets of humongous regions containing
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    95
  // type arrays as they might have been reset after full gc.
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    96
  if (is_live && oop(r->humongous_start_region()->bottom())->is_typeArray() && !r->rem_set()->is_tracked()) {
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    97
    r->rem_set()->set_state_updating();
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    98
    selected_for_rebuild = true;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
    99
  }
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   100
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   101
  size_t const live_bytes = is_live ? HeapRegion::GrainBytes : 0;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   102
  print_before_rebuild(r, selected_for_rebuild, live_bytes, live_bytes);
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   103
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   104
  return selected_for_rebuild;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   105
}
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   106
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   107
bool G1RemSetTrackingPolicy::update_before_rebuild(HeapRegion* r, size_t live_bytes) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   108
  assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
51007
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   109
  assert(!r->is_humongous(), "Region %u is humongous", r->hrm_index());
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   110
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   111
  // Only consider updating the remembered set for old gen regions - excluding archive regions
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   112
  // which never move (but are "Old" regions).
51007
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   113
  if (!r->is_old() || r->is_archive()) {
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   114
    return false;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   115
  }
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   116
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   117
  assert(!r->rem_set()->is_updating(), "Remembered set of region %u is updating before rebuild", r->hrm_index());
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   118
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   119
  size_t between_ntams_and_top = (r->top() - r->next_top_at_mark_start()) * HeapWordSize;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   120
  size_t total_live_bytes = live_bytes + between_ntams_and_top;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   121
51007
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   122
  bool selected_for_rebuild = false;
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   123
  // For old regions, to be of interest for rebuilding the remembered set the following must apply:
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   124
  // - They must contain some live data in them.
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   125
  // - Only need to rebuild non-complete remembered sets.
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   126
  // - Otherwise only add those old gen regions which occupancy is low enough that there
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   127
  // is a chance that we will ever evacuate them in the mixed gcs.
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   128
  if ((total_live_bytes > 0) &&
53704
ef72c85a0534 8217328: Rename CollectionSetChooser to G1CollectionSetChooser
tschatzl
parents: 51494
diff changeset
   129
      G1CollectionSetChooser::region_occupancy_low_enough_for_evac(total_live_bytes) &&
51007
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   130
      !r->rem_set()->is_tracked()) {
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   131
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   132
    r->rem_set()->set_state_updating();
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   133
    selected_for_rebuild = true;
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   134
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   135
51007
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   136
  print_before_rebuild(r, selected_for_rebuild, total_live_bytes, live_bytes);
fc9dd181d70e 8205426: Humongous continues remembered set does not match humongous start region one after Remark
tschatzl
parents: 50565
diff changeset
   137
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   138
  return selected_for_rebuild;
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   139
}
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   140
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   141
void G1RemSetTrackingPolicy::update_after_rebuild(HeapRegion* r) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   142
  assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   143
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51007
diff changeset
   144
  if (r->is_old_or_humongous_or_archive()) {
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   145
    if (r->rem_set()->is_updating()) {
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51007
diff changeset
   146
      assert(!r->is_archive(), "Archive region %u with remembered set", r->hrm_index());
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   147
      r->rem_set()->set_state_complete();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   148
    }
50565
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   149
    G1CollectedHeap* g1h = G1CollectedHeap::heap();
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   150
    // We can drop remembered sets of humongous regions that have a too large remembered set:
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   151
    // We will never try to eagerly reclaim or move them anyway until the next concurrent
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   152
    // cycle as e.g. remembered set entries will always be added.
50565
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   153
    if (r->is_starts_humongous() && !g1h->is_potential_eager_reclaim_candidate(r)) {
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   154
      // Handle HC regions with the HS region.
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   155
      uint const size_in_regions = (uint)g1h->humongous_obj_size_in_regions(oop(r->bottom())->size());
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   156
      uint const region_idx = r->hrm_index();
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   157
      for (uint j = region_idx; j < (region_idx + size_in_regions); j++) {
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   158
        HeapRegion* const cur = g1h->region_at(j);
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   159
        assert(!cur->is_continues_humongous() || cur->rem_set()->is_empty(),
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   160
               "Continues humongous region %u remset should be empty", j);
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   161
        cur->rem_set()->clear_locked(true /* only_cardset */);
69e82329ad01 8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region
tschatzl
parents: 49634
diff changeset
   162
      }
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   163
    }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   164
    G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   165
    log_trace(gc, remset, tracking)("After rebuild region %u "
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   166
                                    "(ntams " PTR_FORMAT " "
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   167
                                    "liveness " SIZE_FORMAT " "
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   168
                                    "next_marked_bytes " SIZE_FORMAT " "
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   169
                                    "remset occ " SIZE_FORMAT " "
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   170
                                    "size " SIZE_FORMAT ")",
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   171
                                    r->hrm_index(),
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   172
                                    p2i(r->next_top_at_mark_start()),
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   173
                                    cm->liveness(r->hrm_index()) * HeapWordSize,
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   174
                                    r->next_marked_bytes(),
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   175
                                    r->rem_set()->occupied_locked(),
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   176
                                    r->rem_set()->mem_size());
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   177
  }
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents:
diff changeset
   178
}