--- old/src/share/vm/oops/arrayOop.hpp 2011-10-26 12:57:24.406307900 +0200 +++ new/src/share/vm/oops/arrayOop.hpp 2011-10-26 12:57:23.969507100 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -113,11 +113,19 @@ return max_jint; } - const int32_t max_words = align_size_down(max_jint, MinObjAlignment); - const int32_t max_element_words = max_words - header_size(type); + const size_t max_words_per_size_t = SIZE_MAX / HeapWordSize; + const int32_t max_words = (int32_t)MIN2((size_t)max_jint, max_words_per_size_t); + const int32_t max_element_words = align_size_down(max_words - header_size(type), MinObjAlignment); const int32_t words_per_element = bytes_per_element >> LogHeapWordSize; return max_element_words / words_per_element; } + +// for unit testing +#ifndef PRODUCT + static bool check_overflow(BasicType type); + static int32_t old_max_array_length(BasicType type); + static bool test_max_array_length(); +#endif }; #endif // SHARE_VM_OOPS_ARRAYOOP_HPP