part of the PathToFirefox4
How things were before before the method JIT
Previously, use of the debug API precluded any sort of JIT. Tracing can simply be turned off when the debugger attaches, so a debugger could be activated and used at any point. There was a lot of flexibility in implementation since all that needed to be considered was the interpreter.
How things are now
With the introduction of the method JIT, it's no longer necessary to punish the developer with interpreter speeds just for using the debugger. With the JIT, however, there's a lot less flexibility in implementation. Every additional branch in generated code is a slowdown, and since performance is critical, these must be minimized.
The patch for bug 578154 adds the concept of a "debug mode", wherein scripts compiled could be recompiled on the fly to add hooks at the expense of being slightly less optimized. This allows traps (and in the future, single stepping), to be implemented by recompiling a (potentially running) script.
JS Debug API Changes
For these and other reasons, some changes to the API were made:
- SetInterrupt no longer immediately interrupts execution on the next instruction. Instead, it interrupts "soon" -- at the top of any loop or before any function call (the same time the operation callback is checked).
- SetInterrupt may not be per-runtime, but this has not been finalized.
- It is an error to call most debug functions when not in debug mode.
- Get/SetDebugMode have been added to enter and leave debug mode when no JS frames are active.
These changes only change the JSDBGAPI side of things. Our primary consumers, Venkman and Firebug, consume JSD. JSD either needs to be able to expose its current API with internal changes to adapt to these changes, or needs to change its API.
- Single stepping may be affected by the changes to SetInterrupt, but this is unclear. A proposed enhancement to the existing JSDBGAPI is to have trap functions return a value JSTRAP_STEP, which would cause a "trap" to be recompiled in for every opcode, and JSTRAP_CONTINUE to undo this transformation.
- JSD may also need to expose some API to enable or disable debug mode. This should probably be accomplished by sending an event to the main event loop which will then do the actual toggling. This is necessary as it is not safe to change debug mode state while there are live JS frames on the stack. It may also be possible to hide this from consumers in existing function calls.