312 } |
312 } |
313 |
313 |
314 #ifndef PRODUCT |
314 #ifndef PRODUCT |
315 #include <signal.h> |
315 #include <signal.h> |
316 |
316 |
317 void test_error_handler(size_t test_num) |
317 void test_error_handler() { |
318 { |
318 uintx test_num = ErrorHandlerTest; |
319 if (test_num == 0) return; |
319 if (test_num == 0) return; |
320 |
320 |
321 // If asserts are disabled, use the corresponding guarantee instead. |
321 // If asserts are disabled, use the corresponding guarantee instead. |
322 size_t n = test_num; |
322 size_t n = test_num; |
323 NOT_DEBUG(if (n <= 2) n += 2); |
323 NOT_DEBUG(if (n <= 2) n += 2); |
325 const char* const str = "hello"; |
325 const char* const str = "hello"; |
326 const size_t num = (size_t)os::vm_page_size(); |
326 const size_t num = (size_t)os::vm_page_size(); |
327 |
327 |
328 const char* const eol = os::line_separator(); |
328 const char* const eol = os::line_separator(); |
329 const char* const msg = "this message should be truncated during formatting"; |
329 const char* const msg = "this message should be truncated during formatting"; |
|
330 char * const dataPtr = NULL; // bad data pointer |
|
331 const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer |
330 |
332 |
331 // Keep this in sync with test/runtime/6888954/vmerrors.sh. |
333 // Keep this in sync with test/runtime/6888954/vmerrors.sh. |
332 switch (n) { |
334 switch (n) { |
333 case 1: assert(str == NULL, "expected null"); |
335 case 1: assert(str == NULL, "expected null"); |
334 case 2: assert(num == 1023 && *str == 'X', |
336 case 2: assert(num == 1023 && *str == 'X', |
346 msg, eol, msg, eol, msg, eol, msg, eol, msg)); |
348 msg, eol, msg, eol, msg, eol, msg, eol, msg)); |
347 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate"); |
349 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate"); |
348 case 9: ShouldNotCallThis(); |
350 case 9: ShouldNotCallThis(); |
349 case 10: ShouldNotReachHere(); |
351 case 10: ShouldNotReachHere(); |
350 case 11: Unimplemented(); |
352 case 11: Unimplemented(); |
351 // This is last because it does not generate an hs_err* file on Windows. |
353 // There's no guarantee the bad data pointer will crash us |
352 case 12: os::signal_raise(SIGSEGV); |
354 // so "break" out to the ShouldNotReachHere(). |
353 |
355 case 12: *dataPtr = '\0'; break; |
354 default: ShouldNotReachHere(); |
356 // There's no guarantee the bad function pointer will crash us |
355 } |
357 // so "break" out to the ShouldNotReachHere(). |
|
358 case 13: (*funcPtr)(); break; |
|
359 |
|
360 default: tty->print_cr("ERROR: %d: unexpected test_num value.", n); |
|
361 } |
|
362 ShouldNotReachHere(); |
356 } |
363 } |
357 #endif // !PRODUCT |
364 #endif // !PRODUCT |
358 |
365 |
359 // ------ helper functions for debugging go here ------------ |
366 // ------ helper functions for debugging go here ------------ |
360 |
367 |