]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/PolymorphicAccessStructureList.h
JavaScriptCore-7601.1.46.3.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"
93a37866
A
32
33#define POLYMORPHIC_LIST_CACHE_SIZE 8
34
35namespace JSC {
36
37// *Sigh*, If the JIT is enabled we need to track the stubRountine (of type CodeLocationLabel),
38// 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
39// curently actually use PolymorphicAccessStructureLists, which we should). Anyway, this seems like the best
40// solution for now - will need to something smarter if/when we actually want mixed-mode operation.
41
42#if ENABLE(JIT)
43// 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.
44struct PolymorphicAccessStructureList {
45 WTF_MAKE_FAST_ALLOCATED;
46public:
47 struct PolymorphicStubInfo {
81345200
A
48 bool isDirect : 1;
49 unsigned count : 31;
93a37866
A
50 RefPtr<JITStubRoutine> stubRoutine;
51 WriteBarrier<Structure> base;
81345200 52 WriteBarrier<StructureChain> chain;
93a37866
A
53
54 PolymorphicStubInfo()
55 {
93a37866
A
56 }
57
81345200 58 void set(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> _stubRoutine, Structure* _base, bool _isDirect)
93a37866
A
59 {
60 stubRoutine = _stubRoutine;
61 base.set(vm, owner, _base);
81345200
A
62 isDirect = _isDirect;
63 count = 0;
93a37866 64 }
81345200
A
65
66 void set(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> _stubRoutine, Structure* _base, StructureChain* _chain, bool _isDirect, unsigned _count)
93a37866
A
67 {
68 stubRoutine = _stubRoutine;
69 base.set(vm, owner, _base);
81345200
A
70 chain.set(vm, owner, _chain);
71 isDirect = _isDirect;
72 count = _count;
93a37866
A
73 }
74 } list[POLYMORPHIC_LIST_CACHE_SIZE];
81345200 75
93a37866
A
76 PolymorphicAccessStructureList()
77 {
78 }
81345200 79
93a37866
A
80 PolymorphicAccessStructureList(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> stubRoutine, Structure* firstBase, bool isDirect)
81 {
82 list[0].set(vm, owner, stubRoutine, firstBase, isDirect);
83 }
84
81345200 85 PolymorphicAccessStructureList(VM& vm, JSCell* owner, PassRefPtr<JITStubRoutine> stubRoutine, Structure* firstBase, StructureChain* firstChain, bool isDirect, unsigned count)
93a37866 86 {
81345200 87 list[0].set(vm, owner, stubRoutine, firstBase, firstChain, isDirect, count);
93a37866
A
88 }
89
90 bool visitWeak(int count)
91 {
92 for (int i = 0; i < count; ++i) {
93 PolymorphicStubInfo& info = list[i];
81345200 94 if (!info.base)
93a37866 95 continue;
93a37866
A
96
97 if (!Heap::isMarked(info.base.get()))
98 return false;
81345200 99 if (info.chain && !Heap::isMarked(info.chain.get()))
93a37866
A
100 return false;
101 }
102
103 return true;
104 }
105};
106
107#endif // ENABLE(JIT)
108
109} // namespace JSC
110
111#endif // PolymorphicAccessStructureList_h
112