1
1
/*
2
2
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
3
+ * Copyright (c) 2017, 2020 SAP SE. All rights reserved.
3
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5
*
5
6
* This code is free software; you can redistribute it and/or modify it
63
64
#include < signal.h>
64
65
#endif // PRODUCT
65
66
66
- bool VMError::_error_reported = false ;
67
-
68
- // call this when the VM is dying--it might loosen some asserts
69
- bool VMError::is_error_reported () { return _error_reported; }
67
+ bool VMError::coredump_status;
68
+ char VMError::coredump_message[O_BUFLEN];
69
+ int VMError::_current_step;
70
+ const char * VMError::_current_step_info;
71
+ volatile jlong VMError::_reporting_start_time = -1 ;
72
+ volatile bool VMError::_reporting_did_timeout = false ;
73
+ volatile jlong VMError::_step_start_time = -1 ;
74
+ volatile bool VMError::_step_did_timeout = false ;
75
+ volatile intptr_t VMError::_first_error_tid = -1 ;
76
+ int VMError::_id;
77
+ const char * VMError::_message;
78
+ char VMError::_detail_msg[1024 ];
79
+ Thread* VMError::_thread;
80
+ address VMError::_pc;
81
+ void * VMError::_siginfo;
82
+ void * VMError::_context;
83
+ const char * VMError::_filename;
84
+ int VMError::_lineno;
85
+ size_t VMError::_size;
70
86
71
87
// returns an address which is guaranteed to generate a SIGSEGV on read,
72
88
// for test purposes, which is not NULL and contains bits in every word
@@ -80,7 +96,7 @@ void* VMError::get_segfault_address() {
80
96
}
81
97
82
98
// List of environment variables that should be reported in error log file.
83
- const char * env_list[] = {
99
+ static const char * env_list[] = {
84
100
// All platforms
85
101
" JAVA_HOME" , " JAVA_TOOL_OPTIONS" , " _JAVA_OPTIONS" , " CLASSPATH" ,
86
102
" PATH" , " USERNAME" ,
@@ -151,9 +167,6 @@ static void print_bug_submit_message(outputStream *out, Thread *thread) {
151
167
out->print_raw_cr (" #" );
152
168
}
153
169
154
- bool VMError::coredump_status;
155
- char VMError::coredump_message[O_BUFLEN];
156
-
157
170
void VMError::record_coredump_status (const char * message, bool status) {
158
171
coredump_status = status;
159
172
strncpy (coredump_message, message, sizeof (coredump_message));
@@ -358,40 +371,15 @@ static void report_vm_version(outputStream* st, char* buf, int buflen) {
358
371
);
359
372
}
360
373
361
- // This is the main function to report a fatal error. Only one thread can
362
- // call this function, so we don't need to worry about MT-safety. But it's
363
- // possible that the error handler itself may crash or die on an internal
364
- // error, for example, when the stack/heap is badly damaged. We must be
365
- // able to handle recursive errors that happen inside error handler.
366
- //
367
- // Error reporting is done in several steps. If a crash or internal error
368
- // occurred when reporting an error, the nested signal/exception handler
369
- // can skip steps that are already (or partially) done. Error reporting will
370
- // continue from the next step. This allows us to retrieve and print
371
- // information that may be unsafe to get after a fatal error. If it happens,
372
- // you may find nested report_and_die() frames when you look at the stack
373
- // in a debugger.
374
- //
375
- // In general, a hang in error handler is much worse than a crash or internal
376
- // error, as it's harder to recover from a hang. Deadlock can happen if we
377
- // try to grab a lock that is already owned by current thread, or if the
378
- // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
379
- // error handler and all the functions it called should avoid grabbing any
380
- // lock. An important thing to notice is that memory allocation needs a lock.
381
- //
382
- // We should avoid using large stack allocated buffers. Many errors happen
383
- // when stack space is already low. Making things even worse is that there
384
- // could be nested report_and_die() calls on stack (see above). Only one
385
- // thread can report error, so large buffers are statically allocated in data
386
- // segment.
387
-
388
- int VMError::_current_step;
389
- const char * VMError::_current_step_info;
374
+ // Returns true if at least one thread reported a fatal error and fatal error handling is in process.
375
+ bool VMError::is_error_reported () {
376
+ return _first_error_tid != -1 ;
377
+ }
390
378
391
- volatile jlong VMError::_reporting_start_time = - 1 ;
392
- volatile bool VMError::_reporting_did_timeout = false ;
393
- volatile jlong VMError::_step_start_time = - 1 ;
394
- volatile bool VMError::_step_did_timeout = false ;
379
+ // Returns true if the current thread reported a fatal error.
380
+ bool VMError::is_error_reported_in_current_thread () {
381
+ return _first_error_tid == os::current_thread_id () ;
382
+ }
395
383
396
384
// Helper, return current timestamp for timeout handling.
397
385
jlong VMError::get_current_timestamp () {
@@ -422,6 +410,32 @@ void VMError::clear_step_start_time() {
422
410
return Atomic::store (&_step_start_time, (jlong)0 );
423
411
}
424
412
413
+ // This is the main function to report a fatal error. Only one thread can
414
+ // call this function, so we don't need to worry about MT-safety. But it's
415
+ // possible that the error handler itself may crash or die on an internal
416
+ // error, for example, when the stack/heap is badly damaged. We must be
417
+ // able to handle recursive errors that happen inside error handler.
418
+ //
419
+ // Error reporting is done in several steps. If a crash or internal error
420
+ // occurred when reporting an error, the nested signal/exception handler
421
+ // can skip steps that are already (or partially) done. Error reporting will
422
+ // continue from the next step. This allows us to retrieve and print
423
+ // information that may be unsafe to get after a fatal error. If it happens,
424
+ // you may find nested report_and_die() frames when you look at the stack
425
+ // in a debugger.
426
+ //
427
+ // In general, a hang in error handler is much worse than a crash or internal
428
+ // error, as it's harder to recover from a hang. Deadlock can happen if we
429
+ // try to grab a lock that is already owned by current thread, or if the
430
+ // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
431
+ // error handler and all the functions it called should avoid grabbing any
432
+ // lock. An important thing to notice is that memory allocation needs a lock.
433
+ //
434
+ // We should avoid using large stack allocated buffers. Many errors happen
435
+ // when stack space is already low. Making things even worse is that there
436
+ // could be nested report_and_die() calls on stack (see above). Only one
437
+ // thread can report error, so large buffers are statically allocated in data
438
+ // segment.
425
439
void VMError::report (outputStream* st, bool _verbose) {
426
440
427
441
# define BEGIN if (_current_step == 0 ) { _current_step = __LINE__;
@@ -654,7 +668,6 @@ void VMError::report(outputStream* st, bool _verbose) {
654
668
os::print_summary_info (st, buf, sizeof (buf));
655
669
}
656
670
657
-
658
671
STEP (" printing date and time" )
659
672
660
673
if (_verbose) {
@@ -695,7 +708,6 @@ void VMError::report(outputStream* st, bool _verbose) {
695
708
}
696
709
}
697
710
698
-
699
711
STEP (" printing stack bounds" )
700
712
701
713
if (_verbose) {
@@ -1240,8 +1252,6 @@ void VMError::print_vm_info(outputStream* st) {
1240
1252
st->print_cr (" END." );
1241
1253
}
1242
1254
1243
- volatile intptr_t VMError::_first_error_tid = -1 ;
1244
-
1245
1255
/* * Expand a pattern into a buffer starting at pos and open a file using constructed path */
1246
1256
static int expand_and_open (const char * pattern, bool overwrite_existing, char * buf, size_t buflen, size_t pos) {
1247
1257
int fd = -1 ;
@@ -1298,17 +1308,6 @@ static int prepare_log_file(const char* pattern, const char* default_pattern, bo
1298
1308
return fd;
1299
1309
}
1300
1310
1301
- int VMError::_id;
1302
- const char * VMError::_message;
1303
- char VMError::_detail_msg[1024 ];
1304
- Thread* VMError::_thread;
1305
- address VMError::_pc;
1306
- void * VMError::_siginfo;
1307
- void * VMError::_context;
1308
- const char * VMError::_filename;
1309
- int VMError::_lineno;
1310
- size_t VMError::_size;
1311
-
1312
1311
void VMError::report_and_die (Thread* thread, unsigned int sig, address pc, void * siginfo,
1313
1312
void * context, const char * detail_fmt, ...)
1314
1313
{
@@ -1395,9 +1394,6 @@ void VMError::report_and_die(int id, const char* message, const char* detail_fmt
1395
1394
_size = size;
1396
1395
jio_vsnprintf (_detail_msg, sizeof (_detail_msg), detail_fmt, detail_args);
1397
1396
1398
- // first time
1399
- _error_reported = true ;
1400
-
1401
1397
reporting_started ();
1402
1398
if (!TestUnresponsiveErrorHandler) {
1403
1399
// Record reporting_start_time unless we're running the
@@ -1420,7 +1416,7 @@ void VMError::report_and_die(int id, const char* message, const char* detail_fmt
1420
1416
1421
1417
// reset signal handlers or exception filter; make sure recursive crashes
1422
1418
// are handled properly.
1423
- reset_signal_handlers ();
1419
+ install_secondary_signal_handler ();
1424
1420
} else {
1425
1421
#if defined(_WINDOWS)
1426
1422
// If UseOSErrorReporting we call this for each level of the call stack
0 commit comments