hotspot/src/share/vm/oops/arrayOop.hpp
changeset 46619 a3919f5e8d2b
parent 41290 8ff9c4ea1690
child 46625 edefffab74e2
equal deleted inserted replaced
46618:d503911aa948 46619:a3919f5e8d2b
    48   // Header size computation.
    48   // Header size computation.
    49   // The header is considered the oop part of this type plus the length.
    49   // The header is considered the oop part of this type plus the length.
    50   // Returns the aligned header_size_in_bytes.  This is not equivalent to
    50   // Returns the aligned header_size_in_bytes.  This is not equivalent to
    51   // sizeof(arrayOopDesc) which should not appear in the code.
    51   // sizeof(arrayOopDesc) which should not appear in the code.
    52   static int header_size_in_bytes() {
    52   static int header_size_in_bytes() {
    53     size_t hs = align_size_up(length_offset_in_bytes() + sizeof(int),
    53     size_t hs = align_up(length_offset_in_bytes() + sizeof(int),
    54                               HeapWordSize);
    54                               HeapWordSize);
    55 #ifdef ASSERT
    55 #ifdef ASSERT
    56     // make sure it isn't called before UseCompressedOops is initialized.
    56     // make sure it isn't called before UseCompressedOops is initialized.
    57     static size_t arrayoopdesc_hs = 0;
    57     static size_t arrayoopdesc_hs = 0;
    58     if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
    58     if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
   110   static int32_t max_array_length(BasicType type) {
   110   static int32_t max_array_length(BasicType type) {
   111     assert(type >= 0 && type < T_CONFLICT, "wrong type");
   111     assert(type >= 0 && type < T_CONFLICT, "wrong type");
   112     assert(type2aelembytes(type) != 0, "wrong type");
   112     assert(type2aelembytes(type) != 0, "wrong type");
   113 
   113 
   114     const size_t max_element_words_per_size_t =
   114     const size_t max_element_words_per_size_t =
   115       align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment);
   115       align_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment);
   116     const size_t max_elements_per_size_t =
   116     const size_t max_elements_per_size_t =
   117       HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
   117       HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
   118     if ((size_t)max_jint < max_elements_per_size_t) {
   118     if ((size_t)max_jint < max_elements_per_size_t) {
   119       // It should be ok to return max_jint here, but parts of the code
   119       // It should be ok to return max_jint here, but parts of the code
   120       // (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for
   120       // (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for
   121       // passing around the size (in words) of an object. So, we need to avoid
   121       // passing around the size (in words) of an object. So, we need to avoid
   122       // overflowing an int when we add the header. See CRs 4718400 and 7110613.
   122       // overflowing an int when we add the header. See CRs 4718400 and 7110613.
   123       return align_size_down(max_jint - header_size(type), MinObjAlignment);
   123       return align_down(max_jint - header_size(type), MinObjAlignment);
   124     }
   124     }
   125     return (int32_t)max_elements_per_size_t;
   125     return (int32_t)max_elements_per_size_t;
   126   }
   126   }
   127 
   127 
   128 };
   128 };