< prev index next >

src/hotspot/share/oops/arrayOop.hpp

Print this page

 58 #ifdef _LP64
 59     if (type == T_OBJECT || type == T_ARRAY) {
 60       return !UseCompressedOops;
 61     }
 62 #endif
 63     return type == T_DOUBLE || type == T_LONG;
 64   }
 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     int hs = length_offset_in_bytes() + (int)sizeof(int);
 72 #ifdef ASSERT
 73     // make sure it isn't called before UseCompressedOops is initialized.
 74     static int 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   // mark-word when using compact headers (+UseCompactObjectHeaders), otherwise
 83   // after the compressed Klass*.
 84   static int length_offset_in_bytes() {

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

 58 #ifdef _LP64
 59     if (type == T_OBJECT || type == T_ARRAY) {
 60       return !UseCompressedOops;
 61     }
 62 #endif
 63     return type == T_DOUBLE || type == T_LONG;
 64   }
 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     int hs = length_offset_in_bytes() + (int)sizeof(int);
 72 #ifdef ASSERT
 73     // make sure it isn't called before UseCompressedOops is initialized.
 74     static int 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     assert(!UseCompactObjectHeaders || hs == 8, "array header must be 8 bytes");
 79     return (int)hs;
 80   }
 81 
 82   // The _length field is not declared in C++.  It is allocated after the
 83   // mark-word when using compact headers (+UseCompactObjectHeaders), otherwise
 84   // after the compressed Klass*.
 85   static int length_offset_in_bytes() {
 86     assert(!UseCompactObjectHeaders || oopDesc::base_offset_in_bytes() == 4, "array length must be at 4 bytes");
 87     return oopDesc::base_offset_in_bytes();
 88   }
 89 
 90   // Returns the offset of the first element.
 91   static int base_offset_in_bytes(BasicType type) {
 92     int hs = header_size_in_bytes();
 93     return element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs;
 94   }
 95 
 96   // Returns the address of the first element. The elements in the array will not
 97   // relocate from this address until a subsequent thread transition.
 98   void* base(BasicType type) const {
 99     return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + base_offset_in_bytes(type));
100   }
101 
102   template <typename T>
103   static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {
104     if (obj != nullptr) {
105       assert(raw == nullptr, "either raw or in-heap");
106       char* base = reinterpret_cast<char*>((void*) obj);
< prev index next >