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   virtual void on_thread_create(Thread* thread);
  39   virtual void on_thread_destroy(Thread* thread);
  40   virtual void on_thread_attach(Thread* thread);
  41   virtual void on_thread_detach(Thread* thread);
  42 
  43   virtual void print_on(outputStream* st) const;
  44 
  45   template <DecoratorSet decorators, typename BarrierSetT = ZBarrierSet>
  46   class AccessBarrier : public BarrierSet::AccessBarrier<decorators, BarrierSetT> {
  47   private:
  48     typedef BarrierSet::AccessBarrier<decorators, BarrierSetT> Raw;
  49 
  50     template <DecoratorSet expected>
  51     static void verify_decorators_present();
  52 
  53     template <DecoratorSet expected>
  54     static void verify_decorators_absent();
  55 
  56     static oop* field_addr(oop base, ptrdiff_t offset);
  57 
  58     template <typename T>
  59     static oop load_barrier_on_oop_field_preloaded(T* addr, oop o);
  60 
  61     template <typename T>
  62     static oop load_barrier_on_unknown_oop_field_preloaded(oop base, ptrdiff_t offset, T* addr, oop o);
  63 
  64   public:
  65     //
  66     // In heap
  67     //
  68     template <typename T>
  69     static oop oop_load_in_heap(T* addr);
  70     static oop oop_load_in_heap_at(oop base, ptrdiff_t offset);
  71 
  72     template <typename T>
  73     static oop oop_atomic_cmpxchg_in_heap(T* addr, oop compare_value, oop new_value);
  74     static oop oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, oop new_value);
  75 
  76     template <typename T>
  77     static oop oop_atomic_xchg_in_heap(T* addr, oop new_value);
  78     static oop oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value);
  79 
  80     template <typename T>
  81     static bool oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
  82                                       arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
  83                                       size_t length);
  84 
  85     static void clone_in_heap(oop src, oop dst, size_t size);
  86 
  87     //
  88     // Not in heap
  89     //
  90     template <typename T>
  91     static oop oop_load_not_in_heap(T* addr);
  92 
  93     template <typename T>
  94     static oop oop_atomic_cmpxchg_not_in_heap(T* addr, oop compare_value, oop new_value);
  95 
  96     template <typename T>
  97     static oop oop_atomic_xchg_not_in_heap(T* addr, oop new_value);
  98   };
  99 };
 100 
 101 template<> struct BarrierSet::GetName<ZBarrierSet> {
 102   static const BarrierSet::Name value = BarrierSet::ZBarrierSet;
 103 };
 104 
 105 template<> struct BarrierSet::GetType<BarrierSet::ZBarrierSet> {
 106   typedef ::ZBarrierSet type;
 107 };
 108 
 109 #endif // SHARE_GC_Z_ZBARRIERSET_HPP