blob: 1af13ef4ee9df490ac3954d579635680495333ed [file] [log] [blame]
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +00001/*
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +00002 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
ossy@webkit.orgbeb0de42014-02-17 19:00:03 +000027#include "DFGDesiredWeakReferences.h"
commit-queue@webkit.org7ad219a2013-08-19 18:28:02 +000028
29#if ENABLE(DFG_JIT)
30
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +000031#include "CodeBlock.h"
32#include "DFGCommonData.h"
fpizlo@apple.comfb7eff22014-02-11 01:45:50 +000033#include "JSCInlines.h"
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +000034
35namespace JSC { namespace DFG {
36
fpizlo@apple.com04a048c2014-04-28 19:01:07 +000037DesiredWeakReferences::DesiredWeakReferences()
38 : m_codeBlock(nullptr)
39{
40}
41
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +000042DesiredWeakReferences::DesiredWeakReferences(CodeBlock* codeBlock)
43 : m_codeBlock(codeBlock)
44{
45}
46
47DesiredWeakReferences::~DesiredWeakReferences()
48{
49}
50
51void DesiredWeakReferences::addLazily(JSCell* cell)
52{
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +000053 if (cell)
54 m_references.add(cell);
55}
56
57void DesiredWeakReferences::addLazily(JSValue value)
58{
59 if (value.isCell())
60 addLazily(value.asCell());
fpizlo@apple.com920c1672014-08-19 00:55:31 +000061}
62
63bool DesiredWeakReferences::contains(JSCell* cell)
64{
65 return m_references.contains(cell);
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +000066}
67
68void DesiredWeakReferences::reallyAdd(VM& vm, CommonData* common)
69{
fpizlo@apple.com920c1672014-08-19 00:55:31 +000070 for (JSCell* target : m_references) {
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +000071 if (Structure* structure = jsDynamicCast<Structure*>(target)) {
72 common->weakStructureReferences.append(
ggaren@apple.com81def5f2015-10-09 23:10:16 +000073 WriteBarrier<Structure>(vm, m_codeBlock, structure));
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +000074 } else {
75 common->weakReferences.append(
ggaren@apple.com81def5f2015-10-09 23:10:16 +000076 WriteBarrier<JSCell>(vm, m_codeBlock, target));
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +000077 }
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +000078 }
79}
80
fpizlo@apple.com1b84a422014-02-08 05:06:33 +000081void DesiredWeakReferences::visitChildren(SlotVisitor& visitor)
82{
fpizlo@apple.com920c1672014-08-19 00:55:31 +000083 for (JSCell* target : m_references)
84 visitor.appendUnbarrieredPointer(&target);
fpizlo@apple.com1b84a422014-02-08 05:06:33 +000085}
86
mhahnenberg@apple.com941ab382013-08-16 03:28:39 +000087} } // namespace JSC::DFG
commit-queue@webkit.org7ad219a2013-08-19 18:28:02 +000088
89#endif // ENABLE(DFG_JIT)