Clarification on AllowJavascriptExecution

42 views
Skip to first unread message

madana gopal

unread,
May 11, 2018, 10:15:05 AM5/11/18
to v8-users
Hi Team,

We are using using node v6.9.0. We faced a crash, when there is a javascript call being made from our app c++ code. Crash is happening because, call is made within the DisallowJavascriptExecutionScope. This scope is set in OptimizedCompileJob::GenerateCode() in compiler.cc. Scenario is garbage collection is initiated from below code, which caused some cleanup calls to be called from our app to javascript.

OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() {
 ............................
  DisallowJavascriptExecution no_js(isolate());
  {  
   .....................
   RegisterWeakObjectsInOptimizedCode() -> it is invoking garbage collection, which landed up to the code in our app
   ..............
  }

Please clarify, during this time of operation, is it good to call our javascript call with AllowJavaScriptExecutionScope. Will it have any side effects?. Please clarify.

Thanks.

Regards,
Madan

Jakob Kummerow

unread,
May 11, 2018, 2:47:51 PM5/11/18
to v8-users
A DisallowJavascriptExecution scope indicates that the following code relies on no JavaScript code being executed. If you execute JavaScript code anyway, you will probably cause corruption and subsequent crashes or misbehavior. The CHECK-failure exists to point out the problem early and in an easy-to-understand fashion; overriding it with an AllowJavascriptExecutionScope is like removing the "Danger! Minefield!" warning sign before walking into a minefield.

You should probably keep a list of cleanup calls you want to make, and execute them when the event loop gets back to you, rather than immediately.


--
--
v8-users mailing list
v8-u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

madana gopal

unread,
May 11, 2018, 8:01:36 PM5/11/18
to v8-users
Thanks Jakob.

Below is the backtrace. Here how can I identify, when I came out of event loop. Because, we want cleanup calls to get called quickly.

Backtrace:

V8_Fatal
0x5ac3ec3
v8::Function::NewInstance(v8::Local<v8::Context>, int, v8::Local<v8::Value>*) const // calling javascript function here
// app code
v8::internal::GlobalHandles::PendingPhantomCallback::Invoke(v8::internal::Isolate*)
v8::internal::GlobalHandles::DispatchPendingPhantomCallbacks(bool)
v8::internal::GlobalHandles::PostGarbageCollectionProcessing(v8::internal::GarbageCollector, v8::GCCallbackFlags)
v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags)
v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char const*, char const*, v8::GCCallbackFlags)
v8::internal::Factory::CopyFixedArrayAndGrow(v8::internal::Handle<v8::internal::FixedArray>, int, v8::internal::PretenureFlag)
v8::internal::ArrayList::EnsureSpace(v8::internal::Handle<v8::internal::ArrayList>, int)
v8::internal::ArrayList::Add(v8::internal::Handle<v8::internal::ArrayList>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::ArrayList::AddMode)
v8::internal::Heap::AddRetainedMap(v8::internal::Handle<v8::internal::Map>)
0x59d0eda
v8::internal::OptimizedCompileJob::GenerateCode() //DisAllowJavascriptExecutionScope set here
v8::internal::Compiler::FinalizeOptimizedCompileJob(v8::internal::OptimizedCompileJob*)
v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions()
v8::internal::Runtime_TryInstallOptimizedCode(int, v8::internal::Object**, v8::internal::Isolate*)
........................

We have many number of cleanup objects, for which we have to call JS code on it being garbage collected. So, we will have cleanup calls for every object being garbage collected. Could you please point the instant, at which it will be good to identify this operation is completed (i.e the point where JS enging completed its garbage collection operation and we are good to do cleanup).

Thanks.

Regards,
Madan

Jakob Kummerow

unread,
May 11, 2018, 9:45:59 PM5/11/18
to v8-users
It's not about the garbage collection operation being completed.

Presumably you have a call to v8::Script::Run() somewhere? When that call returns, you can safely execute other scripts.

--

madana gopal

unread,
May 11, 2018, 11:47:29 PM5/11/18
to v8-users
Thanks, ok. let me go through and update. We have both Script.Run() calls and vm.runScript() calls in our project. 

So, we have to make sure, we are not making any JS calls, when either Run() or vm.runScript()  going on (as they will involve in code compilation) and need to wait for its completion. Is my understanding right Jakob?

Thanks.

Regards,
Madan

Jakob Kummerow

unread,
May 14, 2018, 2:22:59 PM5/14/18
to v8-users
Yes.

--
Reply all
Reply to author
Forward
0 new messages