]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) | |
f9bf01c6 | 3 | * Copyright (C) 2003, 2007, 2008, 2009 Apple Inc. All rights reserved. |
9dae56ea A |
4 | * |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Library General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Library General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Library General Public License | |
16 | * along with this library; see the file COPYING.LIB. If not, write to | |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
18 | * Boston, MA 02110-1301, USA. | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifndef ArgList_h | |
23 | #define ArgList_h | |
24 | ||
14957cd0 | 25 | #include "CallFrame.h" |
9dae56ea | 26 | #include "Register.h" |
14957cd0 | 27 | #include "WriteBarrier.h" |
9dae56ea | 28 | #include <wtf/HashSet.h> |
9dae56ea A |
29 | #include <wtf/Vector.h> |
30 | ||
31 | namespace JSC { | |
f9bf01c6 | 32 | |
6fe7ccc8 | 33 | class SlotVisitor; |
f9bf01c6 | 34 | |
14957cd0 A |
35 | class MarkedArgumentBuffer { |
36 | WTF_MAKE_NONCOPYABLE(MarkedArgumentBuffer); | |
6fe7ccc8 A |
37 | friend class JSGlobalData; |
38 | friend class ArgList; | |
39 | ||
9dae56ea | 40 | private: |
6fe7ccc8 | 41 | static const size_t inlineCapacity = 8; |
9dae56ea | 42 | typedef Vector<Register, inlineCapacity> VectorType; |
ba379fdc | 43 | typedef HashSet<MarkedArgumentBuffer*> ListSet; |
9dae56ea A |
44 | |
45 | public: | |
9dae56ea A |
46 | // Constructor for a read-write list, to which you may append values. |
47 | // FIXME: Remove all clients of this API, then remove this API. | |
ba379fdc | 48 | MarkedArgumentBuffer() |
6fe7ccc8 A |
49 | : m_size(0) |
50 | , m_capacity(inlineCapacity) | |
51 | , m_buffer(&m_inlineBuffer[m_capacity - 1]) | |
ba379fdc | 52 | , m_markSet(0) |
9dae56ea | 53 | { |
9dae56ea A |
54 | } |
55 | ||
ba379fdc | 56 | ~MarkedArgumentBuffer() |
9dae56ea A |
57 | { |
58 | if (m_markSet) | |
59 | m_markSet->remove(this); | |
6fe7ccc8 A |
60 | |
61 | if (EncodedJSValue* base = mallocBase()) | |
62 | delete [] base; | |
9dae56ea A |
63 | } |
64 | ||
65 | size_t size() const { return m_size; } | |
66 | bool isEmpty() const { return !m_size; } | |
67 | ||
6fe7ccc8 | 68 | JSValue at(int i) const |
9dae56ea | 69 | { |
6fe7ccc8 A |
70 | if (i >= m_size) |
71 | return jsUndefined(); | |
72 | ||
73 | return JSValue::decode(slotFor(i)); | |
9dae56ea A |
74 | } |
75 | ||
76 | void clear() | |
77 | { | |
9dae56ea A |
78 | m_size = 0; |
79 | } | |
80 | ||
ba379fdc | 81 | void append(JSValue v) |
9dae56ea | 82 | { |
6fe7ccc8 A |
83 | if (m_size >= m_capacity) |
84 | return slowAppend(v); | |
85 | ||
86 | slotFor(m_size) = JSValue::encode(v); | |
87 | ++m_size; | |
9dae56ea A |
88 | } |
89 | ||
ba379fdc A |
90 | void removeLast() |
91 | { | |
92 | ASSERT(m_size); | |
93 | m_size--; | |
ba379fdc | 94 | } |
9dae56ea | 95 | |
ba379fdc A |
96 | JSValue last() |
97 | { | |
98 | ASSERT(m_size); | |
6fe7ccc8 | 99 | return JSValue::decode(slotFor(m_size - 1)); |
ba379fdc A |
100 | } |
101 | ||
14957cd0 | 102 | static void markLists(HeapRootVisitor&, ListSet&); |
9dae56ea A |
103 | |
104 | private: | |
6fe7ccc8 | 105 | JS_EXPORT_PRIVATE void slowAppend(JSValue); |
9dae56ea | 106 | |
6fe7ccc8 A |
107 | EncodedJSValue& slotFor(int item) const |
108 | { | |
109 | return m_buffer[-item]; | |
110 | } | |
111 | ||
112 | EncodedJSValue* mallocBase() | |
113 | { | |
114 | if (m_capacity == static_cast<int>(inlineCapacity)) | |
115 | return 0; | |
116 | return &slotFor(m_capacity - 1); | |
117 | } | |
118 | ||
119 | int m_size; | |
120 | int m_capacity; | |
121 | EncodedJSValue m_inlineBuffer[inlineCapacity]; | |
122 | EncodedJSValue* m_buffer; | |
9dae56ea | 123 | ListSet* m_markSet; |
9dae56ea A |
124 | |
125 | private: | |
126 | // Prohibits new / delete, which would break GC. | |
9dae56ea A |
127 | void* operator new(size_t size) |
128 | { | |
129 | return fastMalloc(size); | |
130 | } | |
131 | void operator delete(void* p) | |
132 | { | |
133 | fastFree(p); | |
134 | } | |
135 | ||
136 | void* operator new[](size_t); | |
137 | void operator delete[](void*); | |
138 | ||
139 | void* operator new(size_t, void*); | |
140 | void operator delete(void*, size_t); | |
141 | }; | |
142 | ||
ba379fdc A |
143 | class ArgList { |
144 | friend class JIT; | |
145 | public: | |
ba379fdc A |
146 | ArgList() |
147 | : m_args(0) | |
148 | , m_argCount(0) | |
149 | { | |
150 | } | |
6fe7ccc8 | 151 | |
14957cd0 | 152 | ArgList(ExecState* exec) |
6fe7ccc8 | 153 | : m_args(reinterpret_cast<JSValue*>(&exec[CallFrame::argumentOffset(0)])) |
14957cd0 A |
154 | , m_argCount(exec->argumentCount()) |
155 | { | |
156 | } | |
ba379fdc A |
157 | |
158 | ArgList(const MarkedArgumentBuffer& args) | |
6fe7ccc8 | 159 | : m_args(reinterpret_cast<JSValue*>(args.m_buffer)) |
ba379fdc A |
160 | , m_argCount(args.size()) |
161 | { | |
162 | } | |
163 | ||
6fe7ccc8 | 164 | JSValue at(int i) const |
ba379fdc | 165 | { |
6fe7ccc8 A |
166 | if (i >= m_argCount) |
167 | return jsUndefined(); | |
168 | return m_args[-i]; | |
ba379fdc A |
169 | } |
170 | ||
171 | bool isEmpty() const { return !m_argCount; } | |
ba379fdc A |
172 | size_t size() const { return m_argCount; } |
173 | ||
6fe7ccc8 | 174 | JS_EXPORT_PRIVATE void getSlice(int startIndex, ArgList& result) const; |
ba379fdc | 175 | |
ba379fdc A |
176 | private: |
177 | JSValue* m_args; | |
6fe7ccc8 | 178 | int m_argCount; |
ba379fdc A |
179 | }; |
180 | ||
9dae56ea A |
181 | } // namespace JSC |
182 | ||
183 | #endif // ArgList_h |