23
23
*/
24
24
25
25
#include " precompiled.hpp"
26
- #include " gc/shared/oopStorage.hpp"
26
+ #include " gc/shared/oopStorage.inline. hpp"
27
27
#include " gc/shared/oopStorageSet.hpp"
28
28
#include " memory/allocation.inline.hpp"
29
+ #include " runtime/interfaceSupport.inline.hpp"
30
+ #include " runtime/vmOperations.hpp"
31
+ #include " runtime/vmThread.hpp"
29
32
#include " utilities/debug.hpp"
30
33
#include " utilities/enumIterator.hpp"
31
34
#include " utilities/globalDefinitions.hpp"
32
35
#include " utilities/macros.hpp"
33
36
#include " unittest.hpp"
34
37
38
+ using ::testing::HasSubstr;
39
+ using ::testing::Not;
40
+
35
41
class OopStorageSetTest : public ::testing::Test {
36
42
protected:
37
43
// Returns index of s in storages, or size if not found.
@@ -83,6 +89,8 @@ class OopStorageSetTest : public ::testing::Test {
83
89
EnumRange<OopStorageSet::Id>(),
84
90
&OopStorageSet::fill_all);
85
91
}
92
+
93
+ class VM_PrintAtSafepoint ;
86
94
};
87
95
88
96
TEST_VM_F (OopStorageSetTest, strong_iteration) {
@@ -96,3 +104,77 @@ TEST_VM_F(OopStorageSetTest, weak_iteration) {
96
104
TEST_VM_F (OopStorageSetTest, all_iteration) {
97
105
test_all_iteration ();
98
106
}
107
+
108
+ class OopStorageSetTest ::VM_PrintAtSafepoint : public VM_GTestExecuteAtSafepoint {
109
+ private:
110
+ class PrintContainingClosure : public Closure {
111
+ public:
112
+ void do_oop (oop* addr) {
113
+ // Direct slot hit.
114
+ {
115
+ stringStream ss;
116
+ bool printed = OopStorageSet::print_containing (addr, &ss);
117
+ ASSERT_TRUE (printed);
118
+ ASSERT_THAT (ss.freeze (), HasSubstr (" is a pointer" ));
119
+ ASSERT_THAT (ss.freeze (), HasSubstr (" into block" ));
120
+ ASSERT_THAT (ss.freeze (), HasSubstr (" in oop storage" ));
121
+ ASSERT_THAT (ss.freeze (), Not (HasSubstr (" (unaligned)" )));
122
+ }
123
+
124
+ // Unaligned pointer to adjacent slot, should still be in oop storage range.
125
+ {
126
+ char * unaligned_addr = (char *)addr + 1 ;
127
+ stringStream ss;
128
+ bool printed = OopStorageSet::print_containing (unaligned_addr, &ss);
129
+ ASSERT_TRUE (printed);
130
+ ASSERT_THAT (ss.freeze (), HasSubstr (" is a pointer" ));
131
+ ASSERT_THAT (ss.freeze (), HasSubstr (" into block" ));
132
+ ASSERT_THAT (ss.freeze (), HasSubstr (" in oop storage" ));
133
+ ASSERT_THAT (ss.freeze (), HasSubstr (" (unaligned)" ));
134
+ }
135
+ }
136
+ };
137
+
138
+ public:
139
+ void doit () {
140
+ PrintContainingClosure cl;
141
+ for (OopStorage* storage : OopStorageSet::Range<OopStorageSet::Id>()) {
142
+ storage->oops_do (&cl);
143
+ }
144
+ }
145
+ };
146
+
147
+ TEST_VM_F (OopStorageSetTest, print_containing) {
148
+ // nullptrs print nothing
149
+ {
150
+ stringStream ss;
151
+ bool printed = OopStorageSet::print_containing (nullptr , &ss);
152
+ ASSERT_FALSE (printed);
153
+ EXPECT_STREQ (" " , ss.freeze ());
154
+ }
155
+
156
+ // Goofy values print nothing: unaligned out of storage pointer.
157
+ {
158
+ stringStream ss;
159
+ bool printed = OopStorageSet::print_containing ((char *)0x1 , &ss);
160
+ ASSERT_FALSE (printed);
161
+ EXPECT_STREQ (" " , ss.freeze ());
162
+ }
163
+
164
+ // Goofy values print nothing: aligned out of storage pointer.
165
+ {
166
+ stringStream ss;
167
+ bool printed = OopStorageSet::print_containing ((char *)alignof (oop), &ss);
168
+ ASSERT_FALSE (printed);
169
+ EXPECT_STREQ (" " , ss.freeze ());
170
+ }
171
+
172
+ // All slot addresses should print well.
173
+ {
174
+ VM_PrintAtSafepoint op;
175
+ {
176
+ ThreadInVMfromNative invm (JavaThread::current ());
177
+ VMThread::execute (&op);
178
+ }
179
+ }
180
+ }
1 commit comments
openjdk-notifier[bot] commentedon Sep 23, 2024
Review
Issues