Thanks for your reply, Ben. I tried to use V8::InitializePlatform(), V8::Initialize(), V8::Dispose() and V8::ShutdownPlatform() only once as you said. And renew an Isolate instance like the following, still got a SIGSEGV.
int main(int argc, char* argv[]) { > > // Initialize V8. > > v8::V8::InitializeICUDefaultLocation(argv[0]); > > v8::V8::InitializeExternalStartupData(argv[0]); > > std::unique_ptr<v8::Platform> platform = >> v8::platform::NewDefaultPlatform(); > > v8::V8::InitializePlatform(platform.get()); > > v8::V8::Initialize(); > > >> // Create a new Isolate and make it the current one. > > v8::Isolate::CreateParams create_params; > > create_params.array_buffer_allocator = > > v8::ArrayBuffer::Allocator::NewDefaultAllocator(); > > v8::Isolate* isolate = v8::Isolate::New(create_params); > > { > > v8::Isolate::Scope isolate_scope(isolate); > > // ------------------------------------------------- > // ignore. evaluate some js strings here. > > // -------------------------------------------------- > // Dispose the isolate and tear down V8. > > isolate->Dispose(); > > v8::V8::Dispose(); > > v8::V8::ShutdownPlatform(); > > delete create_params.array_buffer_allocator; > > >> // -------------------------------------------------- > // do it again for testing. Now commented those, call only once >> V8::Initializexxx at the begining. > > // -------------------------------------------------- > // v8::V8::InitializeICUDefaultLocation(argv[0]); > > // v8::V8::InitializeExternalStartupData(argv[0]); > > // std::unique_ptr<v8::Platform> platform2 = >> v8::platform::NewDefaultPlatform(); > > // v8::V8::InitializePlatform(platform2.get()); > > // v8::V8::Initialize(); > > >> // Create a new Isolate and make it the current one. > > v8::Isolate::CreateParams create_params2; > > create_params2.array_buffer_allocator = > > v8::ArrayBuffer::Allocator::NewDefaultAllocator(); > > v8::Isolate* isolate2 = v8::Isolate::New(create_params2); // crash here. > > > return 0; > > } > > The backtrace is like this: (gdb) bt #0 0x000000000050aa99 in v8::internal::Heap::MonotonicallyIncreasingTimeInMs() () #1 0x00000000004ca0d3 in v8::internal::Isolate::Init(v8::internal::ReadOnlyDeserializer*, v8::internal::StartupDeserializer*) () #2 0x00000000004cb229 in v8::internal::Isolate::InitWithSnapshot(v8::internal::ReadOnlyDeserializer*, v8::internal::StartupDeserializer*) () #3 0x00000000007d46a5 in v8::internal::Snapshot::Initialize(v8::internal::Isolate*) () #4 0x000000000044ab62 in v8::Isolate::Initialize(v8::Isolate*, v8::Isolate::CreateParams const&) () #5 0x000000000044acb2 in v8::Isolate::New(v8::Isolate::CreateParams const&) () #6 0x00000000004149eb in main () Is that means v8 cannot create two isolates? Also, in my embedded program, two isolates are in different thread, but it fails as the same backtraces as above. 在 2020年4月10日星期五 UTC+8下午11:15:29,Ben Noordhuis写道: > > On Fri, Apr 10, 2020 at 12:47 PM Chris Chen <chenqy...@gmail.com > <javascript:>> wrote: > > > > Hi, all, I am embedding v8 into a c++ program, and when trying to > initialize an Isolate again, the program crashes. > > > > The way I was doing is made an v8::Isolate as a member field of an > JsEngine instance, then call ~JsEngine() and renew a JsEngine instance. In > ~JsEngine(), I do stuff like disposed Isolate, shutdown platform, etc. > > > > This can be reproduced by some modification to samples/hello-world.cc as > following: > > > >>> int main(int argc, char* argv[]) { > >>> > >>> // Initialize V8. > >>> > >>> v8::V8::InitializeICUDefaultLocation(argv[0]); > >>> > >>> v8::V8::InitializeExternalStartupData(argv[0]); > >>> > >>> std::unique_ptr<v8::Platform> platform = > v8::platform::NewDefaultPlatform(); > >>> > >>> v8::V8::InitializePlatform(platform.get()); > >>> > >>> v8::V8::Initialize(); > >>> > >>> > >>> // Create a new Isolate and make it the current one. > >>> > >>> v8::Isolate::CreateParams create_params; > >>> > >>> create_params.array_buffer_allocator = > >>> > >>> v8::ArrayBuffer::Allocator::NewDefaultAllocator(); > >>> > >>> v8::Isolate* isolate = v8::Isolate::New(create_params); > >>> > >>> { > >>> > >>> v8::Isolate::Scope isolate_scope(isolate); > > > > > > // ------------------------------------------------- > >>> > >>> // ignore. evaluate some js strings here. > > > > // -------------------------------------------------- > >>> > >>> // Dispose the isolate and tear down V8. > >>> > >>> isolate->Dispose(); > >>> > >>> v8::V8::Dispose(); > >>> > >>> v8::V8::ShutdownPlatform(); > >>> > >>> delete create_params.array_buffer_allocator; > >>> > >>> > > // -------------------------------------------------- > >>> > >>> // do it again for testing > > > > // -------------------------------------------------- > >>> > >>> v8::V8::InitializeICUDefaultLocation(argv[0]); > >>> > >>> v8::V8::InitializeExternalStartupData(argv[0]); > >>> > >>> std::unique_ptr<v8::Platform> platform2 = > v8::platform::NewDefaultPlatform(); > >>> > >>> v8::V8::InitializePlatform(platform2.get()); > >>> > >>> v8::V8::Initialize(); > >>> > >>> > >>> // Create a new Isolate and make it the current one. > >>> > >>> v8::Isolate::CreateParams create_params2; > >>> > >>> create_params2.array_buffer_allocator = > >>> > >>> v8::ArrayBuffer::Allocator::NewDefaultAllocator(); > >>> > >>> v8::Isolate* isolate2 = v8::Isolate::New(create_params2); // crash > here. > > > > > >>> > >>> return 0; > >>> > >>> } > > > > The output is like this: > >>> > >>> Hello, World! > >>> > >>> 3 + 4 = 7 > >>> > >>> Segmentation fault (core dumped) > >> > >> > > > > The backtrace looks like this: > >> > >> > >> > >> #0 __GI___pthread_mutex_lock (mutex=0x128) at > ../nptl/pthread_mutex_lock.c:67 > >> > >> #1 0x00000000007f2073 in > v8::internal::wasm::WasmEngine::AddIsolate(v8::internal::Isolate*) () > >> > >> #2 0x00000000004cadd8 in > v8::internal::Isolate::Init(v8::internal::ReadOnlyDeserializer*, > v8::internal::StartupDeserializer*) () > >> > >> #3 0x00000000004cb2b9 in > v8::internal::Isolate::InitWithSnapshot(v8::internal::ReadOnlyDeserializer*, > v8::internal::StartupDeserializer*) () > >> > >> #4 0x00000000007d4735 in > v8::internal::Snapshot::Initialize(v8::internal::Isolate*) () > >> > >> #5 0x000000000044abf2 in v8::Isolate::Initialize(v8::Isolate*, > v8::Isolate::CreateParams const&) () > >> > >> #6 0x000000000044ad42 in v8::Isolate::New(v8::Isolate::CreateParams > const&) () > >> > >> #7 0x0000000000414a4e in main () > >> > >> (gdb) q > > > > > > > > Why this behavior will crash, and how to avoid this? > > > > Any hints would be great, Thanks in advance! > > Call V8::InitializePlatform(), V8::Initialize(), V8::Dispose() and > V8::ShutdownPlatform() only once, not twice. > -- -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/b9b1f422-6fef-4e40-ade1-b36774801048%40googlegroups.com.