27
28 #include "oops/oop.hpp"
29 #include "utilities/align.hpp"
30
31 // arrayOopDesc is the abstract baseclass for all arrays. It doesn't
32 // declare pure virtual to enforce this because that would allocate a vtbl
33 // in each instance, which we don't want.
34
35 // The layout of array Oops is:
36 //
37 // markWord
38 // Klass* // 32 bits if compressed but declared 64 in LP64.
39 // length // shares klass memory or allocated after declared fields.
40
41
42 class arrayOopDesc : public oopDesc {
43 friend class VMStructs;
44 friend class arrayOopDescTest;
45
46 // Interpreter/Compiler offsets
47
48 // Header size computation.
49 // The header is considered the oop part of this type plus the length.
50 // Returns the aligned header_size_in_bytes. This is not equivalent to
51 // sizeof(arrayOopDesc) which should not appear in the code.
52 static int header_size_in_bytes() {
53 size_t hs = align_up(length_offset_in_bytes() + sizeof(int),
54 HeapWordSize);
55 #ifdef ASSERT
56 // make sure it isn't called before UseCompressedOops is initialized.
57 static size_t arrayoopdesc_hs = 0;
58 if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
59 assert(arrayoopdesc_hs == hs, "header size can't change");
60 #endif // ASSERT
61 return (int)hs;
62 }
63
64 // Returns the address of the length "field". See length_offset_in_bytes().
65 static int* length_addr_impl(void* obj_ptr) {
66 char* ptr = static_cast<char*>(obj_ptr);
67 return reinterpret_cast<int*>(ptr + length_offset_in_bytes());
68 }
69
70 // Check whether an element of a typeArrayOop with the given type must be
71 // aligned 0 mod 8. The typeArrayOop itself must be aligned at least this
72 // strongly.
73 static bool element_type_should_be_aligned(BasicType type) {
74 return type == T_DOUBLE || type == T_LONG;
75 }
76
77 public:
78 // The _length field is not declared in C++. It is allocated after the
79 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
80 // it occupies the second half of the _klass field in oopDesc.
81 static int length_offset_in_bytes() {
82 return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
83 sizeof(arrayOopDesc);
84 }
85
86 // Returns the offset of the first element.
87 static int base_offset_in_bytes(BasicType type) {
88 return header_size(type) * HeapWordSize;
89 }
90
91 // Returns the address of the first element. The elements in the array will not
92 // relocate from this address until a subsequent thread transition.
93 void* base(BasicType type) const {
94 return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + base_offset_in_bytes(type));
|
27
28 #include "oops/oop.hpp"
29 #include "utilities/align.hpp"
30
31 // arrayOopDesc is the abstract baseclass for all arrays. It doesn't
32 // declare pure virtual to enforce this because that would allocate a vtbl
33 // in each instance, which we don't want.
34
35 // The layout of array Oops is:
36 //
37 // markWord
38 // Klass* // 32 bits if compressed but declared 64 in LP64.
39 // length // shares klass memory or allocated after declared fields.
40
41
42 class arrayOopDesc : public oopDesc {
43 friend class VMStructs;
44 friend class arrayOopDescTest;
45
46 // Interpreter/Compiler offsets
47 protected:
48 // Header size computation.
49 // The header is considered the oop part of this type plus the length.
50 // Returns the aligned header_size_in_bytes. This is not equivalent to
51 // sizeof(arrayOopDesc) which should not appear in the code.
52 static int header_size_in_bytes() {
53 size_t hs = align_up(length_offset_in_bytes() + sizeof(int),
54 HeapWordSize);
55 #ifdef ASSERT
56 // make sure it isn't called before UseCompressedOops is initialized.
57 static size_t arrayoopdesc_hs = 0;
58 if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
59 assert(arrayoopdesc_hs == hs, "header size can't change");
60 #endif // ASSERT
61 return (int)hs;
62 }
63
64 // Returns the address of the length "field". See length_offset_in_bytes().
65 static int* length_addr_impl(void* obj_ptr) {
66 char* ptr = static_cast<char*>(obj_ptr);
67 return reinterpret_cast<int*>(ptr + length_offset_in_bytes());
68 }
69
70 // Check whether an element of a typeArrayOop with the given type must be
71 // aligned 0 mod 8. The typeArrayOop itself must be aligned at least this
72 // strongly.
73 static bool element_type_should_be_aligned(BasicType type) {
74 return type == T_DOUBLE || type == T_LONG || type == T_PRIMITIVE_OBJECT;
75 }
76
77 public:
78 // The _length field is not declared in C++. It is allocated after the
79 // declared nonstatic fields in arrayOopDesc if not compressed, otherwise
80 // it occupies the second half of the _klass field in oopDesc.
81 static int length_offset_in_bytes() {
82 return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
83 sizeof(arrayOopDesc);
84 }
85
86 // Returns the offset of the first element.
87 static int base_offset_in_bytes(BasicType type) {
88 return header_size(type) * HeapWordSize;
89 }
90
91 // Returns the address of the first element. The elements in the array will not
92 // relocate from this address until a subsequent thread transition.
93 void* base(BasicType type) const {
94 return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + base_offset_in_bytes(type));
|