blob: 6eb023985b7631974d116a3eaf22c27917adacc5 [file] [log] [blame]
fpizlo@apple.comb75911b2012-06-13 20:53:52 +00001/*
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.orgfc6d4ea2013-11-12 17:38:07 +000032#include "JSDestructibleObject.h"
fpizlo@apple.comfb7eff22014-02-11 01:45:50 +000033#include "JSCInlines.h"
commit-queue@webkit.orgfc6d4ea2013-11-12 17:38:07 +000034#include "SlotVisitorInlines.h"
35
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000036namespace JSC {
37
fpizlo@apple.combbddb5b2013-11-22 22:03:56 +000038const ClassInfo SymbolTable::s_info = { "SymbolTable", 0, 0, 0, CREATE_METHOD_TABLE(SymbolTable) };
ggaren@apple.com47e224a2012-08-26 03:25:31 +000039
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000040SymbolTableEntry& SymbolTableEntry::copySlow(const SymbolTableEntry& other)
41{
42 ASSERT(other.isFat());
43 FatEntry* newFatEntry = new FatEntry(*other.fatEntry());
44 freeFatEntry();
rniwa@webkit.org3340cf92013-03-22 07:36:58 +000045 m_bits = bitwise_cast<intptr_t>(newFatEntry);
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000046 return *this;
47}
48
fpizlo@apple.combbddb5b2013-11-22 22:03:56 +000049void SymbolTable::destroy(JSCell* cell)
ggaren@apple.com47e224a2012-08-26 03:25:31 +000050{
fpizlo@apple.combbddb5b2013-11-22 22:03:56 +000051 SymbolTable* thisObject = jsCast<SymbolTable*>(cell);
52 thisObject->SymbolTable::~SymbolTable();
ggaren@apple.com47e224a2012-08-26 03:25:31 +000053}
54
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000055void SymbolTableEntry::freeFatEntrySlow()
56{
57 ASSERT(isFat());
58 delete fatEntry();
59}
60
fpizlo@apple.com86468342013-11-27 02:47:43 +000061JSValue SymbolTableEntry::inferredValue()
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000062{
63 if (!isFat())
fpizlo@apple.com86468342013-11-27 02:47:43 +000064 return JSValue();
65 return fatEntry()->m_watchpoints->inferredValue();
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000066}
67
fpizlo@apple.com86468342013-11-27 02:47:43 +000068void SymbolTableEntry::prepareToWatch()
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000069{
70 FatEntry* entry = inflate();
fpizlo@apple.com88fedde2013-12-04 19:29:19 +000071 if (entry->m_watchpoints)
72 return;
fpizlo@apple.com86468342013-11-27 02:47:43 +000073 entry->m_watchpoints = adoptRef(new VariableWatchpointSet());
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000074}
75
76void SymbolTableEntry::addWatchpoint(Watchpoint* watchpoint)
77{
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000078 fatEntry()->m_watchpoints->add(watchpoint);
79}
80
fpizlo@apple.com86468342013-11-27 02:47:43 +000081void SymbolTableEntry::notifyWriteSlow(JSValue value)
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000082{
fpizlo@apple.com86468342013-11-27 02:47:43 +000083 VariableWatchpointSet* watchpoints = fatEntry()->m_watchpoints.get();
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000084 if (!watchpoints)
85 return;
fpizlo@apple.com33961712013-11-20 05:49:05 +000086
fpizlo@apple.com86468342013-11-27 02:47:43 +000087 watchpoints->notifyWrite(value);
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000088}
89
90SymbolTableEntry::FatEntry* SymbolTableEntry::inflateSlow()
91{
92 FatEntry* entry = new FatEntry(m_bits);
rniwa@webkit.org3340cf92013-03-22 07:36:58 +000093 m_bits = bitwise_cast<intptr_t>(entry);
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000094 return entry;
95}
96
fpizlo@apple.combbddb5b2013-11-22 22:03:56 +000097SymbolTable::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.coma4ea0662013-12-02 19:09:15 +0000103 , m_functionEnteredOnce(ClearWatchpoint)
fpizlo@apple.combbddb5b2013-11-22 22:03:56 +0000104{
105}
106
oliver@apple.comf72e22e2013-07-25 03:59:04 +0000107SymbolTable::~SymbolTable() { }
108
fpizlo@apple.com86468342013-11-27 02:47:43 +0000109void 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
120SymbolTable::WatchpointCleanup::WatchpointCleanup(SymbolTable* symbolTable)
121 : m_symbolTable(symbolTable)
122{
123}
124
125SymbolTable::WatchpointCleanup::~WatchpointCleanup() { }
126
127void 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.com10182142014-01-31 03:38:06 +0000137SymbolTable* SymbolTable::cloneCapturedNames(VM& vm)
fpizlo@apple.com022f3682013-11-27 01:22:07 +0000138{
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.com10182142014-01-31 03:38:06 +0000145
146 for (auto iter = m_map.begin(), end = m_map.end(); iter != end; ++iter) {
147 if (!isCaptured(iter->value.getIndex()))
148 continue;
fpizlo@apple.com022f3682013-11-27 01:22:07 +0000149 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.comb75911b2012-06-13 20:53:52 +0000163} // namespace JSC
164