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 2326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2337 } | 2337 } |
2338 | 2338 |
2339 | 2339 |
2340 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, | 2340 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
2341 int number_of_properties, | 2341 int number_of_properties, |
2342 bool is_strong, | 2342 bool is_strong, |
2343 bool* is_result_from_cache) { | 2343 bool* is_result_from_cache) { |
2344 const int kMapCacheSize = 128; | 2344 const int kMapCacheSize = 128; |
2345 | 2345 |
2346 // We do not cache maps for too many properties or when running builtin code. | 2346 // We do not cache maps for too many properties or when running builtin code. |
2347 // TODO(rossberg): cache strong maps properly | 2347 if (number_of_properties > kMapCacheSize || |
2348 if (number_of_properties > kMapCacheSize || is_strong || | |
2349 isolate()->bootstrapper()->IsActive()) { | 2348 isolate()->bootstrapper()->IsActive()) { |
2350 *is_result_from_cache = false; | 2349 *is_result_from_cache = false; |
2351 Handle<Map> map = Map::Create(isolate(), number_of_properties); | 2350 Handle<Map> map = Map::Create(isolate(), number_of_properties); |
2352 if (is_strong) map->set_is_strong(true); | 2351 if (is_strong) map->set_is_strong(); |
2353 return map; | 2352 return map; |
2354 } | 2353 } |
2355 *is_result_from_cache = true; | 2354 *is_result_from_cache = true; |
2356 if (number_of_properties == 0) { | 2355 if (number_of_properties == 0) { |
2357 // Reuse the initial map of the Object function if the literal has no | 2356 // Reuse the initial map of the Object function if the literal has no |
2358 // predeclared properties. | 2357 // predeclared properties, or the strong map if strong. |
2359 return handle(context->object_function()->initial_map(), isolate()); | 2358 return handle(is_strong |
| 2359 ? context->js_object_strong_map() |
| 2360 : context->object_function()->initial_map(), isolate()); |
2360 } | 2361 } |
| 2362 |
| 2363 // Create a new map and add it to the cache. |
| 2364 Handle<Map> map = Map::Create(isolate(), number_of_properties); |
2361 int cache_index = number_of_properties - 1; | 2365 int cache_index = number_of_properties - 1; |
2362 if (context->map_cache()->IsUndefined()) { | 2366 Handle<FixedArray> cache; |
2363 // Allocate the new map cache for the native context. | 2367 if (is_strong) { |
2364 Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED); | 2368 map->set_is_strong(); |
2365 context->set_map_cache(*new_cache); | 2369 if (context->strong_map_cache()->IsUndefined()) { |
| 2370 // Allocate the new map cache for the native context. |
| 2371 Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED); |
| 2372 context->set_strong_map_cache(*new_cache); |
| 2373 } |
| 2374 // Check to see whether there is a matching element in the cache. |
| 2375 cache = handle(FixedArray::cast(context->strong_map_cache())); |
| 2376 } else { |
| 2377 if (context->map_cache()->IsUndefined()) { |
| 2378 // Allocate the new map cache for the native context. |
| 2379 Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED); |
| 2380 context->set_map_cache(*new_cache); |
| 2381 } |
| 2382 // Check to see whether there is a matching element in the cache. |
| 2383 cache = handle(FixedArray::cast(context->map_cache())); |
2366 } | 2384 } |
2367 // Check to see whether there is a matching element in the cache. | |
2368 Handle<FixedArray> cache(FixedArray::cast(context->map_cache())); | |
2369 { | 2385 { |
2370 Object* result = cache->get(cache_index); | 2386 Object* result = cache->get(cache_index); |
2371 if (result->IsWeakCell()) { | 2387 if (result->IsWeakCell()) { |
2372 WeakCell* cell = WeakCell::cast(result); | 2388 WeakCell* cell = WeakCell::cast(result); |
2373 if (!cell->cleared()) { | 2389 if (!cell->cleared()) { |
2374 return handle(Map::cast(cell->value()), isolate()); | 2390 return handle(Map::cast(cell->value()), isolate()); |
2375 } | 2391 } |
2376 } | 2392 } |
2377 } | 2393 } |
2378 // Create a new map and add it to the cache. | |
2379 Handle<Map> map = Map::Create(isolate(), number_of_properties); | |
2380 Handle<WeakCell> cell = NewWeakCell(map); | 2394 Handle<WeakCell> cell = NewWeakCell(map); |
2381 cache->set(cache_index, *cell); | 2395 cache->set(cache_index, *cell); |
2382 return map; | 2396 return map; |
2383 } | 2397 } |
2384 | 2398 |
2385 | 2399 |
2386 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, | 2400 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
2387 JSRegExp::Type type, | 2401 JSRegExp::Type type, |
2388 Handle<String> source, | 2402 Handle<String> source, |
2389 JSRegExp::Flags flags, | 2403 JSRegExp::Flags flags, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2426 return Handle<Object>::null(); | 2440 return Handle<Object>::null(); |
2427 } | 2441 } |
2428 | 2442 |
2429 | 2443 |
2430 Handle<Object> Factory::ToBoolean(bool value) { | 2444 Handle<Object> Factory::ToBoolean(bool value) { |
2431 return value ? true_value() : false_value(); | 2445 return value ? true_value() : false_value(); |
2432 } | 2446 } |
2433 | 2447 |
2434 | 2448 |
2435 } } // namespace v8::internal | 2449 } } // namespace v8::internal |
OLD | NEW |