1 /*
 2  * Copyright Amazon.com Inc. 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/objArrayOop.hpp"
26 #include "unittest.hpp"
27 #include "utilities/globalDefinitions.hpp"
28 
29 TEST_VM(objArrayOop, osize) {
30   static const struct {
31     int objal; bool ccp; bool coops; bool coh; int result;
32   } x[] = {
33 //    ObjAligInB, UseCCP, UseCoops, UseCOH, object size in heap words
34 #ifdef _LP64
35     { 8,          false,  false,    false,  4 },  // 20 byte header, 8 byte oops
36     { 8,          false,  true,     false,  3 },  // 20 byte header, 4 byte oops
37     { 8,          true,   false,    false,  3 },  // 16 byte header, 8 byte oops
38     { 8,          true,   true,     false,  3 },  // 16 byte header, 4 byte oops
39     { 16,         false,  false,    false,  4 },  // 20 byte header, 8 byte oops, 16-byte align
40     { 16,         false,  true,     false,  4 },  // 20 byte header, 4 byte oops, 16-byte align
41     { 16,         true,   false,    false,  4 },  // 16 byte header, 8 byte oops, 16-byte align
42     { 16,         true,   true,     false,  4 },  // 16 byte header, 4 byte oops, 16-byte align
43     { 256,        false,  false,    false,  32 }, // 20 byte header, 8 byte oops, 256-byte align
44     { 256,        false,  true,     false,  32 }, // 20 byte header, 4 byte oops, 256-byte align
45     { 256,        true,   false,    false,  32 }, // 16 byte header, 8 byte oops, 256-byte align
46     { 256,        true,   true,     false,  32 }, // 16 byte header, 4 byte oops, 256-byte align
47     { 8,          false,  false,    true,   3 },  // 16 byte header, 8 byte oops
48     { 8,          false,  true,     true,   2 },  // 12 byte header, 4 byte oops
49     { 8,          true,   false,    true,   3 },  // 16 byte header, 8 byte oops
50     { 8,          true,   true,     true,   2 },  // 12 byte header, 4 byte oops
51     { 16,         false,  false,    true,   4 },  // 16 byte header, 8 byte oops, 16-byte align
52     { 16,         false,  true,     true,   2 },  // 12 byte header, 4 byte oops, 16-byte align
53     { 16,         true,   false,    true,   4 },  // 16 byte header, 8 byte oops, 16-byte align
54     { 16,         true,   true,     true,   2 },  // 12 byte header, 4 byte oops, 16-byte align
55     { 256,        false,  false,    true,   32 }, // 16 byte header, 8 byte oops, 256-byte align
56     { 256,        false,  true,     true,   32 }, // 12 byte header, 4 byte oops, 256-byte align
57     { 256,        true,   false,    true,   32 }, // 16 byte header, 8 byte oops, 256-byte align
58     { 256,        true,   true,     true,   32 }, // 12 byte header, 4 byte oops, 256-byte align
59 #else
60     { 8,          false,  false,    false,  4 }, // 12 byte header, 4 byte oops, wordsize 4
61 #endif
62     { -1,         false,  false,    false, -1 }
63   };
64   for (int i = 0; x[i].result != -1; i++) {
65     if (x[i].objal == (int)ObjectAlignmentInBytes && x[i].ccp == UseCompressedClassPointers && x[i].coops == UseCompressedOops && x[i].coh == UseCompactObjectHeaders) {
66       EXPECT_EQ(objArrayOopDesc::object_size(1), x[i].result);
67     }
68   }
69 }