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) { |