]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/PolymorphicAccessStructureList.h
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / bytecode / PolymorphicAccessStructureList.h
CommitLineData
93a37866
A
1/*
2 * Copyright (C) 2013 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#ifndef PolymorphicAccessStructureList_h
27#define PolymorphicAccessStructureList_h
28
29#include "JITStubRoutine.h"
30#include "Structure.h"
31#include "StructureChain.h"
32#include <wtf/Platform.h>
33
34#define POLYMORPHIC_LIST_CACHE_SIZE 8
35
36namespace JSC {
37
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.
42
43#if ENABLE(JIT)
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.
45struct PolymorphicAccessStructureList {
46 WTF_MAKE_FAST_ALLOCATED;
47public:
48 struct PolymorphicStubInfo {
49 bool isChain;
50 bool isDirect;
51 RefPtr<JITStubRoutine> stubRoutine;
52 WriteBarrier<Structure> base;
53 union {
54 WriteBarrierBase<Structure> proto;
55 WriteBarrierBase<StructureChain> chain;
56 } u;
57
58 PolymorphicStubInfo()
59 {
60 u.proto.clear();
61 }
62
63 void set(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> _stubRoutine, Structure* _base, bool isDirect)
64 {
65 stubRoutine = _stubRoutine;
66 base.set(vm, owner, _base);
67 u.proto.clear();
68 isChain = false;
69 this->isDirect = isDirect;
70 }
71
72 void set(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> _stubRoutine, Structure* _base, Structure* _proto, bool isDirect)
73 {
74 stubRoutine = _stubRoutine;
75 base.set(vm, owner, _base);
76 u.proto.set(vm, owner, _proto);
77 isChain = false;
78 this->isDirect = isDirect;
79 }
80
81 void set(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> _stubRoutine, Structure* _base, StructureChain* _chain, bool isDirect)
82 {
83 stubRoutine = _stubRoutine;
84 base.set(vm, owner, _base);
85 u.chain.set(vm, owner, _chain);
86 isChain = true;
87 this->isDirect = isDirect;
88 }
89 } list[POLYMORPHIC_LIST_CACHE_SIZE];
90
91 PolymorphicAccessStructureList()
92 {
93 }
94
95 PolymorphicAccessStructureList(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> stubRoutine, Structure* firstBase, bool isDirect)
96 {
97 list[0].set(vm, owner, stubRoutine, firstBase, isDirect);
98 }
99
100 PolymorphicAccessStructureList(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> stubRoutine, Structure* firstBase, Structure* firstProto, bool isDirect)
101 {
102 list[0].set(vm, owner, stubRoutine, firstBase, firstProto, isDirect);
103 }
104
105 PolymorphicAccessStructureList(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> stubRoutine, Structure* firstBase, StructureChain* firstChain, bool isDirect)
106 {
107 list[0].set(vm, owner, stubRoutine, firstBase, firstChain, isDirect);
108 }
109
110 bool visitWeak(int count)
111 {
112 for (int i = 0; i < count; ++i) {
113 PolymorphicStubInfo& info = list[i];
114 if (!info.base) {
115 // We're being marked during initialisation of an entry
116 ASSERT(!info.u.proto);
117 continue;
118 }
119
120 if (!Heap::isMarked(info.base.get()))
121 return false;
122 if (info.u.proto && !info.isChain
123 && !Heap::isMarked(info.u.proto.get()))
124 return false;
125 if (info.u.chain && info.isChain
126 && !Heap::isMarked(info.u.chain.get()))
127 return false;
128 }
129
130 return true;
131 }
132};
133
134#endif // ENABLE(JIT)
135
136} // namespace JSC
137
138#endif // PolymorphicAccessStructureList_h
139