mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013-2015 Apple Inc. All rights reserved. |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 3 | * |
| 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.org | beb0de4 | 2014-02-17 19:00:03 +0000 | [diff] [blame] | 27 | #include "DFGDesiredWeakReferences.h" |
commit-queue@webkit.org | 7ad219a | 2013-08-19 18:28:02 +0000 | [diff] [blame] | 28 | |
| 29 | #if ENABLE(DFG_JIT) |
| 30 | |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 31 | #include "CodeBlock.h" |
| 32 | #include "DFGCommonData.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 33 | #include "JSCInlines.h" |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 34 | |
| 35 | namespace JSC { namespace DFG { |
| 36 | |
fpizlo@apple.com | 04a048c | 2014-04-28 19:01:07 +0000 | [diff] [blame] | 37 | DesiredWeakReferences::DesiredWeakReferences() |
| 38 | : m_codeBlock(nullptr) |
| 39 | { |
| 40 | } |
| 41 | |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 42 | DesiredWeakReferences::DesiredWeakReferences(CodeBlock* codeBlock) |
| 43 | : m_codeBlock(codeBlock) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | DesiredWeakReferences::~DesiredWeakReferences() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void DesiredWeakReferences::addLazily(JSCell* cell) |
| 52 | { |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 53 | if (cell) |
| 54 | m_references.add(cell); |
| 55 | } |
| 56 | |
| 57 | void DesiredWeakReferences::addLazily(JSValue value) |
| 58 | { |
| 59 | if (value.isCell()) |
| 60 | addLazily(value.asCell()); |
fpizlo@apple.com | 920c167 | 2014-08-19 00:55:31 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bool DesiredWeakReferences::contains(JSCell* cell) |
| 64 | { |
| 65 | return m_references.contains(cell); |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void DesiredWeakReferences::reallyAdd(VM& vm, CommonData* common) |
| 69 | { |
fpizlo@apple.com | 920c167 | 2014-08-19 00:55:31 +0000 | [diff] [blame] | 70 | for (JSCell* target : m_references) { |
fpizlo@apple.com | 2c4a7e9 | 2014-08-06 05:27:46 +0000 | [diff] [blame] | 71 | if (Structure* structure = jsDynamicCast<Structure*>(target)) { |
| 72 | common->weakStructureReferences.append( |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 73 | WriteBarrier<Structure>(vm, m_codeBlock, structure)); |
fpizlo@apple.com | 2c4a7e9 | 2014-08-06 05:27:46 +0000 | [diff] [blame] | 74 | } else { |
| 75 | common->weakReferences.append( |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 76 | WriteBarrier<JSCell>(vm, m_codeBlock, target)); |
fpizlo@apple.com | 2c4a7e9 | 2014-08-06 05:27:46 +0000 | [diff] [blame] | 77 | } |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
fpizlo@apple.com | 1b84a42 | 2014-02-08 05:06:33 +0000 | [diff] [blame] | 81 | void DesiredWeakReferences::visitChildren(SlotVisitor& visitor) |
| 82 | { |
fpizlo@apple.com | 920c167 | 2014-08-19 00:55:31 +0000 | [diff] [blame] | 83 | for (JSCell* target : m_references) |
| 84 | visitor.appendUnbarrieredPointer(&target); |
fpizlo@apple.com | 1b84a42 | 2014-02-08 05:06:33 +0000 | [diff] [blame] | 85 | } |
| 86 | |
mhahnenberg@apple.com | 941ab38 | 2013-08-16 03:28:39 +0000 | [diff] [blame] | 87 | } } // namespace JSC::DFG |
commit-queue@webkit.org | 7ad219a | 2013-08-19 18:28:02 +0000 | [diff] [blame] | 88 | |
| 89 | #endif // ENABLE(DFG_JIT) |