Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: src/builtins.cc

Issue 8098: - Added conditional write barrier to object accessors.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/bootstrapper.cc ('k') | src/dateparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 // Optimize the case where there are no parameters passed. 171 // Optimize the case where there are no parameters passed.
172 if (__argc__ == 1) return array->Initialize(4); 172 if (__argc__ == 1) return array->Initialize(4);
173 173
174 // Take the arguments as elements. 174 // Take the arguments as elements.
175 int number_of_elements = __argc__ - 1; 175 int number_of_elements = __argc__ - 1;
176 Smi* len = Smi::FromInt(number_of_elements); 176 Smi* len = Smi::FromInt(number_of_elements);
177 Object* obj = Heap::AllocateFixedArrayWithHoles(len->value()); 177 Object* obj = Heap::AllocateFixedArrayWithHoles(len->value());
178 if (obj->IsFailure()) return obj; 178 if (obj->IsFailure()) return obj;
179 FixedArray* elms = FixedArray::cast(obj); 179 FixedArray* elms = FixedArray::cast(obj);
180 FixedArray::WriteBarrierMode mode = elms->GetWriteBarrierMode(); 180 WriteBarrierMode mode = elms->GetWriteBarrierMode();
181 // Fill in the content 181 // Fill in the content
182 for (int index = 0; index < number_of_elements; index++) { 182 for (int index = 0; index < number_of_elements; index++) {
183 elms->set(index, BUILTIN_ARG(index+1), mode); 183 elms->set(index, BUILTIN_ARG(index+1), mode);
184 } 184 }
185 185
186 // Set length and elements on the array. 186 // Set length and elements on the array.
187 array->set_elements(FixedArray::cast(obj)); 187 array->set_elements(FixedArray::cast(obj));
188 array->set_length(len); 188 array->set_length(len, SKIP_WRITE_BARRIER);
189 189
190 return array; 190 return array;
191 } 191 }
192 BUILTIN_END 192 BUILTIN_END
193 193
194 194
195 BUILTIN(ArrayPush) { 195 BUILTIN(ArrayPush) {
196 JSArray* array = JSArray::cast(*receiver); 196 JSArray* array = JSArray::cast(*receiver);
197 ASSERT(array->HasFastElements()); 197 ASSERT(array->HasFastElements());
198 198
199 // Make sure we have space for the elements. 199 // Make sure we have space for the elements.
200 int len = Smi::cast(array->length())->value(); 200 int len = Smi::cast(array->length())->value();
201 201
202 // Set new length. 202 // Set new length.
203 int new_length = len + __argc__ - 1; 203 int new_length = len + __argc__ - 1;
204 FixedArray* elms = FixedArray::cast(array->elements()); 204 FixedArray* elms = FixedArray::cast(array->elements());
205 205
206 if (new_length <= elms->length()) { 206 if (new_length <= elms->length()) {
207 // Backing storage has extra space for the provided values. 207 // Backing storage has extra space for the provided values.
208 for (int index = 0; index < __argc__ - 1; index++) { 208 for (int index = 0; index < __argc__ - 1; index++) {
209 elms->set(index + len, BUILTIN_ARG(index+1)); 209 elms->set(index + len, BUILTIN_ARG(index+1));
210 } 210 }
211 } else { 211 } else {
212 // New backing storage is needed. 212 // New backing storage is needed.
213 int capacity = new_length + (new_length >> 1) + 16; 213 int capacity = new_length + (new_length >> 1) + 16;
214 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); 214 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity);
215 if (obj->IsFailure()) return obj; 215 if (obj->IsFailure()) return obj;
216 FixedArray* new_elms = FixedArray::cast(obj); 216 FixedArray* new_elms = FixedArray::cast(obj);
217 FixedArray::WriteBarrierMode mode = new_elms->GetWriteBarrierMode(); 217 WriteBarrierMode mode = new_elms->GetWriteBarrierMode();
218 // Fill out the new array with old elements. 218 // Fill out the new array with old elements.
219 for (int i = 0; i < len; i++) new_elms->set(i, elms->get(i), mode); 219 for (int i = 0; i < len; i++) new_elms->set(i, elms->get(i), mode);
220 // Add the provided values. 220 // Add the provided values.
221 for (int index = 0; index < __argc__ - 1; index++) { 221 for (int index = 0; index < __argc__ - 1; index++) {
222 new_elms->set(index + len, BUILTIN_ARG(index+1), mode); 222 new_elms->set(index + len, BUILTIN_ARG(index+1), mode);
223 } 223 }
224 // Set the new backing storage. 224 // Set the new backing storage.
225 array->set_elements(new_elms); 225 array->set_elements(new_elms);
226 } 226 }
227 // Set the length. 227 // Set the length.
228 array->set_length(Smi::FromInt(new_length)); 228 array->set_length(Smi::FromInt(new_length), SKIP_WRITE_BARRIER);
229 return array->length(); 229 return array->length();
230 } 230 }
231 BUILTIN_END 231 BUILTIN_END
232 232
233 233
234 BUILTIN(ArrayPop) { 234 BUILTIN(ArrayPop) {
235 JSArray* array = JSArray::cast(*receiver); 235 JSArray* array = JSArray::cast(*receiver);
236 ASSERT(array->HasFastElements()); 236 ASSERT(array->HasFastElements());
237 Object* undefined = Heap::undefined_value(); 237 Object* undefined = Heap::undefined_value();
238 238
239 int len = Smi::cast(array->length())->value(); 239 int len = Smi::cast(array->length())->value();
240 if (len == 0) return undefined; 240 if (len == 0) return undefined;
241 241
242 // Get top element 242 // Get top element
243 FixedArray* elms = FixedArray::cast(array->elements()); 243 FixedArray* elms = FixedArray::cast(array->elements());
244 Object* top = elms->get(len - 1); 244 Object* top = elms->get(len - 1);
245 245
246 // Set the length. 246 // Set the length.
247 array->set_length(Smi::FromInt(len - 1)); 247 array->set_length(Smi::FromInt(len - 1), SKIP_WRITE_BARRIER);
248 248
249 if (!top->IsTheHole()) { 249 if (!top->IsTheHole()) {
250 // Delete the top element. 250 // Delete the top element.
251 elms->set_the_hole(len - 1); 251 elms->set_the_hole(len - 1);
252
253 return top; 252 return top;
254 } 253 }
255 254
256 // Remember to check the prototype chain. 255 // Remember to check the prototype chain.
257 JSFunction* array_function = 256 JSFunction* array_function =
258 Top::context()->global_context()->array_function(); 257 Top::context()->global_context()->array_function();
259 JSObject* prototype = JSObject::cast(array_function->prototype()); 258 JSObject* prototype = JSObject::cast(array_function->prototype());
260 top = prototype->GetElement(len - 1); 259 top = prototype->GetElement(len - 1);
261 260
262 return top; 261 return top;
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 if (entry->contains(pc)) { 705 if (entry->contains(pc)) {
707 return names_[i]; 706 return names_[i];
708 } 707 }
709 } 708 }
710 } 709 }
711 return NULL; 710 return NULL;
712 } 711 }
713 712
714 713
715 } } // namespace v8::internal 714 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/dateparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698