This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Implementation of Exceptions
- From: Halldór Ísak Gylfason <halldori at ru dot is>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 4 Apr 2002 15:26:53 -0000
- Subject: Implementation of Exceptions
Some thoughts concerning implementation of exceptions...
The implementation of exceptions in gcc seems to me to be a pretty
heavy-weight solution. If an exception occurs a linear search is done to
find the right DLL, Inside the right DLL a binary search is done to find
the right frame unwind info, and then a linear search is performed
through the relevant Exception table to find an exception handler. And
all this is done for each stack frame!
I admit that the benefits of this scheme is that a try-catch instruction
costs nothing if no exception occur, however throwing exception becomes
expensive.
Another possible implementation would be to keep 2 extra stacks, one for
exceptions and another one for frame unwind info. Each time a function
is called (in the function prologue) a pointer to the relevant frame
unwind info is pushed on the frame unwind info stack, and the function
epilogue contains a pop instruction for that same stack. Similary each
time a try block is opened a pointer to an exception descriptor is
pushed on the exception stack and again it is the stack is popped when
control leaves the try block.
This way no search is needed for the frame unwind info and the exception
handler, at the cost of a few extra assembly instructions in the normal
flow of the program.
Am I missing some important detail here?
Regards
Halldor Isak Gylfason
halldori@ru.is