1 /*
2 * Copyright (c) 2024, Red Hat, Inc. All rights reserved.
3 * Copyright (c) 2024, 2025, 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/compressedKlass.inline.hpp"
26 #include "utilities/globalDefinitions.hpp"
27
28 #include "unittest.hpp"
29
30 TEST_VM(CompressedKlass, basics) {
31 if (!UseCompressedClassPointers) {
32 return;
33 }
34 ASSERT_LE((address)0, CompressedKlassPointers::base());
35 ASSERT_LE(CompressedKlassPointers::base(), CompressedKlassPointers::klass_range_start());
36 ASSERT_LT(CompressedKlassPointers::klass_range_start(), CompressedKlassPointers::klass_range_end());
37 ASSERT_LE(CompressedKlassPointers::klass_range_end(), CompressedKlassPointers::encoding_range_end());
38
39 switch (CompressedKlassPointers::shift()) {
40 case 0:
41 ASSERT_EQ(CompressedKlassPointers::encoding_range_end() - CompressedKlassPointers::base(), (ptrdiff_t)(4 * G));
42 break;
43 case 3:
44 ASSERT_EQ(CompressedKlassPointers::encoding_range_end() - CompressedKlassPointers::base(), (ptrdiff_t)(32 * G));
90 ASSERT_FALSE(CompressedKlassPointers::is_encodable(addr));
91 // Try word-aligned, but not sufficiently aligned
92 if (alignment > BytesPerWord) {
93 addr = CompressedKlassPointers::klass_range_start() + BytesPerWord;
94 ASSERT_FALSE(CompressedKlassPointers::is_encodable(addr));
95 }
96 addr = CompressedKlassPointers::klass_range_end() - 1;
97 ASSERT_FALSE(CompressedKlassPointers::is_encodable(addr));
98 }
99
100 TEST_VM(CompressedKlass, test_good_address) {
101 if (!UseCompressedClassPointers) {
102 return;
103 }
104 const size_t alignment = CompressedKlassPointers::klass_alignment_in_bytes();
105 address addr = CompressedKlassPointers::klass_range_start();
106 ASSERT_TRUE(CompressedKlassPointers::is_encodable(addr));
107 addr = CompressedKlassPointers::klass_range_end() - alignment;
108 ASSERT_TRUE(CompressedKlassPointers::is_encodable(addr));
109 }
|
1 /*
2 * Copyright (c) 2024, 2025, Red Hat, Inc. All rights reserved.
3 * Copyright (c) 2024, 2025, 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 "classfile/vmClasses.hpp"
26 #include "oops/compressedKlass.inline.hpp"
27 #include "utilities/globalDefinitions.hpp"
28
29 #include "unittest.hpp"
30
31 TEST_VM(CompressedKlass, basics) {
32 if (!UseCompressedClassPointers) {
33 return;
34 }
35 ASSERT_LE((address)0, CompressedKlassPointers::base());
36 ASSERT_LE(CompressedKlassPointers::base(), CompressedKlassPointers::klass_range_start());
37 ASSERT_LT(CompressedKlassPointers::klass_range_start(), CompressedKlassPointers::klass_range_end());
38 ASSERT_LE(CompressedKlassPointers::klass_range_end(), CompressedKlassPointers::encoding_range_end());
39
40 switch (CompressedKlassPointers::shift()) {
41 case 0:
42 ASSERT_EQ(CompressedKlassPointers::encoding_range_end() - CompressedKlassPointers::base(), (ptrdiff_t)(4 * G));
43 break;
44 case 3:
45 ASSERT_EQ(CompressedKlassPointers::encoding_range_end() - CompressedKlassPointers::base(), (ptrdiff_t)(32 * G));
91 ASSERT_FALSE(CompressedKlassPointers::is_encodable(addr));
92 // Try word-aligned, but not sufficiently aligned
93 if (alignment > BytesPerWord) {
94 addr = CompressedKlassPointers::klass_range_start() + BytesPerWord;
95 ASSERT_FALSE(CompressedKlassPointers::is_encodable(addr));
96 }
97 addr = CompressedKlassPointers::klass_range_end() - 1;
98 ASSERT_FALSE(CompressedKlassPointers::is_encodable(addr));
99 }
100
101 TEST_VM(CompressedKlass, test_good_address) {
102 if (!UseCompressedClassPointers) {
103 return;
104 }
105 const size_t alignment = CompressedKlassPointers::klass_alignment_in_bytes();
106 address addr = CompressedKlassPointers::klass_range_start();
107 ASSERT_TRUE(CompressedKlassPointers::is_encodable(addr));
108 addr = CompressedKlassPointers::klass_range_end() - alignment;
109 ASSERT_TRUE(CompressedKlassPointers::is_encodable(addr));
110 }
111
112 TEST_VM(CompressedKlass, test_is_valid_narrow_klass) {
113 if (!UseCompressedClassPointers) {
114 return;
115 }
116 ASSERT_FALSE(CompressedKlassPointers::is_valid_narrow_klass_id(0));
117 narrowKlass nk_jlC = CompressedKlassPointers::encode((Klass*)vmClasses::Class_klass());
118 ASSERT_TRUE(CompressedKlassPointers::is_valid_narrow_klass_id(nk_jlC));
119 if (CompressedClassSpaceSize < 4 * G && CompressedKlassPointers::base() != nullptr) {
120 ASSERT_FALSE(CompressedKlassPointers::is_valid_narrow_klass_id(0xFFFFFFFF));
121 }
122 }
|