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