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

Side by Side Diff: src/bootstrapper.cc

Issue 12255049: Introduce InternalPackedArray. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/array.js ('k') | src/json.js » ('j') | src/messages.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // detached from the other objects in the snapshot. 197 // detached from the other objects in the snapshot.
198 void HookUpInnerGlobal(Handle<GlobalObject> inner_global); 198 void HookUpInnerGlobal(Handle<GlobalObject> inner_global);
199 // New context initialization. Used for creating a context from scratch. 199 // New context initialization. Used for creating a context from scratch.
200 bool InitializeGlobal(Handle<GlobalObject> inner_global, 200 bool InitializeGlobal(Handle<GlobalObject> inner_global,
201 Handle<JSFunction> empty_function); 201 Handle<JSFunction> empty_function);
202 void InitializeExperimentalGlobal(); 202 void InitializeExperimentalGlobal();
203 // Installs the contents of the native .js files on the global objects. 203 // Installs the contents of the native .js files on the global objects.
204 // Used for creating a context from scratch. 204 // Used for creating a context from scratch.
205 void InstallNativeFunctions(); 205 void InstallNativeFunctions();
206 void InstallExperimentalNativeFunctions(); 206 void InstallExperimentalNativeFunctions();
207 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins,
208 const char* name,
209 ElementsKind elements_kind);
207 bool InstallNatives(); 210 bool InstallNatives();
208 bool InstallExperimentalNatives(); 211 bool InstallExperimentalNatives();
209 void InstallBuiltinFunctionIds(); 212 void InstallBuiltinFunctionIds();
210 void InstallJSFunctionResultCaches(); 213 void InstallJSFunctionResultCaches();
211 void InitializeNormalizedMapCaches(); 214 void InitializeNormalizedMapCaches();
212 215
213 enum ExtensionTraversalState { 216 enum ExtensionTraversalState {
214 UNVISITED, VISITED, INSTALLED 217 UNVISITED, VISITED, INSTALLED
215 }; 218 };
216 219
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 if (FLAG_harmony_observation) { 1436 if (FLAG_harmony_observation) {
1434 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); 1437 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change);
1435 INSTALL_NATIVE(JSFunction, "DeliverChangeRecords", 1438 INSTALL_NATIVE(JSFunction, "DeliverChangeRecords",
1436 observers_deliver_changes); 1439 observers_deliver_changes);
1437 } 1440 }
1438 } 1441 }
1439 1442
1440 #undef INSTALL_NATIVE 1443 #undef INSTALL_NATIVE
1441 1444
1442 1445
1446 Handle<JSFunction> Genesis::InstallInternalArray(
1447 Handle<JSBuiltinsObject> builtins,
1448 const char* name,
1449 ElementsKind elements_kind) {
1450 // --- I n t e r n a l A r r a y ---
1451 // An array constructor on the builtins object that works like
1452 // the public Array constructor, except that its prototype
1453 // doesn't inherit from Object.prototype.
1454 // To be used only for internal work by builtins. Instances
1455 // must not be leaked to user code.
1456 Handle<JSFunction> array_function =
1457 InstallFunction(builtins,
1458 name,
1459 JS_ARRAY_TYPE,
1460 JSArray::kSize,
1461 isolate()->initial_object_prototype(),
1462 Builtins::kInternalArrayCode,
1463 true);
1464 Handle<JSObject> prototype =
1465 factory()->NewJSObject(isolate()->object_function(), TENURED);
1466 SetPrototype(array_function, prototype);
1467
1468 array_function->shared()->set_construct_stub(
1469 isolate()->builtins()->builtin(Builtins::kArrayConstructCode));
1470 array_function->shared()->DontAdaptArguments();
1471
1472 MaybeObject* maybe_map = array_function->initial_map()->Copy();
1473 Map* new_map;
1474 if (!maybe_map->To(&new_map)) return Handle<JSFunction>::null();
1475 new_map->set_elements_kind(elements_kind);
1476 array_function->set_initial_map(new_map);
1477
1478 // Make "length" magic on instances.
1479 Handle<Map> initial_map(array_function->initial_map());
1480 Handle<DescriptorArray> array_descriptors(
1481 factory()->NewDescriptorArray(0, 1));
1482 DescriptorArray::WhitenessWitness witness(*array_descriptors);
1483
1484 Handle<Foreign> array_length(factory()->NewForeign(
1485 &Accessors::ArrayLength));
1486 PropertyAttributes attribs = static_cast<PropertyAttributes>(
1487 DONT_ENUM | DONT_DELETE);
1488 initial_map->set_instance_descriptors(*array_descriptors);
1489
1490 { // Add length.
1491 CallbacksDescriptor d(
1492 *factory()->length_symbol(), *array_length, attribs);
1493 array_function->initial_map()->AppendDescriptor(&d, witness);
1494 }
1495
1496 return array_function;
1497 }
1498
1499
1443 bool Genesis::InstallNatives() { 1500 bool Genesis::InstallNatives() {
1444 HandleScope scope(isolate()); 1501 HandleScope scope(isolate());
1445 1502
1446 // Create a function for the builtins object. Allocate space for the 1503 // Create a function for the builtins object. Allocate space for the
1447 // JavaScript builtins, a reference to the builtins object 1504 // JavaScript builtins, a reference to the builtins object
1448 // (itself) and a reference to the native_context directly in the object. 1505 // (itself) and a reference to the native_context directly in the object.
1449 Handle<Code> code = Handle<Code>( 1506 Handle<Code> code = Handle<Code>(
1450 isolate()->builtins()->builtin(Builtins::kIllegal)); 1507 isolate()->builtins()->builtin(Builtins::kIllegal));
1451 Handle<JSFunction> builtins_fun = 1508 Handle<JSFunction> builtins_fun =
1452 factory()->NewFunction(factory()->empty_symbol(), 1509 factory()->NewFunction(factory()->empty_symbol(),
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, 1712 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE,
1656 JSValue::kSize, 1713 JSValue::kSize,
1657 isolate()->initial_object_prototype(), 1714 isolate()->initial_object_prototype(),
1658 Builtins::kIllegal, false); 1715 Builtins::kIllegal, false);
1659 Handle<JSObject> prototype = 1716 Handle<JSObject> prototype =
1660 factory()->NewJSObject(isolate()->object_function(), TENURED); 1717 factory()->NewJSObject(isolate()->object_function(), TENURED);
1661 SetPrototype(opaque_reference_fun, prototype); 1718 SetPrototype(opaque_reference_fun, prototype);
1662 native_context()->set_opaque_reference_function(*opaque_reference_fun); 1719 native_context()->set_opaque_reference_function(*opaque_reference_fun);
1663 } 1720 }
1664 1721
1665 { // --- I n t e r n a l A r r a y --- 1722
1666 // An array constructor on the builtins object that works like 1723 // InternalArrays should not use Smi-Only array optimizations. There are too
1667 // the public Array constructor, except that its prototype 1724 // many places in the C++ runtime code (e.g. RegEx) that assume that
1668 // doesn't inherit from Object.prototype. 1725 // elements in InternalArrays can be set to non-Smi values without going
1669 // To be used only for internal work by builtins. Instances 1726 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
1670 // must not be leaked to user code. 1727 // transition easy to trap. Moreover, they rarely are smi-only.
1728 {
1671 Handle<JSFunction> array_function = 1729 Handle<JSFunction> array_function =
1672 InstallFunction(builtins, 1730 InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS);
1673 "InternalArray", 1731 if (array_function.is_null()) return false;
1674 JS_ARRAY_TYPE, 1732 native_context()->set_internal_array_function(*array_function);
1675 JSArray::kSize, 1733 }
1676 isolate()->initial_object_prototype(),
1677 Builtins::kInternalArrayCode,
1678 true);
1679 Handle<JSObject> prototype =
1680 factory()->NewJSObject(isolate()->object_function(), TENURED);
1681 SetPrototype(array_function, prototype);
1682 1734
1683 array_function->shared()->set_construct_stub( 1735 {
1684 isolate()->builtins()->builtin(Builtins::kArrayConstructCode)); 1736 Handle<JSFunction> array_function =
1685 array_function->shared()->DontAdaptArguments(); 1737 InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS);
1686 1738 if (array_function.is_null()) return false;
1687 // InternalArrays should not use Smi-Only array optimizations. There are too
1688 // many places in the C++ runtime code (e.g. RegEx) that assume that
1689 // elements in InternalArrays can be set to non-Smi values without going
1690 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
1691 // transition easy to trap. Moreover, they rarely are smi-only.
1692 MaybeObject* maybe_map = array_function->initial_map()->Copy();
1693 Map* new_map;
1694 if (!maybe_map->To(&new_map)) return false;
1695 new_map->set_elements_kind(FAST_HOLEY_ELEMENTS);
1696 array_function->set_initial_map(new_map);
1697
1698 // Make "length" magic on instances.
1699 Handle<Map> initial_map(array_function->initial_map());
1700 Handle<DescriptorArray> array_descriptors(
1701 factory()->NewDescriptorArray(0, 1));
1702 DescriptorArray::WhitenessWitness witness(*array_descriptors);
1703
1704 Handle<Foreign> array_length(factory()->NewForeign(
1705 &Accessors::ArrayLength));
1706 PropertyAttributes attribs = static_cast<PropertyAttributes>(
1707 DONT_ENUM | DONT_DELETE);
1708 initial_map->set_instance_descriptors(*array_descriptors);
1709
1710 { // Add length.
1711 CallbacksDescriptor d(
1712 *factory()->length_symbol(), *array_length, attribs);
1713 array_function->initial_map()->AppendDescriptor(&d, witness);
1714 }
1715
1716 native_context()->set_internal_array_function(*array_function);
1717 } 1739 }
1718 1740
1719 if (FLAG_disable_native_files) { 1741 if (FLAG_disable_native_files) {
1720 PrintF("Warning: Running without installed natives!\n"); 1742 PrintF("Warning: Running without installed natives!\n");
1721 return true; 1743 return true;
1722 } 1744 }
1723 1745
1724 // Install natives. 1746 // Install natives.
1725 for (int i = Natives::GetDebuggerCount(); 1747 for (int i = Natives::GetDebuggerCount();
1726 i < Natives::GetBuiltinsCount(); 1748 i < Natives::GetBuiltinsCount();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 { 1804 {
1783 // RegExpResult initial map. 1805 // RegExpResult initial map.
1784 1806
1785 // Find global.Array.prototype to inherit from. 1807 // Find global.Array.prototype to inherit from.
1786 Handle<JSFunction> array_constructor(native_context()->array_function()); 1808 Handle<JSFunction> array_constructor(native_context()->array_function());
1787 Handle<JSObject> array_prototype( 1809 Handle<JSObject> array_prototype(
1788 JSObject::cast(array_constructor->instance_prototype())); 1810 JSObject::cast(array_constructor->instance_prototype()));
1789 1811
1790 // Add initial map. 1812 // Add initial map.
1791 Handle<Map> initial_map = 1813 Handle<Map> initial_map =
1792 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); 1814 factory()->NewMap(JS_ARRAY_TYPE,
1815 JSRegExpResult::kSize,
1816 FAST_ELEMENTS);
1793 initial_map->set_constructor(*array_constructor); 1817 initial_map->set_constructor(*array_constructor);
1794 1818
1795 // Set prototype on map. 1819 // Set prototype on map.
1796 initial_map->set_non_instance_prototype(false); 1820 initial_map->set_non_instance_prototype(false);
1797 initial_map->set_prototype(*array_prototype); 1821 initial_map->set_prototype(*array_prototype);
1798 1822
1799 // Update map with length accessor from Array and add "index" and "input". 1823 // Update map with length accessor from Array and add "index" and "input".
1800 Handle<DescriptorArray> reresult_descriptors = 1824 Handle<DescriptorArray> reresult_descriptors =
1801 factory()->NewDescriptorArray(0, 3); 1825 factory()->NewDescriptorArray(0, 3);
1802 DescriptorArray::WhitenessWitness witness(*reresult_descriptors); 1826 DescriptorArray::WhitenessWitness witness(*reresult_descriptors);
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 return from + sizeof(NestingCounterType); 2459 return from + sizeof(NestingCounterType);
2436 } 2460 }
2437 2461
2438 2462
2439 // Called when the top-level V8 mutex is destroyed. 2463 // Called when the top-level V8 mutex is destroyed.
2440 void Bootstrapper::FreeThreadResources() { 2464 void Bootstrapper::FreeThreadResources() {
2441 ASSERT(!IsActive()); 2465 ASSERT(!IsActive());
2442 } 2466 }
2443 2467
2444 } } // namespace v8::internal 2468 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/json.js » ('j') | src/messages.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698