Re: How expensive are exceptions?
David Abrahams wrote:
on Sat Jun 16 2007, Walter Bright <walter-AT-digitalmars-nospamm.com> wrote:
One way to do this is to instrument every write instruction. Another
way is to mark those sections' pages as "read only". Then, the
hardware throws a "write fault" exception
Whoa, whoa, whoa. The hardware "raises" a _hardware_ "write fault"
exception. There's no reason that should be connected in any way to
C++ EH, and in fact there are really good reasons that it shouldn't be
so connected.
The connection is as follows. The hardware raises a hardware exception.
The operating system has handlers set up to intercept them (that's the
job of the os) and do something meaningful with them. Under Windows,
what this means is it is transformed into a Structured Exception. SE's
can be intercepted by user code, and the SEH model supports both the
termination model (which is what C++ EH relies on) and the resumptive
model (which is what the gc EH relies on).
Both the gc EH and C++ EH are built on top of the SEH mechanism. The gc
EH is not built on top of C++ EH.
Now, what happened with 64 bit Windows is Microsoft *completely changed*
how SEH works. This affects both gc EH and C++ EH because both are built
on top of SEH. So while gc EH is not reliant on C++ EH, they both share
a common reliance on SEH, so if that underlying implementation is slow
in response, then both gc and C++ EH get slow in response.
You can do all that stuff without involving C++ exception unwinding in
the picture. In fact, it doesn't require any unwinding at all.
The way Microsoft Windows provides access to the exceptions is not
something that user level code can change. If your program wants to
intercept hardware exceptions, you MUST play ball with the way the
operating system chooses to present them, and for Windows, that's SEH.
It is also true that a C++ implementation can choose to ignore SEH and
roll their own EH implementation. But the downside of that is the usual
downside of ABI incompatibility - you're in your own world and cannot
talk with binaries compiled with any other compiler or binaries in any
other language. Another downside is when a hardware exception does get
thrown, none of your exception handlers will get executed.
--------------
Walter Bright
http://www.digitalmars.com C, C++, D programming language compilers
http://www.astoriaseminar.com Extraordinary C++
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]