| 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/factory.h" | 5 #include "src/factory.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
| 9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 Handle<AllocationSite> allocation_site) { | 1836 Handle<AllocationSite> allocation_site) { |
| 1837 CALL_HEAP_FUNCTION( | 1837 CALL_HEAP_FUNCTION( |
| 1838 isolate(), | 1838 isolate(), |
| 1839 isolate()->heap()->AllocateJSObjectFromMap( | 1839 isolate()->heap()->AllocateJSObjectFromMap( |
| 1840 *map, | 1840 *map, |
| 1841 pretenure, | 1841 pretenure, |
| 1842 allocation_site.is_null() ? NULL : *allocation_site), | 1842 allocation_site.is_null() ? NULL : *allocation_site), |
| 1843 JSObject); | 1843 JSObject); |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity, |
| 1847 PretenureFlag pretenure) { |
| 1848 DCHECK(map->is_dictionary_map()); |
| 1849 Handle<FixedArray> object_properties = |
| 1850 NameDictionary::New(isolate(), capacity); |
| 1851 Handle<JSObject> js_object = NewJSObjectFromMap(map, pretenure); |
| 1852 js_object->set_properties(*object_properties); |
| 1853 return js_object; |
| 1854 } |
| 1846 | 1855 |
| 1847 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, | 1856 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, |
| 1848 PretenureFlag pretenure) { | 1857 PretenureFlag pretenure) { |
| 1849 Map* map = isolate()->get_initial_js_array_map(elements_kind); | 1858 Map* map = isolate()->get_initial_js_array_map(elements_kind); |
| 1850 if (map == nullptr) { | 1859 if (map == nullptr) { |
| 1851 Context* native_context = isolate()->context()->native_context(); | 1860 Context* native_context = isolate()->context()->native_context(); |
| 1852 JSFunction* array_function = native_context->array_function(); | 1861 JSFunction* array_function = native_context->array_function(); |
| 1853 map = array_function->initial_map(); | 1862 map = array_function->initial_map(); |
| 1854 } | 1863 } |
| 1855 return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); | 1864 return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2605 | 2614 |
| 2606 | 2615 |
| 2607 Handle<JSWeakMap> Factory::NewJSWeakMap() { | 2616 Handle<JSWeakMap> Factory::NewJSWeakMap() { |
| 2608 // TODO(adamk): Currently the map is only created three times per | 2617 // TODO(adamk): Currently the map is only created three times per |
| 2609 // isolate. If it's created more often, the map should be moved into the | 2618 // isolate. If it's created more often, the map should be moved into the |
| 2610 // strong root list. | 2619 // strong root list. |
| 2611 Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); | 2620 Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); |
| 2612 return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); | 2621 return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); |
| 2613 } | 2622 } |
| 2614 | 2623 |
| 2615 | 2624 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context, |
| 2616 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, | |
| 2617 int number_of_properties, | 2625 int number_of_properties, |
| 2618 bool* is_result_from_cache) { | 2626 bool has_null_prototype) { |
| 2627 DCHECK(native_context->IsNativeContext()); |
| 2619 const int kMapCacheSize = 128; | 2628 const int kMapCacheSize = 128; |
| 2620 | 2629 |
| 2630 // Ignoring number_of_properties for force dictionary map with __proto__:null. |
| 2631 if (has_null_prototype) { |
| 2632 return handle(native_context->slow_object_with_null_prototype_map(), |
| 2633 isolate()); |
| 2634 } |
| 2621 // We do not cache maps for too many properties or when running builtin code. | 2635 // We do not cache maps for too many properties or when running builtin code. |
| 2622 if (number_of_properties > kMapCacheSize || | 2636 if (isolate()->bootstrapper()->IsActive()) { |
| 2623 isolate()->bootstrapper()->IsActive()) { | 2637 return Map::Create(isolate(), number_of_properties); |
| 2624 *is_result_from_cache = false; | |
| 2625 Handle<Map> map = Map::Create(isolate(), number_of_properties); | |
| 2626 return map; | |
| 2627 } | 2638 } |
| 2628 *is_result_from_cache = true; | 2639 // Use initial slow object proto map for too many properties. |
| 2640 if (number_of_properties > kMapCacheSize) { |
| 2641 return handle(native_context->slow_object_with_object_prototype_map(), |
| 2642 isolate()); |
| 2643 } |
| 2629 if (number_of_properties == 0) { | 2644 if (number_of_properties == 0) { |
| 2630 // Reuse the initial map of the Object function if the literal has no | 2645 // Reuse the initial map of the Object function if the literal has no |
| 2631 // predeclared properties. | 2646 // predeclared properties. |
| 2632 return handle(context->object_function()->initial_map(), isolate()); | 2647 return handle(native_context->object_function()->initial_map(), isolate()); |
| 2633 } | 2648 } |
| 2634 | 2649 |
| 2635 int cache_index = number_of_properties - 1; | 2650 int cache_index = number_of_properties - 1; |
| 2636 Handle<Object> maybe_cache(context->map_cache(), isolate()); | 2651 Handle<Object> maybe_cache(native_context->map_cache(), isolate()); |
| 2637 if (maybe_cache->IsUndefined(isolate())) { | 2652 if (maybe_cache->IsUndefined(isolate())) { |
| 2638 // Allocate the new map cache for the native context. | 2653 // Allocate the new map cache for the native context. |
| 2639 maybe_cache = NewFixedArray(kMapCacheSize, TENURED); | 2654 maybe_cache = NewFixedArray(kMapCacheSize, TENURED); |
| 2640 context->set_map_cache(*maybe_cache); | 2655 native_context->set_map_cache(*maybe_cache); |
| 2641 } else { | 2656 } else { |
| 2642 // Check to see whether there is a matching element in the cache. | 2657 // Check to see whether there is a matching element in the cache. |
| 2643 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 2658 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
| 2644 Object* result = cache->get(cache_index); | 2659 Object* result = cache->get(cache_index); |
| 2645 if (result->IsWeakCell()) { | 2660 if (result->IsWeakCell()) { |
| 2646 WeakCell* cell = WeakCell::cast(result); | 2661 WeakCell* cell = WeakCell::cast(result); |
| 2647 if (!cell->cleared()) { | 2662 if (!cell->cleared()) { |
| 2648 return handle(Map::cast(cell->value()), isolate()); | 2663 Map* map = Map::cast(cell->value()); |
| 2664 DCHECK(!map->is_dictionary_map()); |
| 2665 return handle(map, isolate()); |
| 2649 } | 2666 } |
| 2650 } | 2667 } |
| 2651 } | 2668 } |
| 2652 // Create a new map and add it to the cache. | 2669 // Create a new map and add it to the cache. |
| 2653 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 2670 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
| 2654 Handle<Map> map = Map::Create(isolate(), number_of_properties); | 2671 Handle<Map> map = Map::Create(isolate(), number_of_properties); |
| 2672 DCHECK(!map->is_dictionary_map()); |
| 2655 Handle<WeakCell> cell = NewWeakCell(map); | 2673 Handle<WeakCell> cell = NewWeakCell(map); |
| 2656 cache->set(cache_index, *cell); | 2674 cache->set(cache_index, *cell); |
| 2657 return map; | 2675 return map; |
| 2658 } | 2676 } |
| 2659 | 2677 |
| 2660 | 2678 |
| 2661 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, | 2679 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 2662 JSRegExp::Type type, | 2680 JSRegExp::Type type, |
| 2663 Handle<String> source, | 2681 Handle<String> source, |
| 2664 JSRegExp::Flags flags, | 2682 JSRegExp::Flags flags, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2884 Handle<AccessorInfo> prototype = | 2902 Handle<AccessorInfo> prototype = |
| 2885 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2903 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
| 2886 Descriptor d = Descriptor::AccessorConstant( | 2904 Descriptor d = Descriptor::AccessorConstant( |
| 2887 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2905 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
| 2888 map->AppendDescriptor(&d); | 2906 map->AppendDescriptor(&d); |
| 2889 } | 2907 } |
| 2890 } | 2908 } |
| 2891 | 2909 |
| 2892 } // namespace internal | 2910 } // namespace internal |
| 2893 } // namespace v8 | 2911 } // namespace v8 |
| OLD | NEW |