blob: 9f02e8cb68cd881faa4fea1d4970101a85fee387 [file] [log] [blame]
keith_miller@apple.com71702d62015-11-11 21:34:57 +00001/*
2 * Copyright (C) 2015 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 * 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. ``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.
24 */
25
26#include "config.h"
27#include "AdaptiveInferredPropertyValueWatchpointBase.h"
28
29#include "JSCellInlines.h"
30#include "StructureInlines.h"
31
32namespace JSC {
33
34AdaptiveInferredPropertyValueWatchpointBase::AdaptiveInferredPropertyValueWatchpointBase(const ObjectPropertyCondition& key)
35 : m_key(key)
36{
37 RELEASE_ASSERT(key.kind() == PropertyCondition::Equivalence);
38}
39
40void AdaptiveInferredPropertyValueWatchpointBase::install()
41{
42 RELEASE_ASSERT(m_key.isWatchable());
43
44 m_key.object()->structure()->addTransitionWatchpoint(&m_structureWatchpoint);
45
46 PropertyOffset offset = m_key.object()->structure()->getConcurrently(m_key.uid());
47 WatchpointSet* set = m_key.object()->structure()->propertyReplacementWatchpointSet(offset);
48 set->add(&m_propertyWatchpoint);
49}
50
51void AdaptiveInferredPropertyValueWatchpointBase::fire(const FireDetail& detail)
52{
keith_miller@apple.com130e6342016-02-12 20:44:44 +000053 // We need to defer GC here otherwise we might trigger a GC that could destroy the owner
54 // CodeBlock. In particular, this can happen when we add rare data to a structure when
55 // we EnsureWatchability.
56 DeferGCForAWhile defer(*Heap::heap(m_key.object()));
keith_miller@apple.com71702d62015-11-11 21:34:57 +000057 // One of the watchpoints fired, but the other one didn't. Make sure that neither of them are
58 // in any set anymore. This simplifies things by allowing us to reinstall the watchpoints
59 // wherever from scratch.
60 if (m_structureWatchpoint.isOnList())
61 m_structureWatchpoint.remove();
62 if (m_propertyWatchpoint.isOnList())
63 m_propertyWatchpoint.remove();
64
65 if (m_key.isWatchable(PropertyCondition::EnsureWatchability)) {
66 install();
67 return;
68 }
69
70 handleFire(detail);
71}
72
73void AdaptiveInferredPropertyValueWatchpointBase::StructureWatchpoint::fireInternal(const FireDetail& detail)
74{
75 ptrdiff_t myOffset = OBJECT_OFFSETOF(AdaptiveInferredPropertyValueWatchpointBase, m_structureWatchpoint);
76
77 AdaptiveInferredPropertyValueWatchpointBase* parent = bitwise_cast<AdaptiveInferredPropertyValueWatchpointBase*>(bitwise_cast<char*>(this) - myOffset);
78
79 parent->fire(detail);
80}
81
82void AdaptiveInferredPropertyValueWatchpointBase::PropertyWatchpoint::fireInternal(const FireDetail& detail)
83{
84 ptrdiff_t myOffset = OBJECT_OFFSETOF(AdaptiveInferredPropertyValueWatchpointBase, m_propertyWatchpoint);
85
86 AdaptiveInferredPropertyValueWatchpointBase* parent = bitwise_cast<AdaptiveInferredPropertyValueWatchpointBase*>(bitwise_cast<char*>(this) - myOffset);
87
88 parent->fire(detail);
89}
90
91} // namespace JSC