| 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 () { | 
|---|
| 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_VM(arrayOopDesc, boolean) { | 
|---|
| 47 | ASSERT_PRED1(check_max_length_overflow, T_BOOLEAN); | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | TEST_VM(arrayOopDesc, char) { | 
|---|
| 51 | ASSERT_PRED1(check_max_length_overflow, T_CHAR); | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | TEST_VM(arrayOopDesc, float) { | 
|---|
| 55 | ASSERT_PRED1(check_max_length_overflow, T_FLOAT); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | TEST_VM(arrayOopDesc, double) { | 
|---|
| 59 | ASSERT_PRED1(check_max_length_overflow, T_DOUBLE); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | TEST_VM(arrayOopDesc, byte) { | 
|---|
| 63 | ASSERT_PRED1(check_max_length_overflow, T_BYTE); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | TEST_VM(arrayOopDesc, short) { | 
|---|
| 67 | ASSERT_PRED1(check_max_length_overflow, T_SHORT); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | TEST_VM(arrayOopDesc, int) { | 
|---|
| 71 | ASSERT_PRED1(check_max_length_overflow, T_INT); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | TEST_VM(arrayOopDesc, long) { | 
|---|
| 75 | ASSERT_PRED1(check_max_length_overflow, T_LONG); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | TEST_VM(arrayOopDesc, object) { | 
|---|
| 79 | ASSERT_PRED1(check_max_length_overflow, T_OBJECT); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | TEST_VM(arrayOopDesc, array) { | 
|---|
| 83 | ASSERT_PRED1(check_max_length_overflow, T_ARRAY); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | TEST_VM(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() | 
|---|
| 90 |  | 
|---|