fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 1 | /* |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +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: |
fpizlo@apple.com | 3a264a1 | 2012-07-11 23:33:20 +0000 | [diff] [blame] | 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. |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 12 | * |
fpizlo@apple.com | 3a264a1 | 2012-07-11 23:33:20 +0000 | [diff] [blame] | 13 | * 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.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "Watchpoint.h" |
| 28 | |
| 29 | #include "LinkBuffer.h" |
oliver@apple.com | 634a76a | 2013-07-25 03:59:09 +0000 | [diff] [blame] | 30 | #include <wtf/CompilationThread.h> |
commit-queue@webkit.org | f06140e | 2012-07-19 15:45:26 +0000 | [diff] [blame] | 31 | #include <wtf/PassRefPtr.h> |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 32 | |
| 33 | namespace JSC { |
| 34 | |
| 35 | Watchpoint::~Watchpoint() |
| 36 | { |
| 37 | if (isOnList()) |
| 38 | remove(); |
| 39 | } |
| 40 | |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 41 | WatchpointSet::WatchpointSet(WatchpointState state) |
| 42 | : m_state(state) |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 43 | , m_setIsNotEmpty(false) |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | WatchpointSet::~WatchpointSet() |
| 48 | { |
fpizlo@apple.com | 4917df2 | 2013-10-31 03:52:23 +0000 | [diff] [blame] | 49 | // 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.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void WatchpointSet::add(Watchpoint* watchpoint) |
| 58 | { |
oliver@apple.com | 634a76a | 2013-07-25 03:59:09 +0000 | [diff] [blame] | 59 | ASSERT(!isCompilationThread()); |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 60 | ASSERT(state() != IsInvalidated); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 61 | if (!watchpoint) |
| 62 | return; |
| 63 | m_set.push(watchpoint); |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 64 | m_setIsNotEmpty = true; |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 65 | m_state = IsWatched; |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 66 | } |
| 67 | |
fpizlo@apple.com | 4bf14eb | 2013-11-19 23:48:23 +0000 | [diff] [blame] | 68 | void WatchpointSet::fireAllSlow() |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 69 | { |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 70 | ASSERT(state() == IsWatched); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 71 | |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 72 | WTF::storeStoreFence(); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 73 | fireAllWatchpoints(); |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 74 | m_state = IsInvalidated; |
oliver@apple.com | 9055d14 | 2013-07-25 03:59:02 +0000 | [diff] [blame] | 75 | WTF::storeStoreFence(); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void WatchpointSet::fireAllWatchpoints() |
| 79 | { |
| 80 | while (!m_set.isEmpty()) |
| 81 | m_set.begin()->fire(); |
| 82 | } |
| 83 | |
fpizlo@apple.com | 04e4115 | 2012-06-15 22:14:53 +0000 | [diff] [blame] | 84 | void InlineWatchpointSet::add(Watchpoint* watchpoint) |
| 85 | { |
| 86 | inflate()->add(watchpoint); |
| 87 | } |
| 88 | |
| 89 | WatchpointSet* InlineWatchpointSet::inflateSlow() |
| 90 | { |
| 91 | ASSERT(isThin()); |
oliver@apple.com | 634a76a | 2013-07-25 03:59:09 +0000 | [diff] [blame] | 92 | ASSERT(!isCompilationThread()); |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 93 | WatchpointSet* fat = adoptRef(new WatchpointSet(decodeState(m_data))).leakRef(); |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 94 | WTF::storeStoreFence(); |
fpizlo@apple.com | 04e4115 | 2012-06-15 22:14:53 +0000 | [diff] [blame] | 95 | m_data = bitwise_cast<uintptr_t>(fat); |
| 96 | return fat; |
| 97 | } |
| 98 | |
| 99 | void InlineWatchpointSet::freeFat() |
| 100 | { |
| 101 | ASSERT(isFat()); |
| 102 | fat()->deref(); |
| 103 | } |
| 104 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 105 | } // namespace JSC |
| 106 | |