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

Side by Side Diff: src/bootstrapper.cc

Issue 9417043: Avoid sharing AccessorPairs during Genesis. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 | src/heap.h » ('j') | src/heap.cc » ('J')
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 Handle<Context> global_context() { return global_context_; } 165 Handle<Context> global_context() { return global_context_; }
166 166
167 // Creates some basic objects. Used for creating a context from scratch. 167 // Creates some basic objects. Used for creating a context from scratch.
168 void CreateRoots(); 168 void CreateRoots();
169 // Creates the empty function. Used for creating a context from scratch. 169 // Creates the empty function. Used for creating a context from scratch.
170 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); 170 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
171 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 171 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
172 Handle<JSFunction> GetThrowTypeErrorFunction(); 172 Handle<JSFunction> GetThrowTypeErrorFunction();
173 173
174 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); 174 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
175
176 // Make the "arguments" and "caller" properties throw a TypeError on access.
177 void InitArgumentsAndCaller(Handle<Map> map);
Michael Starzinger 2012/02/17 13:33:28 In ECMA-Script speak this method should better be
Sven Panne 2012/02/20 08:26:03 Done.
178
175 // Creates the global objects using the global and the template passed in 179 // Creates the global objects using the global and the template passed in
176 // through the API. We call this regardless of whether we are building a 180 // through the API. We call this regardless of whether we are building a
177 // context from scratch or using a deserialized one from the partial snapshot 181 // context from scratch or using a deserialized one from the partial snapshot
178 // but in the latter case we don't use the objects it produces directly, as 182 // but in the latter case we don't use the objects it produces directly, as
179 // we have to used the deserialized ones that are linked together with the 183 // we have to used the deserialized ones that are linked together with the
180 // rest of the context snapshot. 184 // rest of the context snapshot.
181 Handle<JSGlobalProxy> CreateNewGlobals( 185 Handle<JSGlobalProxy> CreateNewGlobals(
182 v8::Handle<v8::ObjectTemplate> global_template, 186 v8::Handle<v8::ObjectTemplate> global_template,
183 Handle<Object> global_object, 187 Handle<Object> global_object,
184 Handle<GlobalObject>* global_proxy_out); 188 Handle<GlobalObject>* global_proxy_out);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 }; 253 };
250 254
251 Handle<Map> CreateFunctionMap(PrototypePropertyMode prototype_mode); 255 Handle<Map> CreateFunctionMap(PrototypePropertyMode prototype_mode);
252 256
253 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( 257 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor(
254 PrototypePropertyMode prototypeMode); 258 PrototypePropertyMode prototypeMode);
255 void MakeFunctionInstancePrototypeWritable(); 259 void MakeFunctionInstancePrototypeWritable();
256 260
257 Handle<Map> CreateStrictModeFunctionMap( 261 Handle<Map> CreateStrictModeFunctionMap(
258 PrototypePropertyMode prototype_mode, 262 PrototypePropertyMode prototype_mode,
259 Handle<JSFunction> empty_function, 263 Handle<JSFunction> empty_function);
260 Handle<AccessorPair> arguments_callbacks,
261 Handle<AccessorPair> caller_callbacks);
262 264
263 Handle<DescriptorArray> ComputeStrictFunctionInstanceDescriptor( 265 Handle<DescriptorArray> ComputeStrictFunctionInstanceDescriptor(
264 PrototypePropertyMode propertyMode, 266 PrototypePropertyMode propertyMode);
265 Handle<AccessorPair> arguments,
266 Handle<AccessorPair> caller);
267 267
268 static bool CompileBuiltin(Isolate* isolate, int index); 268 static bool CompileBuiltin(Isolate* isolate, int index);
269 static bool CompileExperimentalBuiltin(Isolate* isolate, int index); 269 static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
270 static bool CompileNative(Vector<const char> name, Handle<String> source); 270 static bool CompileNative(Vector<const char> name, Handle<String> source);
271 static bool CompileScriptCached(Vector<const char> name, 271 static bool CompileScriptCached(Vector<const char> name,
272 Handle<String> source, 272 Handle<String> source,
273 SourceCodeCache* cache, 273 SourceCodeCache* cache,
274 v8::Extension* extension, 274 v8::Extension* extension,
275 Handle<Context> top_context, 275 Handle<Context> top_context,
276 bool use_runtime_context); 276 bool use_runtime_context);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 function_without_prototype_map); 525 function_without_prototype_map);
526 empty_fm->set_instance_descriptors( 526 empty_fm->set_instance_descriptors(
527 function_without_prototype_map->instance_descriptors()); 527 function_without_prototype_map->instance_descriptors());
528 empty_fm->set_prototype(global_context()->object_function()->prototype()); 528 empty_fm->set_prototype(global_context()->object_function()->prototype());
529 empty_function->set_map(*empty_fm); 529 empty_function->set_map(*empty_fm);
530 return empty_function; 530 return empty_function;
531 } 531 }
532 532
533 533
534 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor( 534 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor(
535 PrototypePropertyMode prototypeMode, 535 PrototypePropertyMode prototypeMode) {
536 Handle<AccessorPair> arguments,
537 Handle<AccessorPair> caller) {
538 Handle<DescriptorArray> descriptors = 536 Handle<DescriptorArray> descriptors =
539 factory()->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE 537 factory()->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE
540 ? 4 538 ? 4
541 : 5); 539 : 5);
542 PropertyAttributes attributes = static_cast<PropertyAttributes>( 540 PropertyAttributes attributes = static_cast<PropertyAttributes>(
543 DONT_ENUM | DONT_DELETE); 541 DONT_ENUM | DONT_DELETE);
544 542
545 DescriptorArray::WhitenessWitness witness(*descriptors); 543 DescriptorArray::WhitenessWitness witness(*descriptors);
546 544
547 { // length 545 { // length
548 Handle<Foreign> foreign = factory()->NewForeign(&Accessors::FunctionLength); 546 Handle<Foreign> foreign = factory()->NewForeign(&Accessors::FunctionLength);
549 CallbacksDescriptor d(*factory()->length_symbol(), *foreign, attributes); 547 CallbacksDescriptor d(*factory()->length_symbol(), *foreign, attributes);
550 descriptors->Set(0, &d, witness); 548 descriptors->Set(0, &d, witness);
551 } 549 }
552 { // name 550 { // name
553 Handle<Foreign> foreign = factory()->NewForeign(&Accessors::FunctionName); 551 Handle<Foreign> foreign = factory()->NewForeign(&Accessors::FunctionName);
554 CallbacksDescriptor d(*factory()->name_symbol(), *foreign, attributes); 552 CallbacksDescriptor d(*factory()->name_symbol(), *foreign, attributes);
555 descriptors->Set(1, &d, witness); 553 descriptors->Set(1, &d, witness);
556 } 554 }
557 { // arguments 555 { // arguments
556 Handle<AccessorPair> arguments(factory()->NewAccessorPair());
Michael Starzinger 2012/02/17 13:33:28 Could you rewrite this as using the assignment ope
Sven Panne 2012/02/20 08:26:03 As discussed offline, I'll do it the other way rou
Kevin Millikin (Chromium) 2012/02/20 09:30:19 The existing V8 style is to prefer '=' notation fo
558 CallbacksDescriptor d(*factory()->arguments_symbol(), 557 CallbacksDescriptor d(*factory()->arguments_symbol(),
559 *arguments, 558 *arguments,
560 attributes); 559 attributes);
561 descriptors->Set(2, &d, witness); 560 descriptors->Set(2, &d, witness);
562 } 561 }
563 { // caller 562 { // caller
563 Handle<AccessorPair> caller(factory()->NewAccessorPair());
Michael Starzinger 2012/02/17 13:33:28 Likewise.
Sven Panne 2012/02/20 08:26:03 See above.
564 CallbacksDescriptor d(*factory()->caller_symbol(), *caller, attributes); 564 CallbacksDescriptor d(*factory()->caller_symbol(), *caller, attributes);
565 descriptors->Set(3, &d, witness); 565 descriptors->Set(3, &d, witness);
566 } 566 }
567 567
568 // prototype 568 // prototype
569 if (prototypeMode != DONT_ADD_PROTOTYPE) { 569 if (prototypeMode != DONT_ADD_PROTOTYPE) {
570 if (prototypeMode != ADD_WRITEABLE_PROTOTYPE) { 570 if (prototypeMode != ADD_WRITEABLE_PROTOTYPE) {
571 attributes = static_cast<PropertyAttributes>(attributes | READ_ONLY); 571 attributes = static_cast<PropertyAttributes>(attributes | READ_ONLY);
572 } 572 }
573 Handle<Foreign> foreign = 573 Handle<Foreign> foreign =
(...skipping 22 matching lines...) Expand all
596 throw_type_error_function->shared()->DontAdaptArguments(); 596 throw_type_error_function->shared()->DontAdaptArguments();
597 597
598 JSObject::PreventExtensions(throw_type_error_function); 598 JSObject::PreventExtensions(throw_type_error_function);
599 } 599 }
600 return throw_type_error_function; 600 return throw_type_error_function;
601 } 601 }
602 602
603 603
604 Handle<Map> Genesis::CreateStrictModeFunctionMap( 604 Handle<Map> Genesis::CreateStrictModeFunctionMap(
605 PrototypePropertyMode prototype_mode, 605 PrototypePropertyMode prototype_mode,
606 Handle<JSFunction> empty_function, 606 Handle<JSFunction> empty_function) {
607 Handle<AccessorPair> arguments_callbacks,
608 Handle<AccessorPair> caller_callbacks) {
609 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 607 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
610 Handle<DescriptorArray> descriptors = 608 Handle<DescriptorArray> descriptors =
611 ComputeStrictFunctionInstanceDescriptor(prototype_mode, 609 ComputeStrictFunctionInstanceDescriptor(prototype_mode);
612 arguments_callbacks,
613 caller_callbacks);
614 map->set_instance_descriptors(*descriptors); 610 map->set_instance_descriptors(*descriptors);
615 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); 611 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
616 map->set_prototype(*empty_function); 612 map->set_prototype(*empty_function);
617 return map; 613 return map;
618 } 614 }
619 615
620 616
621 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { 617 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
622 // Create the callbacks arrays for ThrowTypeError functions.
623 // The get/set callacks are filled in after the maps are created below.
624 Factory* factory = empty->GetIsolate()->factory();
625 Handle<AccessorPair> arguments(factory->NewAccessorPair());
626 Handle<AccessorPair> caller(factory->NewAccessorPair());
627
628 // Allocate map for the strict mode function instances. 618 // Allocate map for the strict mode function instances.
629 Handle<Map> strict_mode_function_instance_map = 619 Handle<Map> strict_mode_function_instance_map =
630 CreateStrictModeFunctionMap( 620 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty);
631 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller);
632 global_context()->set_strict_mode_function_instance_map( 621 global_context()->set_strict_mode_function_instance_map(
633 *strict_mode_function_instance_map); 622 *strict_mode_function_instance_map);
634 623
635 // Allocate map for the prototype-less strict mode instances. 624 // Allocate map for the prototype-less strict mode instances.
636 Handle<Map> strict_mode_function_without_prototype_map = 625 Handle<Map> strict_mode_function_without_prototype_map =
637 CreateStrictModeFunctionMap( 626 CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty);
638 DONT_ADD_PROTOTYPE, empty, arguments, caller);
639 global_context()->set_strict_mode_function_without_prototype_map( 627 global_context()->set_strict_mode_function_without_prototype_map(
640 *strict_mode_function_without_prototype_map); 628 *strict_mode_function_without_prototype_map);
641 629
642 // Allocate map for the strict mode functions. This map is temporary, used 630 // Allocate map for the strict mode functions. This map is temporary, used
643 // only for processing of builtins. 631 // only for processing of builtins.
644 // Later the map is replaced with writable prototype map, allocated below. 632 // Later the map is replaced with writable prototype map, allocated below.
645 Handle<Map> strict_mode_function_map = 633 Handle<Map> strict_mode_function_map =
646 CreateStrictModeFunctionMap( 634 CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty);
647 ADD_READONLY_PROTOTYPE, empty, arguments, caller);
648 global_context()->set_strict_mode_function_map( 635 global_context()->set_strict_mode_function_map(
649 *strict_mode_function_map); 636 *strict_mode_function_map);
650 637
651 // The final map for the strict mode functions. Writeable prototype. 638 // The final map for the strict mode functions. Writeable prototype.
652 // This map is installed in MakeFunctionInstancePrototypeWritable. 639 // This map is installed in MakeFunctionInstancePrototypeWritable.
653 strict_mode_function_instance_map_writable_prototype_ = 640 strict_mode_function_instance_map_writable_prototype_ =
654 CreateStrictModeFunctionMap( 641 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty);
655 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller);
656 642
657 // Create the ThrowTypeError function instance. 643 // Create the ThrowTypeError function instance.
658 Handle<JSFunction> throw_function = 644 Handle<JSFunction> throw_function =
Michael Starzinger 2012/02/17 13:33:28 This is now unused, remove it.
Sven Panne 2012/02/20 08:26:03 Done.
659 GetThrowTypeErrorFunction(); 645 GetThrowTypeErrorFunction();
660 646
661 // Complete the callbacks. 647 // Complete the callbacks.
662 arguments->set_getter(*throw_function); 648 InitArgumentsAndCaller(strict_mode_function_instance_map);
663 arguments->set_setter(*throw_function); 649 InitArgumentsAndCaller(strict_mode_function_without_prototype_map);
664 caller->set_getter(*throw_function); 650 InitArgumentsAndCaller(strict_mode_function_map);
665 caller->set_setter(*throw_function); 651 InitArgumentsAndCaller(strict_mode_function_instance_map_writable_prototype_);
666 } 652 }
667 653
668 654
655 static void SetAccessors(Handle<Map> map,
656 Handle<String> name,
657 Handle<JSFunction> func) {
658 DescriptorArray* descs = map->instance_descriptors();
659 int number = descs->Search(*name);
660 AccessorPair* accessors = AccessorPair::cast(descs->GetValue(number));
661 accessors->set_getter(*func);
662 accessors->set_setter(*func);
663 }
664
665
666 void Genesis::InitArgumentsAndCaller(Handle<Map> map) {
667 SetAccessors(map, factory()->arguments_symbol(), GetThrowTypeErrorFunction());
668 SetAccessors(map, factory()->caller_symbol(), GetThrowTypeErrorFunction());
669 }
670
671
669 static void AddToWeakGlobalContextList(Context* context) { 672 static void AddToWeakGlobalContextList(Context* context) {
670 ASSERT(context->IsGlobalContext()); 673 ASSERT(context->IsGlobalContext());
671 Heap* heap = context->GetIsolate()->heap(); 674 Heap* heap = context->GetIsolate()->heap();
672 #ifdef DEBUG 675 #ifdef DEBUG
673 { // NOLINT 676 { // NOLINT
674 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); 677 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined());
675 // Check that context is not in the list yet. 678 // Check that context is not in the list yet.
676 for (Object* current = heap->global_contexts_list(); 679 for (Object* current = heap->global_contexts_list();
677 !current->IsUndefined(); 680 !current->IsUndefined();
678 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { 681 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) {
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 return from + sizeof(NestingCounterType); 2367 return from + sizeof(NestingCounterType);
2365 } 2368 }
2366 2369
2367 2370
2368 // Called when the top-level V8 mutex is destroyed. 2371 // Called when the top-level V8 mutex is destroyed.
2369 void Bootstrapper::FreeThreadResources() { 2372 void Bootstrapper::FreeThreadResources() {
2370 ASSERT(!IsActive()); 2373 ASSERT(!IsActive());
2371 } 2374 }
2372 2375
2373 } } // namespace v8::internal 2376 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap.h » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698