OLD | NEW |
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { | 188 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
189 CALL_HEAP_FUNCTION(Heap::AllocateFunctionPrototype(*function), JSObject); | 189 CALL_HEAP_FUNCTION(Heap::AllocateFunctionPrototype(*function), JSObject); |
190 } | 190 } |
191 | 191 |
192 | 192 |
193 Handle<Map> Factory::CopyMap(Handle<Map> src) { | 193 Handle<Map> Factory::CopyMap(Handle<Map> src) { |
194 CALL_HEAP_FUNCTION(src->Copy(), Map); | 194 CALL_HEAP_FUNCTION(src->Copy(), Map); |
195 } | 195 } |
196 | 196 |
197 | 197 |
| 198 Handle<Map> Factory::CopyMap(Handle<Map> src, |
| 199 int extra_inobject_properties) { |
| 200 Handle<Map> copy = CopyMap(src); |
| 201 // Check that we do not overflow the instance size when adding the |
| 202 // extra inobject properties. |
| 203 int instance_size_delta = extra_inobject_properties * kPointerSize; |
| 204 int max_instance_size_delta = |
| 205 JSObject::kMaxInstanceSize - copy->instance_size(); |
| 206 if (instance_size_delta > max_instance_size_delta) { |
| 207 // If the instance size overflows, we allocate as many properties |
| 208 // as we can as inobject properties. |
| 209 instance_size_delta = max_instance_size_delta; |
| 210 extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2; |
| 211 } |
| 212 // Adjust the map with the extra inobject properties. |
| 213 int inobject_properties = |
| 214 copy->inobject_properties() + extra_inobject_properties; |
| 215 copy->set_inobject_properties(inobject_properties); |
| 216 copy->set_unused_property_fields(inobject_properties); |
| 217 copy->set_instance_size(copy->instance_size() + instance_size_delta); |
| 218 return copy; |
| 219 } |
| 220 |
198 Handle<Map> Factory::CopyMapDropTransitions(Handle<Map> src) { | 221 Handle<Map> Factory::CopyMapDropTransitions(Handle<Map> src) { |
199 CALL_HEAP_FUNCTION(src->CopyDropTransitions(), Map); | 222 CALL_HEAP_FUNCTION(src->CopyDropTransitions(), Map); |
200 } | 223 } |
201 | 224 |
202 | 225 |
203 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { | 226 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
204 CALL_HEAP_FUNCTION(array->Copy(), FixedArray); | 227 CALL_HEAP_FUNCTION(array->Copy(), FixedArray); |
205 } | 228 } |
206 | 229 |
207 | 230 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 CALL_HEAP_FUNCTION(Heap::AllocateJSObject(*constructor, pretenure), JSObject); | 593 CALL_HEAP_FUNCTION(Heap::AllocateJSObject(*constructor, pretenure), JSObject); |
571 } | 594 } |
572 | 595 |
573 | 596 |
574 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) { | 597 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) { |
575 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, NOT_TENURED), | 598 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, NOT_TENURED), |
576 JSObject); | 599 JSObject); |
577 } | 600 } |
578 | 601 |
579 | 602 |
580 Handle<JSObject> Factory::NewObjectLiteral(int expected_number_of_properties) { | |
581 Handle<Map> map = Handle<Map>(Top::object_function()->initial_map()); | |
582 map = Factory::CopyMap(map); | |
583 map->set_instance_descriptors(Heap::empty_descriptor_array()); | |
584 map->set_unused_property_fields(expected_number_of_properties); | |
585 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, TENURED), | |
586 JSObject); | |
587 } | |
588 | |
589 | |
590 Handle<JSArray> Factory::NewArrayLiteral(int length) { | 603 Handle<JSArray> Factory::NewArrayLiteral(int length) { |
591 return NewJSArrayWithElements(NewFixedArray(length), TENURED); | 604 return NewJSArrayWithElements(NewFixedArray(length), TENURED); |
592 } | 605 } |
593 | 606 |
594 | 607 |
595 Handle<JSArray> Factory::NewJSArray(int length, | 608 Handle<JSArray> Factory::NewJSArray(int length, |
596 PretenureFlag pretenure) { | 609 PretenureFlag pretenure) { |
597 Handle<JSObject> obj = NewJSObject(Top::array_function(), pretenure); | 610 Handle<JSObject> obj = NewJSObject(Top::array_function(), pretenure); |
598 CALL_HEAP_FUNCTION(Handle<JSArray>::cast(obj)->Initialize(length), JSArray); | 611 CALL_HEAP_FUNCTION(Handle<JSArray>::cast(obj)->Initialize(length), JSArray); |
599 } | 612 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 Handle<MapCache> new_cache = NewMapCache(24); | 822 Handle<MapCache> new_cache = NewMapCache(24); |
810 context->set_map_cache(*new_cache); | 823 context->set_map_cache(*new_cache); |
811 } | 824 } |
812 // Check to see whether there is a maching element in the cache. | 825 // Check to see whether there is a maching element in the cache. |
813 Handle<MapCache> cache = | 826 Handle<MapCache> cache = |
814 Handle<MapCache>(MapCache::cast(context->map_cache())); | 827 Handle<MapCache>(MapCache::cast(context->map_cache())); |
815 Handle<Object> result = Handle<Object>(cache->Lookup(*keys)); | 828 Handle<Object> result = Handle<Object>(cache->Lookup(*keys)); |
816 if (result->IsMap()) return Handle<Map>::cast(result); | 829 if (result->IsMap()) return Handle<Map>::cast(result); |
817 // Create a new map and add it to the cache. | 830 // Create a new map and add it to the cache. |
818 Handle<Map> map = | 831 Handle<Map> map = |
819 CopyMap(Handle<Map>(context->object_function()->initial_map())); | 832 CopyMap(Handle<Map>(context->object_function()->initial_map()), |
| 833 keys->length()); |
820 AddToMapCache(context, keys, map); | 834 AddToMapCache(context, keys, map); |
821 return Handle<Map>(map); | 835 return Handle<Map>(map); |
822 } | 836 } |
823 | 837 |
824 | 838 |
825 void Factory::SetRegExpData(Handle<JSRegExp> regexp, | 839 void Factory::SetRegExpData(Handle<JSRegExp> regexp, |
826 JSRegExp::Type type, | 840 JSRegExp::Type type, |
827 Handle<String> source, | 841 Handle<String> source, |
828 JSRegExp::Flags flags, | 842 JSRegExp::Flags flags, |
829 Handle<Object> data) { | 843 Handle<Object> data) { |
(...skipping 16 matching lines...) Expand all Loading... |
846 Execution::ConfigureInstance(instance, | 860 Execution::ConfigureInstance(instance, |
847 instance_template, | 861 instance_template, |
848 pending_exception); | 862 pending_exception); |
849 } else { | 863 } else { |
850 *pending_exception = false; | 864 *pending_exception = false; |
851 } | 865 } |
852 } | 866 } |
853 | 867 |
854 | 868 |
855 } } // namespace v8::internal | 869 } } // namespace v8::internal |
OLD | NEW |