< prev index next >

src/hotspot/share/oops/access.inline.hpp

Print this page

  1 /*
  2  * Copyright (c) 2017, 2018, 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  *

108   template <class GCBarrierType, DecoratorSet decorators>
109   struct PostRuntimeDispatch<GCBarrierType, BARRIER_ATOMIC_CMPXCHG, decorators>: public AllStatic {
110     template <typename T>
111     static T access_barrier(void* addr, T compare_value, T new_value) {
112       return GCBarrierType::atomic_cmpxchg_in_heap(reinterpret_cast<T*>(addr), compare_value, new_value);
113     }
114 
115     static oop oop_access_barrier(void* addr, oop compare_value, oop new_value) {
116       typedef typename HeapOopType<decorators>::type OopType;
117       if (HasDecorator<decorators, IN_HEAP>::value) {
118         return GCBarrierType::oop_atomic_cmpxchg_in_heap(reinterpret_cast<OopType*>(addr), compare_value, new_value);
119       } else {
120         return GCBarrierType::oop_atomic_cmpxchg_not_in_heap(reinterpret_cast<OopType*>(addr), compare_value, new_value);
121       }
122     }
123   };
124 
125   template <class GCBarrierType, DecoratorSet decorators>
126   struct PostRuntimeDispatch<GCBarrierType, BARRIER_ARRAYCOPY, decorators>: public AllStatic {
127     template <typename T>
128     static bool access_barrier(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
129                                arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
130                                size_t length) {
131       GCBarrierType::arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw,
132                                        dst_obj, dst_offset_in_bytes, dst_raw,
133                                        length);
134       return true;
135     }
136 
137     template <typename T>
138     static bool oop_access_barrier(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
139                                    arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
140                                    size_t length) {
141       typedef typename HeapOopType<decorators>::type OopType;
142       return GCBarrierType::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, reinterpret_cast<OopType*>(src_raw),
143                                                   dst_obj, dst_offset_in_bytes, reinterpret_cast<OopType*>(dst_raw),
144                                                   length);
145     }
146   };
147 
148   template <class GCBarrierType, DecoratorSet decorators>
149   struct PostRuntimeDispatch<GCBarrierType, BARRIER_STORE_AT, decorators>: public AllStatic {
150     template <typename T>
151     static void access_barrier(oop base, ptrdiff_t offset, T value) {
152       GCBarrierType::store_in_heap_at(base, offset, value);
153     }
154 
155     static void oop_access_barrier(oop base, ptrdiff_t offset, oop value) {
156       GCBarrierType::oop_store_in_heap_at(base, offset, value);
157     }
158   };
159 
160   template <class GCBarrierType, DecoratorSet decorators>
161   struct PostRuntimeDispatch<GCBarrierType, BARRIER_LOAD_AT, decorators>: public AllStatic {
162     template <typename T>
163     static T access_barrier(oop base, ptrdiff_t offset) {
164       return GCBarrierType::template load_in_heap_at<T>(base, offset);

183 
184   template <class GCBarrierType, DecoratorSet decorators>
185   struct PostRuntimeDispatch<GCBarrierType, BARRIER_ATOMIC_CMPXCHG_AT, decorators>: public AllStatic {
186     template <typename T>
187     static T access_barrier(oop base, ptrdiff_t offset, T compare_value, T new_value) {
188       return GCBarrierType::atomic_cmpxchg_in_heap_at(base, offset, compare_value, new_value);
189     }
190 
191     static oop oop_access_barrier(oop base, ptrdiff_t offset, oop compare_value, oop new_value) {
192       return GCBarrierType::oop_atomic_cmpxchg_in_heap_at(base, offset, compare_value, new_value);
193     }
194   };
195 
196   template <class GCBarrierType, DecoratorSet decorators>
197   struct PostRuntimeDispatch<GCBarrierType, BARRIER_CLONE, decorators>: public AllStatic {
198     static void access_barrier(oop src, oop dst, size_t size) {
199       GCBarrierType::clone_in_heap(src, dst, size);
200     }
201   };
202 







203   // Resolving accessors with barriers from the barrier set happens in two steps.
204   // 1. Expand paths with runtime-decorators, e.g. is UseCompressedOops on or off.
205   // 2. Expand paths for each BarrierSet available in the system.
206   template <DecoratorSet decorators, typename FunctionPointerT, BarrierType barrier_type>
207   struct BarrierResolver: public AllStatic {
208     template <DecoratorSet ds>
209     static typename EnableIf<
210       HasDecorator<ds, INTERNAL_VALUE_IS_OOP>::value,
211       FunctionPointerT>::type
212     resolve_barrier_gc() {
213       BarrierSet* bs = BarrierSet::barrier_set();
214       assert(bs != NULL, "GC barriers invoked before BarrierSet is set");
215       switch (bs->kind()) {
216 #define BARRIER_SET_RESOLVE_BARRIER_CLOSURE(bs_name)                    \
217         case BarrierSet::bs_name: {                                     \
218           return PostRuntimeDispatch<typename BarrierSet::GetType<BarrierSet::bs_name>::type:: \
219             AccessBarrier<ds>, barrier_type, ds>::oop_access_barrier; \
220         }                                                               \
221         break;
222         FOR_EACH_CONCRETE_BARRIER_SET_DO(BARRIER_SET_RESOLVE_BARRIER_CLOSURE)

314     func_t function = BarrierResolver<decorators, func_t, BARRIER_ATOMIC_CMPXCHG_AT>::resolve_barrier();
315     _atomic_cmpxchg_at_func = function;
316     return function(base, offset, compare_value, new_value);
317   }
318 
319   template <DecoratorSet decorators, typename T>
320   T RuntimeDispatch<decorators, T, BARRIER_ATOMIC_XCHG>::atomic_xchg_init(void* addr, T new_value) {
321     func_t function = BarrierResolver<decorators, func_t, BARRIER_ATOMIC_XCHG>::resolve_barrier();
322     _atomic_xchg_func = function;
323     return function(addr, new_value);
324   }
325 
326   template <DecoratorSet decorators, typename T>
327   T RuntimeDispatch<decorators, T, BARRIER_ATOMIC_XCHG_AT>::atomic_xchg_at_init(oop base, ptrdiff_t offset, T new_value) {
328     func_t function = BarrierResolver<decorators, func_t, BARRIER_ATOMIC_XCHG_AT>::resolve_barrier();
329     _atomic_xchg_at_func = function;
330     return function(base, offset, new_value);
331   }
332 
333   template <DecoratorSet decorators, typename T>
334   bool RuntimeDispatch<decorators, T, BARRIER_ARRAYCOPY>::arraycopy_init(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
335                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
336                                                                          size_t length) {
337     func_t function = BarrierResolver<decorators, func_t, BARRIER_ARRAYCOPY>::resolve_barrier();
338     _arraycopy_func = function;
339     return function(src_obj, src_offset_in_bytes, src_raw,
340                     dst_obj, dst_offset_in_bytes, dst_raw,
341                     length);
342   }
343 
344   template <DecoratorSet decorators, typename T>
345   void RuntimeDispatch<decorators, T, BARRIER_CLONE>::clone_init(oop src, oop dst, size_t size) {
346     func_t function = BarrierResolver<decorators, func_t, BARRIER_CLONE>::resolve_barrier();
347     _clone_func = function;
348     function(src, dst, size);
349   }







350 }
351 
352 #endif // SHARE_OOPS_ACCESS_INLINE_HPP

  1 /*
  2  * Copyright (c) 2017, 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  *

108   template <class GCBarrierType, DecoratorSet decorators>
109   struct PostRuntimeDispatch<GCBarrierType, BARRIER_ATOMIC_CMPXCHG, decorators>: public AllStatic {
110     template <typename T>
111     static T access_barrier(void* addr, T compare_value, T new_value) {
112       return GCBarrierType::atomic_cmpxchg_in_heap(reinterpret_cast<T*>(addr), compare_value, new_value);
113     }
114 
115     static oop oop_access_barrier(void* addr, oop compare_value, oop new_value) {
116       typedef typename HeapOopType<decorators>::type OopType;
117       if (HasDecorator<decorators, IN_HEAP>::value) {
118         return GCBarrierType::oop_atomic_cmpxchg_in_heap(reinterpret_cast<OopType*>(addr), compare_value, new_value);
119       } else {
120         return GCBarrierType::oop_atomic_cmpxchg_not_in_heap(reinterpret_cast<OopType*>(addr), compare_value, new_value);
121       }
122     }
123   };
124 
125   template <class GCBarrierType, DecoratorSet decorators>
126   struct PostRuntimeDispatch<GCBarrierType, BARRIER_ARRAYCOPY, decorators>: public AllStatic {
127     template <typename T>
128     static void access_barrier(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
129                                arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
130                                size_t length) {
131       GCBarrierType::arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw,
132                                        dst_obj, dst_offset_in_bytes, dst_raw,
133                                        length);

134     }
135 
136     template <typename T>
137     static void oop_access_barrier(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
138                                    arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
139                                    size_t length) {
140       typedef typename HeapOopType<decorators>::type OopType;
141       GCBarrierType::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, reinterpret_cast<OopType*>(src_raw),
142                                            dst_obj, dst_offset_in_bytes, reinterpret_cast<OopType*>(dst_raw),
143                                            length);
144     }
145   };
146 
147   template <class GCBarrierType, DecoratorSet decorators>
148   struct PostRuntimeDispatch<GCBarrierType, BARRIER_STORE_AT, decorators>: public AllStatic {
149     template <typename T>
150     static void access_barrier(oop base, ptrdiff_t offset, T value) {
151       GCBarrierType::store_in_heap_at(base, offset, value);
152     }
153 
154     static void oop_access_barrier(oop base, ptrdiff_t offset, oop value) {
155       GCBarrierType::oop_store_in_heap_at(base, offset, value);
156     }
157   };
158 
159   template <class GCBarrierType, DecoratorSet decorators>
160   struct PostRuntimeDispatch<GCBarrierType, BARRIER_LOAD_AT, decorators>: public AllStatic {
161     template <typename T>
162     static T access_barrier(oop base, ptrdiff_t offset) {
163       return GCBarrierType::template load_in_heap_at<T>(base, offset);

182 
183   template <class GCBarrierType, DecoratorSet decorators>
184   struct PostRuntimeDispatch<GCBarrierType, BARRIER_ATOMIC_CMPXCHG_AT, decorators>: public AllStatic {
185     template <typename T>
186     static T access_barrier(oop base, ptrdiff_t offset, T compare_value, T new_value) {
187       return GCBarrierType::atomic_cmpxchg_in_heap_at(base, offset, compare_value, new_value);
188     }
189 
190     static oop oop_access_barrier(oop base, ptrdiff_t offset, oop compare_value, oop new_value) {
191       return GCBarrierType::oop_atomic_cmpxchg_in_heap_at(base, offset, compare_value, new_value);
192     }
193   };
194 
195   template <class GCBarrierType, DecoratorSet decorators>
196   struct PostRuntimeDispatch<GCBarrierType, BARRIER_CLONE, decorators>: public AllStatic {
197     static void access_barrier(oop src, oop dst, size_t size) {
198       GCBarrierType::clone_in_heap(src, dst, size);
199     }
200   };
201 
202   template <class GCBarrierType, DecoratorSet decorators>
203   struct PostRuntimeDispatch<GCBarrierType, BARRIER_VALUE_COPY, decorators>: public AllStatic {
204     static void access_barrier(void* src, void* dst, InlineKlass* md) {
205       GCBarrierType::value_copy_in_heap(src, dst, md);
206     }
207   };
208 
209   // Resolving accessors with barriers from the barrier set happens in two steps.
210   // 1. Expand paths with runtime-decorators, e.g. is UseCompressedOops on or off.
211   // 2. Expand paths for each BarrierSet available in the system.
212   template <DecoratorSet decorators, typename FunctionPointerT, BarrierType barrier_type>
213   struct BarrierResolver: public AllStatic {
214     template <DecoratorSet ds>
215     static typename EnableIf<
216       HasDecorator<ds, INTERNAL_VALUE_IS_OOP>::value,
217       FunctionPointerT>::type
218     resolve_barrier_gc() {
219       BarrierSet* bs = BarrierSet::barrier_set();
220       assert(bs != NULL, "GC barriers invoked before BarrierSet is set");
221       switch (bs->kind()) {
222 #define BARRIER_SET_RESOLVE_BARRIER_CLOSURE(bs_name)                    \
223         case BarrierSet::bs_name: {                                     \
224           return PostRuntimeDispatch<typename BarrierSet::GetType<BarrierSet::bs_name>::type:: \
225             AccessBarrier<ds>, barrier_type, ds>::oop_access_barrier; \
226         }                                                               \
227         break;
228         FOR_EACH_CONCRETE_BARRIER_SET_DO(BARRIER_SET_RESOLVE_BARRIER_CLOSURE)

320     func_t function = BarrierResolver<decorators, func_t, BARRIER_ATOMIC_CMPXCHG_AT>::resolve_barrier();
321     _atomic_cmpxchg_at_func = function;
322     return function(base, offset, compare_value, new_value);
323   }
324 
325   template <DecoratorSet decorators, typename T>
326   T RuntimeDispatch<decorators, T, BARRIER_ATOMIC_XCHG>::atomic_xchg_init(void* addr, T new_value) {
327     func_t function = BarrierResolver<decorators, func_t, BARRIER_ATOMIC_XCHG>::resolve_barrier();
328     _atomic_xchg_func = function;
329     return function(addr, new_value);
330   }
331 
332   template <DecoratorSet decorators, typename T>
333   T RuntimeDispatch<decorators, T, BARRIER_ATOMIC_XCHG_AT>::atomic_xchg_at_init(oop base, ptrdiff_t offset, T new_value) {
334     func_t function = BarrierResolver<decorators, func_t, BARRIER_ATOMIC_XCHG_AT>::resolve_barrier();
335     _atomic_xchg_at_func = function;
336     return function(base, offset, new_value);
337   }
338 
339   template <DecoratorSet decorators, typename T>
340   void RuntimeDispatch<decorators, T, BARRIER_ARRAYCOPY>::arraycopy_init(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
341                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
342                                                                          size_t length) {
343     func_t function = BarrierResolver<decorators, func_t, BARRIER_ARRAYCOPY>::resolve_barrier();
344     _arraycopy_func = function;
345     function(src_obj, src_offset_in_bytes, src_raw,
346              dst_obj, dst_offset_in_bytes, dst_raw,
347              length);
348   }
349 
350   template <DecoratorSet decorators, typename T>
351   void RuntimeDispatch<decorators, T, BARRIER_CLONE>::clone_init(oop src, oop dst, size_t size) {
352     func_t function = BarrierResolver<decorators, func_t, BARRIER_CLONE>::resolve_barrier();
353     _clone_func = function;
354     function(src, dst, size);
355   }
356 
357   template <DecoratorSet decorators, typename T>
358   void RuntimeDispatch<decorators, T, BARRIER_VALUE_COPY>::value_copy_init(void* src, void* dst, InlineKlass* md) {
359     func_t function = BarrierResolver<decorators, func_t, BARRIER_VALUE_COPY>::resolve_barrier();
360     _value_copy_func = function;
361     function(src, dst, md);
362   }
363 }
364 
365 #endif // SHARE_OOPS_ACCESS_INLINE_HPP
< prev index next >