summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap/CodeBlockSet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/heap/CodeBlockSet.cpp')
-rw-r--r--Source/JavaScriptCore/heap/CodeBlockSet.cpp143
1 files changed, 82 insertions, 61 deletions
diff --git a/Source/JavaScriptCore/heap/CodeBlockSet.cpp b/Source/JavaScriptCore/heap/CodeBlockSet.cpp
index c04cbacd6..0cfcd1fed 100644
--- a/Source/JavaScriptCore/heap/CodeBlockSet.cpp
+++ b/Source/JavaScriptCore/heap/CodeBlockSet.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2015 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,94 +27,115 @@
#include "CodeBlockSet.h"
#include "CodeBlock.h"
+#include "JSCInlines.h"
#include "SlotVisitor.h"
+#include <wtf/CommaPrinter.h>
namespace JSC {
static const bool verbose = false;
-CodeBlockSet::CodeBlockSet() { }
+CodeBlockSet::CodeBlockSet()
+{
+}
CodeBlockSet::~CodeBlockSet()
{
- HashSet<CodeBlock*>::iterator iter = m_set.begin();
- HashSet<CodeBlock*>::iterator end = m_set.end();
- for (; iter != end; ++iter)
- (*iter)->deref();
}
-void CodeBlockSet::add(PassRefPtr<CodeBlock> codeBlock)
+void CodeBlockSet::add(CodeBlock* codeBlock)
{
- CodeBlock* block = codeBlock.leakRef();
- bool isNewEntry = m_set.add(block).isNewEntry;
+ LockHolder locker(&m_lock);
+ bool isNewEntry = m_newCodeBlocks.add(codeBlock).isNewEntry;
ASSERT_UNUSED(isNewEntry, isNewEntry);
}
-void CodeBlockSet::clearMarks()
+void CodeBlockSet::promoteYoungCodeBlocks(const LockHolder&)
{
- HashSet<CodeBlock*>::iterator iter = m_set.begin();
- HashSet<CodeBlock*>::iterator end = m_set.end();
- for (; iter != end; ++iter) {
- CodeBlock* codeBlock = *iter;
- codeBlock->m_mayBeExecuting = false;
- codeBlock->m_visitAggregateHasBeenCalled = false;
- }
+ ASSERT(m_lock.isLocked());
+ m_oldCodeBlocks.add(m_newCodeBlocks.begin(), m_newCodeBlocks.end());
+ m_newCodeBlocks.clear();
}
-void CodeBlockSet::deleteUnmarkedAndUnreferenced()
+void CodeBlockSet::clearMarksForFullCollection()
{
- // This needs to be a fixpoint because code blocks that are unmarked may
- // refer to each other. For example, a DFG code block that is owned by
- // the GC may refer to an FTL for-entry code block that is also owned by
- // the GC.
- Vector<CodeBlock*, 16> toRemove;
- if (verbose)
- dataLog("Fixpointing over unmarked, set size = ", m_set.size(), "...\n");
- for (;;) {
- HashSet<CodeBlock*>::iterator iter = m_set.begin();
- HashSet<CodeBlock*>::iterator end = m_set.end();
- for (; iter != end; ++iter) {
- CodeBlock* codeBlock = *iter;
- if (!codeBlock->hasOneRef())
- continue;
- if (codeBlock->m_mayBeExecuting)
- continue;
- codeBlock->deref();
- toRemove.append(codeBlock);
- }
- if (verbose)
- dataLog(" Removing ", toRemove.size(), " blocks.\n");
- if (toRemove.isEmpty())
- break;
- for (unsigned i = toRemove.size(); i--;)
- m_set.remove(toRemove[i]);
- toRemove.resize(0);
- }
+ LockHolder locker(&m_lock);
+ for (CodeBlock* codeBlock : m_oldCodeBlocks)
+ codeBlock->clearVisitWeaklyHasBeenCalled();
+
+ // We promote after we clear marks on the old generation CodeBlocks because
+ // none of the young generations CodeBlocks need to be cleared.
+ promoteYoungCodeBlocks(locker);
}
-void CodeBlockSet::traceMarked(SlotVisitor& visitor)
+void CodeBlockSet::lastChanceToFinalize()
{
- if (verbose)
- dataLog("Tracing ", m_set.size(), " code blocks.\n");
- HashSet<CodeBlock*>::iterator iter = m_set.begin();
- HashSet<CodeBlock*>::iterator end = m_set.end();
- for (; iter != end; ++iter) {
- CodeBlock* codeBlock = *iter;
- if (!codeBlock->m_mayBeExecuting)
+ LockHolder locker(&m_lock);
+ for (CodeBlock* codeBlock : m_newCodeBlocks)
+ codeBlock->classInfo()->methodTable.destroy(codeBlock);
+
+ for (CodeBlock* codeBlock : m_oldCodeBlocks)
+ codeBlock->classInfo()->methodTable.destroy(codeBlock);
+}
+
+void CodeBlockSet::deleteUnmarkedAndUnreferenced(HeapOperation collectionType)
+{
+ LockHolder locker(&m_lock);
+ HashSet<CodeBlock*>& set = collectionType == EdenCollection ? m_newCodeBlocks : m_oldCodeBlocks;
+ Vector<CodeBlock*> unmarked;
+ for (CodeBlock* codeBlock : set) {
+ if (Heap::isMarked(codeBlock))
continue;
- codeBlock->visitAggregate(visitor);
+ unmarked.append(codeBlock);
}
+
+ for (CodeBlock* codeBlock : unmarked) {
+ codeBlock->classInfo()->methodTable.destroy(codeBlock);
+ set.remove(codeBlock);
+ }
+
+ // Any remaining young CodeBlocks are live and need to be promoted to the set of old CodeBlocks.
+ if (collectionType == EdenCollection)
+ promoteYoungCodeBlocks(locker);
+}
+
+bool CodeBlockSet::contains(const LockHolder&, void* candidateCodeBlock)
+{
+ RELEASE_ASSERT(m_lock.isLocked());
+ CodeBlock* codeBlock = static_cast<CodeBlock*>(candidateCodeBlock);
+ if (!HashSet<CodeBlock*>::isValidValue(codeBlock))
+ return false;
+ return m_oldCodeBlocks.contains(codeBlock) || m_newCodeBlocks.contains(codeBlock) || m_currentlyExecuting.contains(codeBlock);
}
-void CodeBlockSet::rememberCurrentlyExecutingCodeBlocks(Heap* heap)
+void CodeBlockSet::writeBarrierCurrentlyExecutingCodeBlocks(Heap* heap)
{
-#if ENABLE(GGC)
- for (size_t i = 0; i < m_currentlyExecuting.size(); ++i)
- heap->addToRememberedSet(m_currentlyExecuting[i]->ownerExecutable());
+ LockHolder locker(&m_lock);
+ if (verbose)
+ dataLog("Remembering ", m_currentlyExecuting.size(), " code blocks.\n");
+ for (CodeBlock* codeBlock : m_currentlyExecuting)
+ heap->writeBarrier(codeBlock);
+
+ // It's safe to clear this set because we won't delete the CodeBlocks
+ // in it until the next GC, and we'll recompute it at that time.
m_currentlyExecuting.clear();
-#else
- UNUSED_PARAM(heap);
-#endif // ENABLE(GGC)
+}
+
+void CodeBlockSet::dump(PrintStream& out) const
+{
+ CommaPrinter comma;
+ out.print("{old = [");
+ for (CodeBlock* codeBlock : m_oldCodeBlocks)
+ out.print(comma, pointerDump(codeBlock));
+ out.print("], new = [");
+ comma = CommaPrinter();
+ for (CodeBlock* codeBlock : m_newCodeBlocks)
+ out.print(comma, pointerDump(codeBlock));
+ out.print("], currentlyExecuting = [");
+ comma = CommaPrinter();
+ for (CodeBlock* codeBlock : m_currentlyExecuting)
+ out.print(comma, pointerDump(codeBlock));
+ out.print("]}");
}
} // namespace JSC