1 /*
  2  * Copyright (c) 2015, 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 #ifndef SHARE_GC_Z_ZBARRIERSET_HPP
 25 #define SHARE_GC_Z_ZBARRIERSET_HPP
 26 
 27 #include "gc/shared/barrierSet.hpp"
 28 
 29 class ZBarrierSetAssembler;
 30 
 31 class ZBarrierSet : public BarrierSet {
 32 public:
 33   ZBarrierSet();
 34 
 35   static ZBarrierSetAssembler* assembler();
 36   static bool barrier_needed(DecoratorSet decorators, BasicType type);
 37 
 38   // Loom support
 39   static constexpr bool is_concurrent_gc() { return true; }
 40   static bool requires_barriers(oop obj);
 41 
 42   virtual void on_thread_create(Thread* thread);
 43   virtual void on_thread_destroy(Thread* thread);
 44   virtual void on_thread_attach(Thread* thread);
 45   virtual void on_thread_detach(Thread* thread);
 46 
 47   virtual void print_on(outputStream* st) const;
 48 
 49   template <DecoratorSet decorators, typename BarrierSetT = ZBarrierSet>
 50   class AccessBarrier : public BarrierSet::AccessBarrier<decorators, BarrierSetT> {
 51   private:
 52     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
 53 
 54     template <DecoratorSet expected>
 55     static void verify_decorators_present();
 56 
 57     template <DecoratorSet expected>
 58     static void verify_decorators_absent();
 59 
 60     static oop* field_addr(oop base, ptrdiff_t offset);
 61 
 62     template <typename T>
 63     static oop load_barrier_on_oop_field_preloaded(T* addr, oop o);
 64 
 65     template <typename T>
 66     static oop load_barrier_on_unknown_oop_field_preloaded(oop base, ptrdiff_t offset, T* addr, oop o);
 67 
 68   public:
 69     //
 70     // In heap
 71     //
 72     template <typename T>
 73     static oop oop_load_in_heap(T* addr);
 74     static oop oop_load_in_heap_at(oop base, ptrdiff_t offset);
 75 
 76     template <typename T>
 77     static oop oop_atomic_cmpxchg_in_heap(T* addr, oop compare_value, oop new_value);
 78     static oop oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, oop new_value);
 79 
 80     template <typename T>
 81     static oop oop_atomic_xchg_in_heap(T* addr, oop new_value);
 82     static oop oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value);
 83 
 84     template <typename T>
 85     static bool oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
 86                                       arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
 87                                       size_t length);
 88 
 89     static void clone_in_heap(oop src, oop dst, size_t size);
 90 
 91     //
 92     // Not in heap
 93     //
 94     template <typename T>
 95     static oop oop_load_not_in_heap(T* addr);
 96 
 97     template <typename T>
 98     static oop oop_atomic_cmpxchg_not_in_heap(T* addr, oop compare_value, oop new_value);
 99 
100     template <typename T>
101     static oop oop_atomic_xchg_not_in_heap(T* addr, oop new_value);
102   };
103 };
104 
105 template<> struct BarrierSet::GetName<ZBarrierSet> {
106   static const BarrierSet::Name value = BarrierSet::ZBarrierSet;
107 };
108 
109 template<> struct BarrierSet::GetType<BarrierSet::ZBarrierSet> {
110   typedef ::ZBarrierSet type;
111 };
112 
113 #endif // SHARE_GC_Z_ZBARRIERSET_HPP