1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,172 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP 1.30 + 1.31 +#include "memory/cardTableModRefBS.hpp" 1.32 +#include "memory/memRegion.hpp" 1.33 +#include "oops/oop.inline.hpp" 1.34 +#include "utilities/macros.hpp" 1.35 + 1.36 +#if INCLUDE_ALL_GCS 1.37 + 1.38 +class DirtyCardQueueSet; 1.39 + 1.40 +// This barrier is specialized to use a logging barrier to support 1.41 +// snapshot-at-the-beginning marking. 1.42 + 1.43 +class G1SATBCardTableModRefBS: public CardTableModRefBSForCTRS { 1.44 +protected: 1.45 + enum G1CardValues { 1.46 + g1_young_gen = CT_MR_BS_last_reserved << 1 1.47 + }; 1.48 + 1.49 +public: 1.50 + static int g1_young_card_val() { return g1_young_gen; } 1.51 + 1.52 + // Add "pre_val" to a set of objects that may have been disconnected from the 1.53 + // pre-marking object graph. 1.54 + static void enqueue(oop pre_val); 1.55 + 1.56 + G1SATBCardTableModRefBS(MemRegion whole_heap, 1.57 + int max_covered_regions); 1.58 + 1.59 + bool is_a(BarrierSet::Name bsn) { 1.60 + return bsn == BarrierSet::G1SATBCT || CardTableModRefBS::is_a(bsn); 1.61 + } 1.62 + 1.63 + virtual bool has_write_ref_pre_barrier() { return true; } 1.64 + 1.65 + // This notes that we don't need to access any BarrierSet data 1.66 + // structures, so this can be called from a static context. 1.67 + template <class T> static void write_ref_field_pre_static(T* field, oop newVal) { 1.68 + T heap_oop = oopDesc::load_heap_oop(field); 1.69 + if (!oopDesc::is_null(heap_oop)) { 1.70 + enqueue(oopDesc::decode_heap_oop(heap_oop)); 1.71 + } 1.72 + } 1.73 + 1.74 + // We export this to make it available in cases where the static 1.75 + // type of the barrier set is known. Note that it is non-virtual. 1.76 + template <class T> inline void inline_write_ref_field_pre(T* field, oop newVal) { 1.77 + write_ref_field_pre_static(field, newVal); 1.78 + } 1.79 + 1.80 + // These are the more general virtual versions. 1.81 + virtual void write_ref_field_pre_work(oop* field, oop new_val) { 1.82 + inline_write_ref_field_pre(field, new_val); 1.83 + } 1.84 + virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) { 1.85 + inline_write_ref_field_pre(field, new_val); 1.86 + } 1.87 + virtual void write_ref_field_pre_work(void* field, oop new_val) { 1.88 + guarantee(false, "Not needed"); 1.89 + } 1.90 + 1.91 + template <class T> void write_ref_array_pre_work(T* dst, int count); 1.92 + virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) { 1.93 + if (!dest_uninitialized) { 1.94 + write_ref_array_pre_work(dst, count); 1.95 + } 1.96 + } 1.97 + virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) { 1.98 + if (!dest_uninitialized) { 1.99 + write_ref_array_pre_work(dst, count); 1.100 + } 1.101 + } 1.102 + 1.103 +/* 1.104 + Claimed and deferred bits are used together in G1 during the evacuation 1.105 + pause. These bits can have the following state transitions: 1.106 + 1. The claimed bit can be put over any other card state. Except that 1.107 + the "dirty -> dirty and claimed" transition is checked for in 1.108 + G1 code and is not used. 1.109 + 2. Deferred bit can be set only if the previous state of the card 1.110 + was either clean or claimed. mark_card_deferred() is wait-free. 1.111 + We do not care if the operation is be successful because if 1.112 + it does not it will only result in duplicate entry in the update 1.113 + buffer because of the "cache-miss". So it's not worth spinning. 1.114 + */ 1.115 + 1.116 + bool is_card_claimed(size_t card_index) { 1.117 + jbyte val = _byte_map[card_index]; 1.118 + return (val & (clean_card_mask_val() | claimed_card_val())) == claimed_card_val(); 1.119 + } 1.120 + 1.121 + void set_card_claimed(size_t card_index) { 1.122 + jbyte val = _byte_map[card_index]; 1.123 + if (val == clean_card_val()) { 1.124 + val = (jbyte)claimed_card_val(); 1.125 + } else { 1.126 + val |= (jbyte)claimed_card_val(); 1.127 + } 1.128 + _byte_map[card_index] = val; 1.129 + } 1.130 + 1.131 + void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN; 1.132 + void g1_mark_as_young(const MemRegion& mr); 1.133 + 1.134 + bool mark_card_deferred(size_t card_index); 1.135 + 1.136 + bool is_card_deferred(size_t card_index) { 1.137 + jbyte val = _byte_map[card_index]; 1.138 + return (val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val(); 1.139 + } 1.140 + 1.141 +}; 1.142 + 1.143 +// Adds card-table logging to the post-barrier. 1.144 +// Usual invariant: all dirty cards are logged in the DirtyCardQueueSet. 1.145 +class G1SATBCardTableLoggingModRefBS: public G1SATBCardTableModRefBS { 1.146 + private: 1.147 + DirtyCardQueueSet& _dcqs; 1.148 + public: 1.149 + G1SATBCardTableLoggingModRefBS(MemRegion whole_heap, 1.150 + int max_covered_regions); 1.151 + 1.152 + bool is_a(BarrierSet::Name bsn) { 1.153 + return bsn == BarrierSet::G1SATBCTLogging || 1.154 + G1SATBCardTableModRefBS::is_a(bsn); 1.155 + } 1.156 + 1.157 + void write_ref_field_work(void* field, oop new_val, bool release = false); 1.158 + 1.159 + // Can be called from static contexts. 1.160 + static void write_ref_field_static(void* field, oop new_val); 1.161 + 1.162 + // NB: if you do a whole-heap invalidation, the "usual invariant" defined 1.163 + // above no longer applies. 1.164 + void invalidate(MemRegion mr, bool whole_heap = false); 1.165 + 1.166 + void write_region_work(MemRegion mr) { invalidate(mr); } 1.167 + void write_ref_array_work(MemRegion mr) { invalidate(mr); } 1.168 + 1.169 + 1.170 +}; 1.171 + 1.172 + 1.173 +#endif // INCLUDE_ALL_GCS 1.174 + 1.175 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP