OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void HookUpGlobalObject(Handle<GlobalObject> global_object, | 204 void HookUpGlobalObject(Handle<GlobalObject> global_object, |
205 Handle<FixedArray> outdated_contexts); | 205 Handle<FixedArray> outdated_contexts); |
206 // New context initialization. Used for creating a context from scratch. | 206 // New context initialization. Used for creating a context from scratch. |
207 void InitializeGlobal(Handle<GlobalObject> global_object, | 207 void InitializeGlobal(Handle<GlobalObject> global_object, |
208 Handle<JSFunction> empty_function); | 208 Handle<JSFunction> empty_function); |
209 void InitializeExperimentalGlobal(); | 209 void InitializeExperimentalGlobal(); |
210 // Installs the contents of the native .js files on the global objects. | 210 // Installs the contents of the native .js files on the global objects. |
211 // Used for creating a context from scratch. | 211 // Used for creating a context from scratch. |
212 void InstallNativeFunctions(); | 212 void InstallNativeFunctions(); |
213 void InstallExperimentalNativeFunctions(); | 213 void InstallExperimentalNativeFunctions(); |
| 214 // Typed arrays are not serializable and have to initialized afterwards. |
| 215 void InitializeBuiltinTypedArrays(); |
214 | 216 |
215 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ | 217 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ |
216 void InstallNativeFunctions_##id(); \ | 218 void InstallNativeFunctions_##id(); \ |
217 void InitializeGlobal_##id(); | 219 void InitializeGlobal_##id(); |
218 | 220 |
219 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) | 221 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) |
220 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) | 222 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) |
221 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) | 223 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) |
222 #undef DECLARE_FEATURE_INITIALIZATION | 224 #undef DECLARE_FEATURE_INITIALIZATION |
223 | 225 |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 } | 1571 } |
1570 | 1572 |
1571 #define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id(); | 1573 #define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id(); |
1572 HARMONY_INPROGRESS(INSTALL_NATIVE_FUNCTIONS_FOR) | 1574 HARMONY_INPROGRESS(INSTALL_NATIVE_FUNCTIONS_FOR) |
1573 HARMONY_STAGED(INSTALL_NATIVE_FUNCTIONS_FOR) | 1575 HARMONY_STAGED(INSTALL_NATIVE_FUNCTIONS_FOR) |
1574 HARMONY_SHIPPING(INSTALL_NATIVE_FUNCTIONS_FOR) | 1576 HARMONY_SHIPPING(INSTALL_NATIVE_FUNCTIONS_FOR) |
1575 #undef INSTALL_NATIVE_FUNCTIONS_FOR | 1577 #undef INSTALL_NATIVE_FUNCTIONS_FOR |
1576 } | 1578 } |
1577 | 1579 |
1578 | 1580 |
| 1581 template <typename Data> |
| 1582 Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins, |
| 1583 ExternalArrayType type, Data* data, |
| 1584 size_t num_elements, const char* name) { |
| 1585 size_t byte_length = num_elements * sizeof(*data); |
| 1586 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 1587 bool should_be_freed = false; |
| 1588 if (data == NULL) { |
| 1589 data = reinterpret_cast<Data*>(malloc(byte_length)); |
| 1590 should_be_freed = true; |
| 1591 } |
| 1592 Runtime::SetupArrayBuffer(isolate, buffer, true, data, byte_length); |
| 1593 buffer->set_should_be_freed(should_be_freed); |
| 1594 |
| 1595 Handle<JSTypedArray> typed_array = |
| 1596 isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements); |
| 1597 Handle<String> name_string = isolate->factory()->InternalizeUtf8String(name); |
| 1598 // Reset property cell type before (re)initializing. |
| 1599 JSBuiltinsObject::InvalidatePropertyCell(builtins, name_string); |
| 1600 JSObject::SetOwnPropertyIgnoreAttributes(builtins, name_string, typed_array, |
| 1601 DONT_DELETE).Assert(); |
| 1602 return data; |
| 1603 } |
| 1604 |
| 1605 |
| 1606 void Genesis::InitializeBuiltinTypedArrays() { |
| 1607 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); |
| 1608 { // Initially seed the per-context random number generator using the |
| 1609 // per-isolate random number generator. |
| 1610 const size_t num_elements = 2; |
| 1611 const size_t num_bytes = num_elements * sizeof(uint32_t); |
| 1612 uint32_t* state = SetBuiltinTypedArray<uint32_t>(isolate(), builtins, |
| 1613 kExternalUint32Array, NULL, |
| 1614 num_elements, "rngstate"); |
| 1615 do { |
| 1616 isolate()->random_number_generator()->NextBytes(state, num_bytes); |
| 1617 } while (state[0] == 0 || state[1] == 0); |
| 1618 } |
| 1619 |
| 1620 { // Initialize trigonometric lookup tables and constants. |
| 1621 const size_t num_elements = arraysize(fdlibm::MathConstants::constants); |
| 1622 double* data = const_cast<double*>(fdlibm::MathConstants::constants); |
| 1623 SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array, |
| 1624 data, num_elements, "kMath"); |
| 1625 } |
| 1626 |
| 1627 { // Initialize a result array for rempio2 calculation |
| 1628 const size_t num_elements = 2; |
| 1629 SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array, |
| 1630 NULL, num_elements, "rempio2result"); |
| 1631 } |
| 1632 } |
| 1633 |
| 1634 |
1579 #define EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(id) \ | 1635 #define EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(id) \ |
1580 void Genesis::InstallNativeFunctions_##id() {} | 1636 void Genesis::InstallNativeFunctions_##id() {} |
1581 | 1637 |
1582 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_scoping) | 1638 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_scoping) |
1583 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_modules) | 1639 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_modules) |
1584 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_strings) | 1640 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_strings) |
1585 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrays) | 1641 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrays) |
1586 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_array_includes) | 1642 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_array_includes) |
1587 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_classes) | 1643 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_classes) |
1588 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_object_literals) | 1644 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_object_literals) |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2802 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 2858 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
2803 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2859 isolate->counters()->contexts_created_from_scratch()->Increment(); |
2804 } | 2860 } |
2805 | 2861 |
2806 // Install experimental natives. | 2862 // Install experimental natives. |
2807 if (!InstallExperimentalNatives()) return; | 2863 if (!InstallExperimentalNatives()) return; |
2808 InitializeExperimentalGlobal(); | 2864 InitializeExperimentalGlobal(); |
2809 | 2865 |
2810 // The serializer cannot serialize typed arrays. Reset those typed arrays | 2866 // The serializer cannot serialize typed arrays. Reset those typed arrays |
2811 // for each new context. | 2867 // for each new context. |
2812 { | 2868 InitializeBuiltinTypedArrays(); |
2813 // Initially seed the per-context random number generator using the | |
2814 // per-isolate random number generator. | |
2815 const int num_elems = 2; | |
2816 const int num_bytes = num_elems * sizeof(uint32_t); | |
2817 uint32_t* state = reinterpret_cast<uint32_t*>(malloc(num_bytes)); | |
2818 | |
2819 do { | |
2820 isolate->random_number_generator()->NextBytes(state, num_bytes); | |
2821 } while (state[0] == 0 || state[1] == 0); | |
2822 | |
2823 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New( | |
2824 reinterpret_cast<v8::Isolate*>(isolate), state, num_bytes); | |
2825 Utils::OpenHandle(*buffer)->set_should_be_freed(true); | |
2826 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); | |
2827 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); | |
2828 | |
2829 Handle<String> rngstate = | |
2830 factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("rngstate")); | |
2831 // Reset property cell type before (re)initializing. | |
2832 JSBuiltinsObject::InvalidatePropertyCell(builtins, rngstate); | |
2833 JSObject::SetOwnPropertyIgnoreAttributes( | |
2834 builtins, rngstate, Utils::OpenHandle(*ta), DONT_DELETE).Assert(); | |
2835 | |
2836 // Initialize trigonometric lookup tables and constants. | |
2837 const int constants_size = arraysize(fdlibm::MathConstants::constants); | |
2838 const int table_num_bytes = constants_size * kDoubleSize; | |
2839 v8::Local<v8::ArrayBuffer> trig_buffer = v8::ArrayBuffer::New( | |
2840 reinterpret_cast<v8::Isolate*>(isolate), | |
2841 const_cast<double*>(fdlibm::MathConstants::constants), table_num_bytes); | |
2842 v8::Local<v8::Float64Array> trig_table = | |
2843 v8::Float64Array::New(trig_buffer, 0, constants_size); | |
2844 | |
2845 Handle<String> kmath = | |
2846 factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("kMath")); | |
2847 // Reset property cell type before (re)initializing. | |
2848 JSBuiltinsObject::InvalidatePropertyCell(builtins, kmath); | |
2849 JSObject::SetOwnPropertyIgnoreAttributes( | |
2850 builtins, kmath, Utils::OpenHandle(*trig_table), DONT_DELETE).Assert(); | |
2851 } | |
2852 | 2869 |
2853 result_ = native_context(); | 2870 result_ = native_context(); |
2854 } | 2871 } |
2855 | 2872 |
2856 | 2873 |
2857 // Support for thread preemption. | 2874 // Support for thread preemption. |
2858 | 2875 |
2859 // Reserve space for statics needing saving and restoring. | 2876 // Reserve space for statics needing saving and restoring. |
2860 int Bootstrapper::ArchiveSpacePerThread() { | 2877 int Bootstrapper::ArchiveSpacePerThread() { |
2861 return sizeof(NestingCounterType); | 2878 return sizeof(NestingCounterType); |
(...skipping 14 matching lines...) Expand all Loading... |
2876 return from + sizeof(NestingCounterType); | 2893 return from + sizeof(NestingCounterType); |
2877 } | 2894 } |
2878 | 2895 |
2879 | 2896 |
2880 // Called when the top-level V8 mutex is destroyed. | 2897 // Called when the top-level V8 mutex is destroyed. |
2881 void Bootstrapper::FreeThreadResources() { | 2898 void Bootstrapper::FreeThreadResources() { |
2882 DCHECK(!IsActive()); | 2899 DCHECK(!IsActive()); |
2883 } | 2900 } |
2884 | 2901 |
2885 } } // namespace v8::internal | 2902 } } // namespace v8::internal |
OLD | NEW |