[cppgc] Is it possible to use this with the v8::Locker API?

149 views
Skip to first unread message

Nyannyacha

unread,
Oct 11, 2024, 12:47:24 AM10/11/24
to v8-users
I'm using the Locker API to make an Isolate accessible from multiple threads and it seems to be working well so far.

The problem is that when using cppheap(oilpan), when I call a JS Function via an Isolate, it triggers a GC Task sometimes, which in turn calls PreFinalizerHandler::InvokePreFinalizers() inside CppHeap. It eventually hits DCHECK(CurrentThreadIsCreationThread()), which causes the program to crash.

Backtrace (based on 12.7.224.12)
* frame #0: 0x0000aaaaaf3bfeb0 `v8::base::OS::Abort() at platform-posix.cc:701:7
  frame #1: 0x0000aaaaaf3be29c `V8_Fatal(char const*, int, char const*, ...) at logging.cc:215:3
  frame #2: 0x0000aaaaaf3bdc78 `v8::base::(anonymous namespace)::DefaultDcheckHandler(char const*, int, char const*) at logging.cc:59:3
  frame #3: 0x0000aaaab00c729c `cppgc::internal::PreFinalizerHandler::InvokePreFinalizers() at prefinalizer-handler.cc:57:3
  frame #4: 0x0000aaaab00b634c `cppgc::internal::HeapBase::ExecutePreFinalizers() at heap-base.cc:169:26
  frame #5: 0x0000aaaaaf68ef54 `v8::internal::CppHeap::FinishMarkingAndStartSweeping() at cpp-heap.cc:939:51
  frame #6: 0x0000aaaaaf710608 `v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) at heap.cc:2411:32
  frame #7: 0x0000aaaaaf729d30 `v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1::operator()() const at heap.cc:1767:9
  frame #8: 0x0000aaaaaf7297b4 `void heap::base::Stack::SetMarkerAndCallbackImpl<v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1>(heap::base::Stack*, void*, void const*) at stack.h:176:5
  frame #9: 0x0000aaaab00d75d8 `PushAllRegistersAndIterateStack + 44
  frame #10: 0x0000aaaaaf70bdc8 `v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) at heap.cc:1731:11
  frame #11: 0x0000aaaaaf70d988 `v8::internal::Heap::FinalizeIncrementalMarkingAtomically(v8::internal::GarbageCollectionReason) at heap.cc:3953:3
  frame #12: 0x0000aaaaaf72e7a4 `v8::internal::IncrementalMarkingJob::Task::RunInternal() at incremental-marking-job.cc:137:34
  frame #13: 0x0000aaaaaf3c2e64 `v8::platform::DefaultPlatform::PumpMessageLoop(v8::Isolate*, v8::platform::MessageLoopBehavior) at default-platform.cc:173:9

...


I can find mentions of the v8::Locker API in the Attach/DetachCppHeap in v8-isolate.h and the CppHeap in v8-cppgc.h, but I can't find any tests on how this can be used with the v8::Locker API.

...But I know this is thread-local data that can't be transferred to other threads, so I have a vague feeling that I should use a combination of AttachCppHeap/DetachCppHeap(...and v8::CppHeap::Create, if needed) to replace it every time when an Isolate moves back and forth between threads, but I have no idea what side effects this will cause.

If anyone is familiar with the above case, can someone give me some guidelines?

Nyannyacha

unread,
Oct 14, 2024, 6:41:50 AM10/14/24
to v8-users
After an email with Michael, it turns out that this is a bug.


2024년 10월 11일 금요일 오후 1시 47분 24초 UTC+9에 Nyannyacha님이 작성:
Reply all
Reply to author
Forward
0 new messages