duke@435: /* trims@2708: * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" brutisso@3266: brutisso@3266: /////////////// Unit tests /////////////// brutisso@3266: brutisso@3266: #ifndef PRODUCT brutisso@3266: stefank@2314: #include "oops/arrayOop.hpp" brutisso@3266: #include "utilities/globalDefinitions.hpp" duke@435: brutisso@3266: bool arrayOopDesc::check_max_length_overflow(BasicType type) { brutisso@3266: julong length = max_array_length(type); brutisso@3266: julong bytes_per_element = type2aelembytes(type); brutisso@3266: julong bytes = length * bytes_per_element + header_size_in_bytes(); brutisso@3266: return (julong)(size_t)bytes == bytes; brutisso@3266: } brutisso@3266: stefank@3335: void arrayOopDesc::test_max_array_length() { brutisso@3266: assert(check_max_length_overflow(T_BOOLEAN), "size_t overflow for boolean array"); brutisso@3266: assert(check_max_length_overflow(T_CHAR), "size_t overflow for char array"); brutisso@3266: assert(check_max_length_overflow(T_FLOAT), "size_t overflow for float array"); brutisso@3266: assert(check_max_length_overflow(T_DOUBLE), "size_t overflow for double array"); brutisso@3266: assert(check_max_length_overflow(T_BYTE), "size_t overflow for byte array"); brutisso@3266: assert(check_max_length_overflow(T_SHORT), "size_t overflow for short array"); brutisso@3266: assert(check_max_length_overflow(T_INT), "size_t overflow for int array"); brutisso@3266: assert(check_max_length_overflow(T_LONG), "size_t overflow for long array"); brutisso@3266: assert(check_max_length_overflow(T_OBJECT), "size_t overflow for object array"); brutisso@3266: assert(check_max_length_overflow(T_ARRAY), "size_t overflow for array array"); brutisso@3266: assert(check_max_length_overflow(T_NARROWOOP), "size_t overflow for narrowOop array"); brutisso@3266: brutisso@3266: // T_VOID and T_ADDRESS are not supported by max_array_length() brutisso@3266: } brutisso@3266: brutisso@3266: brutisso@3266: #endif //PRODUCT