2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef PolymorphicAccessStructureList_h
27 #define PolymorphicAccessStructureList_h
29 #include "JITStubRoutine.h"
30 #include "Structure.h"
31 #include "StructureChain.h"
32 #include <wtf/Platform.h>
34 #define POLYMORPHIC_LIST_CACHE_SIZE 8
38 // *Sigh*, If the JIT is enabled we need to track the stubRountine (of type CodeLocationLabel),
39 // If the JIT is not in use we don't actually need the variable (that said, if the JIT is not in use we don't
40 // curently actually use PolymorphicAccessStructureLists, which we should). Anyway, this seems like the best
41 // solution for now - will need to something smarter if/when we actually want mixed-mode operation.
44 // Structure used by op_get_by_id_self_list and op_get_by_id_proto_list instruction to hold data off the main opcode stream.
45 struct PolymorphicAccessStructureList
{
46 WTF_MAKE_FAST_ALLOCATED
;
48 struct PolymorphicStubInfo
{
51 RefPtr
<JITStubRoutine
> stubRoutine
;
52 WriteBarrier
<Structure
> base
;
54 WriteBarrierBase
<Structure
> proto
;
55 WriteBarrierBase
<StructureChain
> chain
;
63 void set(VM
& vm
, JSCell
* owner
, PassRefPtr
<JITStubRoutine
> _stubRoutine
, Structure
* _base
, bool isDirect
)
65 stubRoutine
= _stubRoutine
;
66 base
.set(vm
, owner
, _base
);
69 this->isDirect
= isDirect
;
72 void set(VM
& vm
, JSCell
* owner
, PassRefPtr
<JITStubRoutine
> _stubRoutine
, Structure
* _base
, Structure
* _proto
, bool isDirect
)
74 stubRoutine
= _stubRoutine
;
75 base
.set(vm
, owner
, _base
);
76 u
.proto
.set(vm
, owner
, _proto
);
78 this->isDirect
= isDirect
;
81 void set(VM
& vm
, JSCell
* owner
, PassRefPtr
<JITStubRoutine
> _stubRoutine
, Structure
* _base
, StructureChain
* _chain
, bool isDirect
)
83 stubRoutine
= _stubRoutine
;
84 base
.set(vm
, owner
, _base
);
85 u
.chain
.set(vm
, owner
, _chain
);
87 this->isDirect
= isDirect
;
89 } list
[POLYMORPHIC_LIST_CACHE_SIZE
];
91 PolymorphicAccessStructureList()
95 PolymorphicAccessStructureList(VM
& vm
, JSCell
* owner
, PassRefPtr
<JITStubRoutine
> stubRoutine
, Structure
* firstBase
, bool isDirect
)
97 list
[0].set(vm
, owner
, stubRoutine
, firstBase
, isDirect
);
100 PolymorphicAccessStructureList(VM
& vm
, JSCell
* owner
, PassRefPtr
<JITStubRoutine
> stubRoutine
, Structure
* firstBase
, Structure
* firstProto
, bool isDirect
)
102 list
[0].set(vm
, owner
, stubRoutine
, firstBase
, firstProto
, isDirect
);
105 PolymorphicAccessStructureList(VM
& vm
, JSCell
* owner
, PassRefPtr
<JITStubRoutine
> stubRoutine
, Structure
* firstBase
, StructureChain
* firstChain
, bool isDirect
)
107 list
[0].set(vm
, owner
, stubRoutine
, firstBase
, firstChain
, isDirect
);
110 bool visitWeak(int count
)
112 for (int i
= 0; i
< count
; ++i
) {
113 PolymorphicStubInfo
& info
= list
[i
];
115 // We're being marked during initialisation of an entry
116 ASSERT(!info
.u
.proto
);
120 if (!Heap::isMarked(info
.base
.get()))
122 if (info
.u
.proto
&& !info
.isChain
123 && !Heap::isMarked(info
.u
.proto
.get()))
125 if (info
.u
.chain
&& info
.isChain
126 && !Heap::isMarked(info
.u
.chain
.get()))
134 #endif // ENABLE(JIT)
138 #endif // PolymorphicAccessStructureList_h