src/share/vm/oops/arrayOop.cpp

changeset 3266
6fd81579526f
parent 2708
1d1603768966
child 3335
3c648b9ad052
     1.1 --- a/src/share/vm/oops/arrayOop.cpp	Fri Oct 28 13:04:10 2011 -0400
     1.2 +++ b/src/share/vm/oops/arrayOop.cpp	Mon Oct 31 08:01:20 2011 +0100
     1.3 @@ -23,9 +23,40 @@
     1.4   */
     1.5  
     1.6  #include "precompiled.hpp"
     1.7 +
     1.8 +/////////////// Unit tests ///////////////
     1.9 +
    1.10 +#ifndef PRODUCT
    1.11 +
    1.12  #include "oops/arrayOop.hpp"
    1.13 -#include "oops/objArrayOop.hpp"
    1.14 -#include "oops/oop.inline.hpp"
    1.15 -#include "oops/symbol.hpp"
    1.16 +#include "utilities/globalDefinitions.hpp"
    1.17  
    1.18 -// <<this page is intentionally left blank>>
    1.19 +bool arrayOopDesc::check_max_length_overflow(BasicType type) {
    1.20 +  julong length = max_array_length(type);
    1.21 +  julong bytes_per_element = type2aelembytes(type);
    1.22 +  julong bytes = length * bytes_per_element + header_size_in_bytes();
    1.23 +  return (julong)(size_t)bytes == bytes;
    1.24 +}
    1.25 +
    1.26 +bool arrayOopDesc::test_max_array_length() {
    1.27 +  tty->print_cr("test_max_array_length");
    1.28 +
    1.29 +  assert(check_max_length_overflow(T_BOOLEAN), "size_t overflow for boolean array");
    1.30 +  assert(check_max_length_overflow(T_CHAR), "size_t overflow for char array");
    1.31 +  assert(check_max_length_overflow(T_FLOAT), "size_t overflow for float array");
    1.32 +  assert(check_max_length_overflow(T_DOUBLE), "size_t overflow for double array");
    1.33 +  assert(check_max_length_overflow(T_BYTE), "size_t overflow for byte array");
    1.34 +  assert(check_max_length_overflow(T_SHORT), "size_t overflow for short array");
    1.35 +  assert(check_max_length_overflow(T_INT), "size_t overflow for int array");
    1.36 +  assert(check_max_length_overflow(T_LONG), "size_t overflow for long array");
    1.37 +  assert(check_max_length_overflow(T_OBJECT), "size_t overflow for object array");
    1.38 +  assert(check_max_length_overflow(T_ARRAY), "size_t overflow for array array");
    1.39 +  assert(check_max_length_overflow(T_NARROWOOP), "size_t overflow for narrowOop array");
    1.40 +
    1.41 +  // T_VOID and T_ADDRESS are not supported by max_array_length()
    1.42 +
    1.43 +  return true;
    1.44 +}
    1.45 +
    1.46 +
    1.47 +#endif //PRODUCT

mercurial