< 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* when running with compressed class-pointers
 84   // (+UseCompressedClassPointers), or else after the full Klass*.
 85   static int length_offset_in_bytes() {

 86     return oopDesc::base_offset_in_bytes();
 87   }
 88 
 89   // Returns the offset of the first element.
 90   static int base_offset_in_bytes(BasicType type) {
 91     int hs = header_size_in_bytes();
 92     return 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);

 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* when running with compressed class-pointers
 85   // (+UseCompressedClassPointers), or else after the full Klass*.
 86   static int length_offset_in_bytes() {
 87     assert(!UseCompactObjectHeaders || oopDesc::base_offset_in_bytes() == 4, "array length must be at 4 bytes");
 88     return oopDesc::base_offset_in_bytes();
 89   }
 90 
 91   // Returns the offset of the first element.
 92   static int base_offset_in_bytes(BasicType type) {
 93     int hs = header_size_in_bytes();
 94     return element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs;
 95   }
 96 
 97   // Returns the address of the first element. The elements in the array will not
 98   // relocate from this address until a subsequent thread transition.
 99   void* base(BasicType type) const {
100     return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + base_offset_in_bytes(type));
101   }
102 
103   template <typename T>
104   static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {
105     if (obj != nullptr) {
106       assert(raw == nullptr, "either raw or in-heap");
107       char* base = reinterpret_cast<char*>((void*) obj);
< prev index next >