| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 #include "debug.h" | 34 #include "debug.h" |
| 35 #include "execution.h" | 35 #include "execution.h" |
| 36 #include "global-handles.h" | 36 #include "global-handles.h" |
| 37 #include "isolate-inl.h" | 37 #include "isolate-inl.h" |
| 38 #include "macro-assembler.h" | 38 #include "macro-assembler.h" |
| 39 #include "natives.h" | 39 #include "natives.h" |
| 40 #include "objects-visiting.h" | 40 #include "objects-visiting.h" |
| 41 #include "platform.h" | 41 #include "platform.h" |
| 42 #include "snapshot.h" | 42 #include "snapshot.h" |
| 43 #include "trig-table.h" | 43 #include "trig-table.h" |
| 44 #include "extensions/free-buffer-extension.h" |
| 44 #include "extensions/externalize-string-extension.h" | 45 #include "extensions/externalize-string-extension.h" |
| 45 #include "extensions/gc-extension.h" | 46 #include "extensions/gc-extension.h" |
| 46 #include "extensions/statistics-extension.h" | 47 #include "extensions/statistics-extension.h" |
| 47 #include "code-stubs.h" | 48 #include "code-stubs.h" |
| 48 | 49 |
| 49 namespace v8 { | 50 namespace v8 { |
| 50 namespace internal { | 51 namespace internal { |
| 51 | 52 |
| 52 | 53 |
| 53 NativesExternalStringResource::NativesExternalStringResource( | 54 NativesExternalStringResource::NativesExternalStringResource( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 return Handle<String>::cast(cached_source); | 94 return Handle<String>::cast(cached_source); |
| 94 } | 95 } |
| 95 | 96 |
| 96 | 97 |
| 97 void Bootstrapper::Initialize(bool create_heap_objects) { | 98 void Bootstrapper::Initialize(bool create_heap_objects) { |
| 98 extensions_cache_.Initialize(isolate_, create_heap_objects); | 99 extensions_cache_.Initialize(isolate_, create_heap_objects); |
| 99 } | 100 } |
| 100 | 101 |
| 101 | 102 |
| 102 void Bootstrapper::InitializeOncePerProcess() { | 103 void Bootstrapper::InitializeOncePerProcess() { |
| 104 #ifdef ADDRESS_SANITIZER |
| 105 FreeBufferExtension::Register(); |
| 106 #endif |
| 103 GCExtension::Register(); | 107 GCExtension::Register(); |
| 104 ExternalizeStringExtension::Register(); | 108 ExternalizeStringExtension::Register(); |
| 105 StatisticsExtension::Register(); | 109 StatisticsExtension::Register(); |
| 106 } | 110 } |
| 107 | 111 |
| 108 | 112 |
| 109 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { | 113 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { |
| 110 char* memory = new char[bytes]; | 114 char* memory = new char[bytes]; |
| 111 if (memory != NULL) { | 115 if (memory != NULL) { |
| 112 if (delete_these_arrays_on_tear_down_ == NULL) { | 116 if (delete_these_arrays_on_tear_down_ == NULL) { |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", | 1572 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", |
| 1569 configure_instance_fun); | 1573 configure_instance_fun); |
| 1570 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); | 1574 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); |
| 1571 INSTALL_NATIVE(JSObject, "functionCache", function_cache); | 1575 INSTALL_NATIVE(JSObject, "functionCache", function_cache); |
| 1572 INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", | 1576 INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", |
| 1573 to_complete_property_descriptor); | 1577 to_complete_property_descriptor); |
| 1574 } | 1578 } |
| 1575 | 1579 |
| 1576 | 1580 |
| 1577 void Genesis::InstallExperimentalNativeFunctions() { | 1581 void Genesis::InstallExperimentalNativeFunctions() { |
| 1582 INSTALL_NATIVE(JSFunction, "RunMicrotasks", run_microtasks); |
| 1578 if (FLAG_harmony_proxies) { | 1583 if (FLAG_harmony_proxies) { |
| 1579 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); | 1584 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
| 1580 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); | 1585 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
| 1581 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); | 1586 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
| 1582 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); | 1587 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
| 1583 } | 1588 } |
| 1584 if (FLAG_harmony_observation) { | 1589 if (FLAG_harmony_observation) { |
| 1585 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); | 1590 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); |
| 1586 INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); | 1591 INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); |
| 1587 INSTALL_NATIVE(JSFunction, "BeginPerformSplice", | 1592 INSTALL_NATIVE(JSFunction, "BeginPerformSplice", |
| 1588 observers_begin_perform_splice); | 1593 observers_begin_perform_splice); |
| 1589 INSTALL_NATIVE(JSFunction, "EndPerformSplice", | 1594 INSTALL_NATIVE(JSFunction, "EndPerformSplice", |
| 1590 observers_end_perform_splice); | 1595 observers_end_perform_splice); |
| 1591 INSTALL_NATIVE(JSFunction, "DeliverChangeRecords", | |
| 1592 observers_deliver_changes); | |
| 1593 } | 1596 } |
| 1594 } | 1597 } |
| 1595 | 1598 |
| 1596 #undef INSTALL_NATIVE | 1599 #undef INSTALL_NATIVE |
| 1597 | 1600 |
| 1598 | 1601 |
| 1599 Handle<JSFunction> Genesis::InstallInternalArray( | 1602 Handle<JSFunction> Genesis::InstallInternalArray( |
| 1600 Handle<JSBuiltinsObject> builtins, | 1603 Handle<JSBuiltinsObject> builtins, |
| 1601 const char* name, | 1604 const char* name, |
| 1602 ElementsKind elements_kind) { | 1605 ElementsKind elements_kind) { |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2013 } | 2016 } |
| 2014 | 2017 |
| 2015 #ifdef VERIFY_HEAP | 2018 #ifdef VERIFY_HEAP |
| 2016 builtins->Verify(); | 2019 builtins->Verify(); |
| 2017 #endif | 2020 #endif |
| 2018 | 2021 |
| 2019 return true; | 2022 return true; |
| 2020 } | 2023 } |
| 2021 | 2024 |
| 2022 | 2025 |
| 2026 #define INSTALL_EXPERIMENTAL_NATIVE(i, flag, file) \ |
| 2027 if (FLAG_harmony_##flag && \ |
| 2028 strcmp(ExperimentalNatives::GetScriptName(i).start(), \ |
| 2029 "native " file) == 0) { \ |
| 2030 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ |
| 2031 } |
| 2032 |
| 2033 |
| 2023 bool Genesis::InstallExperimentalNatives() { | 2034 bool Genesis::InstallExperimentalNatives() { |
| 2024 for (int i = ExperimentalNatives::GetDebuggerCount(); | 2035 for (int i = ExperimentalNatives::GetDebuggerCount(); |
| 2025 i < ExperimentalNatives::GetBuiltinsCount(); | 2036 i < ExperimentalNatives::GetBuiltinsCount(); |
| 2026 i++) { | 2037 i++) { |
| 2027 if (FLAG_harmony_symbols && | 2038 INSTALL_EXPERIMENTAL_NATIVE(i, symbols, "symbol.js") |
| 2028 strcmp(ExperimentalNatives::GetScriptName(i).start(), | 2039 INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js") |
| 2029 "native symbol.js") == 0) { | 2040 INSTALL_EXPERIMENTAL_NATIVE(i, collections, "collection.js") |
| 2030 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | 2041 INSTALL_EXPERIMENTAL_NATIVE(i, observation, "object-observe.js") |
| 2031 } | 2042 INSTALL_EXPERIMENTAL_NATIVE(i, promises, "promise.js") |
| 2032 if (FLAG_harmony_proxies && | 2043 INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js") |
| 2033 strcmp(ExperimentalNatives::GetScriptName(i).start(), | 2044 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js") |
| 2034 "native proxy.js") == 0) { | 2045 INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") |
| 2035 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | 2046 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") |
| 2036 } | 2047 INSTALL_EXPERIMENTAL_NATIVE(i, maths, "harmony-math.js") |
| 2037 if (FLAG_harmony_collections && | |
| 2038 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2039 "native collection.js") == 0) { | |
| 2040 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2041 } | |
| 2042 if (FLAG_harmony_observation && | |
| 2043 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2044 "native object-observe.js") == 0) { | |
| 2045 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2046 } | |
| 2047 if (FLAG_harmony_generators && | |
| 2048 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2049 "native generator.js") == 0) { | |
| 2050 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2051 } | |
| 2052 if (FLAG_harmony_iteration && | |
| 2053 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2054 "native array-iterator.js") == 0) { | |
| 2055 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2056 } | |
| 2057 if (FLAG_harmony_strings && | |
| 2058 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2059 "native harmony-string.js") == 0) { | |
| 2060 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2061 } | |
| 2062 if (FLAG_harmony_arrays && | |
| 2063 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2064 "native harmony-array.js") == 0) { | |
| 2065 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2066 } | |
| 2067 if (FLAG_harmony_maths && | |
| 2068 strcmp(ExperimentalNatives::GetScriptName(i).start(), | |
| 2069 "native harmony-math.js") == 0) { | |
| 2070 if (!CompileExperimentalBuiltin(isolate(), i)) return false; | |
| 2071 } | |
| 2072 } | 2048 } |
| 2073 | 2049 |
| 2074 InstallExperimentalNativeFunctions(); | 2050 InstallExperimentalNativeFunctions(); |
| 2075 | 2051 |
| 2076 return true; | 2052 return true; |
| 2077 } | 2053 } |
| 2078 | 2054 |
| 2079 | 2055 |
| 2080 static Handle<JSObject> ResolveBuiltinIdHolder( | 2056 static Handle<JSObject> ResolveBuiltinIdHolder( |
| 2081 Handle<Context> native_context, | 2057 Handle<Context> native_context, |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 Isolate* isolate = native_context->GetIsolate(); | 2247 Isolate* isolate = native_context->GetIsolate(); |
| 2272 ExtensionStates extension_states; // All extensions have state UNVISITED. | 2248 ExtensionStates extension_states; // All extensions have state UNVISITED. |
| 2273 // Install auto extensions. | 2249 // Install auto extensions. |
| 2274 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); | 2250 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| 2275 while (current != NULL) { | 2251 while (current != NULL) { |
| 2276 if (current->extension()->auto_enable()) | 2252 if (current->extension()->auto_enable()) |
| 2277 InstallExtension(isolate, current, &extension_states); | 2253 InstallExtension(isolate, current, &extension_states); |
| 2278 current = current->next(); | 2254 current = current->next(); |
| 2279 } | 2255 } |
| 2280 | 2256 |
| 2257 #ifdef ADDRESS_SANITIZER |
| 2258 if (FLAG_expose_free_buffer) { |
| 2259 InstallExtension(isolate, "v8/free-buffer", &extension_states); |
| 2260 } |
| 2261 #endif |
| 2281 if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states); | 2262 if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states); |
| 2282 if (FLAG_expose_externalize_string) { | 2263 if (FLAG_expose_externalize_string) { |
| 2283 InstallExtension(isolate, "v8/externalize", &extension_states); | 2264 InstallExtension(isolate, "v8/externalize", &extension_states); |
| 2284 } | 2265 } |
| 2285 if (FLAG_track_gc_object_stats) { | 2266 if (FLAG_track_gc_object_stats) { |
| 2286 InstallExtension(isolate, "v8/statistics", &extension_states); | 2267 InstallExtension(isolate, "v8/statistics", &extension_states); |
| 2287 } | 2268 } |
| 2288 | 2269 |
| 2289 if (extensions == NULL) return true; | 2270 if (extensions == NULL) return true; |
| 2290 // Install required extensions | 2271 // Install required extensions |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2641 // Initially seed the per-context random number generator using the | 2622 // Initially seed the per-context random number generator using the |
| 2642 // per-isolate random number generator. | 2623 // per-isolate random number generator. |
| 2643 const int num_elems = 2; | 2624 const int num_elems = 2; |
| 2644 const int num_bytes = num_elems * sizeof(uint32_t); | 2625 const int num_bytes = num_elems * sizeof(uint32_t); |
| 2645 uint32_t* state = reinterpret_cast<uint32_t*>(malloc(num_bytes)); | 2626 uint32_t* state = reinterpret_cast<uint32_t*>(malloc(num_bytes)); |
| 2646 | 2627 |
| 2647 do { | 2628 do { |
| 2648 isolate->random_number_generator()->NextBytes(state, num_bytes); | 2629 isolate->random_number_generator()->NextBytes(state, num_bytes); |
| 2649 } while (state[0] == 0 || state[1] == 0); | 2630 } while (state[0] == 0 || state[1] == 0); |
| 2650 | 2631 |
| 2651 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state, num_bytes); | 2632 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New( |
| 2633 reinterpret_cast<v8::Isolate*>(isolate), state, num_bytes); |
| 2652 Utils::OpenHandle(*buffer)->set_should_be_freed(true); | 2634 Utils::OpenHandle(*buffer)->set_should_be_freed(true); |
| 2653 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); | 2635 v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0, num_elems); |
| 2654 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); | 2636 Handle<JSBuiltinsObject> builtins(native_context()->builtins()); |
| 2655 ForceSetProperty(builtins, | 2637 ForceSetProperty(builtins, |
| 2656 factory()->InternalizeOneByteString( | 2638 factory()->InternalizeOneByteString( |
| 2657 STATIC_ASCII_VECTOR("rngstate")), | 2639 STATIC_ASCII_VECTOR("rngstate")), |
| 2658 Utils::OpenHandle(*ta), | 2640 Utils::OpenHandle(*ta), |
| 2659 NONE); | 2641 NONE); |
| 2660 | 2642 |
| 2661 // Initialize trigonometric lookup tables and constants. | 2643 // Initialize trigonometric lookup tables and constants. |
| 2662 const int table_num_bytes = TrigonometricLookupTable::table_num_bytes(); | 2644 const int table_num_bytes = TrigonometricLookupTable::table_num_bytes(); |
| 2663 v8::Local<v8::ArrayBuffer> sin_buffer = v8::ArrayBuffer::New( | 2645 v8::Local<v8::ArrayBuffer> sin_buffer = v8::ArrayBuffer::New( |
| 2646 reinterpret_cast<v8::Isolate*>(isolate), |
| 2664 TrigonometricLookupTable::sin_table(), table_num_bytes); | 2647 TrigonometricLookupTable::sin_table(), table_num_bytes); |
| 2665 v8::Local<v8::ArrayBuffer> cos_buffer = v8::ArrayBuffer::New( | 2648 v8::Local<v8::ArrayBuffer> cos_buffer = v8::ArrayBuffer::New( |
| 2649 reinterpret_cast<v8::Isolate*>(isolate), |
| 2666 TrigonometricLookupTable::cos_x_interval_table(), table_num_bytes); | 2650 TrigonometricLookupTable::cos_x_interval_table(), table_num_bytes); |
| 2667 v8::Local<v8::Float64Array> sin_table = v8::Float64Array::New( | 2651 v8::Local<v8::Float64Array> sin_table = v8::Float64Array::New( |
| 2668 sin_buffer, 0, TrigonometricLookupTable::table_size()); | 2652 sin_buffer, 0, TrigonometricLookupTable::table_size()); |
| 2669 v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New( | 2653 v8::Local<v8::Float64Array> cos_table = v8::Float64Array::New( |
| 2670 cos_buffer, 0, TrigonometricLookupTable::table_size()); | 2654 cos_buffer, 0, TrigonometricLookupTable::table_size()); |
| 2671 | 2655 |
| 2672 ForceSetProperty(builtins, | 2656 ForceSetProperty(builtins, |
| 2673 factory()->InternalizeOneByteString( | 2657 factory()->InternalizeOneByteString( |
| 2674 STATIC_ASCII_VECTOR("kSinTable")), | 2658 STATIC_ASCII_VECTOR("kSinTable")), |
| 2675 Utils::OpenHandle(*sin_table), | 2659 Utils::OpenHandle(*sin_table), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2719 return from + sizeof(NestingCounterType); | 2703 return from + sizeof(NestingCounterType); |
| 2720 } | 2704 } |
| 2721 | 2705 |
| 2722 | 2706 |
| 2723 // Called when the top-level V8 mutex is destroyed. | 2707 // Called when the top-level V8 mutex is destroyed. |
| 2724 void Bootstrapper::FreeThreadResources() { | 2708 void Bootstrapper::FreeThreadResources() { |
| 2725 ASSERT(!IsActive()); | 2709 ASSERT(!IsActive()); |
| 2726 } | 2710 } |
| 2727 | 2711 |
| 2728 } } // namespace v8::internal | 2712 } } // namespace v8::internal |
| OLD | NEW |