Wed, 22 Dec 2010 11:24:21 -0500
6961186: Better VM handling of unexpected exceptions from application native code
Summary: Trap uncaught C++ exception on Windows and Solaris and generate hs_err report.
Reviewed-by: coleenp, bobv, dholmes
src/os/solaris/vm/os_solaris.cpp | file | annotate | diff | comparison | revisions | |
src/os/windows/vm/os_windows.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/os/solaris/vm/os_solaris.cpp Tue Dec 14 15:10:52 2010 -0500 1.2 +++ b/src/os/solaris/vm/os_solaris.cpp Wed Dec 22 11:24:21 2010 -0500 1.3 @@ -80,6 +80,7 @@ 1.4 // put OS-includes here 1.5 # include <dlfcn.h> 1.6 # include <errno.h> 1.7 +# include <exception> 1.8 # include <link.h> 1.9 # include <poll.h> 1.10 # include <pthread.h> 1.11 @@ -1475,6 +1476,13 @@ 1.12 return &allowdebug_blocked_sigs; 1.13 } 1.14 1.15 + 1.16 +void _handle_uncaught_cxx_exception() { 1.17 + VMError err("An uncaught C++ exception"); 1.18 + err.report_and_die(); 1.19 +} 1.20 + 1.21 + 1.22 // First crack at OS-specific initialization, from inside the new thread. 1.23 void os::initialize_thread() { 1.24 int r = thr_main() ; 1.25 @@ -1564,6 +1572,7 @@ 1.26 // use the dynamic check for T2 libthread. 1.27 1.28 os::Solaris::init_thread_fpu_state(); 1.29 + std::set_terminate(_handle_uncaught_cxx_exception); 1.30 } 1.31 1.32
2.1 --- a/src/os/windows/vm/os_windows.cpp Tue Dec 14 15:10:52 2010 -0500 2.2 +++ b/src/os/windows/vm/os_windows.cpp Wed Dec 22 11:24:21 2010 -0500 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2.6 + * CopyrighT (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -2007,6 +2007,16 @@ 2.11 int number; 2.12 }; 2.13 2.14 +// All Visual C++ exceptions thrown from code generated by the Microsoft Visual 2.15 +// C++ compiler contain this error code. Because this is a compiler-generated 2.16 +// error, the code is not listed in the Win32 API header files. 2.17 +// The code is actually a cryptic mnemonic device, with the initial "E" 2.18 +// standing for "exception" and the final 3 bytes (0x6D7363) representing the 2.19 +// ASCII values of "msc". 2.20 + 2.21 +#define EXCEPTION_UNCAUGHT_CXX_EXCEPTION 0xE06D7363 2.22 + 2.23 + 2.24 struct siglabel exceptlabels[] = { 2.25 def_excpt(EXCEPTION_ACCESS_VIOLATION), 2.26 def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT), 2.27 @@ -2031,6 +2041,7 @@ 2.28 def_excpt(EXCEPTION_INVALID_DISPOSITION), 2.29 def_excpt(EXCEPTION_GUARD_PAGE), 2.30 def_excpt(EXCEPTION_INVALID_HANDLE), 2.31 + def_excpt(EXCEPTION_UNCAUGHT_CXX_EXCEPTION), 2.32 NULL, 0 2.33 }; 2.34 2.35 @@ -2264,7 +2275,6 @@ 2.36 } 2.37 } 2.38 2.39 - 2.40 if (t != NULL && t->is_Java_thread()) { 2.41 JavaThread* thread = (JavaThread*) t; 2.42 bool in_java = thread->thread_state() == _thread_in_Java; 2.43 @@ -2468,8 +2478,9 @@ 2.44 } // switch 2.45 } 2.46 #ifndef _WIN64 2.47 - if ((thread->thread_state() == _thread_in_Java) || 2.48 - (thread->thread_state() == _thread_in_native) ) 2.49 + if (((thread->thread_state() == _thread_in_Java) || 2.50 + (thread->thread_state() == _thread_in_native)) && 2.51 + exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) 2.52 { 2.53 LONG result=Handle_FLT_Exception(exceptionInfo); 2.54 if (result==EXCEPTION_CONTINUE_EXECUTION) return result; 2.55 @@ -2493,6 +2504,7 @@ 2.56 case EXCEPTION_ILLEGAL_INSTRUCTION_2: 2.57 case EXCEPTION_INT_OVERFLOW: 2.58 case EXCEPTION_INT_DIVIDE_BY_ZERO: 2.59 + case EXCEPTION_UNCAUGHT_CXX_EXCEPTION: 2.60 { report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, 2.61 exceptionInfo->ContextRecord); 2.62 }