V8断言`调试检查失败:ThreadId :: Current()。Equals(compilation_info() - > isolate() - > thread_id())`失败

时间:2017-10-09 07:31:08

标签: multithreading chromium v8

我正致力于将某些第三方产品集成到Chromium(Android)中,该产品在浏览器流程(主要版本)中运行。 该产品使用Chromium的V8,并使用Isolate创建新的IsolateHolder

// thread
thread = new base::Thread("MyProductThread");
thread->Start();

#ifdef V8_USE_EXTERNAL_STARTUP_DATA
LOG(WARNING) << "MyProduct: loading v8 snapshot & natives ...";
gin::V8Initializer::LoadV8Snapshot();
gin::V8Initializer::LoadV8Natives();
LOG(WARNING) << "MyProduct: loaded v8 snapshot & natives";
#endif

LOG(WARNING) << "MyProduct: initialize isolate holder";
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
                               gin::IsolateHolder::kStableV8Extras,
                               gin::ArrayBufferAllocator::SharedInstance());

isolate_holder = new gin::IsolateHolder(
  thread->task_runner(),
  gin::IsolateHolder::AccessMode::kUseLocker);
isolate_holder->isolate()->Enter();

LOG(WARNING) << "MyProduct: created isolate holder";

// return isolate pointer
v8::Isolate* isolate = isolate_holder->isolate();

我正在创建新的线程,以便不阻止UI,因为代码是从主线程调用的(来自Android的活动,通过生成的JNI转发到C ++)。

然后有时它会崩溃:

  

...... E / v8:#                                        #../../v8/src/compiler.cc,第87行致命错误

     

调试检查失败:ThreadId :: Current()。Equals(compilation_info() - &gt; isolate() - &gt; thread_id())

这是什么意思?

有限的堆栈跟踪:

Stack Trace:


RELADDR   FUNCTION                                                                                                                                                                                                                                                                                                                                                                                                                               FILE:LINE
  000161d5  gin::(anonymous namespace)::PrintStackTrace()                                                                                                                                                                                                                                                                                                                                                                                          /home/antoine/chromium/src/gin/v8_platform.cc:55
  0000d051  V8_Fatal(char const*, int, char const*, ...)                                                                                                                                                                                                                                                                                                                                                                                           /home/antoine/chromium/src/v8/src/base/logging.cc:123
  0022eca5  v8::internal::CompilationJob::PrepareJob()                                                                                                                                                                                                                                                                                                                                                                                             /home/antoine/chromium/src/v8/src/compiler.cc:86
  00235733  v8::internal::(anonymous namespace)::PrepareAndExecuteUnoptimizedCompileJob(v8::internal::ParseInfo*, v8::internal::FunctionLiteral*, v8::internal::Isolate*)                                                                                                                                                                                                                                                                          /home/antoine/chromium/src/v8/src/compiler.cc:387
  0022fe25  v8::internal::(anonymous namespace)::GenerateUnoptimizedCode(v8::internal::ParseInfo*, v8::internal::Isolate*, std::__ndk1::forward_list<std::__ndk1::unique_ptr<v8::internal::CompilationJob, std::__ndk1::default_delete<v8::internal::CompilationJob> >, std::__ndk1::allocator<std::__ndk1::unique_ptr<v8::internal::CompilationJob, std::__ndk1::default_delete<v8::internal::CompilationJob> > > >*)                             /home/antoine/chromium/src/v8/src/compiler.cc:413
  00231f13  v8::internal::(anonymous namespace)::CompileToplevel(v8::internal::ParseInfo*, v8::internal::Isolate*)                                                                                                                                                                                                                                                                                                                                 /home/antoine/chromium/src/v8/src/compiler.cc:786
  0023358d  v8::internal::Compiler::GetSharedFunctionInfoForScript(v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::Object>, int, int, v8::ScriptOriginOptions, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Context>, v8::Extension*, v8::internal::ScriptData**, v8::ScriptCompiler::CompileOptions, v8::internal::NativesFlag, v8::internal::Handle<v8::internal::FixedArray>)  /home/antoine/chromium/src/v8/src/compiler.cc:1331
  000ff8f1  v8::ScriptCompiler::CompileUnboundInternal(v8::Isolate*, v8::ScriptCompiler::Source*, v8::ScriptCompiler::CompileOptions)                                                                                                                                                                                                                                                                                                              /home/antoine/chromium/src/v8/src/api.cc:2314
  00100299  v8::ScriptCompiler::Compile(v8::Local<v8::Context>, v8::ScriptCompiler::Source*, v8::ScriptCompiler::CompileOptions)                                                                                                                                                                                                                                                                                                                   /home/antoine/chromium/src/v8/src/api.cc:2373
  00102047  v8::Script::Compile(v8::Local<v8::Context>, v8::Local<v8::String>, v8::ScriptOrigin*)                                                                                                                                                                                                                                                                                                                                                  /data/app/org.chromium.chrome-1/lib/arm/libv8.cr.so

任何建议都非常感谢!

PS。我没有使用最新版本的Chromium,但我不认为这是问题的原因。

PPS。我尝试使用一些现有的后台线程(使用content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::FILE)),甚至在后台线程中创建Isolate并将其作为IsolateHolder参数传递 - 没有运气。

2 个答案:

答案 0 :(得分:1)

如果我理解正确,你试图在后台线程上运行一个V8实例,同时从主线程调用它(代码片段的末尾返回一个Isolate*指针 - 到主线程,我猜想?)。这是不受支持的。

你当然可以在后台线程上运行V8,但是你需要确保所有V8 API调用都发生在同一个后台线程上。您必须自己实现跨线程通信逻辑(可能使用Chromium现有的PostTask等原语)。

答案 1 :(得分:0)

isolate_holder->isolate()->Enter();不是必需的,甚至是伤害(因为它是由使用Isolate实例的库完成的)但后来影响很大。