Path: blob/master/test/hotspot/gtest/oops/test_arrayOop.cpp
41145 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "oops/arrayOop.hpp"25#include "oops/oop.inline.hpp"26#include "unittest.hpp"27#include "utilities/globalDefinitions.hpp"2829class arrayOopDescTest {30public:3132static int header_size_in_bytes() {33return arrayOopDesc::header_size_in_bytes();34}35};3637static bool check_max_length_overflow(BasicType type) {38julong length = arrayOopDesc::max_array_length(type);39julong bytes_per_element = type2aelembytes(type);40julong bytes = length * bytes_per_element41+ arrayOopDescTest::header_size_in_bytes();42return (julong) (size_t) bytes == bytes;43}4445TEST_VM(arrayOopDesc, boolean) {46ASSERT_PRED1(check_max_length_overflow, T_BOOLEAN);47}4849TEST_VM(arrayOopDesc, char) {50ASSERT_PRED1(check_max_length_overflow, T_CHAR);51}5253TEST_VM(arrayOopDesc, float) {54ASSERT_PRED1(check_max_length_overflow, T_FLOAT);55}5657TEST_VM(arrayOopDesc, double) {58ASSERT_PRED1(check_max_length_overflow, T_DOUBLE);59}6061TEST_VM(arrayOopDesc, byte) {62ASSERT_PRED1(check_max_length_overflow, T_BYTE);63}6465TEST_VM(arrayOopDesc, short) {66ASSERT_PRED1(check_max_length_overflow, T_SHORT);67}6869TEST_VM(arrayOopDesc, int) {70ASSERT_PRED1(check_max_length_overflow, T_INT);71}7273TEST_VM(arrayOopDesc, long) {74ASSERT_PRED1(check_max_length_overflow, T_LONG);75}7677TEST_VM(arrayOopDesc, object) {78ASSERT_PRED1(check_max_length_overflow, T_OBJECT);79}8081TEST_VM(arrayOopDesc, array) {82ASSERT_PRED1(check_max_length_overflow, T_ARRAY);83}8485TEST_VM(arrayOopDesc, narrowOop) {86ASSERT_PRED1(check_max_length_overflow, T_NARROWOOP);87}88// T_VOID and T_ADDRESS are not supported by max_array_length()899091