Mercurial > hg > truffle
comparison src/share/vm/utilities/array.hpp @ 20804:7848fc12602b
Merge with jdk8u40-b25
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Tue, 07 Apr 2015 14:58:49 +0200 |
parents | 52b4284cb496 870c03421152 |
children |
comparison
equal
deleted
inserted
replaced
20184:84105dcdb05b | 20804:7848fc12602b |
---|---|
26 #define SHARE_VM_UTILITIES_ARRAY_HPP | 26 #define SHARE_VM_UTILITIES_ARRAY_HPP |
27 | 27 |
28 #include "memory/allocation.hpp" | 28 #include "memory/allocation.hpp" |
29 #include "memory/allocation.inline.hpp" | 29 #include "memory/allocation.inline.hpp" |
30 #include "memory/metaspace.hpp" | 30 #include "memory/metaspace.hpp" |
31 #include "runtime/orderAccess.hpp" | |
31 | 32 |
32 // correct linkage required to compile w/o warnings | 33 // correct linkage required to compile w/o warnings |
33 // (must be on file level - cannot be local) | 34 // (must be on file level - cannot be local) |
34 extern "C" { typedef int (*ftype)(const void*, const void*); } | 35 extern "C" { typedef int (*ftype)(const void*, const void*); } |
35 | 36 |
302 template <typename T> | 303 template <typename T> |
303 class Array: public MetaspaceObj { | 304 class Array: public MetaspaceObj { |
304 friend class MetadataFactory; | 305 friend class MetadataFactory; |
305 friend class VMStructs; | 306 friend class VMStructs; |
306 friend class MethodHandleCompiler; // special case | 307 friend class MethodHandleCompiler; // special case |
308 friend class WhiteBox; | |
307 protected: | 309 protected: |
308 int _length; // the number of array elements | 310 int _length; // the number of array elements |
309 T _data[1]; // the array memory | 311 T _data[1]; // the array memory |
310 | 312 |
311 void initialize(int length) { | 313 void initialize(int length) { |
322 return (void*) Metaspace::allocate(loader_data, word_size, read_only, | 324 return (void*) Metaspace::allocate(loader_data, word_size, read_only, |
323 MetaspaceObj::array_type(sizeof(T)), CHECK_NULL); | 325 MetaspaceObj::array_type(sizeof(T)), CHECK_NULL); |
324 } | 326 } |
325 | 327 |
326 static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); } | 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; | |
353 } | |
327 | 354 |
328 explicit Array(int length) : _length(length) { | 355 explicit Array(int length) : _length(length) { |
329 assert(length >= 0, "illegal length"); | 356 assert(length >= 0, "illegal length"); |
330 } | 357 } |
331 | 358 |