summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap/WeakSet.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/heap/WeakSet.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/heap/WeakSet.cpp')
-rw-r--r--Source/JavaScriptCore/heap/WeakSet.cpp47
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