71
72 public:
73 // The _length field is not declared in C++. It is allocated after the
74 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
75 // it occupies the second half of the _klass field in oopDesc.
76 static int length_offset_in_bytes() {
77 return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
78 sizeof(arrayOopDesc);
79 }
80
81 // Returns the offset of the first element.
82 static int base_offset_in_bytes(BasicType type) {
83 return header_size(type) * HeapWordSize;
84 }
85
86 // Returns the address of the first element. The elements in the array will not
87 // relocate from this address until a subsequent thread transition.
88 inline void* base(BasicType type) const;
89 inline void* base_raw(BasicType type) const; // GC barrier invariant
90
91 // Tells whether index is within bounds.
92 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
93
94 // Accessors for instance variable which is not a C++ declared nonstatic
95 // field.
96 int length() const {
97 return *(int*)(((intptr_t)this) + length_offset_in_bytes());
98 }
99 void set_length(int length) {
100 *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;
101 }
102
103 // Should only be called with constants as argument
104 // (will not constant fold otherwise)
105 // Returns the header size in words aligned to the requirements of the
106 // array object type.
107 static int header_size(BasicType type) {
108 size_t typesize_in_bytes = header_size_in_bytes();
109 return (int)(element_type_should_be_aligned(type)
110 ? align_object_offset(typesize_in_bytes/HeapWordSize)
|
71
72 public:
73 // The _length field is not declared in C++. It is allocated after the
74 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
75 // it occupies the second half of the _klass field in oopDesc.
76 static int length_offset_in_bytes() {
77 return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
78 sizeof(arrayOopDesc);
79 }
80
81 // Returns the offset of the first element.
82 static int base_offset_in_bytes(BasicType type) {
83 return header_size(type) * HeapWordSize;
84 }
85
86 // Returns the address of the first element. The elements in the array will not
87 // relocate from this address until a subsequent thread transition.
88 inline void* base(BasicType type) const;
89 inline void* base_raw(BasicType type) const; // GC barrier invariant
90
91 template <typename T>
92 static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {
93 if (obj != NULL) {
94 assert(raw == NULL, "either raw or in-heap");
95 char* base = reinterpret_cast<char*>((void*) obj);
96 raw = reinterpret_cast<T*>(base + offset_in_bytes);
97 } else {
98 assert(raw != NULL, "either raw or in-heap");
99 }
100 return raw;
101 }
102
103 // Tells whether index is within bounds.
104 bool is_within_bounds(int index) const { return 0 <= index && index < length(); }
105
106 // Accessors for instance variable which is not a C++ declared nonstatic
107 // field.
108 int length() const {
109 return *(int*)(((intptr_t)this) + length_offset_in_bytes());
110 }
111 void set_length(int length) {
112 *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;
113 }
114
115 // Should only be called with constants as argument
116 // (will not constant fold otherwise)
117 // Returns the header size in words aligned to the requirements of the
118 // array object type.
119 static int header_size(BasicType type) {
120 size_t typesize_in_bytes = header_size_in_bytes();
121 return (int)(element_type_should_be_aligned(type)
122 ? align_object_offset(typesize_in_bytes/HeapWordSize)
|