1/*
2 * Copyright (C) 2013, 2014 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "ClassInfo.h"
29#include "JSCast.h"
30#include "JSTypeInfo.h"
31#include "PropertyOffset.h"
32#include "PropertySlot.h"
33
34namespace JSC {
35
36class JSPropertyNameEnumerator;
37class Structure;
38class ObjectToStringAdaptiveInferredPropertyValueWatchpoint;
39class ObjectToStringAdaptiveStructureWatchpoint;
40
41class StructureRareData final : public JSCell {
42public:
43 typedef JSCell Base;
44 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
45
46 template<typename CellType, SubspaceAccess>
47 static IsoSubspace* subspaceFor(VM& vm)
48 {
49 return &vm.structureRareDataSpace;
50 }
51
52 static StructureRareData* create(VM&, Structure*);
53
54 static const bool needsDestruction = true;
55 static void destroy(JSCell*);
56
57 static void visitChildren(JSCell*, SlotVisitor&);
58
59 static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
60
61 Structure* previousID() const
62 {
63 return m_previous.get();
64 }
65 void setPreviousID(VM&, Structure*);
66 void clearPreviousID();
67
68 JSString* objectToStringValue() const;
69 void setObjectToStringValue(ExecState*, VM&, Structure* baseStructure, JSString* value, PropertySlot toStringTagSymbolSlot);
70
71 JSPropertyNameEnumerator* cachedPropertyNameEnumerator() const;
72 void setCachedPropertyNameEnumerator(VM&, JSPropertyNameEnumerator*);
73
74 JSImmutableButterfly* cachedOwnKeys() const;
75 JSImmutableButterfly* cachedOwnKeysIgnoringSentinel() const;
76 JSImmutableButterfly* cachedOwnKeysConcurrently() const;
77 void setCachedOwnKeys(VM&, JSImmutableButterfly*);
78
79 Box<InlineWatchpointSet> copySharedPolyProtoWatchpoint() const { return m_polyProtoWatchpoint; }
80 const Box<InlineWatchpointSet>& sharedPolyProtoWatchpoint() const { return m_polyProtoWatchpoint; }
81 void setSharedPolyProtoWatchpoint(Box<InlineWatchpointSet>&& sharedPolyProtoWatchpoint) { m_polyProtoWatchpoint = WTFMove(sharedPolyProtoWatchpoint); }
82 bool hasSharedPolyProtoWatchpoint() const { return static_cast<bool>(m_polyProtoWatchpoint); }
83
84 static JSImmutableButterfly* cachedOwnKeysSentinel() { return bitwise_cast<JSImmutableButterfly*>(static_cast<uintptr_t>(1)); }
85
86 static ptrdiff_t offsetOfCachedOwnKeys()
87 {
88 return OBJECT_OFFSETOF(StructureRareData, m_cachedOwnKeys);
89 }
90
91 DECLARE_EXPORT_INFO;
92
93 void finalizeUnconditionally(VM&);
94
95private:
96 friend class Structure;
97 friend class ObjectToStringAdaptiveStructureWatchpoint;
98 friend class ObjectToStringAdaptiveInferredPropertyValueWatchpoint;
99
100 void clearObjectToStringValue();
101
102 StructureRareData(VM&, Structure*);
103
104 WriteBarrier<Structure> m_previous;
105 WriteBarrier<JSString> m_objectToStringValue;
106 // FIXME: We should have some story for clearing these property names caches in GC.
107 // https://bugs.webkit.org/show_bug.cgi?id=192659
108 WriteBarrier<JSPropertyNameEnumerator> m_cachedPropertyNameEnumerator;
109 WriteBarrier<JSImmutableButterfly> m_cachedOwnKeys;
110
111 typedef HashMap<PropertyOffset, RefPtr<WatchpointSet>, WTF::IntHash<PropertyOffset>, WTF::UnsignedWithZeroKeyHashTraits<PropertyOffset>> PropertyWatchpointMap;
112 std::unique_ptr<PropertyWatchpointMap> m_replacementWatchpointSets;
113 Bag<ObjectToStringAdaptiveStructureWatchpoint> m_objectToStringAdaptiveWatchpointSet;
114 std::unique_ptr<ObjectToStringAdaptiveInferredPropertyValueWatchpoint> m_objectToStringAdaptiveInferredValueWatchpoint;
115 Box<InlineWatchpointSet> m_polyProtoWatchpoint;
116 bool m_giveUpOnObjectToStringValueCache;
117};
118
119} // namespace JSC
120