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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); | 131 ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); |
132 | 132 |
133 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 133 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 class Genesis BASE_EMBEDDED { | 137 class Genesis BASE_EMBEDDED { |
138 public: | 138 public: |
139 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 139 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
140 v8::Local<v8::ObjectTemplate> global_proxy_template, | 140 v8::Local<v8::ObjectTemplate> global_proxy_template, |
141 v8::ExtensionConfiguration* extensions, | 141 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, |
142 GlobalContextType context_type); | 142 GlobalContextType context_type); |
143 ~Genesis() { } | 143 ~Genesis() { } |
144 | 144 |
145 Isolate* isolate() const { return isolate_; } | 145 Isolate* isolate() const { return isolate_; } |
146 Factory* factory() const { return isolate_->factory(); } | 146 Factory* factory() const { return isolate_->factory(); } |
147 Heap* heap() const { return isolate_->heap(); } | 147 Heap* heap() const { return isolate_->heap(); } |
148 | 148 |
149 Handle<Context> result() { return result_; } | 149 Handle<Context> result() { return result_; } |
150 | 150 |
151 private: | 151 private: |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 317 |
318 | 318 |
319 void Bootstrapper::Iterate(ObjectVisitor* v) { | 319 void Bootstrapper::Iterate(ObjectVisitor* v) { |
320 extensions_cache_.Iterate(v); | 320 extensions_cache_.Iterate(v); |
321 v->Synchronize(VisitorSynchronization::kExtensions); | 321 v->Synchronize(VisitorSynchronization::kExtensions); |
322 } | 322 } |
323 | 323 |
324 Handle<Context> Bootstrapper::CreateEnvironment( | 324 Handle<Context> Bootstrapper::CreateEnvironment( |
325 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 325 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
326 v8::Local<v8::ObjectTemplate> global_proxy_template, | 326 v8::Local<v8::ObjectTemplate> global_proxy_template, |
327 v8::ExtensionConfiguration* extensions, GlobalContextType context_type) { | 327 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, |
| 328 GlobalContextType context_type) { |
328 HandleScope scope(isolate_); | 329 HandleScope scope(isolate_); |
329 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, | 330 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, |
330 extensions, context_type); | 331 extensions, context_snapshot_index, context_type); |
331 Handle<Context> env = genesis.result(); | 332 Handle<Context> env = genesis.result(); |
332 if (env.is_null() || | 333 if (env.is_null() || |
333 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { | 334 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { |
334 return Handle<Context>(); | 335 return Handle<Context>(); |
335 } | 336 } |
336 return scope.CloseAndEscape(env); | 337 return scope.CloseAndEscape(env); |
337 } | 338 } |
338 | 339 |
339 | 340 |
340 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | 341 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
(...skipping 3448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3789 | 3790 |
3790 private: | 3791 private: |
3791 bool flag_; | 3792 bool flag_; |
3792 bool enabled_; | 3793 bool enabled_; |
3793 }; | 3794 }; |
3794 | 3795 |
3795 Genesis::Genesis(Isolate* isolate, | 3796 Genesis::Genesis(Isolate* isolate, |
3796 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 3797 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
3797 v8::Local<v8::ObjectTemplate> global_proxy_template, | 3798 v8::Local<v8::ObjectTemplate> global_proxy_template, |
3798 v8::ExtensionConfiguration* extensions, | 3799 v8::ExtensionConfiguration* extensions, |
3799 GlobalContextType context_type) | 3800 size_t context_snapshot_index, GlobalContextType context_type) |
3800 : isolate_(isolate), active_(isolate->bootstrapper()) { | 3801 : isolate_(isolate), active_(isolate->bootstrapper()) { |
3801 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | 3802 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); |
3802 result_ = Handle<Context>::null(); | 3803 result_ = Handle<Context>::null(); |
3803 // Before creating the roots we must save the context and restore it | 3804 // Before creating the roots we must save the context and restore it |
3804 // on all function exits. | 3805 // on all function exits. |
3805 SaveContext saved_context(isolate); | 3806 SaveContext saved_context(isolate); |
3806 | 3807 |
3807 // During genesis, the boilerplate for stack overflow won't work until the | 3808 // During genesis, the boilerplate for stack overflow won't work until the |
3808 // environment has been at least partially initialized. Add a stack check | 3809 // environment has been at least partially initialized. Add a stack check |
3809 // before entering JS code to catch overflow early. | 3810 // before entering JS code to catch overflow early. |
3810 StackLimitCheck check(isolate); | 3811 StackLimitCheck check(isolate); |
3811 if (check.HasOverflowed()) { | 3812 if (check.HasOverflowed()) { |
3812 isolate->StackOverflow(); | 3813 isolate->StackOverflow(); |
3813 return; | 3814 return; |
3814 } | 3815 } |
3815 | 3816 |
3816 // The deserializer needs to hook up references to the global proxy. | 3817 // The deserializer needs to hook up references to the global proxy. |
3817 // Create an uninitialized global proxy now if we don't have one | 3818 // Create an uninitialized global proxy now if we don't have one |
3818 // and initialize it later in CreateNewGlobals. | 3819 // and initialize it later in CreateNewGlobals. |
3819 Handle<JSGlobalProxy> global_proxy; | 3820 Handle<JSGlobalProxy> global_proxy; |
3820 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 3821 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
3821 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); | 3822 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); |
3822 } | 3823 } |
3823 | 3824 |
3824 // We can only de-serialize a context if the isolate was initialized from | 3825 // We can only de-serialize a context if the isolate was initialized from |
3825 // a snapshot. Otherwise we have to build the context from scratch. | 3826 // a snapshot. Otherwise we have to build the context from scratch. |
3826 // Also create a context from scratch to expose natives, if required by flag. | 3827 // Also create a context from scratch to expose natives, if required by flag. |
3827 if (!isolate->initialized_from_snapshot() || | 3828 if (!isolate->initialized_from_snapshot() || |
3828 !Snapshot::NewContextFromSnapshot(isolate, global_proxy) | 3829 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, |
| 3830 context_snapshot_index) |
3829 .ToHandle(&native_context_)) { | 3831 .ToHandle(&native_context_)) { |
3830 native_context_ = Handle<Context>(); | 3832 native_context_ = Handle<Context>(); |
3831 } | 3833 } |
3832 | 3834 |
3833 if (!native_context().is_null()) { | 3835 if (!native_context().is_null()) { |
3834 AddToWeakNativeContextList(*native_context()); | 3836 AddToWeakNativeContextList(*native_context()); |
3835 isolate->set_context(*native_context()); | 3837 isolate->set_context(*native_context()); |
3836 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 3838 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
3837 #if TRACE_MAPS | 3839 #if TRACE_MAPS |
3838 if (FLAG_trace_maps) { | 3840 if (FLAG_trace_maps) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3932 } | 3934 } |
3933 | 3935 |
3934 | 3936 |
3935 // Called when the top-level V8 mutex is destroyed. | 3937 // Called when the top-level V8 mutex is destroyed. |
3936 void Bootstrapper::FreeThreadResources() { | 3938 void Bootstrapper::FreeThreadResources() { |
3937 DCHECK(!IsActive()); | 3939 DCHECK(!IsActive()); |
3938 } | 3940 } |
3939 | 3941 |
3940 } // namespace internal | 3942 } // namespace internal |
3941 } // namespace v8 | 3943 } // namespace v8 |
OLD | NEW |