| 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 1845 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1856     Handle<AllocationSite> allocation_site) { | 1856     Handle<AllocationSite> allocation_site) { | 
| 1857   CALL_HEAP_FUNCTION( | 1857   CALL_HEAP_FUNCTION( | 
| 1858       isolate(), | 1858       isolate(), | 
| 1859       isolate()->heap()->AllocateJSObjectFromMap( | 1859       isolate()->heap()->AllocateJSObjectFromMap( | 
| 1860           *map, | 1860           *map, | 
| 1861           pretenure, | 1861           pretenure, | 
| 1862           allocation_site.is_null() ? NULL : *allocation_site), | 1862           allocation_site.is_null() ? NULL : *allocation_site), | 
| 1863       JSObject); | 1863       JSObject); | 
| 1864 } | 1864 } | 
| 1865 | 1865 | 
|  | 1866 Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity, | 
|  | 1867                                                  PretenureFlag pretenure) { | 
|  | 1868   DCHECK(map->is_dictionary_map()); | 
|  | 1869   Handle<FixedArray> object_properties = | 
|  | 1870       NameDictionary::New(isolate(), capacity); | 
|  | 1871   Handle<JSObject> js_object = NewJSObjectFromMap(map, pretenure); | 
|  | 1872   js_object->set_properties(*object_properties); | 
|  | 1873   return js_object; | 
|  | 1874 } | 
| 1866 | 1875 | 
| 1867 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, | 1876 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, | 
| 1868                                     PretenureFlag pretenure) { | 1877                                     PretenureFlag pretenure) { | 
| 1869   Map* map = isolate()->get_initial_js_array_map(elements_kind); | 1878   Map* map = isolate()->get_initial_js_array_map(elements_kind); | 
| 1870   if (map == nullptr) { | 1879   if (map == nullptr) { | 
| 1871     Context* native_context = isolate()->context()->native_context(); | 1880     Context* native_context = isolate()->context()->native_context(); | 
| 1872     JSFunction* array_function = native_context->array_function(); | 1881     JSFunction* array_function = native_context->array_function(); | 
| 1873     map = array_function->initial_map(); | 1882     map = array_function->initial_map(); | 
| 1874   } | 1883   } | 
| 1875   return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); | 1884   return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); | 
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2656 | 2665 | 
| 2657 | 2666 | 
| 2658 Handle<JSWeakMap> Factory::NewJSWeakMap() { | 2667 Handle<JSWeakMap> Factory::NewJSWeakMap() { | 
| 2659   // TODO(adamk): Currently the map is only created three times per | 2668   // TODO(adamk): Currently the map is only created three times per | 
| 2660   // isolate. If it's created more often, the map should be moved into the | 2669   // isolate. If it's created more often, the map should be moved into the | 
| 2661   // strong root list. | 2670   // strong root list. | 
| 2662   Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); | 2671   Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); | 
| 2663   return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); | 2672   return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); | 
| 2664 } | 2673 } | 
| 2665 | 2674 | 
| 2666 | 2675 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context, | 
| 2667 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, | 2676                                                int number_of_properties) { | 
| 2668                                                int number_of_properties, | 2677   DCHECK(native_context->IsNativeContext()); | 
| 2669                                                bool* is_result_from_cache) { |  | 
| 2670   const int kMapCacheSize = 128; | 2678   const int kMapCacheSize = 128; | 
| 2671 |  | 
| 2672   // We do not cache maps for too many properties or when running builtin code. | 2679   // We do not cache maps for too many properties or when running builtin code. | 
| 2673   if (number_of_properties > kMapCacheSize || | 2680   if (isolate()->bootstrapper()->IsActive()) { | 
| 2674       isolate()->bootstrapper()->IsActive()) { | 2681     return Map::Create(isolate(), number_of_properties); | 
| 2675     *is_result_from_cache = false; |  | 
| 2676     Handle<Map> map = Map::Create(isolate(), number_of_properties); |  | 
| 2677     return map; |  | 
| 2678   } | 2682   } | 
| 2679   *is_result_from_cache = true; | 2683   // Use initial slow object proto map for too many properties. | 
|  | 2684   if (number_of_properties > kMapCacheSize) { | 
|  | 2685     return handle(native_context->slow_object_with_object_prototype_map(), | 
|  | 2686                   isolate()); | 
|  | 2687   } | 
| 2680   if (number_of_properties == 0) { | 2688   if (number_of_properties == 0) { | 
| 2681     // Reuse the initial map of the Object function if the literal has no | 2689     // Reuse the initial map of the Object function if the literal has no | 
| 2682     // predeclared properties. | 2690     // predeclared properties. | 
| 2683     return handle(context->object_function()->initial_map(), isolate()); | 2691     return handle(native_context->object_function()->initial_map(), isolate()); | 
| 2684   } | 2692   } | 
| 2685 | 2693 | 
| 2686   int cache_index = number_of_properties - 1; | 2694   int cache_index = number_of_properties - 1; | 
| 2687   Handle<Object> maybe_cache(context->map_cache(), isolate()); | 2695   Handle<Object> maybe_cache(native_context->map_cache(), isolate()); | 
| 2688   if (maybe_cache->IsUndefined(isolate())) { | 2696   if (maybe_cache->IsUndefined(isolate())) { | 
| 2689     // Allocate the new map cache for the native context. | 2697     // Allocate the new map cache for the native context. | 
| 2690     maybe_cache = NewFixedArray(kMapCacheSize, TENURED); | 2698     maybe_cache = NewFixedArray(kMapCacheSize, TENURED); | 
| 2691     context->set_map_cache(*maybe_cache); | 2699     native_context->set_map_cache(*maybe_cache); | 
| 2692   } else { | 2700   } else { | 
| 2693     // Check to see whether there is a matching element in the cache. | 2701     // Check to see whether there is a matching element in the cache. | 
| 2694     Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 2702     Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 
| 2695     Object* result = cache->get(cache_index); | 2703     Object* result = cache->get(cache_index); | 
| 2696     if (result->IsWeakCell()) { | 2704     if (result->IsWeakCell()) { | 
| 2697       WeakCell* cell = WeakCell::cast(result); | 2705       WeakCell* cell = WeakCell::cast(result); | 
| 2698       if (!cell->cleared()) { | 2706       if (!cell->cleared()) { | 
| 2699         return handle(Map::cast(cell->value()), isolate()); | 2707         Map* map = Map::cast(cell->value()); | 
|  | 2708         DCHECK(!map->is_dictionary_map()); | 
|  | 2709         return handle(map, isolate()); | 
| 2700       } | 2710       } | 
| 2701     } | 2711     } | 
| 2702   } | 2712   } | 
| 2703   // Create a new map and add it to the cache. | 2713   // Create a new map and add it to the cache. | 
| 2704   Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 2714   Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 
| 2705   Handle<Map> map = Map::Create(isolate(), number_of_properties); | 2715   Handle<Map> map = Map::Create(isolate(), number_of_properties); | 
|  | 2716   DCHECK(!map->is_dictionary_map()); | 
| 2706   Handle<WeakCell> cell = NewWeakCell(map); | 2717   Handle<WeakCell> cell = NewWeakCell(map); | 
| 2707   cache->set(cache_index, *cell); | 2718   cache->set(cache_index, *cell); | 
| 2708   return map; | 2719   return map; | 
| 2709 } | 2720 } | 
| 2710 | 2721 | 
| 2711 | 2722 | 
| 2712 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, | 2723 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, | 
| 2713                                 JSRegExp::Type type, | 2724                                 JSRegExp::Type type, | 
| 2714                                 Handle<String> source, | 2725                                 Handle<String> source, | 
| 2715                                 JSRegExp::Flags flags, | 2726                                 JSRegExp::Flags flags, | 
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2935     Handle<AccessorInfo> prototype = | 2946     Handle<AccessorInfo> prototype = | 
| 2936         Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2947         Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 
| 2937     Descriptor d = Descriptor::AccessorConstant( | 2948     Descriptor d = Descriptor::AccessorConstant( | 
| 2938         Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2949         Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 
| 2939     map->AppendDescriptor(&d); | 2950     map->AppendDescriptor(&d); | 
| 2940   } | 2951   } | 
| 2941 } | 2952 } | 
| 2942 | 2953 | 
| 2943 }  // namespace internal | 2954 }  // namespace internal | 
| 2944 }  // namespace v8 | 2955 }  // namespace v8 | 
| OLD | NEW | 
|---|