Skip to content

Commit 811059e

Browse files
committed
CodeBlock should do a better job accounting for extra memory it allocates.
https://bugs.webkit.org/show_bug.cgi?id=225068 Reviewed by Mark Lam. Source/JavaScriptCore: Right now we aren't telling the JS GC about the extra memory attached to CodeBlocks. It looks like on at least some sites this can be a fairly large percentage of the total memory retained by the JS object graph. * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): (JSC::CodeBlock::JITData::size const): * bytecode/CodeBlock.h: * jit/JITCodeMap.h: (JSC::JITCodeMap::memorySize const): Source/WTF: Small convenience function to help compute the memory used by a Bag for JS GC accounting. * wtf/Bag.h: Canonical link: https://commits.webkit.org/237039@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276610 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 13a6adc commit 811059e

6 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2021-04-26 Keith Miller <keith_miller@apple.com>
2+
3+
CodeBlock should do a better job accounting for extra memory it allocates.
4+
https://bugs.webkit.org/show_bug.cgi?id=225068
5+
6+
Reviewed by Mark Lam.
7+
8+
Right now we aren't telling the JS GC about the extra memory
9+
attached to CodeBlocks. It looks like on at least some sites this
10+
can be a fairly large percentage of the total memory retained by
11+
the JS object graph.
12+
13+
* bytecode/CodeBlock.cpp:
14+
(JSC::CodeBlock::visitChildren):
15+
(JSC::CodeBlock::JITData::size const):
16+
* bytecode/CodeBlock.h:
17+
* jit/JITCodeMap.h:
18+
(JSC::JITCodeMap::memorySize const):
19+
120
2021-04-26 Keith Miller <keith_miller@apple.com>
221

322
numCalleeLocals, numParameters, and numVars should be unsigned

‎Source/JavaScriptCore/bytecode/CodeBlock.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,14 @@ void CodeBlock::visitChildren(Visitor& visitor)
984984
extraMemory += m_metadata->sizeInBytes();
985985
if (m_jitCode && !m_jitCode->isShared())
986986
extraMemory += m_jitCode->size();
987+
#if ENABLE(JIT)
988+
if (m_jitData)
989+
extraMemory += m_jitData->size(locker);
990+
#endif
991+
extraMemory += m_argumentValueProfiles.size() * sizeof(ValueProfile);
992+
extraMemory += m_functionDecls.size() * sizeof(decltype(*m_functionDecls.data()));
993+
extraMemory += m_functionExprs.size() * sizeof(decltype(*m_functionExprs.data()));
994+
987995
visitor.reportExtraMemoryVisited(extraMemory);
988996

989997
stronglyVisitStrongReferences(locker, visitor);
@@ -1021,6 +1029,29 @@ bool CodeBlock::shouldVisitStrongly(const ConcurrentJSLocker& locker, Visitor& v
10211029
template bool CodeBlock::shouldVisitStrongly(const ConcurrentJSLocker&, AbstractSlotVisitor&);
10221030
template bool CodeBlock::shouldVisitStrongly(const ConcurrentJSLocker&, SlotVisitor&);
10231031

1032+
#if ENABLE(JIT)
1033+
size_t CodeBlock::JITData::size(const ConcurrentJSLocker&) const
1034+
{
1035+
size_t size = sizeof(JITData);
1036+
size += m_stubInfos.estimatedAllocationSizeInBytes();
1037+
size += m_addICs.estimatedAllocationSizeInBytes();
1038+
size += m_mulICs.estimatedAllocationSizeInBytes();
1039+
size += m_negICs.estimatedAllocationSizeInBytes();
1040+
size += m_subICs.estimatedAllocationSizeInBytes();
1041+
size += m_byValInfos.estimatedAllocationSizeInBytes();
1042+
size += m_callLinkInfos.estimatedAllocationSizeInBytes();
1043+
size += m_rareCaseProfiles.size() * sizeof(decltype(*m_rareCaseProfiles.data()));
1044+
size += m_switchJumpTables.size() * sizeof(decltype(*m_switchJumpTables.data()));
1045+
size += m_stringSwitchJumpTables.size() * sizeof(decltype(*m_stringSwitchJumpTables.data()));
1046+
// FIXME: account for m_calleeSaveRegisters but it's not a big deal since it's a fixed size and small.
1047+
if (m_pcToCodeOriginMap)
1048+
size += m_pcToCodeOriginMap->memorySize();
1049+
if (m_jitCodeMap)
1050+
size += m_jitCodeMap.memorySize();
1051+
return size;
1052+
}
1053+
#endif
1054+
10241055
bool CodeBlock::shouldJettisonDueToWeakReference(VM& vm)
10251056
{
10261057
if (!JITCode::isOptimizingJIT(jitType()))

‎Source/JavaScriptCore/bytecode/CodeBlock.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ class CodeBlock : public JSCell {
268268
struct JITData {
269269
WTF_MAKE_STRUCT_FAST_ALLOCATED;
270270

271+
size_t size(const ConcurrentJSLocker&) const;
272+
271273
Bag<StructureStubInfo> m_stubInfos;
272274
Bag<JITAddIC> m_addICs;
273275
Bag<JITMulIC> m_mulICs;

‎Source/JavaScriptCore/jit/JITCodeMap.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class JITCodeMap {
5858

5959
explicit operator bool() const { return m_size; }
6060

61+
size_t memorySize() const { return sizeof(CodeLocationLabel<JSEntryPtrTag>) * m_size + sizeof(BytecodeIndex) * m_size; }
62+
6163
private:
6264
CodeLocationLabel<JSEntryPtrTag>* codeLocations() const
6365
{

‎Source/WTF/ChangeLog‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2021-04-26 Keith Miller <keith_miller@apple.com>
2+
3+
CodeBlock should do a better job accounting for extra memory it allocates.
4+
https://bugs.webkit.org/show_bug.cgi?id=225068
5+
6+
Reviewed by Mark Lam.
7+
8+
Small convenience function to help compute the memory used by a Bag for JS GC
9+
accounting.
10+
11+
* wtf/Bag.h:
12+
113
2021-04-26 Angelos Oikonomopoulos <angelos@igalia.com>
214

315
Bump CeilingOnPageSize to 16KB on MIPS

‎Source/WTF/wtf/Bag.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ class Bag final {
139139
return result;
140140
}
141141

142+
// Note: if the contents of the bag have allocated bytes that won't be accounted for here.
143+
size_t estimatedAllocationSizeInBytes() const
144+
{
145+
size_t result = 0;
146+
for (auto node : *this) {
147+
UNUSED_PARAM(node);
148+
result += sizeof(Node) + sizeof(T);
149+
}
150+
return result;
151+
}
142152

143153
iterator end() const { return iterator(); }
144154

0 commit comments

Comments
 (0)