src/share/vm/utilities/array.hpp

Print this page
rev 6670 : 8049426: Minor cleanups after G1 class unloading
Reviewed-by: stefank


 311   T   _data[1];                                // the array memory
 312 
 313   void initialize(int length) {
 314     _length = length;
 315   }
 316 
 317  private:
 318   // Turn off copy constructor and assignment operator.
 319   Array(const Array<T>&);
 320   void operator=(const Array<T>&);
 321 
 322   void* operator new(size_t size, ClassLoaderData* loader_data, int length, bool read_only, TRAPS) throw() {
 323     size_t word_size = Array::size(length);
 324     return (void*) Metaspace::allocate(loader_data, word_size, read_only,
 325                                        MetaspaceObj::array_type(sizeof(T)), CHECK_NULL);
 326   }
 327 
 328   static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); }
 329 
 330   // WhiteBox API helper.


 331   static int bytes_to_length(size_t bytes)       {
 332     assert(is_size_aligned(bytes, BytesPerWord), "Must be, for now");
 333 
 334     if (sizeof(Array<T>) >= bytes) {
 335       return 0;
 336     }
 337 
 338     size_t left = bytes - sizeof(Array<T>);
 339     assert(is_size_aligned(left, sizeof(T)), "Must be");
 340 
 341     size_t elements = left / sizeof(T);
 342     assert(elements <= (size_t)INT_MAX, err_msg("number of elements " SIZE_FORMAT "doesn't fit into an int.", elements));
 343 
 344     int length = (int)elements;
 345 
 346     assert((size_t)size(length) * BytesPerWord == bytes,
 347         err_msg("Expected: " SIZE_FORMAT " got: " SIZE_FORMAT,
 348                 bytes, (size_t)size(length) * BytesPerWord));
 349 
 350     return length;




 311   T   _data[1];                                // the array memory
 312 
 313   void initialize(int length) {
 314     _length = length;
 315   }
 316 
 317  private:
 318   // Turn off copy constructor and assignment operator.
 319   Array(const Array<T>&);
 320   void operator=(const Array<T>&);
 321 
 322   void* operator new(size_t size, ClassLoaderData* loader_data, int length, bool read_only, TRAPS) throw() {
 323     size_t word_size = Array::size(length);
 324     return (void*) Metaspace::allocate(loader_data, word_size, read_only,
 325                                        MetaspaceObj::array_type(sizeof(T)), CHECK_NULL);
 326   }
 327 
 328   static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); }
 329 
 330   // WhiteBox API helper.
 331   // Can't distinguish between array of length 0 and length 1,
 332   // will always return 0 in those cases.
 333   static int bytes_to_length(size_t bytes)       {
 334     assert(is_size_aligned(bytes, BytesPerWord), "Must be, for now");
 335 
 336     if (sizeof(Array<T>) >= bytes) {
 337       return 0;
 338     }
 339 
 340     size_t left = bytes - sizeof(Array<T>);
 341     assert(is_size_aligned(left, sizeof(T)), "Must be");
 342 
 343     size_t elements = left / sizeof(T);
 344     assert(elements <= (size_t)INT_MAX, err_msg("number of elements " SIZE_FORMAT "doesn't fit into an int.", elements));
 345 
 346     int length = (int)elements;
 347 
 348     assert((size_t)size(length) * BytesPerWord == bytes,
 349         err_msg("Expected: " SIZE_FORMAT " got: " SIZE_FORMAT,
 350                 bytes, (size_t)size(length) * BytesPerWord));
 351 
 352     return length;