summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.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/dfg/DFGDesiredWeakReferences.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp')
-rw-r--r--Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp48
1 files changed, 41 insertions, 7 deletions
diff --git a/Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp b/Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp
index a8376ea8a..68ff2a6c2 100644
--- a/Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp
+++ b/Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-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
@@ -24,16 +24,21 @@
*/
#include "config.h"
+#include "DFGDesiredWeakReferences.h"
#if ENABLE(DFG_JIT)
-#include "DFGDesiredWeakReferences.h"
-
#include "CodeBlock.h"
#include "DFGCommonData.h"
+#include "JSCInlines.h"
namespace JSC { namespace DFG {
+DesiredWeakReferences::DesiredWeakReferences()
+ : m_codeBlock(nullptr)
+{
+}
+
DesiredWeakReferences::DesiredWeakReferences(CodeBlock* codeBlock)
: m_codeBlock(codeBlock)
{
@@ -45,17 +50,46 @@ DesiredWeakReferences::~DesiredWeakReferences()
void DesiredWeakReferences::addLazily(JSCell* cell)
{
- m_references.append(cell);
+ if (cell)
+ m_references.add(cell);
+}
+
+void DesiredWeakReferences::addLazily(JSValue value)
+{
+ if (value.isCell())
+ addLazily(value.asCell());
+}
+
+bool DesiredWeakReferences::contains(JSCell* cell)
+{
+ return m_references.contains(cell);
}
void DesiredWeakReferences::reallyAdd(VM& vm, CommonData* common)
{
- for (unsigned i = 0; i < m_references.size(); i++) {
- JSCell* target = m_references[i];
- common->weakReferences.append(WriteBarrier<JSCell>(vm, m_codeBlock->ownerExecutable(), target));
+ for (JSCell* target : m_references) {
+ if (Structure* structure = jsDynamicCast<Structure*>(vm, target)) {
+ common->weakStructureReferences.append(
+ WriteBarrier<Structure>(vm, m_codeBlock, structure));
+ } else {
+ // There are weird relationships in how optimized CodeBlocks
+ // point to other CodeBlocks. We don't want to have them be
+ // part of the weak pointer set. For example, an optimized CodeBlock
+ // having a weak pointer to itself will cause it to get collected.
+ RELEASE_ASSERT(!jsDynamicCast<CodeBlock*>(vm, target));
+
+ common->weakReferences.append(
+ WriteBarrier<JSCell>(vm, m_codeBlock, target));
+ }
}
}
+void DesiredWeakReferences::visitChildren(SlotVisitor& visitor)
+{
+ for (JSCell* target : m_references)
+ visitor.appendUnbarriered(target);
+}
+
} } // namespace JSC::DFG
#endif // ENABLE(DFG_JIT)