]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 A |
1 | /* |
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 | * 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 "PolymorphicPutByIdList.h" | |
28 | ||
29 | #if ENABLE(JIT) | |
30 | ||
31 | #include "StructureStubInfo.h" | |
32 | ||
33 | namespace JSC { | |
34 | ||
35 | PutByIdAccess PutByIdAccess::fromStructureStubInfo( | |
36 | StructureStubInfo& stubInfo, | |
37 | MacroAssemblerCodePtr initialSlowPath) | |
38 | { | |
39 | PutByIdAccess result; | |
40 | ||
41 | switch (stubInfo.accessType) { | |
42 | case access_put_by_id_replace: | |
43 | result.m_type = Replace; | |
44 | result.m_oldStructure.copyFrom(stubInfo.u.putByIdReplace.baseObjectStructure); | |
93a37866 | 45 | result.m_stubRoutine = JITStubRoutine::createSelfManagedRoutine(initialSlowPath); |
6fe7ccc8 A |
46 | break; |
47 | ||
48 | case access_put_by_id_transition_direct: | |
49 | case access_put_by_id_transition_normal: | |
50 | result.m_type = Transition; | |
51 | result.m_oldStructure.copyFrom(stubInfo.u.putByIdTransition.previousStructure); | |
52 | result.m_newStructure.copyFrom(stubInfo.u.putByIdTransition.structure); | |
53 | result.m_chain.copyFrom(stubInfo.u.putByIdTransition.chain); | |
54 | result.m_stubRoutine = stubInfo.stubRoutine; | |
55 | break; | |
56 | ||
57 | default: | |
93a37866 | 58 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 A |
59 | } |
60 | ||
61 | return result; | |
62 | } | |
63 | ||
64 | bool PutByIdAccess::visitWeak() const | |
65 | { | |
66 | switch (m_type) { | |
67 | case Replace: | |
68 | if (!Heap::isMarked(m_oldStructure.get())) | |
69 | return false; | |
70 | break; | |
71 | case Transition: | |
72 | if (!Heap::isMarked(m_oldStructure.get())) | |
73 | return false; | |
74 | if (!Heap::isMarked(m_newStructure.get())) | |
75 | return false; | |
76 | if (!Heap::isMarked(m_chain.get())) | |
77 | return false; | |
78 | break; | |
79 | default: | |
93a37866 | 80 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 A |
81 | return false; |
82 | } | |
83 | return true; | |
84 | } | |
85 | ||
86 | PolymorphicPutByIdList::PolymorphicPutByIdList( | |
87 | PutKind putKind, | |
88 | StructureStubInfo& stubInfo, | |
89 | MacroAssemblerCodePtr initialSlowPath) | |
90 | : m_kind(putKind) | |
91 | { | |
92 | m_list.append(PutByIdAccess::fromStructureStubInfo(stubInfo, initialSlowPath)); | |
93 | } | |
94 | ||
95 | PolymorphicPutByIdList* PolymorphicPutByIdList::from( | |
96 | PutKind putKind, | |
97 | StructureStubInfo& stubInfo, | |
98 | MacroAssemblerCodePtr initialSlowPath) | |
99 | { | |
100 | if (stubInfo.accessType == access_put_by_id_list) | |
101 | return stubInfo.u.putByIdList.list; | |
102 | ||
103 | ASSERT(stubInfo.accessType == access_put_by_id_replace | |
104 | || stubInfo.accessType == access_put_by_id_transition_normal | |
105 | || stubInfo.accessType == access_put_by_id_transition_direct); | |
106 | ||
107 | PolymorphicPutByIdList* result = | |
108 | new PolymorphicPutByIdList(putKind, stubInfo, initialSlowPath); | |
109 | ||
110 | stubInfo.initPutByIdList(result); | |
111 | ||
112 | return result; | |
113 | } | |
114 | ||
115 | PolymorphicPutByIdList::~PolymorphicPutByIdList() { } | |
116 | ||
117 | bool PolymorphicPutByIdList::isFull() const | |
118 | { | |
119 | ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE); | |
120 | return size() == POLYMORPHIC_LIST_CACHE_SIZE; | |
121 | } | |
122 | ||
123 | bool PolymorphicPutByIdList::isAlmostFull() const | |
124 | { | |
125 | ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE); | |
126 | return size() >= POLYMORPHIC_LIST_CACHE_SIZE - 1; | |
127 | } | |
128 | ||
129 | void PolymorphicPutByIdList::addAccess(const PutByIdAccess& putByIdAccess) | |
130 | { | |
131 | ASSERT(!isFull()); | |
132 | // Make sure that the resizing optimizes for space, not time. | |
133 | m_list.resize(m_list.size() + 1); | |
134 | m_list.last() = putByIdAccess; | |
135 | } | |
136 | ||
137 | bool PolymorphicPutByIdList::visitWeak() const | |
138 | { | |
139 | for (unsigned i = 0; i < size(); ++i) { | |
140 | if (!at(i).visitWeak()) | |
141 | return false; | |
142 | } | |
143 | return true; | |
144 | } | |
145 | ||
146 | } // namespace JSC | |
147 | ||
148 | #endif // ENABLE(JIT) |