1 /*
 2  * Copyright (c) 2000, 2017, 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_MODREFBARRIERSET_HPP
26 #define SHARE_VM_GC_SHARED_MODREFBARRIERSET_HPP
27 
28 #include "gc/shared/barrierSet.hpp"
29 #include "memory/memRegion.hpp"
30 
31 class Klass;
32 
33 class ModRefBarrierSet: public BarrierSet {
34 protected:
35   ModRefBarrierSet(const BarrierSet::FakeRtti& fake_rtti)
36     : BarrierSet(fake_rtti.add_tag(BarrierSet::ModRef)) { }
37   ~ModRefBarrierSet() { }
38 
39 public:
40   template <DecoratorSet decorators, typename T>
41   inline void write_ref_field_pre(T* addr) {}
42 
43   template <DecoratorSet decorators, typename T>
44   inline void write_ref_field_post(T *addr, oop new_value) {}
45 
46   // Causes all refs in "mr" to be assumed to be modified.
47   virtual void invalidate(MemRegion mr) = 0;
48 
49   // The caller guarantees that "mr" contains no references.  (Perhaps it's
50   // objects have been moved elsewhere.)
51   virtual void clear(MemRegion mr) = 0;
52 
53   // The ModRef abstraction introduces pre and post barriers
54   template <DecoratorSet decorators, typename BarrierSetT>
55   class AccessBarrier: public BarrierSet::AccessBarrier<decorators, BarrierSetT> {
56     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
57 
58   public:
59     template <typename T>
60     static void oop_store_in_heap(T* addr, oop value);
61     template <typename T>
62     static oop oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value);
63     template <typename T>
64     static oop oop_atomic_xchg_in_heap(oop new_value, T* addr);
65 
66     template <typename T>
67     static bool oop_arraycopy_in_heap(arrayOop src_obj, arrayOop dst_obj, T* src, T* dst, size_t length);
68 
69     static void clone_in_heap(oop src, oop dst, size_t size);
70 
71     static void oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value) {
72       oop_store_in_heap(AccessInternal::oop_field_addr<decorators>(base, offset), value);
73     }
74 
75     static oop oop_atomic_xchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset) {
76       return oop_atomic_xchg_in_heap(new_value, AccessInternal::oop_field_addr<decorators>(base, offset));
77     }
78 
79     static oop oop_atomic_cmpxchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset, oop compare_value) {
80       return oop_atomic_cmpxchg_in_heap(new_value, AccessInternal::oop_field_addr<decorators>(base, offset), compare_value);
81     }
82   };
83 };
84 
85 template<>
86 struct BarrierSet::GetName<ModRefBarrierSet> {
87   static const BarrierSet::Name value = BarrierSet::ModRef;
88 };
89 
90 #endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_HPP