Threading in Spidermonkey

542 views Asked by At

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:

  1. Catch a JSScript before the main loop of Interpret() begins.
  2. Open a separate thread.
  3. In that thread, invoke js_Disassemble with the script to get the machine code.
  4. 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,

1

There are 1 answers

0
Jason Orendorff On

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 an onclick= 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.