This is an interesting question. I could be completely wrong about
this, so please, someone correct me if I am, but it seems threading
works like this-
They expect you to have one instance of V8 per process, which means
one virtual machine ("processor") that is capable of actually running
code (probably has to do with the fact that all threads have to share
the same address space and whatnot). In order to facilitate multiple
scripts running at once, they provide a Locker class to effectively
create a "processor" scheduler, where different threads can request
exclusive access to the "processor" and then serialize their execution
state and yield to another thread when they are done. Now, with this
scheme, there is the problem that a thread can hold exclusive access
to the "processor" for a rude amount of time, and so V8 provides a way
for the implementer to tell the "processor" to force preemption after
a certain amount of time so that no one may, for example, hold
exclusive access for more than 100ms before letting someone else get a
chance to do some work.
If you're willing to jump into the V8 code a little, you could
probably count the number of times the VM forces preemption on a
thread and kill the thread if it's doing it too much.
I don't know about the whole stack limit checks thing. This is just
what I've deduced from the code, and, again, I could be completely
wrong.
On Sep 2, 11:01 pm, "Feng Qian" <
feng.qian...@gmail.com> wrote:
> Stack limit check is put on the entry point of a function and the back-edge
> of loops, so infinite loopswill call stack limit check in each iteration.
>
> V8 does not provide instruction counts since the source code is compiled
> into native code.
> Unless you use CPU hardware monitors, it would be nearly impossible to count
> machine
> instructions.
>
> V8 does have an ARM simulator which interprets generated ARM instructions,
> so the simulator
> is able to count instructions. And again, JS code often calls into C++
> runtime code,
> so the instruction count is not accurate.
>