blob: f29c2141cf21a41a5763ba2d7bfeaa5f7613dcbf [file] [log] [blame]
fpizlo@apple.comb75911b2012-06-13 20:53:52 +00001/*
oliver@apple.com9397e002013-07-25 03:58:49 +00002 * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
fpizlo@apple.comb75911b2012-06-13 20:53:52 +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:
fpizlo@apple.com3a264a12012-07-11 23:33:20 +00007 * 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.
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000012 *
fpizlo@apple.com3a264a12012-07-11 23:33:20 +000013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000024 */
25
26#include "config.h"
27#include "Watchpoint.h"
28
29#include "LinkBuffer.h"
oliver@apple.com634a76a2013-07-25 03:59:09 +000030#include <wtf/CompilationThread.h>
commit-queue@webkit.orgf06140e2012-07-19 15:45:26 +000031#include <wtf/PassRefPtr.h>
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000032
33namespace JSC {
34
35Watchpoint::~Watchpoint()
36{
37 if (isOnList())
38 remove();
39}
40
fpizlo@apple.com09a6af02013-11-18 02:10:42 +000041WatchpointSet::WatchpointSet(WatchpointState state)
42 : m_state(state)
fpizlo@apple.com33961712013-11-20 05:49:05 +000043 , m_setIsNotEmpty(false)
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000044{
45}
46
47WatchpointSet::~WatchpointSet()
48{
fpizlo@apple.com4917df22013-10-31 03:52:23 +000049 // Remove all watchpoints, so that they don't try to remove themselves. Note that we
50 // don't fire watchpoints on deletion. We assume that any code that is interested in
51 // watchpoints already also separately has a mechanism to make sure that the code is
52 // either keeping the watchpoint set's owner alive, or does some weak reference thing.
53 while (!m_set.isEmpty())
54 m_set.begin()->remove();
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000055}
56
57void WatchpointSet::add(Watchpoint* watchpoint)
58{
oliver@apple.com634a76a2013-07-25 03:59:09 +000059 ASSERT(!isCompilationThread());
fpizlo@apple.com09a6af02013-11-18 02:10:42 +000060 ASSERT(state() != IsInvalidated);
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000061 if (!watchpoint)
62 return;
63 m_set.push(watchpoint);
fpizlo@apple.com33961712013-11-20 05:49:05 +000064 m_setIsNotEmpty = true;
fpizlo@apple.com09a6af02013-11-18 02:10:42 +000065 m_state = IsWatched;
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000066}
67
fpizlo@apple.com4bf14eb2013-11-19 23:48:23 +000068void WatchpointSet::fireAllSlow()
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000069{
fpizlo@apple.com09a6af02013-11-18 02:10:42 +000070 ASSERT(state() == IsWatched);
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000071
fpizlo@apple.com33961712013-11-20 05:49:05 +000072 WTF::storeStoreFence();
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000073 fireAllWatchpoints();
fpizlo@apple.com09a6af02013-11-18 02:10:42 +000074 m_state = IsInvalidated;
oliver@apple.com9055d142013-07-25 03:59:02 +000075 WTF::storeStoreFence();
fpizlo@apple.comb75911b2012-06-13 20:53:52 +000076}
77
78void WatchpointSet::fireAllWatchpoints()
79{
80 while (!m_set.isEmpty())
81 m_set.begin()->fire();
82}
83
fpizlo@apple.com04e41152012-06-15 22:14:53 +000084void InlineWatchpointSet::add(Watchpoint* watchpoint)
85{
86 inflate()->add(watchpoint);
87}
88
89WatchpointSet* InlineWatchpointSet::inflateSlow()
90{
91 ASSERT(isThin());
oliver@apple.com634a76a2013-07-25 03:59:09 +000092 ASSERT(!isCompilationThread());
fpizlo@apple.com09a6af02013-11-18 02:10:42 +000093 WatchpointSet* fat = adoptRef(new WatchpointSet(decodeState(m_data))).leakRef();
oliver@apple.com9397e002013-07-25 03:58:49 +000094 WTF::storeStoreFence();
fpizlo@apple.com04e41152012-06-15 22:14:53 +000095 m_data = bitwise_cast<uintptr_t>(fat);
96 return fat;
97}
98
99void InlineWatchpointSet::freeFat()
100{
101 ASSERT(isFat());
102 fat()->deref();
103}
104
fpizlo@apple.comb75911b2012-06-13 20:53:52 +0000105} // namespace JSC
106