source: webkit/trunk/JavaScriptCore/runtime/MarkStack.h@ 64655

Last change on this file since 64655 was 64655, checked in by [email protected], 15 years ago

2010-08-04 Nathan Lawrence <[email protected]>

Reviewed by Darin Adler.

Refactoring MarkStack::append to take a reference. This is in
preparation for movable objects when we will need to update pointers.
http://bugs.webkit.org/show_bug.cgi?id=41177

Unless otherwise noted, all changes are to either return by reference
or pass a reference to MarkStack::append.

  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::markAggregate):
  • runtime/Collector.cpp: (JSC::Heap::markConservatively):

Added a temporary variable to prevent marking from changing an
unknown value on the stack

  • runtime/JSCell.h: (JSC::JSValue::asCell): (JSC::MarkStack::append): (JSC::MarkStack::appendInternal):
  • runtime/JSGlobalObject.cpp: (JSC::markIfNeeded):
  • runtime/JSONObject.cpp: (JSC::Stringifier::Holder::object):
  • runtime/JSObject.h: (JSC::JSObject::prototype):
  • runtime/JSStaticScopeObject.cpp: (JSC::JSStaticScopeObject::markChildren):
  • runtime/JSValue.h: (JSC::JSValue::JSValue): (JSC::JSValue::asCell):
  • runtime/MarkStack.h:
  • runtime/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::createStructure):

Changed the structure flags to include a custom markChildren.

(JSC::NativeErrorConstructor::markChildren):

Update the prototype of the stored structure.

  • runtime/NativeErrorConstructor.h:

Added structure flags.

  • runtime/Structure.h: (JSC::Structure::storedPrototype):

2010-08-04 Nathan Lawrence <[email protected]>

Reviewed by Darin Adler.

Removed unneeded marking. We need to remove this marking in order to have
MarkStack::append take references for updating movable objects.

https://bugs.webkit.org/show_bug.cgi?id=41177

  • JSValueWrapper.cpp: (JSValueWrapper::JSObjectMark):
File size: 5.9 KB
Line 
1/*
2 * Copyright (C) 2009 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 MarkStack_h
27#define MarkStack_h
28
29#include "JSValue.h"
30#include <wtf/Noncopyable.h>
31
32namespace JSC {
33
34 class JSGlobalData;
35 class Register;
36
37 enum MarkSetProperties { MayContainNullValues, NoNullValues };
38
39 class MarkStack : Noncopyable {
40 public:
41 MarkStack(void* jsArrayVPtr)
42 : m_jsArrayVPtr(jsArrayVPtr)
43#ifndef NDEBUG
44 , m_isCheckingForDefaultMarkViolation(false)
45#endif
46 {
47 }
48
49 template<typename T> ALWAYS_INLINE void append(T*& cell);
50 ALWAYS_INLINE void append(JSValue&);
51 ALWAYS_INLINE void append(Register&);
52
53 ALWAYS_INLINE void appendValues(Register* values, size_t count, MarkSetProperties properties = NoNullValues)
54 {
55 appendValues(reinterpret_cast<JSValue*>(values), count, properties);
56 }
57
58 ALWAYS_INLINE void appendValues(JSValue* values, size_t count, MarkSetProperties properties = NoNullValues)
59 {
60 if (count)
61 m_markSets.append(MarkSet(values, values + count, properties));
62 }
63
64 inline void drain();
65 void compact();
66
67 ~MarkStack()
68 {
69 ASSERT(m_markSets.isEmpty());
70 ASSERT(m_values.isEmpty());
71 }
72
73 private:
74 void appendInternal(JSCell*&);
75
76 void markChildren(JSCell*);
77
78 struct MarkSet {
79 MarkSet(JSValue* values, JSValue* end, MarkSetProperties properties)
80 : m_values(values)
81 , m_end(end)
82 , m_properties(properties)
83 {
84 ASSERT(values);
85 }
86 JSValue* m_values;
87 JSValue* m_end;
88 MarkSetProperties m_properties;
89 };
90
91 static void* allocateStack(size_t size);
92 static void releaseStack(void* addr, size_t size);
93
94 static void initializePagesize();
95 static size_t pageSize()
96 {
97 if (!s_pageSize)
98 initializePagesize();
99 return s_pageSize;
100 }
101
102 template <typename T> struct MarkStackArray {
103 MarkStackArray()
104 : m_top(0)
105 , m_allocated(MarkStack::pageSize())
106 , m_capacity(m_allocated / sizeof(T))
107 {
108 m_data = reinterpret_cast<T*>(allocateStack(m_allocated));
109 }
110
111 ~MarkStackArray()
112 {
113 releaseStack(m_data, m_allocated);
114 }
115
116 void expand()
117 {
118 size_t oldAllocation = m_allocated;
119 m_allocated *= 2;
120 m_capacity = m_allocated / sizeof(T);
121 void* newData = allocateStack(m_allocated);
122 memcpy(newData, m_data, oldAllocation);
123 releaseStack(m_data, oldAllocation);
124 m_data = reinterpret_cast<T*>(newData);
125 }
126
127 inline void append(const T& v)
128 {
129 if (m_top == m_capacity)
130 expand();
131 m_data[m_top++] = v;
132 }
133
134 inline T removeLast()
135 {
136 ASSERT(m_top);
137 return m_data[--m_top];
138 }
139
140 inline T& last()
141 {
142 ASSERT(m_top);
143 return m_data[m_top - 1];
144 }
145
146 inline bool isEmpty()
147 {
148 return m_top == 0;
149 }
150
151 inline size_t size() { return m_top; }
152
153 inline void shrinkAllocation(size_t size)
154 {
155 ASSERT(size <= m_allocated);
156 ASSERT(0 == (size % MarkStack::pageSize()));
157 if (size == m_allocated)
158 return;
159#if OS(WINDOWS) || OS(SYMBIAN) || PLATFORM(BREWMP)
160 // We cannot release a part of a region with VirtualFree. To get around this,
161 // we'll release the entire region and reallocate the size that we want.
162 releaseStack(m_data, m_allocated);
163 m_data = reinterpret_cast<T*>(allocateStack(size));
164#else
165 releaseStack(reinterpret_cast<char*>(m_data) + size, m_allocated - size);
166#endif
167 m_allocated = size;
168 m_capacity = m_allocated / sizeof(T);
169 }
170
171 private:
172 size_t m_top;
173 size_t m_allocated;
174 size_t m_capacity;
175 T* m_data;
176 };
177
178 void* m_jsArrayVPtr;
179 MarkStackArray<MarkSet> m_markSets;
180 MarkStackArray<JSCell*> m_values;
181 static size_t s_pageSize;
182
183#ifndef NDEBUG
184 public:
185 bool m_isCheckingForDefaultMarkViolation;
186#endif
187 };
188}
189
190#endif
Note: See TracBrowser for help on using the repository browser.