< prev index next >

src/hotspot/share/oops/arrayOop.hpp

Print this page

 65 
 66  public:
 67   // Header size computation.
 68   // The header is considered the oop part of this type plus the length.
 69   // This is not equivalent to sizeof(arrayOopDesc) which should not appear in the code.
 70   static int header_size_in_bytes() {
 71     size_t hs = length_offset_in_bytes() + sizeof(int);
 72 #ifdef ASSERT
 73     // make sure it isn't called before UseCompressedOops is initialized.
 74     static size_t arrayoopdesc_hs = 0;
 75     if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
 76     assert(arrayoopdesc_hs == hs, "header size can't change");
 77 #endif // ASSERT
 78     return (int)hs;
 79   }
 80 
 81   // The _length field is not declared in C++.  It is allocated after the
 82   // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
 83   // it occupies the second half of the _klass field in oopDesc.
 84   static int length_offset_in_bytes() {
 85     return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
 86                                sizeof(arrayOopDesc);





 87   }
 88 
 89   // Returns the offset of the first element.
 90   static int base_offset_in_bytes(BasicType type) {
 91     size_t hs = header_size_in_bytes();
 92     return (int)(element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs);
 93   }
 94 
 95   // Returns the address of the first element. The elements in the array will not
 96   // relocate from this address until a subsequent thread transition.
 97   void* base(BasicType type) const {
 98     return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + base_offset_in_bytes(type));
 99   }
100 
101   template <typename T>
102   static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {
103     if (obj != nullptr) {
104       assert(raw == nullptr, "either raw or in-heap");
105       char* base = reinterpret_cast<char*>((void*) obj);
106       raw = reinterpret_cast<T*>(base + offset_in_bytes);

 65 
 66  public:
 67   // Header size computation.
 68   // The header is considered the oop part of this type plus the length.
 69   // This is not equivalent to sizeof(arrayOopDesc) which should not appear in the code.
 70   static int header_size_in_bytes() {
 71     size_t hs = length_offset_in_bytes() + sizeof(int);
 72 #ifdef ASSERT
 73     // make sure it isn't called before UseCompressedOops is initialized.
 74     static size_t arrayoopdesc_hs = 0;
 75     if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
 76     assert(arrayoopdesc_hs == hs, "header size can't change");
 77 #endif // ASSERT
 78     return (int)hs;
 79   }
 80 
 81   // The _length field is not declared in C++.  It is allocated after the
 82   // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
 83   // it occupies the second half of the _klass field in oopDesc.
 84   static int length_offset_in_bytes() {
 85     if (UseCompactObjectHeaders) {
 86       return oopDesc::base_offset_in_bytes();
 87     } else if (UseCompressedClassPointers) {
 88       return klass_gap_offset_in_bytes();
 89     } else {
 90       return sizeof(arrayOopDesc);
 91     }
 92   }
 93 
 94   // Returns the offset of the first element.
 95   static int base_offset_in_bytes(BasicType type) {
 96     size_t hs = header_size_in_bytes();
 97     return (int)(element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs);
 98   }
 99 
100   // Returns the address of the first element. The elements in the array will not
101   // relocate from this address until a subsequent thread transition.
102   void* base(BasicType type) const {
103     return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + base_offset_in_bytes(type));
104   }
105 
106   template <typename T>
107   static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {
108     if (obj != nullptr) {
109       assert(raw == nullptr, "either raw or in-heap");
110       char* base = reinterpret_cast<char*>((void*) obj);
111       raw = reinterpret_cast<T*>(base + offset_in_bytes);
< prev index next >