src/share/vm/oops/arrayOop.cpp

Thu, 21 Mar 2013 09:27:54 +0100

author
roland
date
Thu, 21 Mar 2013 09:27:54 +0100
changeset 4860
46f6f063b272
parent 3500
0382d2b469b2
child 6876
710a3c8b516e
permissions
-rw-r--r--

7153771: array bound check elimination for c1
Summary: when possible optimize out array bound checks, inserting predicates when needed.
Reviewed-by: never, kvn, twisti
Contributed-by: thomaswue <thomas.wuerthinger@oracle.com>

duke@435 1 /*
never@3500 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
brutisso@3266 26
brutisso@3266 27 /////////////// Unit tests ///////////////
brutisso@3266 28
brutisso@3266 29 #ifndef PRODUCT
brutisso@3266 30
stefank@2314 31 #include "oops/arrayOop.hpp"
never@3500 32 #include "oops/oop.inline.hpp"
brutisso@3266 33 #include "utilities/globalDefinitions.hpp"
duke@435 34
brutisso@3266 35 bool arrayOopDesc::check_max_length_overflow(BasicType type) {
brutisso@3266 36 julong length = max_array_length(type);
brutisso@3266 37 julong bytes_per_element = type2aelembytes(type);
brutisso@3266 38 julong bytes = length * bytes_per_element + header_size_in_bytes();
brutisso@3266 39 return (julong)(size_t)bytes == bytes;
brutisso@3266 40 }
brutisso@3266 41
stefank@3335 42 void arrayOopDesc::test_max_array_length() {
brutisso@3266 43 assert(check_max_length_overflow(T_BOOLEAN), "size_t overflow for boolean array");
brutisso@3266 44 assert(check_max_length_overflow(T_CHAR), "size_t overflow for char array");
brutisso@3266 45 assert(check_max_length_overflow(T_FLOAT), "size_t overflow for float array");
brutisso@3266 46 assert(check_max_length_overflow(T_DOUBLE), "size_t overflow for double array");
brutisso@3266 47 assert(check_max_length_overflow(T_BYTE), "size_t overflow for byte array");
brutisso@3266 48 assert(check_max_length_overflow(T_SHORT), "size_t overflow for short array");
brutisso@3266 49 assert(check_max_length_overflow(T_INT), "size_t overflow for int array");
brutisso@3266 50 assert(check_max_length_overflow(T_LONG), "size_t overflow for long array");
brutisso@3266 51 assert(check_max_length_overflow(T_OBJECT), "size_t overflow for object array");
brutisso@3266 52 assert(check_max_length_overflow(T_ARRAY), "size_t overflow for array array");
brutisso@3266 53 assert(check_max_length_overflow(T_NARROWOOP), "size_t overflow for narrowOop array");
brutisso@3266 54
brutisso@3266 55 // T_VOID and T_ADDRESS are not supported by max_array_length()
brutisso@3266 56 }
brutisso@3266 57
brutisso@3266 58
brutisso@3266 59 #endif //PRODUCT

mercurial