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 "oops/objArrayOop.hpp"
25 #include "unittest.hpp"
26 #include "utilities/globalDefinitions.hpp"
27
28 TEST_VM(objArrayOop, osize) {
29 static const struct {
30 int objal; bool coops; bool coh; int result;
31 } x[] = {
32 // ObjAligInB, UseCoops, UseCOH, object size in heap words
33 #ifdef _LP64
34 { 8, false, false, 3 }, // 16 byte header, 8 byte oops
35 { 8, true, false, 3 }, // 16 byte header, 4 byte oops
36 { 8, false, true, 3 }, // 12 byte header, 8 byte oops
37 { 8, true, true, 2 }, // 12 byte header, 4 byte oops
38 { 16, false, false, 4 }, // 16 byte header, 8 byte oops, 16-byte align
39 { 16, true, false, 4 }, // 16 byte header, 4 byte oops, 16-byte align
40 { 16, false, true, 4 }, // 12 byte header, 8 byte oops, 16-byte align
41 { 16, true, true, 2 }, // 12 byte header, 4 byte oops, 16-byte align
42 { 256, false, false, 32 }, // 16 byte header, 8 byte oops, 256-byte align
43 { 256, true, false, 32 }, // 16 byte header, 4 byte oops, 256-byte align
44 { 256, false, true, 32 }, // 12 byte header, 8 byte oops, 256-byte align
45 { 256, true, true, 32 }, // 12 byte header, 4 byte oops, 256-byte align
46 #else
47 { 8, false, false, 4 }, // 12 byte header, 4 byte oops, wordsize 4
48 #endif
49 { -1, false, false, -1 }
50 };
51 for (int i = 0; x[i].result != -1; i++) {
52 if (x[i].objal == (int)ObjectAlignmentInBytes && x[i].coops == UseCompressedOops &&
53 x[i].coh == UseCompactObjectHeaders) {
54 EXPECT_EQ(objArrayOopDesc::object_size(1), (size_t)x[i].result);
55 }
56 }
57 }
|
1 /*
2 * Copyright Amazon.com Inc. or its affiliates. All rights reserved.
3 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 #include "oops/objArrayOop.hpp"
26 #include "oops/refArrayOop.hpp"
27 #include "oops/flatArrayOop.hpp"
28 #include "unittest.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 TEST_VM(objArrayOop, osize_refarray) {
32 struct ObjArrayStruct {
33 int objal; // Object alignment in bytes
34 bool coops; // UseCompressedOops
35 bool coh; // UseCompactObjectHeaders
36 int result; // Expected size in heap words
37 };
38
39 static const ObjArrayStruct refCases[] = {
40 #ifdef _LP64
41 { 8, false, false, 3 }, // 16 byte header, 8 byte oops
42 { 8, true, false, 3 }, // 16 byte header, 4 byte oops
43 { 8, false, true, 3 }, // 12 byte header, 8 byte oops
44 { 8, true, true, 2 }, // 12 byte header, 4 byte oops
45 { 16, false, false, 4 }, // 16 byte header, 8 byte oops, 16-byte align
46 { 16, true, false, 4 }, // 16 byte header, 4 byte oops, 16-byte align
47 { 16, false, true, 4 }, // 12 byte header, 8 byte oops, 16-byte align
48 { 16, true, true, 2 }, // 12 byte header, 4 byte oops, 16-byte align
49 { 256, false, false, 32 }, // 16 byte header, 8 byte oops, 256-byte align
50 { 256, true, false, 32 }, // 16 byte header, 4 byte oops, 256-byte align
51 { 256, false, true, 32 }, // 12 byte header, 8 byte oops, 256-byte align
52 { 256, true, true, 32 }, // 12 byte header, 4 byte oops, 256-byte align
53 #else
54 { 8, false, false, 4 }, // 12 byte header, 4 byte oops, wordsize 4
55 #endif
56 };
57
58 for (const ObjArrayStruct c : refCases) {
59 if (c.objal == (int)ObjectAlignmentInBytes && c.coops == UseCompressedOops &&
60 c.coh == UseCompactObjectHeaders) {
61 EXPECT_EQ(refArrayOopDesc::object_size(1), (size_t)c.result);
62 }
63 }
64 }
65
66 static int make_flat_array_layout_helper(int payload_size_bytes, bool null_free) {
67 BasicType etype = T_FLAT_ELEMENT;
68 int esize = log2i_exact(round_up_power_of_2(payload_size_bytes));
69 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
70 return Klass::array_layout_helper(Klass::_lh_array_tag_flat_value, null_free, hsize, etype, esize);
71 }
72
73 TEST_VM(objArrayOop, osize_flatarray) {
74 struct FlatArraySizeCase {
75 int objal; // Object alignment in bytes
76 int payload_size; // Raw inline payload size
77 bool null_free; // Null free
78 int result; // Expected size in heap words
79 };
80
81 static const FlatArraySizeCase flatCases[] = {
82 #ifdef _LP64
83 {8, 4, false, 3},
84 {8, 8, false, 3},
85 {8, 4, true, 3},
86 {8, 8, true, 3},
87 {16, 4, false, 4},
88 {16, 8, false, 4},
89 {16, 4, true, 4},
90 {16, 8, true, 4},
91 {256, 4, false, 32},
92 {256, 8, false, 32},
93 {256, 4, true, 32},
94 {256, 8, true, 32},
95 #endif
96 };
97
98 for (const FlatArraySizeCase c : flatCases) {
99 if (c.objal == (int)ObjectAlignmentInBytes) {
100 int lh = make_flat_array_layout_helper(c.payload_size, c.null_free);
101 EXPECT_EQ(flatArrayOopDesc::object_size(lh, 1), c.result);
102 }
103 }
104 }
|