]>
Commit | Line | Data |
---|---|---|
b37bf2e1 | 1 | /* |
f9bf01c6 | 2 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. |
b37bf2e1 A |
3 | * |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Library General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Library General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Library General Public License | |
15 | * along with this library; see the file COPYING.LIB. If not, write to | |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 | * Boston, MA 02110-1301, USA. | |
18 | * | |
19 | */ | |
20 | ||
21 | #include "config.h" | |
9dae56ea A |
22 | #include "ArgList.h" |
23 | ||
6fe7ccc8 | 24 | #include "HeapRootVisitor.h" |
93a37866 | 25 | #include "JSCJSValue.h" |
14957cd0 | 26 | #include "JSObject.h" |
81345200 | 27 | #include "JSCInlines.h" |
b37bf2e1 A |
28 | |
29 | using std::min; | |
30 | ||
9dae56ea | 31 | namespace JSC { |
b37bf2e1 | 32 | |
9dae56ea | 33 | void ArgList::getSlice(int startIndex, ArgList& result) const |
b37bf2e1 | 34 | { |
6fe7ccc8 A |
35 | if (startIndex <= 0 || startIndex >= m_argCount) { |
36 | result = ArgList(); | |
ba379fdc A |
37 | return; |
38 | } | |
6fe7ccc8 | 39 | |
81345200 | 40 | result.m_args = m_args + startIndex; |
6fe7ccc8 | 41 | result.m_argCount = m_argCount - startIndex; |
b37bf2e1 A |
42 | } |
43 | ||
6fe7ccc8 | 44 | void MarkedArgumentBuffer::markLists(HeapRootVisitor& heapRootVisitor, ListSet& markSet) |
b37bf2e1 | 45 | { |
9dae56ea A |
46 | ListSet::iterator end = markSet.end(); |
47 | for (ListSet::iterator it = markSet.begin(); it != end; ++it) { | |
ba379fdc | 48 | MarkedArgumentBuffer* list = *it; |
6fe7ccc8 A |
49 | for (int i = 0; i < list->m_size; ++i) |
50 | heapRootVisitor.visit(reinterpret_cast<JSValue*>(&list->slotFor(i))); | |
b37bf2e1 A |
51 | } |
52 | } | |
53 | ||
ba379fdc | 54 | void MarkedArgumentBuffer::slowAppend(JSValue v) |
b37bf2e1 | 55 | { |
6fe7ccc8 | 56 | int newCapacity = m_capacity * 4; |
81345200 | 57 | EncodedJSValue* newBuffer = new EncodedJSValue[newCapacity]; |
6fe7ccc8 | 58 | for (int i = 0; i < m_capacity; ++i) |
81345200 | 59 | newBuffer[i] = m_buffer[i]; |
6fe7ccc8 A |
60 | |
61 | if (EncodedJSValue* base = mallocBase()) | |
62 | delete [] base; | |
63 | ||
64 | m_buffer = newBuffer; | |
65 | m_capacity = newCapacity; | |
66 | ||
67 | slotFor(m_size) = JSValue::encode(v); | |
68 | ++m_size; | |
69 | ||
70 | if (m_markSet) | |
71 | return; | |
72 | ||
b37bf2e1 A |
73 | // As long as our size stays within our Vector's inline |
74 | // capacity, all our values are allocated on the stack, and | |
75 | // therefore don't need explicit marking. Once our size exceeds | |
76 | // our Vector's inline capacity, though, our values move to the | |
77 | // heap, where they do need explicit marking. | |
6fe7ccc8 A |
78 | for (int i = 0; i < m_size; ++i) { |
79 | Heap* heap = Heap::heap(JSValue::decode(slotFor(i))); | |
80 | if (!heap) | |
81 | continue; | |
9dae56ea | 82 | |
6fe7ccc8 A |
83 | m_markSet = &heap->markListSet(); |
84 | m_markSet->add(this); | |
85 | break; | |
b37bf2e1 | 86 | } |
b37bf2e1 A |
87 | } |
88 | ||
9dae56ea | 89 | } // namespace JSC |