1 /*
  2  * Copyright (c) 2015, 2023, 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 #ifndef SHARE_GC_Z_ZBARRIERSET_HPP
 25 #define SHARE_GC_Z_ZBARRIERSET_HPP
 26 
 27 #include "gc/shared/barrierSet.hpp"
 28 #include "gc/z/zAddress.hpp"
 29 
 30 class ZBarrierSetAssembler;
 31 
 32 class ZBarrierSet : public BarrierSet {
 33 private:
 34   static zpointer store_good(oop obj);
 35 
 36 public:
 37   ZBarrierSet();
 38 
 39   static ZBarrierSetAssembler* assembler();
 40   static bool barrier_needed(DecoratorSet decorators, BasicType type);
 41 
 42   static void clone_obj_array(objArrayOop src, objArrayOop dst, size_t size);
 43 
 44   virtual void on_thread_create(Thread* thread);
 45   virtual void on_thread_destroy(Thread* thread);
 46   virtual void on_thread_attach(Thread* thread);
 47   virtual void on_thread_detach(Thread* thread);
 48 
 49   virtual void on_slowpath_allocation_exit(JavaThread* thread, oop new_obj);
 50 
 51   virtual void print_on(outputStream* st) const;
 52 
 53   enum OopCopyCheckStatus {
 54     oop_copy_check_ok = 0,         // oop array copy sucessful
 55     oop_copy_check_class_cast = 1, // oop array copy failed subtype check (ARRAYCOPY_CHECKCAST)
 56     oop_copy_check_null = 2        // oop array copy failed null check (ARRAYCOPY_NOTNULL)
 57   };
 58 
 59   template <DecoratorSet decorators, typename BarrierSetT = ZBarrierSet>
 60   class AccessBarrier : public BarrierSet::AccessBarrier<decorators, BarrierSetT> {
 61   private:
 62     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
 63 
 64     template <DecoratorSet expected>
 65     static void verify_decorators_present();
 66 
 67     template <DecoratorSet expected>
 68     static void verify_decorators_absent();
 69 
 70     static zpointer* field_addr(oop base, ptrdiff_t offset);
 71 
 72     static zaddress load_barrier(zpointer* p, zpointer o);
 73     static zaddress load_barrier_on_unknown_oop_ref(oop base, ptrdiff_t offset, zpointer* p, zpointer o);
 74 
 75     static void store_barrier_heap_with_healing(zpointer* p);
 76     static void store_barrier_heap_without_healing(zpointer* p);
 77     static void no_keep_alive_store_barrier_heap(zpointer* p);
 78 
 79     static void store_barrier_native_with_healing(zpointer* p);
 80     static void store_barrier_native_without_healing(zpointer* p);
 81 
 82     static void unsupported();
 83     static zaddress load_barrier(narrowOop* p, zpointer o) { unsupported(); return zaddress::null; }
 84     static zaddress load_barrier_on_unknown_oop_ref(oop base, ptrdiff_t offset, narrowOop* p, zpointer o) { unsupported(); return zaddress::null; }
 85     static void store_barrier_heap_with_healing(narrowOop* p) { unsupported(); }
 86     static void store_barrier_heap_without_healing(narrowOop* p)  { unsupported(); }
 87     static void no_keep_alive_store_barrier_heap(narrowOop* p)  { unsupported(); }
 88     static void store_barrier_native_with_healing(narrowOop* p)  { unsupported(); }
 89     static void store_barrier_native_without_healing(narrowOop* p)  { unsupported(); }
 90 
 91     static zaddress oop_copy_one_barriers(zpointer* dst, zpointer* src);
 92     static OopCopyCheckStatus oop_copy_one_check_cast(zpointer* dst, zpointer* src, Klass* dst_klass);
 93     static OopCopyCheckStatus oop_copy_one(zpointer* dst, zpointer* src);
 94 
 95     static OopCopyCheckStatus oop_arraycopy_in_heap_check_cast(zpointer* dst, zpointer* src, size_t length, Klass* dst_klass);
 96     static OopCopyCheckStatus oop_arraycopy_in_heap_no_check_cast(zpointer* dst, zpointer* src, size_t length);
 97 
 98   public:
 99     //
100     // In heap
101     //
102     static oop oop_load_in_heap(zpointer* p);
103     static oop oop_load_in_heap(oop* p)       { return oop_load_in_heap((zpointer*)p); };
104     static oop oop_load_in_heap(narrowOop* p) { unsupported(); return nullptr; }
105 
106     static oop oop_load_in_heap_at(oop base, ptrdiff_t offset);
107 
108     static void oop_store_in_heap(zpointer* p, oop value);
109     static void oop_store_in_heap(oop* p, oop value)       { oop_store_in_heap((zpointer*)p, value); }
110     static void oop_store_in_heap(narrowOop* p, oop value) { unsupported(); }
111     static void oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value);
112 
113     static void oop_store_not_in_heap(zpointer* p, oop value);
114     static void oop_store_not_in_heap(oop* p, oop value)       { oop_store_not_in_heap((zpointer*)p, value); }
115     static void oop_store_not_in_heap(narrowOop* p, oop value) { unsupported(); }
116     static void oop_store_not_in_heap_at(oop base, ptrdiff_t offset, oop value);
117 
118     static oop oop_atomic_cmpxchg_in_heap(zpointer* p, oop compare_value, oop new_value);
119     static oop oop_atomic_cmpxchg_in_heap(oop* p, oop compare_value, oop new_value)       { return oop_atomic_cmpxchg_in_heap((zpointer*)p, compare_value, new_value); }
120     static oop oop_atomic_cmpxchg_in_heap(narrowOop* p, oop compare_value, oop new_value) { unsupported(); return nullptr; }
121     static oop oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, oop new_value);
122 
123     static oop oop_atomic_xchg_in_heap(zpointer* p, oop new_value);
124     static oop oop_atomic_xchg_in_heap(oop* p, oop new_value)       { return oop_atomic_xchg_in_heap((zpointer*)p, new_value); }
125     static oop oop_atomic_xchg_in_heap(narrowOop* p, oop new_value) { unsupported(); return nullptr; }
126     static oop oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value);
127 
128     static void oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
129                                       arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
130                                       size_t length);
131     static void oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, oop* src_raw,
132                                       arrayOop dst_obj, size_t dst_offset_in_bytes, oop* dst_raw,
133                                       size_t length) {
134       oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, (zpointer*)src_raw,
135                             dst_obj, dst_offset_in_bytes, (zpointer*)dst_raw,
136                             length);
137     }
138     static void oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, narrowOop* src_raw,
139                                       arrayOop dst_obj, size_t dst_offset_in_bytes, narrowOop* dst_raw,
140                                       size_t length) { unsupported(); }
141 
142     static void clone_in_heap(oop src, oop dst, size_t size);
143 
144     static void value_copy_in_heap(void* src, void* dst, InlineKlass* md);
145 
146     //
147     // Not in heap
148     //
149     static oop oop_load_not_in_heap(zpointer* p);
150     static oop oop_load_not_in_heap(oop* p);
151     static oop oop_load_not_in_heap(narrowOop* p) { unsupported(); return nullptr; }
152 
153     static oop oop_atomic_cmpxchg_not_in_heap(zpointer* p, oop compare_value, oop new_value);
154     static oop oop_atomic_cmpxchg_not_in_heap(oop* p, oop compare_value, oop new_value) {
155       return oop_atomic_cmpxchg_not_in_heap((zpointer*)p, compare_value, new_value);
156     }
157     static oop oop_atomic_cmpxchg_not_in_heap(narrowOop* addr, oop compare_value, oop new_value) { unsupported(); return nullptr; }
158 
159     static oop oop_atomic_xchg_not_in_heap(zpointer* p, oop new_value);
160     static oop oop_atomic_xchg_not_in_heap(oop* p, oop new_value)       { return oop_atomic_xchg_not_in_heap((zpointer*)p, new_value); }
161     static oop oop_atomic_xchg_not_in_heap(narrowOop* p, oop new_value) { unsupported(); return nullptr; }
162   };
163 };
164 
165 template<> struct BarrierSet::GetName<ZBarrierSet> {
166   static const BarrierSet::Name value = BarrierSet::ZBarrierSet;
167 };
168 
169 template<> struct BarrierSet::GetType<BarrierSet::ZBarrierSet> {
170   typedef ::ZBarrierSet type;
171 };
172 
173 #endif // SHARE_GC_Z_ZBARRIERSET_HPP
--- EOF ---