< prev index next >

src/hotspot/share/oops/access.hpp

erik arraycopy
 // * store_at: Store a value in an internal pointer relative to a base object.
 // * atomic_cmpxchg: Atomically compare-and-swap a new value at an address if previous value matched the compared value.
 // * atomic_cmpxchg_at: Atomically compare-and-swap a new value at an internal pointer address if previous value matched the compared value.
 // * atomic_xchg: Atomically swap a new value at an address if previous value matched the compared value.
 // * atomic_xchg_at: Atomically swap a new value at an internal pointer address if previous value matched the compared value.
-// * arraycopy: Copy data from one heap array to another heap array.
+// * arraycopy: Copy data from one heap array to another heap array. The ArrayAccess class has convenience functions for this.
 // * clone: Clone the contents of an object to a newly allocated object.
 // * resolve: Resolve a stable to-space invariant oop that is guaranteed not to relocate its payload until a subsequent thread transition.
 // * equals: Object equality, e.g. when different copies of the same objects are in use (from-space vs. to-space)
 //
 // == IMPLEMENTATION ==

@@ -128,10 +128,33 static const DecoratorSet load_mo_decorators = MO_UNORDERED | MO_VOLATILE | MO_RELAXED | MO_ACQUIRE | MO_SEQ_CST; static const DecoratorSet store_mo_decorators = MO_UNORDERED | MO_VOLATILE | MO_RELAXED | MO_RELEASE | MO_SEQ_CST; static const DecoratorSet atomic_xchg_mo_decorators = MO_SEQ_CST; static const DecoratorSet atomic_cmpxchg_mo_decorators = MO_RELAXED | MO_SEQ_CST; +protected: + template <typename T> + static inline bool oop_arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, const T* src_raw, + arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw, + size_t length) { + verify_decorators<ARRAYCOPY_DECORATOR_MASK | IN_HEAP | IN_HEAP_ARRAY | + AS_DECORATOR_MASK>(); + return AccessInternal::arraycopy<decorators | INTERNAL_VALUE_IS_OOP>(src_obj, src_offset_in_bytes, src_raw, + dst_obj, dst_offset_in_bytes, dst_raw, + length); + } + + template <typename T> + static inline void arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, const T* src_raw, + arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw, + size_t length) { + verify_decorators<ARRAYCOPY_DECORATOR_MASK | IN_HEAP | IN_HEAP_ARRAY | + AS_DECORATOR_MASK>(); + AccessInternal::arraycopy<decorators>(src_obj, src_offset_in_bytes, src_raw, + dst_obj, dst_offset_in_bytes, dst_raw, + length); + } + public: // Primitive heap accesses static inline AccessInternal::LoadAtProxy<decorators> load_at(oop base, ptrdiff_t offset) { verify_primitive_decorators<load_mo_decorators>(); return AccessInternal::LoadAtProxy<decorators>(base, offset);
@@ -153,21 +176,10 static inline T atomic_xchg_at(T new_value, oop base, ptrdiff_t offset) { verify_primitive_decorators<atomic_xchg_mo_decorators>(); return AccessInternal::atomic_xchg_at<decorators>(new_value, base, offset); } - template <typename T> - static inline void arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, const T* src_raw, - arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw, - size_t length) { - verify_decorators<ARRAYCOPY_DECORATOR_MASK | IN_HEAP | IN_HEAP_ARRAY | - AS_DECORATOR_MASK>(); - AccessInternal::arraycopy<decorators>(src_obj, src_offset_in_bytes, src_raw, - dst_obj, dst_offset_in_bytes, dst_raw, - length); - } - // Oop heap accesses static inline AccessInternal::OopLoadAtProxy<decorators> oop_load_at(oop base, ptrdiff_t offset) { verify_heap_oop_decorators<load_mo_decorators>(); return AccessInternal::OopLoadAtProxy<decorators>(base, offset); }
@@ -195,21 +207,10 typedef typename AccessInternal::OopOrNarrowOop<T>::type OopType; OopType new_oop_value = new_value; return AccessInternal::atomic_xchg_at<decorators | INTERNAL_VALUE_IS_OOP>(new_oop_value, base, offset); } - template <typename T> - static inline bool oop_arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, const T* src_raw, - arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw, - size_t length) { - verify_decorators<ARRAYCOPY_DECORATOR_MASK | IN_HEAP | IN_HEAP_ARRAY | - AS_DECORATOR_MASK>(); - return AccessInternal::arraycopy<decorators | INTERNAL_VALUE_IS_OOP>(src_obj, src_offset_in_bytes, src_raw, - dst_obj, dst_offset_in_bytes, dst_raw, - length); - } - // Clone an object from src to dst static inline void clone(oop src, oop dst, size_t size) { verify_decorators<IN_HEAP>(); AccessInternal::clone<decorators>(src, dst, size); }
@@ -298,43 +299,52 class RootAccess: public Access<IN_ROOT | decorators> {}; // Helper for array access. template <DecoratorSet decorators = INTERNAL_EMPTY> class ArrayAccess: public HeapAccess<IN_HEAP_ARRAY | decorators> { + typedef HeapAccess<IN_HEAP_ARRAY | decorators> AccessT; public: template <typename T> static inline void arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, arrayOop dst_obj, size_t dst_offset_in_bytes, size_t length) { - HeapAccess<decorators | IN_HEAP_ARRAY>::arraycopy(src_obj, src_offset_in_bytes, (const T*) NULL, - dst_obj, dst_offset_in_bytes, (T*) NULL, - length); + AccessT::arraycopy(src_obj, src_offset_in_bytes, reinterpret_cast<const T*>(NULL), + dst_obj, dst_offset_in_bytes, reinterpret_cast<T*>(NULL), + length); } template <typename T> - static inline void arraycopy_to_native(arrayOop src_obj, size_t src_offset_in_bytes, T* dst, size_t length) { - HeapAccess<decorators | IN_HEAP_ARRAY>::arraycopy(src_obj, src_offset_in_bytes, (const T*) NULL, - NULL, 0, dst, - length); + static inline void arraycopy_to_native(arrayOop src_obj, size_t src_offset_in_bytes, + T* dst, + size_t length) { + AccessT::arraycopy(src_obj, src_offset_in_bytes, reinterpret_cast<const T*>(NULL), + NULL, 0, dst, + length); } template <typename T> - static inline void arraycopy_from_native(const T* src, arrayOop dst_obj, size_t dst_offset_in_bytes, size_t length) { - HeapAccess<decorators | IN_HEAP_ARRAY>::arraycopy(NULL, 0, src, dst_obj, dst_offset_in_bytes, (T*) NULL, length); + static inline void arraycopy_from_native(const T* src, + arrayOop dst_obj, size_t dst_offset_in_bytes, + size_t length) { + AccessT::arraycopy(NULL, 0, src, + dst_obj, dst_offset_in_bytes, reinterpret_cast<T*>(NULL), + length); } - template <typename T> static inline bool oop_arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, arrayOop dst_obj, size_t dst_offset_in_bytes, size_t length) { - return HeapAccess<decorators | IN_HEAP_ARRAY>::oop_arraycopy(src_obj, src_offset_in_bytes, (const T*) NULL, - dst_obj, dst_offset_in_bytes, (T*) NULL, length); + return AccessT::oop_arraycopy(src_obj, src_offset_in_bytes, reinterpret_cast<const HeapWord*>(NULL), + dst_obj, dst_offset_in_bytes, reinterpret_cast<HeapWord*>(NULL), + length); } template <typename T> static inline bool oop_arraycopy_raw(T* src, T* dst, size_t length) { - return HeapAccess<decorators | IN_HEAP_ARRAY>::oop_arraycopy(NULL, 0, src, NULL, 0, dst, length); + return AccessT::oop_arraycopy(NULL, 0, src, + NULL, 0, dst, + length); } }; template <DecoratorSet decorators>
< prev index next >