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

Side by Side Diff: src/bootstrapper.cc

Issue 12919009: Move context global handle creation out of Genesis. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 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 | « no previous file | no next file » | no next file with comments »
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 141
142 class Genesis BASE_EMBEDDED { 142 class Genesis BASE_EMBEDDED {
143 public: 143 public:
144 Genesis(Isolate* isolate, 144 Genesis(Isolate* isolate,
145 Handle<Object> global_object, 145 Handle<Object> global_object,
146 v8::Handle<v8::ObjectTemplate> global_template, 146 v8::Handle<v8::ObjectTemplate> global_template,
147 v8::ExtensionConfiguration* extensions); 147 v8::ExtensionConfiguration* extensions);
148 ~Genesis() { } 148 ~Genesis() { }
149 149
150 Handle<Context> result() { return result_; }
151
152 Isolate* isolate() const { return isolate_; } 150 Isolate* isolate() const { return isolate_; }
153 Factory* factory() const { return isolate_->factory(); } 151 Factory* factory() const { return isolate_->factory(); }
154 Heap* heap() const { return isolate_->heap(); } 152 Heap* heap() const { return isolate_->heap(); }
155 153
154 Handle<Context> result() { return result_; }
155
156 private: 156 private:
157 Handle<Context> native_context_;
158 Isolate* isolate_;
159
160 Handle<Context> native_context() { return native_context_; } 157 Handle<Context> native_context() { return native_context_; }
161 158
162 // Creates some basic objects. Used for creating a context from scratch. 159 // Creates some basic objects. Used for creating a context from scratch.
163 void CreateRoots(); 160 void CreateRoots();
164 // Creates the empty function. Used for creating a context from scratch. 161 // Creates the empty function. Used for creating a context from scratch.
165 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); 162 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
166 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 163 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
167 Handle<JSFunction> GetThrowTypeErrorFunction(); 164 Handle<JSFunction> GetThrowTypeErrorFunction();
168 165
169 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); 166 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 Vector<const char> name, 267 Vector<const char> name,
271 Handle<String> source); 268 Handle<String> source);
272 static bool CompileScriptCached(Isolate* isolate, 269 static bool CompileScriptCached(Isolate* isolate,
273 Vector<const char> name, 270 Vector<const char> name,
274 Handle<String> source, 271 Handle<String> source,
275 SourceCodeCache* cache, 272 SourceCodeCache* cache,
276 v8::Extension* extension, 273 v8::Extension* extension,
277 Handle<Context> top_context, 274 Handle<Context> top_context,
278 bool use_runtime_context); 275 bool use_runtime_context);
279 276
277 Isolate* isolate_;
280 Handle<Context> result_; 278 Handle<Context> result_;
279 Handle<Context> native_context_;
281 280
282 // Function instance maps. Function literal maps are created initially with 281 // Function instance maps. Function literal maps are created initially with
283 // a read only prototype for the processing of JS builtins. Later the function 282 // a read only prototype for the processing of JS builtins. Later the function
284 // instance maps are replaced in order to make prototype writable. 283 // instance maps are replaced in order to make prototype writable.
285 // These are the final, writable prototype, maps. 284 // These are the final, writable prototype, maps.
286 Handle<Map> function_instance_map_writable_prototype_; 285 Handle<Map> function_instance_map_writable_prototype_;
287 Handle<Map> strict_mode_function_instance_map_writable_prototype_; 286 Handle<Map> strict_mode_function_instance_map_writable_prototype_;
288 Handle<JSFunction> throw_type_error_function; 287 Handle<JSFunction> throw_type_error_function;
289 288
290 BootstrapperActive active_; 289 BootstrapperActive active_;
291 friend class Bootstrapper; 290 friend class Bootstrapper;
292 }; 291 };
293 292
294 293
295 void Bootstrapper::Iterate(ObjectVisitor* v) { 294 void Bootstrapper::Iterate(ObjectVisitor* v) {
296 extensions_cache_.Iterate(v); 295 extensions_cache_.Iterate(v);
297 v->Synchronize(VisitorSynchronization::kExtensions); 296 v->Synchronize(VisitorSynchronization::kExtensions);
298 } 297 }
299 298
300 299
301 Handle<Context> Bootstrapper::CreateEnvironment( 300 Handle<Context> Bootstrapper::CreateEnvironment(
302 Handle<Object> global_object, 301 Handle<Object> global_object,
303 v8::Handle<v8::ObjectTemplate> global_template, 302 v8::Handle<v8::ObjectTemplate> global_template,
304 v8::ExtensionConfiguration* extensions) { 303 v8::ExtensionConfiguration* extensions) {
305 HandleScope scope(isolate_); 304 HandleScope scope(isolate_);
306 Handle<Context> env;
307 Genesis genesis(isolate_, global_object, global_template, extensions); 305 Genesis genesis(isolate_, global_object, global_template, extensions);
308 env = genesis.result(); 306 Handle<Object> context(isolate_->global_handles()->Create(*genesis.result()));
307 Handle<Context> env = Handle<Context>::cast(context);
309 if (!env.is_null()) { 308 if (!env.is_null()) {
310 if (InstallExtensions(env, extensions)) { 309 if (InstallExtensions(env, extensions)) {
311 return env; 310 return env;
312 } 311 }
313 } 312 }
314 return Handle<Context>(); 313 return Handle<Context>();
315 } 314 }
316 315
317 316
318 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { 317 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list()); 684 context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list());
686 heap->set_native_contexts_list(context); 685 heap->set_native_contexts_list(context);
687 } 686 }
688 687
689 688
690 void Genesis::CreateRoots() { 689 void Genesis::CreateRoots() {
691 // Allocate the native context FixedArray first and then patch the 690 // Allocate the native context FixedArray first and then patch the
692 // closure and extension object later (we need the empty function 691 // closure and extension object later (we need the empty function
693 // and the global object, but in order to create those, we need the 692 // and the global object, but in order to create those, we need the
694 // native context). 693 // native context).
695 native_context_ = Handle<Context>::cast(isolate()->global_handles()->Create( 694 native_context_ = factory()->NewNativeContext();
696 *factory()->NewNativeContext())); 695 AddToWeakNativeContextList(*native_context());
697 AddToWeakNativeContextList(*native_context_);
698 isolate()->set_context(*native_context()); 696 isolate()->set_context(*native_context());
699 697
700 // Allocate the message listeners object. 698 // Allocate the message listeners object.
701 { 699 {
702 v8::NeanderArray listeners; 700 v8::NeanderArray listeners;
703 native_context()->set_message_listeners(*listeners.value()); 701 native_context()->set_message_listeners(*listeners.value());
704 } 702 }
705 } 703 }
706 704
707 705
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 inner_global->set_native_context(*native_context()); 814 inner_global->set_native_context(*native_context());
817 inner_global->set_global_context(*native_context()); 815 inner_global->set_global_context(*native_context());
818 inner_global->set_global_receiver(*global_proxy); 816 inner_global->set_global_receiver(*global_proxy);
819 global_proxy->set_native_context(*native_context()); 817 global_proxy->set_native_context(*native_context());
820 native_context()->set_global_proxy(*global_proxy); 818 native_context()->set_global_proxy(*global_proxy);
821 } 819 }
822 820
823 821
824 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { 822 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) {
825 Handle<GlobalObject> inner_global_from_snapshot( 823 Handle<GlobalObject> inner_global_from_snapshot(
826 GlobalObject::cast(native_context_->extension())); 824 GlobalObject::cast(native_context()->extension()));
827 Handle<JSBuiltinsObject> builtins_global(native_context_->builtins()); 825 Handle<JSBuiltinsObject> builtins_global(native_context()->builtins());
828 native_context_->set_extension(*inner_global); 826 native_context()->set_extension(*inner_global);
829 native_context_->set_global_object(*inner_global); 827 native_context()->set_global_object(*inner_global);
830 native_context_->set_security_token(*inner_global); 828 native_context()->set_security_token(*inner_global);
831 static const PropertyAttributes attributes = 829 static const PropertyAttributes attributes =
832 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 830 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
833 ForceSetProperty(builtins_global, 831 ForceSetProperty(builtins_global,
834 factory()->InternalizeOneByteString( 832 factory()->InternalizeOneByteString(
835 STATIC_ASCII_VECTOR("global")), 833 STATIC_ASCII_VECTOR("global")),
836 inner_global, 834 inner_global,
837 attributes); 835 attributes);
838 // Set up the reference from the global object to the builtins object. 836 // Set up the reference from the global object to the builtins object.
839 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); 837 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global);
840 TransferNamedProperties(inner_global_from_snapshot, inner_global); 838 TransferNamedProperties(inner_global_from_snapshot, inner_global);
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 v8::Handle<v8::ObjectTemplate> global_template, 2408 v8::Handle<v8::ObjectTemplate> global_template,
2411 v8::ExtensionConfiguration* extensions) 2409 v8::ExtensionConfiguration* extensions)
2412 : isolate_(isolate), 2410 : isolate_(isolate),
2413 active_(isolate->bootstrapper()) { 2411 active_(isolate->bootstrapper()) {
2414 result_ = Handle<Context>::null(); 2412 result_ = Handle<Context>::null();
2415 // If V8 isn't running and cannot be initialized, just return. 2413 // If V8 isn't running and cannot be initialized, just return.
2416 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; 2414 if (!V8::IsRunning() && !V8::Initialize(NULL)) return;
2417 2415
2418 // Before creating the roots we must save the context and restore it 2416 // Before creating the roots we must save the context and restore it
2419 // on all function exits. 2417 // on all function exits.
2420 HandleScope scope(isolate);
2421 SaveContext saved_context(isolate); 2418 SaveContext saved_context(isolate);
2422 2419
2423 // During genesis, the boilerplate for stack overflow won't work until the 2420 // During genesis, the boilerplate for stack overflow won't work until the
2424 // environment has been at least partially initialized. Add a stack check 2421 // environment has been at least partially initialized. Add a stack check
2425 // before entering JS code to catch overflow early. 2422 // before entering JS code to catch overflow early.
2426 StackLimitCheck check(isolate); 2423 StackLimitCheck check(isolate);
2427 if (check.HasOverflowed()) return; 2424 if (check.HasOverflowed()) return;
2428 2425
2429 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); 2426 native_context_ = Snapshot::NewContextFromSnapshot();
2430 if (!new_context.is_null()) { 2427 if (!native_context().is_null()) {
2431 native_context_ = 2428 AddToWeakNativeContextList(*native_context());
2432 Handle<Context>::cast(isolate->global_handles()->Create(*new_context)); 2429 isolate->set_context(*native_context());
2433 AddToWeakNativeContextList(*native_context_);
2434 isolate->set_context(*native_context_);
2435 isolate->counters()->contexts_created_by_snapshot()->Increment(); 2430 isolate->counters()->contexts_created_by_snapshot()->Increment();
2436 Handle<GlobalObject> inner_global; 2431 Handle<GlobalObject> inner_global;
2437 Handle<JSGlobalProxy> global_proxy = 2432 Handle<JSGlobalProxy> global_proxy =
2438 CreateNewGlobals(global_template, 2433 CreateNewGlobals(global_template,
2439 global_object, 2434 global_object,
2440 &inner_global); 2435 &inner_global);
2441 2436
2442 HookUpGlobalProxy(inner_global, global_proxy); 2437 HookUpGlobalProxy(inner_global, global_proxy);
2443 HookUpInnerGlobal(inner_global); 2438 HookUpInnerGlobal(inner_global);
2444 2439
(...skipping 15 matching lines...) Expand all
2460 MakeFunctionInstancePrototypeWritable(); 2455 MakeFunctionInstancePrototypeWritable();
2461 2456
2462 if (!ConfigureGlobalObjects(global_template)) return; 2457 if (!ConfigureGlobalObjects(global_template)) return;
2463 isolate->counters()->contexts_created_from_scratch()->Increment(); 2458 isolate->counters()->contexts_created_from_scratch()->Increment();
2464 } 2459 }
2465 2460
2466 // Initialize experimental globals and install experimental natives. 2461 // Initialize experimental globals and install experimental natives.
2467 InitializeExperimentalGlobal(); 2462 InitializeExperimentalGlobal();
2468 if (!InstallExperimentalNatives()) return; 2463 if (!InstallExperimentalNatives()) return;
2469 2464
2470 result_ = native_context_; 2465 result_ = native_context();
2471 } 2466 }
2472 2467
2473 2468
2474 // Support for thread preemption. 2469 // Support for thread preemption.
2475 2470
2476 // Reserve space for statics needing saving and restoring. 2471 // Reserve space for statics needing saving and restoring.
2477 int Bootstrapper::ArchiveSpacePerThread() { 2472 int Bootstrapper::ArchiveSpacePerThread() {
2478 return sizeof(NestingCounterType); 2473 return sizeof(NestingCounterType);
2479 } 2474 }
2480 2475
(...skipping 12 matching lines...) Expand all
2493 return from + sizeof(NestingCounterType); 2488 return from + sizeof(NestingCounterType);
2494 } 2489 }
2495 2490
2496 2491
2497 // Called when the top-level V8 mutex is destroyed. 2492 // Called when the top-level V8 mutex is destroyed.
2498 void Bootstrapper::FreeThreadResources() { 2493 void Bootstrapper::FreeThreadResources() {
2499 ASSERT(!IsActive()); 2494 ASSERT(!IsActive());
2500 } 2495 }
2501 2496
2502 } } // namespace v8::internal 2497 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698