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

Side by Side Diff: src/factory.cc

Issue 4078: - Added a map cache for literal objects. This will... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 Handle<JSFunction> result = 204 Handle<JSFunction> result =
205 BaseNewFunctionFromBoilerplate(boilerplate, Top::function_map()); 205 BaseNewFunctionFromBoilerplate(boilerplate, Top::function_map());
206 result->set_context(*context); 206 result->set_context(*context);
207 int number_of_literals = boilerplate->NumberOfLiterals(); 207 int number_of_literals = boilerplate->NumberOfLiterals();
208 Handle<FixedArray> literals = 208 Handle<FixedArray> literals =
209 Factory::NewFixedArray(number_of_literals, TENURED); 209 Factory::NewFixedArray(number_of_literals, TENURED);
210 if (number_of_literals > 0) { 210 if (number_of_literals > 0) {
211 // Store the object, regexp and array functions in the literals 211 // Store the object, regexp and array functions in the literals
212 // array prefix. These functions will be used when creating 212 // array prefix. These functions will be used when creating
213 // object, regexp and array literals in this function. 213 // object, regexp and array literals in this function.
214 literals->set(JSFunction::kLiteralObjectFunctionIndex, 214 literals->set(JSFunction::kLiteralGlobalContextIndex,
215 context->global_context()->object_function()); 215 context->global_context());
216 literals->set(JSFunction::kLiteralRegExpFunctionIndex,
217 context->global_context()->regexp_function());
218 literals->set(JSFunction::kLiteralArrayFunctionIndex,
219 context->global_context()->array_function());
220 } 216 }
221 result->set_literals(*literals); 217 result->set_literals(*literals);
222 ASSERT(!result->IsBoilerplate()); 218 ASSERT(!result->IsBoilerplate());
223 return result; 219 return result;
224 } 220 }
225 221
226 222
227 Handle<Object> Factory::NewNumber(double value, 223 Handle<Object> Factory::NewNumber(double value,
228 PretenureFlag pretenure) { 224 PretenureFlag pretenure) {
229 CALL_HEAP_FUNCTION(Heap::NumberFromDouble(value, pretenure), Object); 225 CALL_HEAP_FUNCTION(Heap::NumberFromDouble(value, pretenure), Object);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return result; 547 return result;
552 } 548 }
553 549
554 550
555 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, 551 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
556 PretenureFlag pretenure) { 552 PretenureFlag pretenure) {
557 CALL_HEAP_FUNCTION(Heap::AllocateJSObject(*constructor, pretenure), JSObject); 553 CALL_HEAP_FUNCTION(Heap::AllocateJSObject(*constructor, pretenure), JSObject);
558 } 554 }
559 555
560 556
557 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) {
558 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, NOT_TENURED),
559 JSObject);
560 }
561
562
561 Handle<JSObject> Factory::NewObjectLiteral(int expected_number_of_properties) { 563 Handle<JSObject> Factory::NewObjectLiteral(int expected_number_of_properties) {
562 Handle<Map> map = Handle<Map>(Top::object_function()->initial_map()); 564 Handle<Map> map = Handle<Map>(Top::object_function()->initial_map());
563 map = Factory::CopyMap(map); 565 map = Factory::CopyMap(map);
564 map->set_instance_descriptors(Heap::empty_descriptor_array()); 566 map->set_instance_descriptors(Heap::empty_descriptor_array());
565 map->set_unused_property_fields(expected_number_of_properties); 567 map->set_unused_property_fields(expected_number_of_properties);
566 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, TENURED), 568 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, TENURED),
567 JSObject); 569 JSObject);
568 } 570 }
569 571
570 572
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 obj = Handle<FunctionTemplateInfo>::cast(parent); 744 obj = Handle<FunctionTemplateInfo>::cast(parent);
743 } 745 }
744 if (!array->IsEmpty()) { 746 if (!array->IsEmpty()) {
745 map->set_instance_descriptors(*array); 747 map->set_instance_descriptors(*array);
746 } 748 }
747 749
748 return result; 750 return result;
749 } 751 }
750 752
751 753
754 Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
755 CALL_HEAP_FUNCTION(MapCache::Allocate(at_least_space_for), MapCache);
756 }
757
758
759 static Object* UpdateMapCacheWith(Context* context,
760 FixedArray* keys,
761 Map* map) {
762 Object* result = MapCache::cast(context->map_cache())->Put(keys, map);
763 if (!result->IsFailure()) context->set_map_cache(MapCache::cast(result));
764 return result;
765 }
766
767
768 Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
769 Handle<FixedArray> keys,
Mads Ager (chromium) 2008/09/25 07:23:19 Indentation slightly off here.
770 Handle<Map> map) {
771 CALL_HEAP_FUNCTION(UpdateMapCacheWith(*context, *keys, *map), MapCache);
772 }
773
774
775 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
776 Handle<FixedArray> keys) {
777 if (context->map_cache()->IsUndefined()) {
778 // Allocate the new map cache for the global context.
779 Handle<MapCache> new_cache = NewMapCache(24);
780 context->set_map_cache(*new_cache);
781 }
782 // Check to see whether there is a maching element in the cache.
783 Handle<MapCache> cache =
784 Handle<MapCache>(MapCache::cast(context->map_cache()));
785 Handle<Object> result = Handle<Object>(cache->Lookup(*keys));
786 if (result->IsMap()) return Handle<Map>::cast(result);
787 // Create a new map and add it to the cache.
788 Handle<Map> map =
789 CopyMap(Handle<Map>(context->object_function()->initial_map()));
790 AddToMapCache(context, keys, map);
791 return Handle<Map>(map);
792 }
793
794
752 void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc, 795 void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc,
753 Handle<JSObject> instance, 796 Handle<JSObject> instance,
754 bool* pending_exception) { 797 bool* pending_exception) {
755 // Configure the instance by adding the properties specified by the 798 // Configure the instance by adding the properties specified by the
756 // instance template. 799 // instance template.
757 Handle<Object> instance_template = Handle<Object>(desc->instance_template()); 800 Handle<Object> instance_template = Handle<Object>(desc->instance_template());
758 if (!instance_template->IsUndefined()) { 801 if (!instance_template->IsUndefined()) {
759 Execution::ConfigureInstance(instance, 802 Execution::ConfigureInstance(instance,
760 instance_template, 803 instance_template,
761 pending_exception); 804 pending_exception);
762 } else { 805 } else {
763 *pending_exception = false; 806 *pending_exception = false;
764 } 807 }
765 } 808 }
766 809
767 810
768 } } // namespace v8::internal 811 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/flag-definitions.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698