< prev index next >

src/hotspot/share/oops/arrayOop.hpp

heap allocator

91   static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {                                                        
92     if (obj != NULL) {                                                                                                               
93       assert(raw == NULL, "either raw or in-heap");                                                                                  
94       char* base = reinterpret_cast<char*>((void*) obj);                                                                             
95       raw = reinterpret_cast<T*>(base + offset_in_bytes);                                                                            
96     } else {                                                                                                                         
97       assert(raw != NULL, "either raw or in-heap");                                                                                  
98     }                                                                                                                                
99     return raw;                                                                                                                      
100   }                                                                                                                                  
101 
102   // Tells whether index is within bounds.                                                                                           
103   bool is_within_bounds(int index) const        { return 0 <= index && index < length(); }                                           
104 
105   // Accessors for instance variable which is not a C++ declared nonstatic                                                           
106   // field.                                                                                                                          
107   int length() const {                                                                                                               
108     return *(int*)(((intptr_t)this) + length_offset_in_bytes());                                                                     
109   }                                                                                                                                  
110   void set_length(int length) {                                                                                                      
111     *(int*)(((intptr_t)this) + length_offset_in_bytes()) = length;                                                                   
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
112   }                                                                                                                                  
113 
114   // Should only be called with constants as argument                                                                                
115   // (will not constant fold otherwise)                                                                                              
116   // Returns the header size in words aligned to the requirements of the                                                             
117   // array object type.                                                                                                              
118   static int header_size(BasicType type) {                                                                                           
119     size_t typesize_in_bytes = header_size_in_bytes();                                                                               
120     return (int)(element_type_should_be_aligned(type)                                                                                
121       ? align_object_offset(typesize_in_bytes/HeapWordSize)                                                                          
122       : typesize_in_bytes/HeapWordSize);                                                                                             
123   }                                                                                                                                  
124 
125   // Return the maximum length of an array of BasicType.  The length can passed                                                      
126   // to typeArrayOop::object_size(scale, length, header_size) without causing an                                                     
127   // overflow. We also need to make sure that this will not overflow a size_t on                                                     
128   // 32 bit platforms when we convert it to a byte size.                                                                             
129   static int32_t max_array_length(BasicType type) {                                                                                  
130     assert(type >= 0 && type < T_CONFLICT, "wrong type");                                                                            

91   static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) {
92     if (obj != NULL) {
93       assert(raw == NULL, "either raw or in-heap");
94       char* base = reinterpret_cast<char*>((void*) obj);
95       raw = reinterpret_cast<T*>(base + offset_in_bytes);
96     } else {
97       assert(raw != NULL, "either raw or in-heap");
98     }
99     return raw;
100   }
101 
102   // Tells whether index is within bounds.
103   bool is_within_bounds(int index) const        { return 0 <= index && index < length(); }
104 
105   // Accessors for instance variable which is not a C++ declared nonstatic
106   // field.
107   int length() const {
108     return *(int*)(((intptr_t)this) + length_offset_in_bytes());
109   }
110   void set_length(int length) {
111     set_length((HeapWord*)this, length);
112   }
113   static void set_length(HeapWord* mem, int length) {
114     *(int*)(((char*)mem) + length_offset_in_bytes()) = length;
115   }
116 
117   // Should only be called with constants as argument
118   // (will not constant fold otherwise)
119   // Returns the header size in words aligned to the requirements of the
120   // array object type.
121   static int header_size(BasicType type) {
122     size_t typesize_in_bytes = header_size_in_bytes();
123     return (int)(element_type_should_be_aligned(type)
124       ? align_object_offset(typesize_in_bytes/HeapWordSize)
125       : typesize_in_bytes/HeapWordSize);
126   }
127 
128   // Return the maximum length of an array of BasicType.  The length can passed
129   // to typeArrayOop::object_size(scale, length, header_size) without causing an
130   // overflow. We also need to make sure that this will not overflow a size_t on
131   // 32 bit platforms when we convert it to a byte size.
132   static int32_t max_array_length(BasicType type) {
133     assert(type >= 0 && type < T_CONFLICT, "wrong type");
< prev index next >