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

Side by Side Diff: src/bootstrapper.cc

Issue 9050001: Ensure newly allocated empty Arrays are transitioned to FAST_ELEMENT (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix existing and add new tests Created 8 years, 11 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 | « no previous file | src/contexts.h » ('j') | src/flag-definitions.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 // is 1. 885 // is 1.
886 array_function->shared()->set_length(1); 886 array_function->shared()->set_length(1);
887 Handle<DescriptorArray> array_descriptors = 887 Handle<DescriptorArray> array_descriptors =
888 factory->CopyAppendForeignDescriptor( 888 factory->CopyAppendForeignDescriptor(
889 factory->empty_descriptor_array(), 889 factory->empty_descriptor_array(),
890 factory->length_symbol(), 890 factory->length_symbol(),
891 factory->NewForeign(&Accessors::ArrayLength), 891 factory->NewForeign(&Accessors::ArrayLength),
892 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); 892 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE));
893 893
894 // Cache the fast JavaScript array map 894 // Cache the fast JavaScript array map
895 global_context()->set_js_array_map(array_function->initial_map()); 895 Map* initial_map = array_function->initial_map();
896 global_context()->js_array_map()->set_instance_descriptors( 896 initial_map->set_instance_descriptors(*array_descriptors);
897 *array_descriptors);
898 // array_function is used internally. JS code creating array object should 897 // array_function is used internally. JS code creating array object should
899 // search for the 'Array' property on the global object and use that one 898 // search for the 'Array' property on the global object and use that one
900 // as the constructor. 'Array' property on a global object can be 899 // as the constructor. 'Array' property on a global object can be
901 // overwritten by JS code. 900 // overwritten by JS code.
902 global_context()->set_array_function(*array_function); 901 global_context()->set_array_function(*array_function);
903 } 902 }
904 903
905 { // --- N u m b e r --- 904 { // --- N u m b e r ---
906 Handle<JSFunction> number_fun = 905 Handle<JSFunction> number_fun =
907 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, 906 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize,
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 array_function->shared()->DontAdaptArguments(); 1629 array_function->shared()->DontAdaptArguments();
1631 1630
1632 // InternalArrays should not use Smi-Only array optimizations. There are too 1631 // InternalArrays should not use Smi-Only array optimizations. There are too
1633 // many places in the C++ runtime code (e.g. RegEx) that assume that 1632 // many places in the C++ runtime code (e.g. RegEx) that assume that
1634 // elements in InternalArrays can be set to non-Smi values without going 1633 // elements in InternalArrays can be set to non-Smi values without going
1635 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT 1634 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
1636 // transition easy to trap. Moreover, they rarely are smi-only. 1635 // transition easy to trap. Moreover, they rarely are smi-only.
1637 MaybeObject* maybe_map = 1636 MaybeObject* maybe_map =
1638 array_function->initial_map()->CopyDropTransitions(); 1637 array_function->initial_map()->CopyDropTransitions();
1639 Map* new_map; 1638 Map* new_map;
1640 if (!maybe_map->To<Map>(&new_map)) return maybe_map; 1639 if (!maybe_map->To<Map>(&new_map)) return false;
1641 new_map->set_elements_kind(FAST_ELEMENTS); 1640 new_map->set_elements_kind(FAST_ELEMENTS);
1642 array_function->set_initial_map(new_map); 1641 array_function->set_initial_map(new_map);
1643 1642
1644 // Make "length" magic on instances. 1643 // Make "length" magic on instances.
1645 Handle<DescriptorArray> array_descriptors = 1644 Handle<DescriptorArray> array_descriptors =
1646 factory()->CopyAppendForeignDescriptor( 1645 factory()->CopyAppendForeignDescriptor(
1647 factory()->empty_descriptor_array(), 1646 factory()->empty_descriptor_array(),
1648 factory()->length_symbol(), 1647 factory()->length_symbol(),
1649 factory()->NewForeign(&Accessors::ArrayLength), 1648 factory()->NewForeign(&Accessors::ArrayLength),
1650 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); 1649 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 // Add initial map. 1728 // Add initial map.
1730 Handle<Map> initial_map = 1729 Handle<Map> initial_map =
1731 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); 1730 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize);
1732 initial_map->set_constructor(*array_constructor); 1731 initial_map->set_constructor(*array_constructor);
1733 1732
1734 // Set prototype on map. 1733 // Set prototype on map.
1735 initial_map->set_non_instance_prototype(false); 1734 initial_map->set_non_instance_prototype(false);
1736 initial_map->set_prototype(*array_prototype); 1735 initial_map->set_prototype(*array_prototype);
1737 1736
1738 // Update map with length accessor from Array and add "index" and "input". 1737 // Update map with length accessor from Array and add "index" and "input".
1739 Handle<Map> array_map(global_context()->js_array_map());
1740 Handle<DescriptorArray> array_descriptors(
1741 array_map->instance_descriptors());
1742 ASSERT_EQ(1, array_descriptors->number_of_descriptors());
1743
1744 Handle<DescriptorArray> reresult_descriptors = 1738 Handle<DescriptorArray> reresult_descriptors =
1745 factory()->NewDescriptorArray(3); 1739 factory()->NewDescriptorArray(3);
1746
1747 DescriptorArray::WhitenessWitness witness(*reresult_descriptors); 1740 DescriptorArray::WhitenessWitness witness(*reresult_descriptors);
1748 1741
1749 reresult_descriptors->CopyFrom(0, *array_descriptors, 0, witness); 1742 JSFunction* array_function = global_context()->array_function();
1743 Handle<DescriptorArray> array_descriptors(
1744 array_function->initial_map()->instance_descriptors());
1745 int index = array_descriptors->SearchWithCache(heap()->length_symbol());
1746 reresult_descriptors->CopyFrom(0, *array_descriptors, index, witness);
1750 1747
1751 int enum_index = 0; 1748 int enum_index = 0;
1752 { 1749 {
1753 FieldDescriptor index_field(heap()->index_symbol(), 1750 FieldDescriptor index_field(heap()->index_symbol(),
1754 JSRegExpResult::kIndexIndex, 1751 JSRegExpResult::kIndexIndex,
1755 NONE, 1752 NONE,
1756 enum_index++); 1753 enum_index++);
1757 reresult_descriptors->Set(1, &index_field, witness); 1754 reresult_descriptors->Set(1, &index_field, witness);
1758 } 1755 }
1759 1756
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 InstallJSFunctionResultCaches(); 2314 InstallJSFunctionResultCaches();
2318 InitializeNormalizedMapCaches(); 2315 InitializeNormalizedMapCaches();
2319 if (!InstallNatives()) return; 2316 if (!InstallNatives()) return;
2320 2317
2321 MakeFunctionInstancePrototypeWritable(); 2318 MakeFunctionInstancePrototypeWritable();
2322 2319
2323 if (!ConfigureGlobalObjects(global_template)) return; 2320 if (!ConfigureGlobalObjects(global_template)) return;
2324 isolate->counters()->contexts_created_from_scratch()->Increment(); 2321 isolate->counters()->contexts_created_from_scratch()->Increment();
2325 } 2322 }
2326 2323
2324 Handle<Context> context = global_context();
2325 context->set_untransitioned_js_array_map(
2326 context->array_function()->initial_map());
2327 context->set_fast_array_element_bias(0);
Jakob Kummerow 2012/01/04 20:55:17 I have a weak preference to use "Smi::FromInt(0)"
2328
2327 // Initialize experimental globals and install experimental natives. 2329 // Initialize experimental globals and install experimental natives.
2328 InitializeExperimentalGlobal(); 2330 InitializeExperimentalGlobal();
2329 if (!InstallExperimentalNatives()) return; 2331 if (!InstallExperimentalNatives()) return;
2330 2332
2331 result_ = global_context_; 2333 result_ = global_context_;
2332 } 2334 }
2333 2335
2334 2336
2335 // Support for thread preemption. 2337 // Support for thread preemption.
2336 2338
(...skipping 17 matching lines...) Expand all
2354 return from + sizeof(NestingCounterType); 2356 return from + sizeof(NestingCounterType);
2355 } 2357 }
2356 2358
2357 2359
2358 // Called when the top-level V8 mutex is destroyed. 2360 // Called when the top-level V8 mutex is destroyed.
2359 void Bootstrapper::FreeThreadResources() { 2361 void Bootstrapper::FreeThreadResources() {
2360 ASSERT(!IsActive()); 2362 ASSERT(!IsActive());
2361 } 2363 }
2362 2364
2363 } } // namespace v8::internal 2365 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/contexts.h » ('j') | src/flag-definitions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698