1 /* 2 * Copyright (c) 2001, 2018, 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_G1_G1BARRIERSET_HPP 26 #define SHARE_VM_GC_G1_G1BARRIERSET_HPP 27 28 #include "gc/g1/dirtyCardQueue.hpp" 29 #include "gc/g1/satbMarkQueue.hpp" 30 #include "gc/shared/cardTableBarrierSet.hpp" 31 32 class DirtyCardQueueSet; 33 class CardTable; 34 class G1CardTable; 35 36 // This barrier is specialized to use a logging barrier to support 37 // snapshot-at-the-beginning marking. 38 39 class G1BarrierSet: public CardTableBarrierSet { 40 friend class VMStructs; 41 private: 42 static SATBMarkQueueSet _satb_mark_queue_set; 43 static DirtyCardQueueSet _dirty_card_queue_set; 44 45 public: 46 G1BarrierSet(G1CardTable* table); 47 ~G1BarrierSet() { } 48 49 // Add "pre_val" to a set of objects that may have been disconnected from the 50 // pre-marking object graph. 51 static void enqueue(oop pre_val); 52 53 static void enqueue_if_weak_or_archive(DecoratorSet decorators, oop value); 54 55 template <class T> void write_ref_array_pre_work(T* dst, size_t count); 56 virtual void write_ref_array_pre(oop* dst, size_t count, bool dest_uninitialized); 57 virtual void write_ref_array_pre(narrowOop* dst, size_t count, bool dest_uninitialized); 58 59 template <DecoratorSet decorators, typename T> 60 void write_ref_field_pre(T* field); 61 62 // NB: if you do a whole-heap invalidation, the "usual invariant" defined 63 // above no longer applies. 64 void invalidate(MemRegion mr); 65 66 void write_region(MemRegion mr) { invalidate(mr); } 67 void write_ref_array_work(MemRegion mr) { invalidate(mr); } 68 69 template <DecoratorSet decorators, typename T> 70 void write_ref_field_post(T* field, oop new_val); 71 void write_ref_field_post_slow(volatile jbyte* byte); 72 73 virtual void on_thread_create(Thread* thread); 74 virtual void on_thread_destroy(Thread* thread); 75 virtual void on_thread_attach(JavaThread* thread); 76 virtual void on_thread_detach(JavaThread* thread); 77 78 static SATBMarkQueueSet& satb_mark_queue_set() { 79 return _satb_mark_queue_set; 80 } 81 82 static DirtyCardQueueSet& dirty_card_queue_set() { 83 return _dirty_card_queue_set; 84 } 85 86 // Callbacks for runtime accesses. 87 template <DecoratorSet decorators, typename BarrierSetT = G1BarrierSet> 88 class AccessBarrier: public ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> { 89 typedef ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> ModRef; 90 typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw; 91 92 public: 93 // Needed for loads on non-heap weak references 94 template <typename T> 95 static oop oop_load_not_in_heap(T* addr); 96 97 // Needed for non-heap stores 98 template <typename T> 99 static void oop_store_not_in_heap(T* addr, oop new_value); 100 101 // Needed for weak references 102 static oop oop_load_in_heap_at(oop base, ptrdiff_t offset); 103 104 // Defensive: will catch weak oops at addresses in heap 105 template <typename T> 106 static oop oop_load_in_heap(T* addr); 107 }; 108 }; 109 110 template<> 111 struct BarrierSet::GetName<G1BarrierSet> { 112 static const BarrierSet::Name value = BarrierSet::G1BarrierSet; 113 }; 114 115 template<> 116 struct BarrierSet::GetType<BarrierSet::G1BarrierSet> { 117 typedef ::G1BarrierSet type; 118 }; 119 120 #endif // SHARE_VM_GC_G1_G1BARRIERSET_HPP