I am trying to enable a threaded debug dump in SpiderMonkey, by editing the jsinterp.cpp file. Basically, the things I am trying to do are as follows:
- Catch a JSScript before the main loop of Interpret() begins.
- Open a separate thread.
- In that thread, invoke js_Disassemble with the script to get the machine code.
- Write the machine code to a file.
The reason for trying a threaded version is simply for performance issues. Some addons become "unresponsive" if I run the disassmeble and write the output in the same thread. I can get some output in a single thread but it's way too slow.
I followed the tutorial in https://developer.mozilla.org/en/Making_Cross-Thread_Calls_Using_Runnables for creating threads. But when I built it, I faced 11 "unresolved external symbol error." Again after some googling, I found out about setting XPCOM_GLUE by #define XPCOM_GLUE 1. However, this time I am facing a new problem: "base class nsRunnable not defined". I can't find a solution for this.
Any help would be appreciated. Thanks,
You can't safely use a separate thread for this. Garbage collection could run on the main thread and collect the
JSScript
out from under you. Then the process would crash.js_Interpret
is called every time SpiderMonkey enters the interpreter, whether the browser is running a<script>
or just calling a function or anonclick=
event listener. So you probably end up dumping the same scripts many times. Maybe that's why it's so slow. Consider dumping the bytecode at compile time instead.