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

Side by Side Diff: src/runtime.cc

Issue 6524010: Fix issue 1152: temporary JS array invariant violation in ArrayConcat. (Closed)
Patch Set: Created 9 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 8338 matching lines...) Expand 10 before | Expand all | Expand 10 after
8349 } 8349 }
8350 if (JSObject::kMaxElementCount - result_length < length_estimate) { 8350 if (JSObject::kMaxElementCount - result_length < length_estimate) {
8351 result_length = JSObject::kMaxElementCount; 8351 result_length = JSObject::kMaxElementCount;
8352 break; 8352 break;
8353 } 8353 }
8354 result_length += length_estimate; 8354 result_length += length_estimate;
8355 } 8355 }
8356 } 8356 }
8357 } 8357 }
8358 8358
8359 // Allocate an empty array, will set length and content later. 8359 // Allocate an empty array, will set map, length, and content later.
8360 Handle<JSArray> result = Factory::NewJSArray(0); 8360 Handle<JSArray> result = Factory::NewJSArray(0);
8361 8361
8362 uint32_t estimate_nof_elements = IterateArguments(arguments, NULL); 8362 uint32_t estimate_nof_elements = IterateArguments(arguments, NULL);
8363 // If estimated number of elements is more than half of length, a 8363 // If estimated number of elements is more than half of length, a
8364 // fixed array (fast case) is more time and space-efficient than a 8364 // fixed array (fast case) is more time and space-efficient than a
8365 // dictionary. 8365 // dictionary.
8366 bool fast_case = (estimate_nof_elements * 2) >= result_length; 8366 bool fast_case = (estimate_nof_elements * 2) >= result_length;
8367 8367
8368 Handle<Map> map;
8368 Handle<FixedArray> storage; 8369 Handle<FixedArray> storage;
8369 if (fast_case) { 8370 if (fast_case) {
8370 // The backing storage array must have non-existing elements to 8371 // The backing storage array must have non-existing elements to
8371 // preserve holes across concat operations. 8372 // preserve holes across concat operations.
8373 map = Factory::GetFastElementsMap(Handle<Map>(result->map()));
8372 storage = Factory::NewFixedArrayWithHoles(result_length); 8374 storage = Factory::NewFixedArrayWithHoles(result_length);
8373 Handle<Map> fast_map =
8374 Factory::GetFastElementsMap(Handle<Map>(result->map()));
8375 result->set_map(*fast_map);
8376 } else { 8375 } else {
8376 map = Factory::GetSlowElementsMap(Handle<Map>(result->map()));
8377 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate 8377 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate
8378 uint32_t at_least_space_for = estimate_nof_elements + 8378 uint32_t at_least_space_for = estimate_nof_elements +
8379 (estimate_nof_elements >> 2); 8379 (estimate_nof_elements >> 2);
8380 storage = Handle<FixedArray>::cast( 8380 storage = Handle<FixedArray>::cast(
8381 Factory::NewNumberDictionary(at_least_space_for)); 8381 Factory::NewNumberDictionary(at_least_space_for));
8382 Handle<Map> slow_map =
8383 Factory::GetSlowElementsMap(Handle<Map>(result->map()));
8384 result->set_map(*slow_map);
8385 } 8382 }
8386 8383
8387 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length)); 8384 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length));
8388 8385
8389 ArrayConcatVisitor visitor(storage, result_length, fast_case); 8386 ArrayConcatVisitor visitor(storage, result_length, fast_case);
8390 8387
8391 IterateArguments(arguments, &visitor); 8388 IterateArguments(arguments, &visitor);
8392 8389
8390 // Please note:
8391 // - the storage might have been changed in the visitor;
8392 // - the map and the storage must be set together to avoid breaking
8393 // the invariant that the map describes the array's elements.
8394 result->set_map(*map);
8393 result->set_length(*len); 8395 result->set_length(*len);
8394 // Please note the storage might have changed in the visitor.
8395 result->set_elements(*visitor.storage()); 8396 result->set_elements(*visitor.storage());
8396 8397
8397 return *result; 8398 return *result;
8398 } 8399 }
8399 8400
8400 8401
8401 // This will not allocate (flatten the string), but it may run 8402 // This will not allocate (flatten the string), but it may run
8402 // very slowly for very deeply nested ConsStrings. For debugging use only. 8403 // very slowly for very deeply nested ConsStrings. For debugging use only.
8403 static MaybeObject* Runtime_GlobalPrint(Arguments args) { 8404 static MaybeObject* Runtime_GlobalPrint(Arguments args) {
8404 NoHandleAllocation ha; 8405 NoHandleAllocation ha;
(...skipping 2790 matching lines...) Expand 10 before | Expand all | Expand 10 after
11195 } else { 11196 } else {
11196 // Handle last resort GC and make sure to allow future allocations 11197 // Handle last resort GC and make sure to allow future allocations
11197 // to grow the heap without causing GCs (if possible). 11198 // to grow the heap without causing GCs (if possible).
11198 Counters::gc_last_resort_from_js.Increment(); 11199 Counters::gc_last_resort_from_js.Increment();
11199 Heap::CollectAllGarbage(false); 11200 Heap::CollectAllGarbage(false);
11200 } 11201 }
11201 } 11202 }
11202 11203
11203 11204
11204 } } // namespace v8::internal 11205 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698