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/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 2366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 } | 2377 } |
2378 *is_result_from_cache = true; | 2378 *is_result_from_cache = true; |
2379 if (number_of_properties == 0) { | 2379 if (number_of_properties == 0) { |
2380 // Reuse the initial map of the Object function if the literal has no | 2380 // Reuse the initial map of the Object function if the literal has no |
2381 // predeclared properties, or the strong map if strong. | 2381 // predeclared properties, or the strong map if strong. |
2382 return handle(is_strong | 2382 return handle(is_strong |
2383 ? context->js_object_strong_map() | 2383 ? context->js_object_strong_map() |
2384 : context->object_function()->initial_map(), isolate()); | 2384 : context->object_function()->initial_map(), isolate()); |
2385 } | 2385 } |
2386 | 2386 |
2387 // Create a new map and add it to the cache. | |
2388 Handle<Map> map = Map::Create(isolate(), number_of_properties); | |
2389 int cache_index = number_of_properties - 1; | 2387 int cache_index = number_of_properties - 1; |
2390 Handle<FixedArray> cache; | 2388 Handle<Object> maybe_cache(is_strong ? context->strong_map_cache() |
2391 if (is_strong) { | 2389 : context->map_cache(), isolate()); |
2392 map->set_is_strong(); | 2390 if (maybe_cache->IsUndefined()) { |
2393 if (context->strong_map_cache()->IsUndefined()) { | 2391 // Allocate the new map cache for the native context. |
2394 // Allocate the new map cache for the native context. | 2392 maybe_cache = NewFixedArray(kMapCacheSize, TENURED); |
2395 Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED); | 2393 if (is_strong) { |
2396 context->set_strong_map_cache(*new_cache); | 2394 context->set_strong_map_cache(*maybe_cache); |
| 2395 } else { |
| 2396 context->set_map_cache(*maybe_cache); |
2397 } | 2397 } |
| 2398 } else { |
2398 // Check to see whether there is a matching element in the cache. | 2399 // Check to see whether there is a matching element in the cache. |
2399 cache = handle(FixedArray::cast(context->strong_map_cache())); | 2400 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
2400 } else { | |
2401 if (context->map_cache()->IsUndefined()) { | |
2402 // Allocate the new map cache for the native context. | |
2403 Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED); | |
2404 context->set_map_cache(*new_cache); | |
2405 } | |
2406 // Check to see whether there is a matching element in the cache. | |
2407 cache = handle(FixedArray::cast(context->map_cache())); | |
2408 } | |
2409 { | |
2410 Object* result = cache->get(cache_index); | 2401 Object* result = cache->get(cache_index); |
2411 if (result->IsWeakCell()) { | 2402 if (result->IsWeakCell()) { |
2412 WeakCell* cell = WeakCell::cast(result); | 2403 WeakCell* cell = WeakCell::cast(result); |
2413 if (!cell->cleared()) { | 2404 if (!cell->cleared()) { |
2414 return handle(Map::cast(cell->value()), isolate()); | 2405 return handle(Map::cast(cell->value()), isolate()); |
2415 } | 2406 } |
2416 } | 2407 } |
2417 } | 2408 } |
| 2409 // Create a new map and add it to the cache. |
| 2410 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
| 2411 Handle<Map> map = Map::Create(isolate(), number_of_properties); |
| 2412 if (is_strong) map->set_is_strong(); |
2418 Handle<WeakCell> cell = NewWeakCell(map); | 2413 Handle<WeakCell> cell = NewWeakCell(map); |
2419 cache->set(cache_index, *cell); | 2414 cache->set(cache_index, *cell); |
2420 return map; | 2415 return map; |
2421 } | 2416 } |
2422 | 2417 |
2423 | 2418 |
2424 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, | 2419 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
2425 JSRegExp::Type type, | 2420 JSRegExp::Type type, |
2426 Handle<String> source, | 2421 Handle<String> source, |
2427 JSRegExp::Flags flags, | 2422 JSRegExp::Flags flags, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 return Handle<Object>::null(); | 2459 return Handle<Object>::null(); |
2465 } | 2460 } |
2466 | 2461 |
2467 | 2462 |
2468 Handle<Object> Factory::ToBoolean(bool value) { | 2463 Handle<Object> Factory::ToBoolean(bool value) { |
2469 return value ? true_value() : false_value(); | 2464 return value ? true_value() : false_value(); |
2470 } | 2465 } |
2471 | 2466 |
2472 | 2467 |
2473 } } // namespace v8::internal | 2468 } } // namespace v8::internal |
OLD | NEW |