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/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/extensions/externalize-string-extension.h" | 9 #include "src/extensions/externalize-string-extension.h" |
10 #include "src/extensions/free-buffer-extension.h" | 10 #include "src/extensions/free-buffer-extension.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 194 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
195 Handle<GlobalObject>* global_object_out); | 195 Handle<GlobalObject>* global_object_out); |
196 // Hooks the given global proxy into the context. If the context was created | 196 // Hooks the given global proxy into the context. If the context was created |
197 // by deserialization then this will unhook the global proxy that was | 197 // by deserialization then this will unhook the global proxy that was |
198 // deserialized, leaving the GC to pick it up. | 198 // deserialized, leaving the GC to pick it up. |
199 void HookUpGlobalProxy(Handle<GlobalObject> global_object, | 199 void HookUpGlobalProxy(Handle<GlobalObject> global_object, |
200 Handle<JSGlobalProxy> global_proxy); | 200 Handle<JSGlobalProxy> global_proxy); |
201 // Similarly, we want to use the global that has been created by the templates | 201 // Similarly, we want to use the global that has been created by the templates |
202 // passed through the API. The global from the snapshot is detached from the | 202 // passed through the API. The global from the snapshot is detached from the |
203 // other objects in the snapshot. | 203 // other objects in the snapshot. |
204 void HookUpGlobalObject(Handle<GlobalObject> global_object); | 204 void HookUpGlobalObject(Handle<GlobalObject> global_object, |
205 Handle<FixedArray> outdated_contexts); | |
205 // New context initialization. Used for creating a context from scratch. | 206 // New context initialization. Used for creating a context from scratch. |
206 void InitializeGlobal(Handle<GlobalObject> global_object, | 207 void InitializeGlobal(Handle<GlobalObject> global_object, |
207 Handle<JSFunction> empty_function); | 208 Handle<JSFunction> empty_function); |
208 void InitializeExperimentalGlobal(); | 209 void InitializeExperimentalGlobal(); |
209 // 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. |
210 // Used for creating a context from scratch. | 211 // Used for creating a context from scratch. |
211 void InstallNativeFunctions(); | 212 void InstallNativeFunctions(); |
212 void InstallExperimentalNativeFunctions(); | 213 void InstallExperimentalNativeFunctions(); |
213 | 214 |
214 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ | 215 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> global_object, | 865 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> global_object, |
865 Handle<JSGlobalProxy> global_proxy) { | 866 Handle<JSGlobalProxy> global_proxy) { |
866 // Set the native context for the global object. | 867 // Set the native context for the global object. |
867 global_object->set_native_context(*native_context()); | 868 global_object->set_native_context(*native_context()); |
868 global_object->set_global_proxy(*global_proxy); | 869 global_object->set_global_proxy(*global_proxy); |
869 global_proxy->set_native_context(*native_context()); | 870 global_proxy->set_native_context(*native_context()); |
870 native_context()->set_global_proxy(*global_proxy); | 871 native_context()->set_global_proxy(*global_proxy); |
871 } | 872 } |
872 | 873 |
873 | 874 |
874 void Genesis::HookUpGlobalObject(Handle<GlobalObject> global_object) { | 875 void Genesis::HookUpGlobalObject(Handle<GlobalObject> global_object, |
876 Handle<FixedArray> outdated_contexts) { | |
875 Handle<GlobalObject> global_object_from_snapshot( | 877 Handle<GlobalObject> global_object_from_snapshot( |
876 GlobalObject::cast(native_context()->extension())); | 878 GlobalObject::cast(native_context()->extension())); |
877 Handle<JSBuiltinsObject> builtins_global(native_context()->builtins()); | 879 Handle<JSBuiltinsObject> builtins_global(native_context()->builtins()); |
878 native_context()->set_extension(*global_object); | 880 native_context()->set_extension(*global_object); |
879 native_context()->set_global_object(*global_object); | |
880 native_context()->set_security_token(*global_object); | 881 native_context()->set_security_token(*global_object); |
882 | |
883 // Replace outdated global objects in deserialized contexts. | |
884 for (int i = 0; i < outdated_contexts->length(); i++) { | |
jochen (gone - plz use gerrit)
2015/01/12 19:57:10
nit. ++i
Yang
2015/01/13 08:20:10
Done.
| |
885 Context* context = Context::cast(outdated_contexts->get(i)); | |
886 DCHECK_EQ(context->global_object(), *global_object_from_snapshot); | |
887 context->set_global_object(*global_object); | |
888 } | |
889 | |
881 static const PropertyAttributes attributes = | 890 static const PropertyAttributes attributes = |
882 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 891 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
883 Runtime::DefineObjectProperty(builtins_global, factory()->global_string(), | 892 Runtime::DefineObjectProperty(builtins_global, factory()->global_string(), |
884 global_object, attributes).Assert(); | 893 global_object, attributes).Assert(); |
885 // Set up the reference from the global object to the builtins object. | 894 // Set up the reference from the global object to the builtins object. |
886 JSGlobalObject::cast(*global_object)->set_builtins(*builtins_global); | 895 JSGlobalObject::cast(*global_object)->set_builtins(*builtins_global); |
887 TransferNamedProperties(global_object_from_snapshot, global_object); | 896 TransferNamedProperties(global_object_from_snapshot, global_object); |
888 TransferIndexedProperties(global_object_from_snapshot, global_object); | 897 TransferIndexedProperties(global_object_from_snapshot, global_object); |
889 } | 898 } |
890 | 899 |
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2717 SaveContext saved_context(isolate); | 2726 SaveContext saved_context(isolate); |
2718 | 2727 |
2719 // During genesis, the boilerplate for stack overflow won't work until the | 2728 // During genesis, the boilerplate for stack overflow won't work until the |
2720 // environment has been at least partially initialized. Add a stack check | 2729 // environment has been at least partially initialized. Add a stack check |
2721 // before entering JS code to catch overflow early. | 2730 // before entering JS code to catch overflow early. |
2722 StackLimitCheck check(isolate); | 2731 StackLimitCheck check(isolate); |
2723 if (check.HasOverflowed()) return; | 2732 if (check.HasOverflowed()) return; |
2724 | 2733 |
2725 // We can only de-serialize a context if the isolate was initialized from | 2734 // We can only de-serialize a context if the isolate was initialized from |
2726 // a snapshot. Otherwise we have to build the context from scratch. | 2735 // a snapshot. Otherwise we have to build the context from scratch. |
2727 if (isolate->initialized_from_snapshot()) { | 2736 Handle<FixedArray> outdated_contexts; |
2728 native_context_ = Snapshot::NewContextFromSnapshot(isolate); | 2737 if (!isolate->initialized_from_snapshot() || |
2729 } else { | 2738 !Snapshot::NewContextFromSnapshot(isolate, &outdated_contexts) |
2739 .ToHandle(&native_context_)) { | |
2730 native_context_ = Handle<Context>(); | 2740 native_context_ = Handle<Context>(); |
2731 } | 2741 } |
2732 | 2742 |
2733 if (!native_context().is_null()) { | 2743 if (!native_context().is_null()) { |
2734 AddToWeakNativeContextList(*native_context()); | 2744 AddToWeakNativeContextList(*native_context()); |
2735 isolate->set_context(*native_context()); | 2745 isolate->set_context(*native_context()); |
2736 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 2746 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
2737 #if TRACE_MAPS | 2747 #if TRACE_MAPS |
2738 if (FLAG_trace_maps) { | 2748 if (FLAG_trace_maps) { |
2739 Handle<JSFunction> object_fun = isolate->object_function(); | 2749 Handle<JSFunction> object_fun = isolate->object_function(); |
2740 PrintF("[TraceMap: InitialMap map= %p SFI= %d_Object ]\n", | 2750 PrintF("[TraceMap: InitialMap map= %p SFI= %d_Object ]\n", |
2741 reinterpret_cast<void*>(object_fun->initial_map()), | 2751 reinterpret_cast<void*>(object_fun->initial_map()), |
2742 object_fun->shared()->unique_id()); | 2752 object_fun->shared()->unique_id()); |
2743 Map::TraceAllTransitions(object_fun->initial_map()); | 2753 Map::TraceAllTransitions(object_fun->initial_map()); |
2744 } | 2754 } |
2745 #endif | 2755 #endif |
2746 Handle<GlobalObject> global_object; | 2756 Handle<GlobalObject> global_object; |
2747 Handle<JSGlobalProxy> global_proxy = CreateNewGlobals( | 2757 Handle<JSGlobalProxy> global_proxy = CreateNewGlobals( |
2748 global_proxy_template, maybe_global_proxy, &global_object); | 2758 global_proxy_template, maybe_global_proxy, &global_object); |
2749 | 2759 |
2750 HookUpGlobalProxy(global_object, global_proxy); | 2760 HookUpGlobalProxy(global_object, global_proxy); |
2751 HookUpGlobalObject(global_object); | 2761 HookUpGlobalObject(global_object, outdated_contexts); |
2752 native_context()->builtins()->set_global_proxy( | 2762 native_context()->builtins()->set_global_proxy( |
2753 native_context()->global_proxy()); | 2763 native_context()->global_proxy()); |
2754 | 2764 |
2755 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 2765 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
2756 } else { | 2766 } else { |
2757 // We get here if there was no context snapshot. | 2767 // We get here if there was no context snapshot. |
2758 CreateRoots(); | 2768 CreateRoots(); |
2759 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 2769 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
2760 CreateStrictModeFunctionMaps(empty_function); | 2770 CreateStrictModeFunctionMaps(empty_function); |
2761 Handle<GlobalObject> global_object; | 2771 Handle<GlobalObject> global_object; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2841 return from + sizeof(NestingCounterType); | 2851 return from + sizeof(NestingCounterType); |
2842 } | 2852 } |
2843 | 2853 |
2844 | 2854 |
2845 // Called when the top-level V8 mutex is destroyed. | 2855 // Called when the top-level V8 mutex is destroyed. |
2846 void Bootstrapper::FreeThreadResources() { | 2856 void Bootstrapper::FreeThreadResources() { |
2847 DCHECK(!IsActive()); | 2857 DCHECK(!IsActive()); |
2848 } | 2858 } |
2849 | 2859 |
2850 } } // namespace v8::internal | 2860 } } // namespace v8::internal |
OLD | NEW |