kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 7d1b3b9 | 2017-02-21 01:51:05 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003-2017 Apple Inc. All rights reserved. |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 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 |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
ggaren | 07d4ce6 | 2005-07-14 18:27:04 +0000 | [diff] [blame] | 17 | * Boston, MA 02110-1301, USA. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 18 | * |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 21 | #include "config.h" |
weinig@apple.com | 49b3250 | 2008-07-06 00:10:04 +0000 | [diff] [blame] | 22 | #include "ArgList.h" |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 23 | |
mhahnenberg@apple.com | c1bc9d3 | 2013-01-24 21:39:55 +0000 | [diff] [blame] | 24 | #include "JSCJSValue.h" |
oliver@apple.com | 9d4f0ec | 2011-03-14 18:16:36 +0000 | [diff] [blame] | 25 | #include "JSObject.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 26 | #include "JSCInlines.h" |
ap@webkit.org | 960c28e | 2008-06-19 17:29:29 +0000 | [diff] [blame] | 27 | |
mrowe@apple.com | cf617a5 | 2007-11-05 23:05:03 +0000 | [diff] [blame] | 28 | using std::min; |
| 29 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 30 | namespace JSC { |
darin | ff399e0 | 2002-11-23 07:49:05 +0000 | [diff] [blame] | 31 | |
ggaren@apple.com | 9688409 | 2016-08-17 21:22:46 +0000 | [diff] [blame] | 32 | void MarkedArgumentBuffer::addMarkSet(JSValue v) |
| 33 | { |
| 34 | if (m_markSet) |
| 35 | return; |
| 36 | |
| 37 | Heap* heap = Heap::heap(v); |
| 38 | if (!heap) |
| 39 | return; |
| 40 | |
| 41 | m_markSet = &heap->markListSet(); |
| 42 | m_markSet->add(this); |
| 43 | } |
| 44 | |
darin@apple.com | 80d38f9 | 2008-06-16 05:28:46 +0000 | [diff] [blame] | 45 | void ArgList::getSlice(int startIndex, ArgList& result) const |
darin | ff399e0 | 2002-11-23 07:49:05 +0000 | [diff] [blame] | 46 | { |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 47 | if (startIndex <= 0 || startIndex >= m_argCount) { |
ggaren@apple.com | 2fd96da | 2011-11-16 23:37:15 +0000 | [diff] [blame] | 48 | result = ArgList(); |
oliver@apple.com | f32186e | 2009-04-30 01:21:52 +0000 | [diff] [blame] | 49 | return; |
| 50 | } |
ggaren@apple.com | 2fd96da | 2011-11-16 23:37:15 +0000 | [diff] [blame] | 51 | |
msaboff@apple.com | b70e41b | 2013-09-13 18:03:55 +0000 | [diff] [blame] | 52 | result.m_args = m_args + startIndex; |
ggaren@apple.com | 2fd96da | 2011-11-16 23:37:15 +0000 | [diff] [blame] | 53 | result.m_argCount = m_argCount - startIndex; |
mjs | 0e6b4f0 | 2002-11-26 23:52:00 +0000 | [diff] [blame] | 54 | } |
| 55 | |
fpizlo@apple.com | f7240e0 | 2016-12-16 02:16:19 +0000 | [diff] [blame] | 56 | void MarkedArgumentBuffer::markLists(SlotVisitor& visitor, ListSet& markSet) |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 57 | { |
ap@webkit.org | a1669f3 | 2008-06-12 14:34:38 +0000 | [diff] [blame] | 58 | ListSet::iterator end = markSet.end(); |
| 59 | for (ListSet::iterator it = markSet.begin(); it != end; ++it) { |
oliver@apple.com | f32186e | 2009-04-30 01:21:52 +0000 | [diff] [blame] | 60 | MarkedArgumentBuffer* list = *it; |
ggaren@apple.com | 58adda0 | 2011-12-14 02:55:02 +0000 | [diff] [blame] | 61 | for (int i = 0; i < list->m_size; ++i) |
fpizlo@apple.com | f7240e0 | 2016-12-16 02:16:19 +0000 | [diff] [blame] | 62 | visitor.appendUnbarriered(JSValue::decode(list->slotFor(i))); |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
mark.lam@apple.com | 7d1b3b9 | 2017-02-21 01:51:05 +0000 | [diff] [blame] | 66 | void MarkedArgumentBuffer::slowEnsureCapacity(size_t requestedCapacity) |
| 67 | { |
| 68 | int newCapacity = Checked<int>(requestedCapacity).unsafeGet(); |
| 69 | expandCapacity(newCapacity); |
| 70 | } |
| 71 | |
ggaren@apple.com | 9688409 | 2016-08-17 21:22:46 +0000 | [diff] [blame] | 72 | void MarkedArgumentBuffer::expandCapacity() |
ggaren | 879ab75 | 2007-11-05 21:27:15 +0000 | [diff] [blame] | 73 | { |
fpizlo@apple.com | d21b45e | 2016-02-07 19:03:29 +0000 | [diff] [blame] | 74 | int newCapacity = (Checked<int>(m_capacity) * 2).unsafeGet(); |
mark.lam@apple.com | 7d1b3b9 | 2017-02-21 01:51:05 +0000 | [diff] [blame] | 75 | expandCapacity(newCapacity); |
| 76 | } |
| 77 | |
| 78 | void MarkedArgumentBuffer::expandCapacity(int newCapacity) |
| 79 | { |
| 80 | ASSERT(m_capacity < newCapacity); |
fpizlo@apple.com | d21b45e | 2016-02-07 19:03:29 +0000 | [diff] [blame] | 81 | size_t size = (Checked<size_t>(newCapacity) * sizeof(EncodedJSValue)).unsafeGet(); |
| 82 | EncodedJSValue* newBuffer = static_cast<EncodedJSValue*>(fastMalloc(size)); |
mark.lam@apple.com | 7d1b3b9 | 2017-02-21 01:51:05 +0000 | [diff] [blame] | 83 | for (int i = 0; i < m_size; ++i) { |
msaboff@apple.com | b70e41b | 2013-09-13 18:03:55 +0000 | [diff] [blame] | 84 | newBuffer[i] = m_buffer[i]; |
ggaren@apple.com | 9688409 | 2016-08-17 21:22:46 +0000 | [diff] [blame] | 85 | addMarkSet(JSValue::decode(m_buffer[i])); |
| 86 | } |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 87 | |
ggaren@apple.com | 58adda0 | 2011-12-14 02:55:02 +0000 | [diff] [blame] | 88 | if (EncodedJSValue* base = mallocBase()) |
fpizlo@apple.com | d21b45e | 2016-02-07 19:03:29 +0000 | [diff] [blame] | 89 | fastFree(base); |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 90 | |
| 91 | m_buffer = newBuffer; |
| 92 | m_capacity = newCapacity; |
ggaren@apple.com | 9688409 | 2016-08-17 21:22:46 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void MarkedArgumentBuffer::slowAppend(JSValue v) |
| 96 | { |
mark.lam@apple.com | 7d1b3b9 | 2017-02-21 01:51:05 +0000 | [diff] [blame] | 97 | ASSERT(m_size <= m_capacity); |
| 98 | if (m_size == m_capacity) |
ggaren@apple.com | 9688409 | 2016-08-17 21:22:46 +0000 | [diff] [blame] | 99 | expandCapacity(); |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 100 | |
ggaren@apple.com | 58adda0 | 2011-12-14 02:55:02 +0000 | [diff] [blame] | 101 | slotFor(m_size) = JSValue::encode(v); |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 102 | ++m_size; |
ggaren@apple.com | 9688409 | 2016-08-17 21:22:46 +0000 | [diff] [blame] | 103 | addMarkSet(v); |
darin | f7fc08d | 2002-11-20 08:53:04 +0000 | [diff] [blame] | 104 | } |
darin | 20330f7 | 2002-11-20 22:59:04 +0000 | [diff] [blame] | 105 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 106 | } // namespace JSC |