Re: [v8-users] V8::TerminateExecution().
Thanks Jakob. As I'm an embedder, and when I need to terminate execution, it's when I need to throw a retry-able exception to my system and start from scratch. So I'm following the practice Ben suggested a while ago, which seems to work with some basic testing: v8::V8::TerminateExecution(isolate); v8::Local script_source = v8::String::NewFromUtf8(isolate, "0"); v8::TryCatch try_catch; v8::Script::Compile(script_source)->Run(); assert(v8::V8::IsExecutionTerminating(isolate)); Is this the recommended way to force termination? Any gochas I should watch out for? Thanks, Jane On Tuesday, September 30, 2014 1:18:46 AM UTC-7, Jakob Kummerow wrote: > > Generated code doesn't check for termination requests after every machine > instruction, because that would be way too slow. It does check in loops > (not on every iteration, though, only now and then), and some other > situations like function calls. > > Note that TerminateExecution is intended for permanent *termination*, not > suspension. Primary use case: allow a user to kill hanging tabs in Chrome. > This also motivates why it's perfectly fine if termination doesn't happen > instantly, as long as it happens within a time that a human perceives as > "quickly" (a couple of milliseconds). > > > On Tue, Sep 30, 2014 at 7:29 AM, Jane Chen > wrote: > >> I'm following the example in TestTerminateOnlyV8ThreadFromThreadItself() >> in test-thread-termination.cc, and it works for me: >> >> function f() { >> var term = true; >> try { >> while (true) { >> if (term) terminate(); >> term = false; >> } >> print("not terminated."); >> } catch (err) { >> print("not terminated."); >> err.toString(); >> } >> } >> f() >> >> But if I modify the test and remove the while loop, it doesn't work and >> print will be called and fail: >> >> function f() { >> var term = true; >> try { >> if (term) terminate(); >> term = false; >> print("not terminated."); >> } catch (err) { >> print("not terminated."); >> err.toString(); >> } >> } >> f() >> >> What's the significance of the while loop here? >> >> Thanks. >> >> -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [v8-users] V8::TerminateExecution().
Generated code doesn't check for termination requests after every machine instruction, because that would be way too slow. It does check in loops (not on every iteration, though, only now and then), and some other situations like function calls. Note that TerminateExecution is intended for permanent *termination*, not suspension. Primary use case: allow a user to kill hanging tabs in Chrome. This also motivates why it's perfectly fine if termination doesn't happen instantly, as long as it happens within a time that a human perceives as "quickly" (a couple of milliseconds). On Tue, Sep 30, 2014 at 7:29 AM, Jane Chen wrote: > I'm following the example in TestTerminateOnlyV8ThreadFromThreadItself() > in test-thread-termination.cc, and it works for me: > > function f() { > var term = true; > try { > while (true) { > if (term) terminate(); > term = false; > } > print("not terminated."); > } catch (err) { > print("not terminated."); > err.toString(); > } > } > f() > > But if I modify the test and remove the while loop, it doesn't work and > print will be called and fail: > > function f() { > var term = true; > try { > if (term) terminate(); > term = false; > print("not terminated."); > } catch (err) { > print("not terminated."); > err.toString(); > } > } > f() > > What's the significance of the while loop here? > > Thanks. > > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [v8-users] V8::TerminateExecution() corrupts the stack;
Is this 64bit? If so it could be this issue: http://code.google.com/p/v8/issues/detail?id=1180 I only observed this issue with stack overflows but the root cause is that stack limits are not being set correctly so perhaps they're related? Try this.. right after you enter the context in your new thread put this line: Script::Compile(String::New("void 0;")); On Tue, Apr 26, 2011 at 9:38 PM, Mads Sig Ager wrote: > Hi Ravi, > > would you provide a reduced test case that reproduces this issue? Without > that I can only guess. Exception termination takes place by throwing > uncatchable exceptions. However, when terminating execution we have to > return control to C++ frames on the stack. When that happens the embedder > should return out of C++ back to JavaScript until there are no more > JavaScript frames on the stack. > > Thanks,-- Mads > > > On Sat, Apr 16, 2011 at 12:54 PM, Chinnu wrote: > >> Hi, >> >> I've been trying to come up with a way to terminate the V8 execution >> on a script if it runs too long. >> >> For this, I've used the Locker::StartPreemption() and on receiving a >> preemption (in RuntimePreempt() method in execution.cc), am >> incrementing a count and invoking >> V8::TerminateExecution(current_thread_id) if the count exceeds a >> limit. >> >> However, the use of V8::TerminateExecution(current_thread_id) at that >> point is causing a crash probably due to a stack corruption. I was >> wondering if this isn't an appropriate place to use this API, and if >> this API is supposed to be invoked in a specific way. >> >> Please let me know if there is a proper way to use the >> V8::TerminateExecution() API. >> >> Thanks, >> Ravi >> >> -- >> v8-users mailing list >> v8-users@googlegroups.com >> http://groups.google.com/group/v8-users >> > > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users
Re: [v8-users] V8::TerminateExecution() corrupts the stack;
Hi Ravi, would you provide a reduced test case that reproduces this issue? Without that I can only guess. Exception termination takes place by throwing uncatchable exceptions. However, when terminating execution we have to return control to C++ frames on the stack. When that happens the embedder should return out of C++ back to JavaScript until there are no more JavaScript frames on the stack. Thanks,-- Mads On Sat, Apr 16, 2011 at 12:54 PM, Chinnu wrote: > Hi, > > I've been trying to come up with a way to terminate the V8 execution > on a script if it runs too long. > > For this, I've used the Locker::StartPreemption() and on receiving a > preemption (in RuntimePreempt() method in execution.cc), am > incrementing a count and invoking > V8::TerminateExecution(current_thread_id) if the count exceeds a > limit. > > However, the use of V8::TerminateExecution(current_thread_id) at that > point is causing a crash probably due to a stack corruption. I was > wondering if this isn't an appropriate place to use this API, and if > this API is supposed to be invoked in a specific way. > > Please let me know if there is a proper way to use the > V8::TerminateExecution() API. > > Thanks, > Ravi > > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users