src/hotspot/share/gc/g1/g1CardTable.cpp
author eosterlund
Mon, 26 Feb 2018 09:34:12 +0100
changeset 49164 7e958a8ebcd3
parent 49007 src/hotspot/share/gc/g1/g1SATBCardTableModRefBS.cpp@82d9d5744e5f
child 49194 ece10494786c
permissions -rw-r--r--
8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy Reviewed-by: stefank, coleenp, kvn, ehelin
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
/*
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48102
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5082
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5082
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5082
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    26
#include "gc/g1/g1CardTable.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/g1/g1CollectedHeap.inline.hpp"
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
    28
#include "gc/shared/memset_with_concurrent_readers.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34615
diff changeset
    29
#include "logging/log.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 35862
diff changeset
    30
#include "runtime/atomic.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22859
diff changeset
    31
#include "runtime/orderAccess.inline.hpp"
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 7397
diff changeset
    32
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    33
bool G1CardTable::mark_card_deferred(size_t card_index) {
20309
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    34
  jbyte val = _byte_map[card_index];
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    35
  // It's already processed
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    36
  if ((val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val()) {
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    37
    return false;
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    38
  }
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    39
20309
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    40
  // Cached bit can be installed either on a clean card or on a claimed card.
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    41
  jbyte new_val = val;
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    42
  if (val == clean_card_val()) {
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    43
    new_val = (jbyte)deferred_card_val();
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    44
  } else {
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    45
    if (val & claimed_card_val()) {
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    46
      new_val = val | (jbyte)deferred_card_val();
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    47
    }
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    48
  }
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    49
  if (new_val != val) {
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    50
    Atomic::cmpxchg(new_val, &_byte_map[card_index], val);
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    51
  }
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    52
  return true;
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    53
}
7445302daff6 8025305: Cleanup CardTableModRefBS usage in G1
mgerdin
parents: 18495
diff changeset
    54
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    55
void G1CardTable::g1_mark_as_young(const MemRegion& mr) {
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    56
  jbyte *const first = byte_for(mr.start());
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    57
  jbyte *const last = byte_after(mr.last());
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    58
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
    59
  memset_with_concurrent_readers(first, g1_young_gen, last - first);
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    60
}
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    61
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    62
#ifndef PRODUCT
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    63
void G1CardTable::verify_g1_young_region(MemRegion mr) {
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    64
  verify_region(mr, g1_young_gen,  true);
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    65
}
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    66
#endif
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
    67
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    68
void G1CardTableChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
27149
9246fc481aa3 8059758: Footprint regressions with JDK-8038423
tschatzl
parents: 26160
diff changeset
    69
  // Default value for a clean card on the card table is -1. So we cannot take advantage of the zero_filled parameter.
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    70
  MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    71
  _card_table->clear(mr);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    72
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    73
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    74
void G1CardTable::initialize(G1RegionToSpaceMapper* mapper) {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    75
  mapper->set_mapping_changed_listener(&_listener);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    76
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    77
  _byte_map_size = mapper->reserved().byte_size();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    78
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    79
  _guard_index = cards_required(_whole_heap.word_size()) - 1;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    80
  _last_valid_index = _guard_index - 1;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    81
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    82
  HeapWord* low_bound  = _whole_heap.start();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    83
  HeapWord* high_bound = _whole_heap.end();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    84
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    85
  _cur_covered_regions = 1;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    86
  _covered[0] = _whole_heap;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    87
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    88
  _byte_map = (jbyte*) mapper->reserved().start();
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    89
  _byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    90
  assert(byte_for(low_bound) == &_byte_map[0], "Checking start of map");
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    91
  assert(byte_for(high_bound-1) <= &_byte_map[_last_valid_index], "Checking end of map");
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 25480
diff changeset
    92
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    93
  log_trace(gc, barrier)("G1CardTable::G1CardTable: ");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34615
diff changeset
    94
  log_trace(gc, barrier)("    &_byte_map[0]: " INTPTR_FORMAT "  &_byte_map[_last_valid_index]: " INTPTR_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34615
diff changeset
    95
                         p2i(&_byte_map[0]), p2i(&_byte_map[_last_valid_index]));
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    96
  log_trace(gc, barrier)("    _byte_map_base: " INTPTR_FORMAT,  p2i(_byte_map_base));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    99
bool G1CardTable::is_in_young(oop obj) const {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   100
  volatile jbyte* p = byte_for(obj);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   101
  return *p == G1CardTable::g1_young_card_val();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
}