38 friend class ArchiveBuilder;
39 friend class MetadataFactory;
40 friend class VMStructs;
41 friend class JVMCIVMStructs;
42 friend class MethodHandleCompiler; // special case
43 friend class WhiteBox;
44 friend class FieldInfoStream;
45 protected:
46 int _length; // the number of array elements
47 T _data[1]; // the array memory
48
49 void initialize(int length) {
50 _length = length;
51 }
52
53 private:
54 NONCOPYABLE(Array);
55
56 inline void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw();
57
58 static size_t byte_sizeof(int length, size_t elm_byte_size) {
59 return sizeof(Array<T>) + MAX2(length - 1, 0) * elm_byte_size;
60 }
61 static size_t byte_sizeof(int length) { return byte_sizeof(length, sizeof(T)); }
62
63 // WhiteBox API helper.
64 // Can't distinguish between array of length 0 and length 1,
65 // will always return 0 in those cases.
66 static int bytes_to_length(size_t bytes) {
67 assert(is_aligned(bytes, BytesPerWord), "Must be, for now");
68
69 if (sizeof(Array<T>) >= bytes) {
70 return 0;
71 }
72
73 size_t left = bytes - sizeof(Array<T>);
74 assert(is_aligned(left, sizeof(T)), "Must be");
75
76 size_t elements = left / sizeof(T);
77 assert(elements <= (size_t)INT_MAX, "number of elements %zu doesn't fit into an int.", elements);
|
38 friend class ArchiveBuilder;
39 friend class MetadataFactory;
40 friend class VMStructs;
41 friend class JVMCIVMStructs;
42 friend class MethodHandleCompiler; // special case
43 friend class WhiteBox;
44 friend class FieldInfoStream;
45 protected:
46 int _length; // the number of array elements
47 T _data[1]; // the array memory
48
49 void initialize(int length) {
50 _length = length;
51 }
52
53 private:
54 NONCOPYABLE(Array);
55
56 inline void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw();
57
58 inline void* operator new(size_t size, ClassLoaderData* loader_data, int length) throw();
59
60 // Work-around -- see JDK-8331086
61 inline void* operator new(size_t size, int length, MemTag flags) throw();
62
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)); }
67
68 // WhiteBox API helper.
69 // Can't distinguish between array of length 0 and length 1,
70 // will always return 0 in those cases.
71 static int bytes_to_length(size_t bytes) {
72 assert(is_aligned(bytes, BytesPerWord), "Must be, for now");
73
74 if (sizeof(Array<T>) >= bytes) {
75 return 0;
76 }
77
78 size_t left = bytes - sizeof(Array<T>);
79 assert(is_aligned(left, sizeof(T)), "Must be");
80
81 size_t elements = left / sizeof(T);
82 assert(elements <= (size_t)INT_MAX, "number of elements %zu doesn't fit into an int.", elements);
|