hotspot/test/native/oops/test_arrayOop.cpp
changeset 41290 8ff9c4ea1690
parent 35529 39376b4613b5
child 41671 9e0c6db4918a
equal deleted inserted replaced
41289:f307cc24f1e9 41290:8ff9c4ea1690
       
     1 /*
       
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 #include "precompiled.hpp"
       
    25 #include "oops/arrayOop.hpp"
       
    26 #include "oops/oop.inline.hpp"
       
    27 #include "unittest.hpp"
       
    28 #include "utilities/globalDefinitions.hpp"
       
    29 
       
    30 class arrayOopDescTest {
       
    31  public:
       
    32 
       
    33   static int header_size_in_bytes() {
       
    34     return arrayOopDesc::header_size_in_bytes();
       
    35   }
       
    36 };
       
    37 
       
    38 static bool check_max_length_overflow(BasicType type) {
       
    39   julong length = arrayOopDesc::max_array_length(type);
       
    40   julong bytes_per_element = type2aelembytes(type);
       
    41   julong bytes = length * bytes_per_element
       
    42           + arrayOopDescTest::header_size_in_bytes();
       
    43   return (julong) (size_t) bytes == bytes;
       
    44 }
       
    45 
       
    46 TEST(arrayOopDesc, boolean) {
       
    47   ASSERT_PRED1(check_max_length_overflow, T_BOOLEAN);
       
    48 }
       
    49 
       
    50 TEST(arrayOopDesc, char) {
       
    51   ASSERT_PRED1(check_max_length_overflow, T_CHAR);
       
    52 }
       
    53 
       
    54 TEST(arrayOopDesc, float) {
       
    55   ASSERT_PRED1(check_max_length_overflow, T_FLOAT);
       
    56 }
       
    57 
       
    58 TEST(arrayOopDesc, double) {
       
    59   ASSERT_PRED1(check_max_length_overflow, T_DOUBLE);
       
    60 }
       
    61 
       
    62 TEST(arrayOopDesc, byte) {
       
    63   ASSERT_PRED1(check_max_length_overflow, T_BYTE);
       
    64 }
       
    65 
       
    66 TEST(arrayOopDesc, short) {
       
    67   ASSERT_PRED1(check_max_length_overflow, T_SHORT);
       
    68 }
       
    69 
       
    70 TEST(arrayOopDesc, int) {
       
    71   ASSERT_PRED1(check_max_length_overflow, T_INT);
       
    72 }
       
    73 
       
    74 TEST(arrayOopDesc, long) {
       
    75   ASSERT_PRED1(check_max_length_overflow, T_LONG);
       
    76 }
       
    77 
       
    78 TEST(arrayOopDesc, object) {
       
    79   ASSERT_PRED1(check_max_length_overflow, T_OBJECT);
       
    80 }
       
    81 
       
    82 TEST(arrayOopDesc, array) {
       
    83   ASSERT_PRED1(check_max_length_overflow, T_ARRAY);
       
    84 }
       
    85 
       
    86 TEST(arrayOopDesc, narrowOop) {
       
    87   ASSERT_PRED1(check_max_length_overflow, T_NARROWOOP);
       
    88 }
       
    89 // T_VOID and T_ADDRESS are not supported by max_array_length()