src/hotspot/share/gc/g1/g1BarrierSet.cpp
author eosterlund
Thu, 26 Apr 2018 20:42:43 +0200
changeset 49906 4bb58f644e4e
parent 49752 93d84f667d12
child 50180 ffa644980dff
permissions -rw-r--r--
8201543: Modularize C1 GC barriers Reviewed-by: pliden, rbackman, rkennke
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"
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
    26
#include "gc/g1/g1BarrierSet.inline.hpp"
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    27
#include "gc/g1/g1BarrierSetAssembler.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    28
#include "gc/g1/g1CardTable.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    29
#include "gc/g1/g1CollectedHeap.inline.hpp"
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
    30
#include "gc/g1/g1ThreadLocalData.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    31
#include "gc/g1/heapRegion.hpp"
33792
2bae5bf9e431 8077571: ObjPtrQueue is poorly named
kbarrett
parents: 33784
diff changeset
    32
#include "gc/g1/satbMarkQueue.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34615
diff changeset
    33
#include "logging/log.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
    34
#include "oops/access.inline.hpp"
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
    35
#include "oops/compressedOops.inline.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28830
diff changeset
    36
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/mutexLocker.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 10565
diff changeset
    38
#include "runtime/thread.inline.hpp"
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    39
#include "utilities/macros.hpp"
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49752
diff changeset
    40
#ifdef COMPILER1
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49752
diff changeset
    41
#include "gc/g1/c1/g1BarrierSetC1.hpp"
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49752
diff changeset
    42
#endif
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49752
diff changeset
    43
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49752
diff changeset
    44
class G1BarrierSetC1;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    46
SATBMarkQueueSet G1BarrierSet::_satb_mark_queue_set;
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    47
DirtyCardQueueSet G1BarrierSet::_dirty_card_queue_set;
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    48
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
    49
G1BarrierSet::G1BarrierSet(G1CardTable* card_table) :
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    50
  CardTableBarrierSet(make_barrier_set_assembler<G1BarrierSetAssembler>(),
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49752
diff changeset
    51
                      make_barrier_set_c1<G1BarrierSetC1>(),
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    52
                      card_table,
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    53
                      BarrierSet::FakeRtti(BarrierSet::G1BarrierSet)) {}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
    55
void G1BarrierSet::enqueue(oop pre_val) {
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 7397
diff changeset
    56
  // Nulls should have been already filtered.
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 42598
diff changeset
    57
  assert(oopDesc::is_oop(pre_val, true), "Error");
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 7397
diff changeset
    58
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    59
  if (!_satb_mark_queue_set.is_active()) return;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
  Thread* thr = Thread::current();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
  if (thr->is_Java_thread()) {
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
    62
    G1ThreadLocalData::satb_mark_queue(thr).enqueue(pre_val);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
  } else {
18495
65a0d2ae4b22 8014022: G1: Non Java threads should lock the shared SATB queue lock without safepoint checks.
brutisso
parents: 14583
diff changeset
    64
    MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    65
    _satb_mark_queue_set.shared_satb_queue()->enqueue(pre_val);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    69
void G1BarrierSet::write_ref_array_pre_oop_entry(oop* dst, size_t length) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    70
  G1BarrierSet *bs = barrier_set_cast<G1BarrierSet>(BarrierSet::barrier_set());
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    71
  bs->write_ref_array_pre(dst, length, false);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    72
}
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    73
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    74
void G1BarrierSet::write_ref_array_pre_narrow_oop_entry(narrowOop* dst, size_t length) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    75
  G1BarrierSet *bs = barrier_set_cast<G1BarrierSet>(BarrierSet::barrier_set());
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    76
  bs->write_ref_array_pre(dst, length, false);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    77
}
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    78
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    79
void G1BarrierSet::write_ref_array_post_entry(HeapWord* dst, size_t length) {
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    80
  G1BarrierSet *bs = barrier_set_cast<G1BarrierSet>(BarrierSet::barrier_set());
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    81
  bs->G1BarrierSet::write_ref_array(dst, length);
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    82
}
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    83
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 1374
diff changeset
    84
template <class T> void
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    85
G1BarrierSet::write_ref_array_pre_work(T* dst, size_t count) {
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
    86
  if (!_satb_mark_queue_set.is_active()) return;
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 1374
diff changeset
    87
  T* elem_ptr = dst;
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    88
  for (size_t i = 0; i < count; i++, elem_ptr++) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
    89
    T heap_oop = RawAccess<>::oop_load(elem_ptr);
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
    90
    if (!CompressedOops::is_null(heap_oop)) {
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 49484
diff changeset
    91
      enqueue(CompressedOops::decode_not_null(heap_oop));
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 1374
diff changeset
    92
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
    96
void G1BarrierSet::write_ref_array_pre(oop* dst, size_t count, bool dest_uninitialized) {
25480
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
    97
  if (!dest_uninitialized) {
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
    98
    write_ref_array_pre_work(dst, count);
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
    99
  }
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
   100
}
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents: 47794
diff changeset
   101
49484
ee8fa73b90f9 8198949: Modularize arraycopy stub routine GC barriers
eosterlund
parents: 49455
diff changeset
   102
void G1BarrierSet::write_ref_array_pre(narrowOop* dst, size_t count, bool dest_uninitialized) {
25480
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
   103
  if (!dest_uninitialized) {
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
   104
    write_ref_array_pre_work(dst, count);
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
   105
  }
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
   106
}
190facf4e732 8048214: Linker error when compiling G1SATBCardTableModRefBS after include order changes
mgerdin
parents: 25351
diff changeset
   107
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
   108
void G1BarrierSet::write_ref_field_post_slow(volatile jbyte* byte) {
47998
fb0275c320a0 8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents: 47794
diff changeset
   109
  // In the slow path, we know a card is not young
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   110
  assert(*byte != G1CardTable::g1_young_card_val(), "slow path invoked without filtering");
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
   111
  OrderAccess::storeload();
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   112
  if (*byte != G1CardTable::dirty_card_val()) {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   113
    *byte = G1CardTable::dirty_card_val();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
    Thread* thr = Thread::current();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
    if (thr->is_Java_thread()) {
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   116
      G1ThreadLocalData::dirty_card_queue(thr).enqueue(byte);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
      MutexLockerEx x(Shared_DirtyCardQ_lock,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
                      Mutex::_no_safepoint_check_flag);
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
   120
      _dirty_card_queue_set.shared_dirty_card_queue()->enqueue(byte);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
   125
void G1BarrierSet::invalidate(MemRegion mr) {
48102
08be4c1e540e 8182050: assert(_whole_heap.contains(p)) failed: Attempt to access p out of bounds of card marking array's _whole_heap
tschatzl
parents: 47998
diff changeset
   126
  if (mr.is_empty()) {
08be4c1e540e 8182050: assert(_whole_heap.contains(p)) failed: Attempt to access p out of bounds of card marking array's _whole_heap
tschatzl
parents: 47998
diff changeset
   127
    return;
08be4c1e540e 8182050: assert(_whole_heap.contains(p)) failed: Attempt to access p out of bounds of card marking array's _whole_heap
tschatzl
parents: 47998
diff changeset
   128
  }
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   129
  volatile jbyte* byte = _card_table->byte_for(mr.start());
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   130
  jbyte* last_byte = _card_table->byte_for(mr.last());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
  Thread* thr = Thread::current();
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
   132
    // skip all consecutive young cards
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   133
  for (; byte <= last_byte && *byte == G1CardTable::g1_young_card_val(); byte++);
20403
45a89fbcd8f7 8014555: G1: Memory ordering problem with Conc refinement and card marking
mgerdin
parents: 20309
diff changeset
   134
42598
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   135
  if (byte <= last_byte) {
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   136
    OrderAccess::storeload();
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   137
    // Enqueue if necessary.
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   138
    if (thr->is_Java_thread()) {
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   139
      for (; byte <= last_byte; byte++) {
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   140
        if (*byte == G1CardTable::g1_young_card_val()) {
42598
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   141
          continue;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
        }
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   143
        if (*byte != G1CardTable::dirty_card_val()) {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   144
          *byte = G1CardTable::dirty_card_val();
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   145
          G1ThreadLocalData::dirty_card_queue(thr).enqueue(byte);
42598
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   146
        }
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   147
      }
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   148
    } else {
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   149
      MutexLockerEx x(Shared_DirtyCardQ_lock,
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   150
                      Mutex::_no_safepoint_check_flag);
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   151
      for (; byte <= last_byte; byte++) {
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   152
        if (*byte == G1CardTable::g1_young_card_val()) {
42598
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   153
          continue;
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 40655
diff changeset
   154
        }
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   155
        if (*byte != G1CardTable::dirty_card_val()) {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   156
          *byte = G1CardTable::dirty_card_val();
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
   157
          _dirty_card_queue_set.shared_dirty_card_queue()->enqueue(byte);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   159
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   161
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
}
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48102
diff changeset
   163
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   164
void G1BarrierSet::on_thread_create(Thread* thread) {
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   165
  // Create thread local data
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   166
  G1ThreadLocalData::create(thread);
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   167
}
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   168
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   169
void G1BarrierSet::on_thread_destroy(Thread* thread) {
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   170
  // Destroy thread local data
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   171
  G1ThreadLocalData::destroy(thread);
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   172
}
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   173
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
   174
void G1BarrierSet::on_thread_attach(JavaThread* thread) {
49007
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   175
  // This method initializes the SATB and dirty card queues before a
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   176
  // JavaThread is added to the Java thread list. Right now, we don't
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   177
  // have to do anything to the dirty card queue (it should have been
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   178
  // activated when the thread was created), but we have to activate
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   179
  // the SATB queue if the thread is created while a marking cycle is
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   180
  // in progress. The activation / de-activation of the SATB queues at
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   181
  // the beginning / end of a marking cycle is done during safepoints
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   182
  // so we have to make sure this method is called outside one to be
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   183
  // able to safely read the active field of the SATB queue set. Right
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   184
  // now, it is called just before the thread is added to the Java
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   185
  // thread list in the Threads::add() method. That method is holding
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   186
  // the Threads_lock which ensures we are outside a safepoint. We
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   187
  // cannot do the obvious and set the active field of the SATB queue
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   188
  // when the thread is created given that, in some cases, safepoints
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   189
  // might happen between the JavaThread constructor being called and the
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   190
  // thread being added to the Java thread list (an example of this is
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   191
  // when the structure for the DestroyJavaVM thread is created).
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   192
  assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   193
  assert(!G1ThreadLocalData::satb_mark_queue(thread).is_active(), "SATB queue should not be active");
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   194
  assert(G1ThreadLocalData::satb_mark_queue(thread).is_empty(), "SATB queue should be empty");
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   195
  assert(G1ThreadLocalData::dirty_card_queue(thread).is_active(), "Dirty card queue should be active");
49007
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   196
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   197
  // If we are creating the thread during a marking cycle, we should
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   198
  // set the active field of the SATB queue to true.
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 49679
diff changeset
   199
  if (_satb_mark_queue_set.is_active()) {
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   200
    G1ThreadLocalData::satb_mark_queue(thread).set_active(true);
49007
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   201
  }
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   202
}
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   203
49347
edb65305d3ac 8195148: Collapse G1SATBCardTableModRefBS and G1SATBCardTableLoggingModRefBS into a single G1BarrierSet
eosterlund
parents: 49164
diff changeset
   204
void G1BarrierSet::on_thread_detach(JavaThread* thread) {
49007
82d9d5744e5f 8197994: Move JavaThread::initialize_queues() logic to G1SATBCardTableLoggingModRefBS
pliden
parents: 48961
diff changeset
   205
  // Flush any deferred card marks, SATB buffers and dirty card queue buffers
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49347
diff changeset
   206
  CardTableBarrierSet::on_thread_detach(thread);
49752
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   207
  G1ThreadLocalData::satb_mark_queue(thread).flush();
93d84f667d12 8201318: Introduce GCThreadLocalData to abstract GC-specific data belonging to a thread
pliden
parents: 49751
diff changeset
   208
  G1ThreadLocalData::dirty_card_queue(thread).flush();
48961
120b61d50f85 8195103: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 48102
diff changeset
   209
}