Setting an execution limit

163 views
Skip to first unread message

James Lovejoy

unread,
Nov 19, 2016, 4:11:28 PM11/19/16
to v8-users
Hi,

Is there a way to set a hard execution limit in the V8 engine? I want to be able to prevent things like infinite loops and recursions. I realise that since V8 compiles to machine code I don't get a program counter or anything. I feel like setting the "stack limit" is the right way to go but the usage of this feature from the documentation is unclear. Can someone guide me as to how to achieve such a limit?

James

Ben Noordhuis

unread,
Nov 20, 2016, 4:02:16 AM11/20/16
to v8-users
If 'execution limit' means 'time limit': start a watchdog thread and
call v8::Isolate::TerminateExecution() from that thread on timeout.
It must be a thread, it's not safe to call from a signal handler.

James Lovejoy

unread,
Nov 20, 2016, 1:18:24 PM11/20/16
to v8-u...@googlegroups.com
Really I need something a little more deterministic than a time limit. Is there a way to set an instruction limit? Or perhaps something similar to lua_sethook (http://pgl.yoyo.org/luai/i/lua_sethook) in Lua which calls a callback every given number of instructions.


--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/Qwdd66xCtTU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tbl...@icloud.com

unread,
Nov 20, 2016, 5:11:35 PM11/20/16
to v8-users
I don't think there's any way. V8 JavaScript code is compiled to native code, and no instrumentation is really possible on that.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

Jakob Kummerow

unread,
Nov 21, 2016, 5:40:10 AM11/21/16
to v8-users
There is always a stack limit, which always prevents infinite recursion; as well as, in fact, finite but very deep recursion.

As Ben said, the only way to prevent infinite or long-running loops is by interrupting the program from another thread. You may have heard of the Halting Problem, TL;DR: there really can be no other way, because in the general case it is impossible to predict whether a loop will terminate at all, and how soon.

There is no way to set a limit for executed instructions. You could hack it, but it's going to be non-trivial.

You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages