@@ -167,82 +167,95 @@ TEST_VM_ASSERT_MSG(os, page_size_for_region_with_zero_min_pages,
167
167
}
168
168
#endif
169
169
170
- static void do_test_print_hex_dump (address addr, size_t len, int unitsize, const char * expected) {
171
- char buf[256 ];
170
+ #ifndef AIX
171
+ // Test relies on the ability to protect memory allocated with os::reserve_memory. AIX may not be able
172
+ // to do that (mprotect won't work on System V shm).
173
+ static void do_test_print_hex_dump (const_address from, const_address to, int unitsize, int bytes_per_line,
174
+ const_address logical_start, const char * expected) {
175
+ char buf[2048 ];
172
176
buf[0 ] = ' \0 ' ;
173
177
stringStream ss (buf, sizeof (buf));
174
- os::print_hex_dump (&ss, addr, addr + len, unitsize);
175
- // tty->print_cr("expected: %s", expected);
176
- // tty->print_cr("result: %s", buf);
177
- EXPECT_THAT (buf, HasSubstr (expected));
178
+ os::print_hex_dump (&ss, from, to, unitsize, /* print_ascii=*/ true , bytes_per_line, logical_start);
179
+ EXPECT_STREQ (buf, expected);
178
180
}
179
181
180
182
TEST_VM (os, test_print_hex_dump) {
181
- const char * pattern [4 ] = {
182
- #ifdef VM_LITTLE_ENDIAN
183
- " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f" ,
184
- " 0100 0302 0504 0706 0908 0b0a 0d0c 0f0e" ,
185
- " 03020100 07060504 0b0a0908 0f0e0d0c" ,
186
- " 0706050403020100 0f0e0d0c0b0a0908"
183
+
184
+ #ifdef _LP64
185
+ #define ADDRESS1 " 0x0000aaaaaaaaaa00"
186
+ #define ADDRESS2 " 0x0000aaaaaaaaaa20"
187
+ #define ADDRESS3 " 0x0000aaaaaaaaaa40"
187
188
#else
188
- " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f" ,
189
- " 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f" ,
190
- " 00010203 04050607 08090a0b 0c0d0e0f" ,
191
- " 0001020304050607 08090a0b0c0d0e0f"
189
+ #define ADDRESS1 " 0xaaaaaa00"
190
+ #define ADDRESS2 " 0xaaaaaa20"
191
+ #define ADDRESS3 " 0xaaaaaa40"
192
192
#endif
193
- };
194
193
195
- const char * pattern_not_readable [4 ] = {
196
- " ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??" ,
197
- " ???? ???? ???? ???? ???? ???? ???? ????" ,
198
- " ???????? ???????? ???????? ????????" ,
199
- " ???????????????? ????????????????"
200
- };
194
+ #define ASCII_1 " ....#.jdk/internal/loader/Native"
195
+ #define ASCII_2 " Libraries......."
201
196
202
- // On AIX, zero page is readable.
203
- address unreadable =
204
- #ifdef AIX
205
- (address) 0xFFFFFFFFFFFF0000ULL ;
197
+ #define PAT_1 ADDRESS1 " : ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??\n " \
198
+ ADDRESS2 " : ff ff e0 dc 23 00 6a 64 6b 2f 69 6e 74 65 72 6e 61 6c 2f 6c 6f 61 64 65 72 2f 4e 61 74 69 76 65 " ASCII_1 " \n " \
199
+ ADDRESS3 " : 4c 69 62 72 61 72 69 65 73 00 00 00 00 00 00 00 " ASCII_2 " \n "
200
+
201
+ #ifdef VM_LITTLE_ENDIAN
202
+ #define PAT_2 ADDRESS1 " : ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ????\n " \
203
+ ADDRESS2 " : ffff dce0 0023 646a 2f6b 6e69 6574 6e72 6c61 6c2f 616f 6564 2f72 614e 6974 6576 " ASCII_1 " \n " \
204
+ ADDRESS3 " : 694c 7262 7261 6569 0073 0000 0000 0000 " ASCII_2 " \n "
205
+
206
+ #define PAT_4 ADDRESS1 " : ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????\n " \
207
+ ADDRESS2 " : dce0ffff 646a0023 6e692f6b 6e726574 6c2f6c61 6564616f 614e2f72 65766974 " ASCII_1 " \n " \
208
+ ADDRESS3 " : 7262694c 65697261 00000073 00000000 " ASCII_2 " \n "
209
+
210
+ #define PAT_8 ADDRESS1 " : ???????????????? ???????????????? ???????????????? ????????????????\n " \
211
+ ADDRESS2 " : 646a0023dce0ffff 6e7265746e692f6b 6564616f6c2f6c61 65766974614e2f72 " ASCII_1 " \n " \
212
+ ADDRESS3 " : 656972617262694c 0000000000000073 " ASCII_2 " \n "
206
213
#else
207
- (address) 0
208
- # endif
209
- ;
214
+ # define PAT_2 ADDRESS1 " : ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? \n " \
215
+ ADDRESS2 " : ffff e0dc 2300 6a64 6b2f 696e 7465 726e 616c 2f6c 6f61 6465 722f 4e61 7469 7665 " ASCII_1 " \n " \
216
+ ADDRESS3 " : 4c69 6272 6172 6965 7300 0000 0000 0000 " ASCII_2 " \n "
210
217
211
- ResourceMark rm;
212
- char buf[64 ];
213
- stringStream ss (buf, sizeof (buf));
214
- outputStream* out = &ss;
215
- // outputStream* out = tty; // enable for printout
216
-
217
- // Test dumping unreadable memory
218
- // Exclude test for Windows for now, since it needs SEH handling to work which cannot be
219
- // guaranteed when we call directly into VM code. (see JDK-8220220)
220
- #ifndef _WIN32
221
- do_test_print_hex_dump (unreadable, 100 , 1 , pattern_not_readable[0 ]);
222
- do_test_print_hex_dump (unreadable, 100 , 2 , pattern_not_readable[1 ]);
223
- do_test_print_hex_dump (unreadable, 100 , 4 , pattern_not_readable[2 ]);
224
- do_test_print_hex_dump (unreadable, 100 , 8 , pattern_not_readable[3 ]);
218
+ #define PAT_4 ADDRESS1 " : ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????\n " \
219
+ ADDRESS2 " : ffffe0dc 23006a64 6b2f696e 7465726e 616c2f6c 6f616465 722f4e61 74697665 " ASCII_1 " \n " \
220
+ ADDRESS3 " : 4c696272 61726965 73000000 00000000 " ASCII_2 " \n "
221
+
222
+ #define PAT_8 ADDRESS1 " : ???????????????? ???????????????? ???????????????? ????????????????\n " \
223
+ ADDRESS2 " : ffffe0dc23006a64 6b2f696e7465726e 616c2f6c6f616465 722f4e6174697665 " ASCII_1 " \n " \
224
+ ADDRESS3 " : 4c69627261726965 7300000000000000 " ASCII_2 " \n "
225
225
#endif
226
226
227
- // Test dumping readable memory
228
- address arr = (address)os::malloc (100 , mtInternal);
229
- for (u1 c = 0 ; c < 100 ; c++) {
230
- arr[c] = c;
231
- }
227
+ constexpr uint8_t bytes[] = {
228
+ 0xff , 0xff , 0xe0 , 0xdc , 0x23 , 0x00 , 0x6a , 0x64 , 0x6b , 0x2f , 0x69 , 0x6e , 0x74 , 0x65 , 0x72 , 0x6e ,
229
+ 0x61 , 0x6c , 0x2f , 0x6c , 0x6f , 0x61 , 0x64 , 0x65 , 0x72 , 0x2f , 0x4e , 0x61 , 0x74 , 0x69 , 0x76 , 0x65 ,
230
+ 0x4c , 0x69 , 0x62 , 0x72 , 0x61 , 0x72 , 0x69 , 0x65 , 0x73 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
231
+ };
232
+
233
+ // two pages, first one protected.
234
+ const size_t ps = os::vm_page_size ();
235
+ char * two_pages = os::reserve_memory (ps * 2 , false , mtTest);
236
+ os::commit_memory (two_pages, ps * 2 , false );
237
+ os::protect_memory (two_pages, ps, os::MEM_PROT_NONE, true );
238
+
239
+ memcpy (two_pages + ps, bytes, sizeof (bytes));
240
+
241
+ // print
242
+ const const_address from = (const_address) two_pages + ps - 32 ;
243
+ const const_address to = (const_address) from + 32 + sizeof (bytes);
244
+ const const_address logical_start = (const_address) LP64_ONLY (0xAAAAAAAAAA00ULL ) NOT_LP64 (0xAAAAAA00ULL );
232
245
233
- // properly aligned
234
- do_test_print_hex_dump (arr, 100 , 1 , pattern[0 ]);
235
- do_test_print_hex_dump (arr, 100 , 2 , pattern[1 ]);
236
- do_test_print_hex_dump (arr, 100 , 4 , pattern[2 ]);
237
- do_test_print_hex_dump (arr, 100 , 8 , pattern[3 ]);
246
+ do_test_print_hex_dump (from, to, 1 , 32 , logical_start, PAT_1);
247
+ do_test_print_hex_dump (from, to, 2 , 32 , logical_start, PAT_2);
248
+ do_test_print_hex_dump (from, to, 4 , 32 , logical_start, PAT_4);
249
+ do_test_print_hex_dump (from, to, 8 , 32 , logical_start, PAT_8);
238
250
239
- // Not properly aligned. Should automatically down-align by unitsize
240
- do_test_print_hex_dump (arr + 1 , 100 , 2 , pattern[ 1 ] );
241
- do_test_print_hex_dump (arr + 1 , 100 , 4 , pattern[ 2 ] );
242
- do_test_print_hex_dump (arr + 1 , 100 , 8 , pattern[ 3 ] );
251
+ // unaligned printing, should align to next lower unitsize
252
+ do_test_print_hex_dump (from + 1 , to , 2 , 32 , logical_start, PAT_2 );
253
+ do_test_print_hex_dump (from + 1 , to , 4 , 32 , logical_start, PAT_4 );
254
+ do_test_print_hex_dump (from + 1 , to , 8 , 32 , logical_start, PAT_8 );
243
255
244
- os::free (arr );
256
+ os::release_memory (two_pages, ps * 2 );
245
257
}
258
+ #endif // not AIX
246
259
247
260
// ////////////////////////////////////////////////////////////////////////////
248
261
// Test os::vsnprintf and friends.
0 commit comments