Thread-safe v8::Isolate::getHeapUsage

28 views
Skip to first unread message

Elliott Brossard

unread,
Dec 16, 2024, 5:41:09 PM12/16/24
to v8-dev
Is there a thread-safe way to get the current heap usage for an isolate? What I observed is that if one thread is performing an allocation, attempting to call v8::Isolate::getHeapUsage from another triggers a data race. Apologies if I missed it, but I didn't see anything relevant in the documentation or past discussion threads. The use case is that I'd like to be able to track heap usage over time as a long-running call into a JavaScript function executes. The output I get (under a recent Clang with TSan) is of the form below. Thanks in advance!

2024-12-16 20:49:36,949     WARNING: ThreadSanitizer: data race (pid=21642)
2024-12-16 20:49:36,949     Write of size 8 at 0x725000002be8 by main thread (mutexes: write M0):
2024-12-16 20:49:36,949     #0 v8::internal::LinearAllocationArea::IncrementTop(unsigned long) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x36fed5d)
2024-12-16 20:49:36,949     #1 v8::internal::SpaceWithLinearArea::AllocateFastUnaligned(int, v8::internal::AllocationOrigin) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x384ab82)
2024-12-16 20:49:36,949     #2 v8::internal::SpaceWithLinearArea::AllocateRaw(int, v8::internal::AllocationAlignment, v8::internal::AllocationOrigin) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x384a807)
2024-12-16 20:49:36,949     #3 v8::internal::AllocationResult v8::internal::HeapAllocator::AllocateRaw<(v8::internal::AllocationType)2>(int, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x3849227)
2024-12-16 20:49:36,949     #4 v8::internal::HeapAllocator::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x3848498)
2024-12-16 20:49:36,949     #5 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x39aae43)
2024-12-16 20:49:36,949     #6 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x39ab103)
...
2024-12-16 20:49:36,951     Previous read of size 8 at 0x725000002be8 by thread T17 (mutexes: write M1):
2024-12-16 20:49:36,951     #0 v8::internal::LinearAllocationArea::top() const <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x36fd936)
2024-12-16 20:49:36,951     #1 v8::internal::PagedSpaceBase::CommittedPhysicalMemory() const <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x3b4c1c1)
2024-12-16 20:49:36,951     #2 v8::internal::Heap::CommittedPhysicalMemory() <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x390d3a1)
2024-12-16 20:49:36,951     #3 v8::Isolate::GetHeapStatistics(v8::HeapStatistics*) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x2ec38ad)
...

Dominik Inführ

unread,
Dec 17, 2024, 7:32:38 AM12/17/24
to v8-...@googlegroups.com
Hi,

GetHeapStatistics needs to be used from the main thread and there was a feature request filed for this here: https://issues.chromium.org/u/1/issues/345822325. There is also a workaround discussed in there using RequestInterrupt.

Best,
Dominik

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/v8-dev/c9c8701e-245e-4de1-a347-d7a33003f869n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages