diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/heap/WeakSet.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/heap/WeakSet.cpp')
-rw-r--r-- | Source/JavaScriptCore/heap/WeakSet.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/Source/JavaScriptCore/heap/WeakSet.cpp b/Source/JavaScriptCore/heap/WeakSet.cpp index e62e66eae..faae02c7e 100644 --- a/Source/JavaScriptCore/heap/WeakSet.cpp +++ b/Source/JavaScriptCore/heap/WeakSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2012, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,26 +27,60 @@ #include "WeakSet.h" #include "Heap.h" +#include "JSCInlines.h" #include "VM.h" namespace JSC { WeakSet::~WeakSet() { + if (isOnList()) + remove(); + + Heap& heap = *this->heap(); WeakBlock* next = 0; for (WeakBlock* block = m_blocks.head(); block; block = next) { next = block->next(); - heap()->blockAllocator().deallocate(WeakBlock::destroy(block)); + WeakBlock::destroy(heap, block); } m_blocks.clear(); } void WeakSet::sweep() { - for (WeakBlock* block = m_blocks.head(); block; block = block->next()) + for (WeakBlock* block = m_blocks.head(); block;) { + heap()->sweepNextLogicallyEmptyWeakBlock(); + + WeakBlock* nextBlock = block->next(); block->sweep(); + if (block->isLogicallyEmptyButNotFree()) { + // If this WeakBlock is logically empty, but still has Weaks pointing into it, + // we can't destroy it just yet. Detach it from the WeakSet and hand ownership + // to the Heap so we don't pin down the entire MarkedBlock or LargeAllocation. + m_blocks.remove(block); + heap()->addLogicallyEmptyWeakBlock(block); + block->disconnectContainer(); + } + block = nextBlock; + } + + resetAllocator(); +} + +void WeakSet::shrink() +{ + WeakBlock* next; + for (WeakBlock* block = m_blocks.head(); block; block = next) { + next = block->next(); + + if (block->isEmpty()) + removeAllocator(block); + } resetAllocator(); + + if (m_blocks.isEmpty() && isOnList()) + remove(); } WeakBlock::FreeCell* WeakSet::findAllocator() @@ -73,7 +107,10 @@ WeakBlock::FreeCell* WeakSet::tryFindAllocator() WeakBlock::FreeCell* WeakSet::addAllocator() { - WeakBlock* block = WeakBlock::create(heap()->blockAllocator().allocate<WeakBlock>()); + if (!isOnList()) + heap()->objectSpace().addActiveWeakSet(this); + + WeakBlock* block = WeakBlock::create(*heap(), m_container); heap()->didAllocate(WeakBlock::blockSize); m_blocks.append(block); WeakBlock::SweepResult sweepResult = block->takeSweepResult(); @@ -84,7 +121,7 @@ WeakBlock::FreeCell* WeakSet::addAllocator() void WeakSet::removeAllocator(WeakBlock* block) { m_blocks.remove(block); - heap()->blockAllocator().deallocate(WeakBlock::destroy(block)); + WeakBlock::destroy(*heap(), block); } } // namespace JSC |