hotspot/src/share/vm/oops/array.hpp
changeset 46746 ea379ebb9447
parent 46625 edefffab74e2
child 46749 9db1408787eb
equal deleted inserted replaced
46745:f7b9bb98bb72 46746:ea379ebb9447
    34 // Array for metadata allocation
    34 // Array for metadata allocation
    35 
    35 
    36 template <typename T>
    36 template <typename T>
    37 class Array: public MetaspaceObj {
    37 class Array: public MetaspaceObj {
    38   friend class MetadataFactory;
    38   friend class MetadataFactory;
       
    39   friend class MetaspaceShared;
    39   friend class VMStructs;
    40   friend class VMStructs;
    40   friend class JVMCIVMStructs;
    41   friend class JVMCIVMStructs;
    41   friend class MethodHandleCompiler;           // special case
    42   friend class MethodHandleCompiler;           // special case
    42   friend class WhiteBox;
    43   friend class WhiteBox;
    43 protected:
    44 protected:
    51  private:
    52  private:
    52   // Turn off copy constructor and assignment operator.
    53   // Turn off copy constructor and assignment operator.
    53   Array(const Array<T>&);
    54   Array(const Array<T>&);
    54   void operator=(const Array<T>&);
    55   void operator=(const Array<T>&);
    55 
    56 
    56   void* operator new(size_t size, ClassLoaderData* loader_data, int length, bool read_only, TRAPS) throw() {
    57   void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw() {
    57     size_t word_size = Array::size(length);
    58     size_t word_size = Array::size(length);
    58     return (void*) Metaspace::allocate(loader_data, word_size, read_only,
    59     return (void*) Metaspace::allocate(loader_data, word_size,
    59                                        MetaspaceObj::array_type(sizeof(T)), THREAD);
    60                                        MetaspaceObj::array_type(sizeof(T)), THREAD);
    60   }
    61   }
    61 
    62 
    62   static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); }
    63   static size_t byte_sizeof(int length, size_t elm_byte_size) {
       
    64     return sizeof(Array<T>) + MAX2(length - 1, 0) * elm_byte_size;
       
    65   }
       
    66   static size_t byte_sizeof(int length) { return byte_sizeof(length, sizeof(T)); }
    63 
    67 
    64   // WhiteBox API helper.
    68   // WhiteBox API helper.
    65   // Can't distinguish between array of length 0 and length 1,
    69   // Can't distinguish between array of length 0 and length 1,
    66   // will always return 0 in those cases.
    70   // will always return 0 in those cases.
    67   static int bytes_to_length(size_t bytes)       {
    71   static int bytes_to_length(size_t bytes)       {
   128 
   132 
   129     assert(words <= INT_MAX, "Overflow: " SIZE_FORMAT, words);
   133     assert(words <= INT_MAX, "Overflow: " SIZE_FORMAT, words);
   130 
   134 
   131     return (int)words;
   135     return (int)words;
   132   }
   136   }
       
   137   static int size(int length, int elm_byte_size) {
       
   138     return align_size_up(byte_sizeof(length, elm_byte_size), BytesPerWord) / BytesPerWord; // FIXME
       
   139   }
   133 
   140 
   134   int size() {
   141   int size() {
   135     return size(_length);
   142     return size(_length);
   136   }
   143   }
   137 
   144