| 1 | /* | 
|---|
| 2 | * Copyright (c) 2001, 2019, 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_GC_G1_G1BARRIERSET_HPP | 
|---|
| 26 | #define SHARE_GC_G1_G1BARRIERSET_HPP | 
|---|
| 27 |  | 
|---|
| 28 | #include "gc/g1/g1DirtyCardQueue.hpp" | 
|---|
| 29 | #include "gc/g1/g1SATBMarkQueueSet.hpp" | 
|---|
| 30 | #include "gc/g1/g1SharedDirtyCardQueue.hpp" | 
|---|
| 31 | #include "gc/shared/cardTable.hpp" | 
|---|
| 32 | #include "gc/shared/cardTableBarrierSet.hpp" | 
|---|
| 33 |  | 
|---|
| 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 | BufferNode::Allocator _satb_mark_queue_buffer_allocator; | 
|---|
| 43 | BufferNode::Allocator _dirty_card_queue_buffer_allocator; | 
|---|
| 44 | G1SATBMarkQueueSet _satb_mark_queue_set; | 
|---|
| 45 | G1DirtyCardQueueSet _dirty_card_queue_set; | 
|---|
| 46 | G1SharedDirtyCardQueue _shared_dirty_card_queue; | 
|---|
| 47 |  | 
|---|
| 48 | static G1BarrierSet* g1_barrier_set() { | 
|---|
| 49 | return barrier_set_cast<G1BarrierSet>(BarrierSet::barrier_set()); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | public: | 
|---|
| 53 | G1BarrierSet(G1CardTable* table); | 
|---|
| 54 | ~G1BarrierSet() { } | 
|---|
| 55 |  | 
|---|
| 56 | // Add "pre_val" to a set of objects that may have been disconnected from the | 
|---|
| 57 | // pre-marking object graph. | 
|---|
| 58 | static void enqueue(oop pre_val); | 
|---|
| 59 |  | 
|---|
| 60 | static void enqueue_if_weak(DecoratorSet decorators, oop value); | 
|---|
| 61 |  | 
|---|
| 62 | template <class T> void write_ref_array_pre_work(T* dst, size_t count); | 
|---|
| 63 | virtual void write_ref_array_pre(oop* dst, size_t count, bool dest_uninitialized); | 
|---|
| 64 | virtual void write_ref_array_pre(narrowOop* dst, size_t count, bool dest_uninitialized); | 
|---|
| 65 |  | 
|---|
| 66 | template <DecoratorSet decorators, typename T> | 
|---|
| 67 | void write_ref_field_pre(T* field); | 
|---|
| 68 |  | 
|---|
| 69 | // NB: if you do a whole-heap invalidation, the "usual invariant" defined | 
|---|
| 70 | // above no longer applies. | 
|---|
| 71 | void invalidate(MemRegion mr); | 
|---|
| 72 |  | 
|---|
| 73 | void write_region(MemRegion mr)         { invalidate(mr); } | 
|---|
| 74 | void write_ref_array_work(MemRegion mr) { invalidate(mr); } | 
|---|
| 75 |  | 
|---|
| 76 | template <DecoratorSet decorators, typename T> | 
|---|
| 77 | void write_ref_field_post(T* field, oop new_val); | 
|---|
| 78 | void write_ref_field_post_slow(volatile CardValue* byte); | 
|---|
| 79 |  | 
|---|
| 80 | virtual void on_thread_create(Thread* thread); | 
|---|
| 81 | virtual void on_thread_destroy(Thread* thread); | 
|---|
| 82 | virtual void on_thread_attach(Thread* thread); | 
|---|
| 83 | virtual void on_thread_detach(Thread* thread); | 
|---|
| 84 |  | 
|---|
| 85 | BufferNode::Allocator& satb_mark_queue_buffer_allocator(); | 
|---|
| 86 | BufferNode::Allocator& dirty_card_queue_buffer_allocator(); | 
|---|
| 87 |  | 
|---|
| 88 | static G1SATBMarkQueueSet& satb_mark_queue_set() { | 
|---|
| 89 | return g1_barrier_set()->_satb_mark_queue_set; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | static G1DirtyCardQueueSet& dirty_card_queue_set() { | 
|---|
| 93 | return g1_barrier_set()->_dirty_card_queue_set; | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | static G1SharedDirtyCardQueue& shared_dirty_card_queue() { | 
|---|
| 97 | return g1_barrier_set()->_shared_dirty_card_queue; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | // Callbacks for runtime accesses. | 
|---|
| 101 | template <DecoratorSet decorators, typename BarrierSetT = G1BarrierSet> | 
|---|
| 102 | class AccessBarrier: public ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> { | 
|---|
| 103 | typedef ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> ModRef; | 
|---|
| 104 | typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw; | 
|---|
| 105 |  | 
|---|
| 106 | public: | 
|---|
| 107 | // Needed for loads on non-heap weak references | 
|---|
| 108 | template <typename T> | 
|---|
| 109 | static oop oop_load_not_in_heap(T* addr); | 
|---|
| 110 |  | 
|---|
| 111 | // Needed for non-heap stores | 
|---|
| 112 | template <typename T> | 
|---|
| 113 | static void oop_store_not_in_heap(T* addr, oop new_value); | 
|---|
| 114 |  | 
|---|
| 115 | // Needed for weak references | 
|---|
| 116 | static oop oop_load_in_heap_at(oop base, ptrdiff_t offset); | 
|---|
| 117 |  | 
|---|
| 118 | // Defensive: will catch weak oops at addresses in heap | 
|---|
| 119 | template <typename T> | 
|---|
| 120 | static oop oop_load_in_heap(T* addr); | 
|---|
| 121 | }; | 
|---|
| 122 | }; | 
|---|
| 123 |  | 
|---|
| 124 | template<> | 
|---|
| 125 | struct BarrierSet::GetName<G1BarrierSet> { | 
|---|
| 126 | static const BarrierSet::Name value = BarrierSet::G1BarrierSet; | 
|---|
| 127 | }; | 
|---|
| 128 |  | 
|---|
| 129 | template<> | 
|---|
| 130 | struct BarrierSet::GetType<BarrierSet::G1BarrierSet> { | 
|---|
| 131 | typedef ::G1BarrierSet type; | 
|---|
| 132 | }; | 
|---|
| 133 |  | 
|---|
| 134 | #endif // SHARE_GC_G1_G1BARRIERSET_HPP | 
|---|
| 135 |  | 
|---|