src/share/vm/utilities/array.hpp

changeset 6992
2c6ef90f030a
parent 6911
ce8f6bb717c9
child 6993
870c03421152
     1.1 --- a/src/share/vm/utilities/array.hpp	Tue Jul 01 09:03:55 2014 +0200
     1.2 +++ b/src/share/vm/utilities/array.hpp	Mon Jul 07 10:12:40 2014 +0200
     1.3 @@ -305,6 +305,7 @@
     1.4    friend class MetadataFactory;
     1.5    friend class VMStructs;
     1.6    friend class MethodHandleCompiler;           // special case
     1.7 +  friend class WhiteBox;
     1.8  protected:
     1.9    int _length;                                 // the number of array elements
    1.10    T   _data[1];                                // the array memory
    1.11 @@ -326,6 +327,29 @@
    1.12  
    1.13    static size_t byte_sizeof(int length) { return sizeof(Array<T>) + MAX2(length - 1, 0) * sizeof(T); }
    1.14  
    1.15 +  // WhiteBox API helper.
    1.16 +  static int bytes_to_length(size_t bytes)       {
    1.17 +    assert(is_size_aligned(bytes, BytesPerWord), "Must be, for now");
    1.18 +
    1.19 +    if (sizeof(Array<T>) >= bytes) {
    1.20 +      return 0;
    1.21 +    }
    1.22 +
    1.23 +    size_t left = bytes - sizeof(Array<T>);
    1.24 +    assert(is_size_aligned(left, sizeof(T)), "Must be");
    1.25 +
    1.26 +    size_t elements = left / sizeof(T);
    1.27 +    assert(elements <= (size_t)INT_MAX, err_msg("number of elements " SIZE_FORMAT "doesn't fit into an int.", elements));
    1.28 +
    1.29 +    int length = (int)elements;
    1.30 +
    1.31 +    assert((size_t)size(length) * BytesPerWord == bytes,
    1.32 +        err_msg("Expected: " SIZE_FORMAT " got: " SIZE_FORMAT,
    1.33 +                bytes, (size_t)size(length) * BytesPerWord));
    1.34 +
    1.35 +    return length;
    1.36 +  }
    1.37 +
    1.38    explicit Array(int length) : _length(length) {
    1.39      assert(length >= 0, "illegal length");
    1.40    }

mercurial