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   template <DecoratorSet decorators, typename BarrierSetT = ZBarrierSet>
 54   class AccessBarrier : public BarrierSet::AccessBarrier<decorators, BarrierSetT> {
 55   private:
 56     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
 57 
 58     template <DecoratorSet expected>
 59     static void verify_decorators_present();
 60 
 61     template <DecoratorSet expected>
 62     static void verify_decorators_absent();
 63 
 64     static zpointer* field_addr(oop base, ptrdiff_t offset);
 65 
 66     static zaddress load_barrier(zpointer* p, zpointer o);
 67     static zaddress load_barrier_on_unknown_oop_ref(oop base, ptrdiff_t offset, zpointer* p, zpointer o);
 68 
 69     static void store_barrier_heap_with_healing(zpointer* p);
 70     static void store_barrier_heap_without_healing(zpointer* p);
 71     static void no_keep_alive_store_barrier_heap(zpointer* p);
 72 
 73     static void store_barrier_native_with_healing(zpointer* p);
 74     static void store_barrier_native_without_healing(zpointer* p);
 75 
 76     static void unsupported();
 77     static zaddress load_barrier(narrowOop* p, zpointer o) { unsupported(); return zaddress::null; }
 78     static zaddress load_barrier_on_unknown_oop_ref(oop base, ptrdiff_t offset, narrowOop* p, zpointer o) { unsupported(); return zaddress::null; }
 79     static void store_barrier_heap_with_healing(narrowOop* p) { unsupported(); }
 80     static void store_barrier_heap_without_healing(narrowOop* p)  { unsupported(); }
 81     static void no_keep_alive_store_barrier_heap(narrowOop* p)  { unsupported(); }
 82     static void store_barrier_native_with_healing(narrowOop* p)  { unsupported(); }
 83     static void store_barrier_native_without_healing(narrowOop* p)  { unsupported(); }
 84 
 85     static zaddress oop_copy_one_barriers(zpointer* dst, zpointer* src);
 86     static bool oop_copy_one_check_cast(zpointer* dst, zpointer* src, Klass* dst_klass);
 87     static void oop_copy_one(zpointer* dst, zpointer* src);
 88 
 89     static bool oop_arraycopy_in_heap_check_cast(zpointer* dst, zpointer* src, size_t length, Klass* dst_klass);
 90     static bool oop_arraycopy_in_heap_no_check_cast(zpointer* dst, zpointer* src, size_t length);
 91 
 92   public:
 93     //
 94     // In heap
 95     //
 96     static oop oop_load_in_heap(zpointer* p);
 97     static oop oop_load_in_heap(oop* p)       { return oop_load_in_heap((zpointer*)p); };
 98     static oop oop_load_in_heap(narrowOop* p) { unsupported(); return nullptr; }
 99 
100     static oop oop_load_in_heap_at(oop base, ptrdiff_t offset);
101 
102     static void oop_store_in_heap(zpointer* p, oop value);
103     static void oop_store_in_heap(oop* p, oop value)       { oop_store_in_heap((zpointer*)p, value); }
104     static void oop_store_in_heap(narrowOop* p, oop value) { unsupported(); }
105     static void oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value);
106 
107     static void oop_store_not_in_heap(zpointer* p, oop value);
108     static void oop_store_not_in_heap(oop* p, oop value)       { oop_store_not_in_heap((zpointer*)p, value); }
109     static void oop_store_not_in_heap(narrowOop* p, oop value) { unsupported(); }
110     static void oop_store_not_in_heap_at(oop base, ptrdiff_t offset, oop value);
111 
112     static oop oop_atomic_cmpxchg_in_heap(zpointer* p, oop compare_value, oop new_value);
113     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); }
114     static oop oop_atomic_cmpxchg_in_heap(narrowOop* p, oop compare_value, oop new_value) { unsupported(); return nullptr; }
115     static oop oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, oop new_value);
116 
117     static oop oop_atomic_xchg_in_heap(zpointer* p, oop new_value);
118     static oop oop_atomic_xchg_in_heap(oop* p, oop new_value)       { return oop_atomic_xchg_in_heap((zpointer*)p, new_value); }
119     static oop oop_atomic_xchg_in_heap(narrowOop* p, oop new_value) { unsupported(); return nullptr; }
120     static oop oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value);
121 
122     static bool oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
123                                       arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
124                                       size_t length);
125     static bool oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, oop* src_raw,
126                                       arrayOop dst_obj, size_t dst_offset_in_bytes, oop* dst_raw,
127                                       size_t length) {
128       return oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, (zpointer*)src_raw,
129                                    dst_obj, dst_offset_in_bytes, (zpointer*)dst_raw,
130                                    length);
131     }
132     static bool oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, narrowOop* src_raw,
133                                       arrayOop dst_obj, size_t dst_offset_in_bytes, narrowOop* dst_raw,
134                                       size_t length) { unsupported(); return false; }
135 
136     static void clone_in_heap(oop src, oop dst, size_t size);
137 


138     //
139     // Not in heap
140     //
141     static oop oop_load_not_in_heap(zpointer* p);
142     static oop oop_load_not_in_heap(oop* p);
143     static oop oop_load_not_in_heap(narrowOop* p) { unsupported(); return nullptr; }
144 
145     static oop oop_atomic_cmpxchg_not_in_heap(zpointer* p, oop compare_value, oop new_value);
146     static oop oop_atomic_cmpxchg_not_in_heap(oop* p, oop compare_value, oop new_value) {
147       return oop_atomic_cmpxchg_not_in_heap((zpointer*)p, compare_value, new_value);
148     }
149     static oop oop_atomic_cmpxchg_not_in_heap(narrowOop* addr, oop compare_value, oop new_value) { unsupported(); return nullptr; }
150 
151     static oop oop_atomic_xchg_not_in_heap(zpointer* p, oop new_value);
152     static oop oop_atomic_xchg_not_in_heap(oop* p, oop new_value)       { return oop_atomic_xchg_not_in_heap((zpointer*)p, new_value); }
153     static oop oop_atomic_xchg_not_in_heap(narrowOop* p, oop new_value) { unsupported(); return nullptr; }
154   };
155 };
156 
157 template<> struct BarrierSet::GetName<ZBarrierSet> {
158   static const BarrierSet::Name value = BarrierSet::ZBarrierSet;
159 };
160 
161 template<> struct BarrierSet::GetType<BarrierSet::ZBarrierSet> {
162   typedef ::ZBarrierSet type;
163 };
164 
165 #endif // SHARE_GC_Z_ZBARRIERSET_HPP
--- EOF ---