fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 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 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "config.h" |
| 30 | #include "SymbolTable.h" |
| 31 | |
commit-queue@webkit.org | fc6d4ea | 2013-11-12 17:38:07 +0000 | [diff] [blame] | 32 | #include "JSDestructibleObject.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame^] | 33 | #include "JSCInlines.h" |
commit-queue@webkit.org | fc6d4ea | 2013-11-12 17:38:07 +0000 | [diff] [blame] | 34 | #include "SlotVisitorInlines.h" |
| 35 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 36 | namespace JSC { |
| 37 | |
fpizlo@apple.com | bbddb5b | 2013-11-22 22:03:56 +0000 | [diff] [blame] | 38 | const ClassInfo SymbolTable::s_info = { "SymbolTable", 0, 0, 0, CREATE_METHOD_TABLE(SymbolTable) }; |
ggaren@apple.com | 47e224a | 2012-08-26 03:25:31 +0000 | [diff] [blame] | 39 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 40 | SymbolTableEntry& SymbolTableEntry::copySlow(const SymbolTableEntry& other) |
| 41 | { |
| 42 | ASSERT(other.isFat()); |
| 43 | FatEntry* newFatEntry = new FatEntry(*other.fatEntry()); |
| 44 | freeFatEntry(); |
rniwa@webkit.org | 3340cf9 | 2013-03-22 07:36:58 +0000 | [diff] [blame] | 45 | m_bits = bitwise_cast<intptr_t>(newFatEntry); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 46 | return *this; |
| 47 | } |
| 48 | |
fpizlo@apple.com | bbddb5b | 2013-11-22 22:03:56 +0000 | [diff] [blame] | 49 | void SymbolTable::destroy(JSCell* cell) |
ggaren@apple.com | 47e224a | 2012-08-26 03:25:31 +0000 | [diff] [blame] | 50 | { |
fpizlo@apple.com | bbddb5b | 2013-11-22 22:03:56 +0000 | [diff] [blame] | 51 | SymbolTable* thisObject = jsCast<SymbolTable*>(cell); |
| 52 | thisObject->SymbolTable::~SymbolTable(); |
ggaren@apple.com | 47e224a | 2012-08-26 03:25:31 +0000 | [diff] [blame] | 53 | } |
| 54 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 55 | void SymbolTableEntry::freeFatEntrySlow() |
| 56 | { |
| 57 | ASSERT(isFat()); |
| 58 | delete fatEntry(); |
| 59 | } |
| 60 | |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 61 | JSValue SymbolTableEntry::inferredValue() |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 62 | { |
| 63 | if (!isFat()) |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 64 | return JSValue(); |
| 65 | return fatEntry()->m_watchpoints->inferredValue(); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 66 | } |
| 67 | |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 68 | void SymbolTableEntry::prepareToWatch() |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 69 | { |
| 70 | FatEntry* entry = inflate(); |
fpizlo@apple.com | 88fedde | 2013-12-04 19:29:19 +0000 | [diff] [blame] | 71 | if (entry->m_watchpoints) |
| 72 | return; |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 73 | entry->m_watchpoints = adoptRef(new VariableWatchpointSet()); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void SymbolTableEntry::addWatchpoint(Watchpoint* watchpoint) |
| 77 | { |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 78 | fatEntry()->m_watchpoints->add(watchpoint); |
| 79 | } |
| 80 | |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 81 | void SymbolTableEntry::notifyWriteSlow(JSValue value) |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 82 | { |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 83 | VariableWatchpointSet* watchpoints = fatEntry()->m_watchpoints.get(); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 84 | if (!watchpoints) |
| 85 | return; |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 86 | |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 87 | watchpoints->notifyWrite(value); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | SymbolTableEntry::FatEntry* SymbolTableEntry::inflateSlow() |
| 91 | { |
| 92 | FatEntry* entry = new FatEntry(m_bits); |
rniwa@webkit.org | 3340cf9 | 2013-03-22 07:36:58 +0000 | [diff] [blame] | 93 | m_bits = bitwise_cast<intptr_t>(entry); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 94 | return entry; |
| 95 | } |
| 96 | |
fpizlo@apple.com | bbddb5b | 2013-11-22 22:03:56 +0000 | [diff] [blame] | 97 | SymbolTable::SymbolTable(VM& vm) |
| 98 | : JSCell(vm, vm.symbolTableStructure.get()) |
| 99 | , m_parameterCountIncludingThis(0) |
| 100 | , m_usesNonStrictEval(false) |
| 101 | , m_captureStart(0) |
| 102 | , m_captureEnd(0) |
fpizlo@apple.com | a4ea066 | 2013-12-02 19:09:15 +0000 | [diff] [blame] | 103 | , m_functionEnteredOnce(ClearWatchpoint) |
fpizlo@apple.com | bbddb5b | 2013-11-22 22:03:56 +0000 | [diff] [blame] | 104 | { |
| 105 | } |
| 106 | |
oliver@apple.com | f72e22e | 2013-07-25 03:59:04 +0000 | [diff] [blame] | 107 | SymbolTable::~SymbolTable() { } |
| 108 | |
fpizlo@apple.com | 8646834 | 2013-11-27 02:47:43 +0000 | [diff] [blame] | 109 | void SymbolTable::visitChildren(JSCell* thisCell, SlotVisitor& visitor) |
| 110 | { |
| 111 | SymbolTable* thisSymbolTable = jsCast<SymbolTable*>(thisCell); |
| 112 | if (!thisSymbolTable->m_watchpointCleanup) { |
| 113 | thisSymbolTable->m_watchpointCleanup = |
| 114 | std::make_unique<WatchpointCleanup>(thisSymbolTable); |
| 115 | } |
| 116 | |
| 117 | visitor.addUnconditionalFinalizer(thisSymbolTable->m_watchpointCleanup.get()); |
| 118 | } |
| 119 | |
| 120 | SymbolTable::WatchpointCleanup::WatchpointCleanup(SymbolTable* symbolTable) |
| 121 | : m_symbolTable(symbolTable) |
| 122 | { |
| 123 | } |
| 124 | |
| 125 | SymbolTable::WatchpointCleanup::~WatchpointCleanup() { } |
| 126 | |
| 127 | void SymbolTable::WatchpointCleanup::finalizeUnconditionally() |
| 128 | { |
| 129 | Map::iterator iter = m_symbolTable->m_map.begin(); |
| 130 | Map::iterator end = m_symbolTable->m_map.end(); |
| 131 | for (; iter != end; ++iter) { |
| 132 | if (VariableWatchpointSet* set = iter->value.watchpointSet()) |
| 133 | set->finalizeUnconditionally(); |
| 134 | } |
| 135 | } |
| 136 | |
akling@apple.com | 1018214 | 2014-01-31 03:38:06 +0000 | [diff] [blame] | 137 | SymbolTable* SymbolTable::cloneCapturedNames(VM& vm) |
fpizlo@apple.com | 022f368 | 2013-11-27 01:22:07 +0000 | [diff] [blame] | 138 | { |
| 139 | SymbolTable* result = SymbolTable::create(vm); |
| 140 | |
| 141 | result->m_parameterCountIncludingThis = m_parameterCountIncludingThis; |
| 142 | result->m_usesNonStrictEval = m_usesNonStrictEval; |
| 143 | result->m_captureStart = m_captureStart; |
| 144 | result->m_captureEnd = m_captureEnd; |
akling@apple.com | 1018214 | 2014-01-31 03:38:06 +0000 | [diff] [blame] | 145 | |
| 146 | for (auto iter = m_map.begin(), end = m_map.end(); iter != end; ++iter) { |
| 147 | if (!isCaptured(iter->value.getIndex())) |
| 148 | continue; |
fpizlo@apple.com | 022f368 | 2013-11-27 01:22:07 +0000 | [diff] [blame] | 149 | result->m_map.add( |
| 150 | iter->key, |
| 151 | SymbolTableEntry(iter->value.getIndex(), iter->value.getAttributes())); |
| 152 | } |
| 153 | |
| 154 | if (m_slowArguments) { |
| 155 | result->m_slowArguments = std::make_unique<SlowArgument[]>(parameterCount()); |
| 156 | for (unsigned i = parameterCount(); i--;) |
| 157 | result->m_slowArguments[i] = m_slowArguments[i]; |
| 158 | } |
| 159 | |
| 160 | return result; |
| 161 | } |
| 162 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 163 | } // namespace JSC |
| 164 | |