1 /* 2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_SHARED_CARDTABLEMODREFBS_HPP 26 #define SHARE_VM_GC_SHARED_CARDTABLEMODREFBS_HPP 27 28 #include "gc/shared/modRefBarrierSet.hpp" 29 30 class CardTable; 31 32 // This kind of "BarrierSet" allows a "CollectedHeap" to detect and 33 // enumerate ref fields that have been modified (since the last 34 // enumeration.) 35 36 // As it currently stands, this barrier is *imprecise*: when a ref field in 37 // an object "o" is modified, the card table entry for the card containing 38 // the head of "o" is dirtied, not necessarily the card containing the 39 // modified field itself. For object arrays, however, the barrier *is* 40 // precise; only the card containing the modified element is dirtied. 41 // Closures used to scan dirty cards should take these 42 // considerations into account. 43 44 class CardTableModRefBS: public ModRefBarrierSet { 45 // Some classes get to look at some private stuff. 46 friend class VMStructs; 47 protected: 48 // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 49 // or INCLUDE_JVMCI is being used 50 bool _defer_initial_card_mark; 51 bool _can_elide_tlab_store_barriers; 52 CardTable* _card_table; 53 54 CardTableModRefBS(CardTable* card_table, const BarrierSet::FakeRtti& fake_rtti); 55 56 public: 57 CardTableModRefBS(CardTable* card_table); 58 ~CardTableModRefBS(); 59 60 void initialize(); 61 62 CardTable* card_table() const { return _card_table; } 63 64 // Record a reference update. Note that these versions are precise! 65 // The scanning code has to handle the fact that the write barrier may be 66 // either precise or imprecise. We make non-virtual inline variants of 67 // these functions here for performance. 68 69 template <DecoratorSet decorators> 70 void write_ref_field_post(void* field, oop newVal); 71 72 virtual void write_region(MemRegion mr); 73 virtual void write_ref_array_region(MemRegion mr); 74 75 // ModRefBS functions. 76 virtual void invalidate(MemRegion mr); 77 78 // Print a description of the memory for the barrier set 79 virtual void print_on(outputStream* st) const; 80 81 // ReduceInitialCardMarks 82 void new_deferred_store_barrier(JavaThread* thread, oop new_obj); 83 84 // If the CollectedHeap was asked to defer a store barrier above, 85 // this informs it to flush such a deferred store barrier to the 86 // remembered set. 87 void flush_deferred_store_barrier(JavaThread* thread); 88 89 // Can a compiler initialize a new object without store barriers? 90 // This permission only extends from the creation of a new object 91 // via a TLAB up to the first subsequent safepoint. If such permission 92 // is granted for this heap type, the compiler promises to call 93 // defer_store_barrier() below on any slow path allocation of 94 // a new object for which such initializing store barriers will 95 // have been elided. G1, like CMS, allows this, but should be 96 // ready to provide a compensating write barrier as necessary 97 // if that storage came out of a non-young region. The efficiency 98 // of this implementation depends crucially on being able to 99 // answer very efficiently in constant time whether a piece of 100 // storage in the heap comes from a young region or not. 101 // See ReduceInitialCardMarks. 102 virtual bool can_elide_tlab_store_barriers() const { return true; } 103 104 // If a compiler is eliding store barriers for TLAB-allocated objects, 105 // we will be informed of a slow-path allocation by a call 106 // to new_deferred_store_barrier() above. Such a call precedes the 107 // initialization of the object itself, and no post-store-barriers will 108 // be issued. Some heap types require that the barrier strictly follows 109 // the initializing stores. (This is currently implemented by deferring the 110 // barrier until the next slow-path allocation or gc-related safepoint.) 111 // This interface answers whether a particular barrier type needs the card 112 // mark to be thus strictly sequenced after the stores. 113 virtual bool card_mark_must_follow_store() const; 114 115 void on_slowpath_allocation(JavaThread* thread, oop new_obj) { 116 if (_can_elide_tlab_store_barriers) { 117 new_deferred_store_barrier(thread, new_obj); 118 } 119 } 120 void on_destroy_thread(JavaThread* thread); 121 void make_parsable(JavaThread* thread); 122 123 protected: 124 virtual BarrierSetCodeGen* make_code_gen(); 125 virtual C1BarrierSetCodeGen* make_c1_code_gen(); 126 virtual C2BarrierSetCodeGen* make_c2_code_gen(); 127 128 public: 129 template <DecoratorSet decorators> 130 class AccessBarrier: public ModRefBarrierSet::AccessBarrier<decorators, CardTableModRefBS> {}; 131 }; 132 133 template<> 134 struct BSTypeToName<CardTableModRefBS> { 135 static const BarrierSet::Name value = BarrierSet::CardTableModRef; 136 }; 137 138 template<> 139 struct BSNameToType<BarrierSet::CardTableModRef> { 140 typedef CardTableModRefBS type; 141 }; 142 143 #endif // SHARE_VM_GC_SHARED_CARDTABLEMODREFBS_HPP