Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Side by Side Diff: src/factory.cc

Issue 712943002: MapCache simplification. It is now a FixedArray that maps number of properties to a WeakCell with... (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/factory.h ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/conversions.h" 9 #include "src/conversions.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 for (int i = 0; i < valid_descriptors; i++) { 2413 for (int i = 0; i < valid_descriptors; i++) {
2414 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); 2414 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
2415 JSObject::SetAccessor(result, accessor).Assert(); 2415 JSObject::SetAccessor(result, accessor).Assert();
2416 } 2416 }
2417 2417
2418 DCHECK(result->shared()->IsApiFunction()); 2418 DCHECK(result->shared()->IsApiFunction());
2419 return result; 2419 return result;
2420 } 2420 }
2421 2421
2422 2422
2423 Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
2424 Handle<FixedArray> keys,
2425 Handle<Map> map) {
2426 Handle<MapCache> map_cache = handle(MapCache::cast(context->map_cache()));
2427 Handle<MapCache> result = MapCache::Put(map_cache, keys, map);
2428 context->set_map_cache(*result);
2429 return result;
2430 }
2431
2432
2433 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, 2423 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
2434 Handle<FixedArray> keys) { 2424 int number_of_properties,
2425 bool* is_result_from_cache) {
2426 const int kMapCacheSize = 128;
2427
2428 if (number_of_properties > kMapCacheSize) {
2429 *is_result_from_cache = false;
2430 return Map::Create(isolate(), number_of_properties);
2431 }
2432 *is_result_from_cache = true;
2433 if (number_of_properties == 0) {
2434 // Reuse the initial map of the Object function if the literal has no
2435 // predeclared properties.
2436 return handle(context->object_function()->initial_map(), isolate());
2437 }
2438 int cache_index = number_of_properties - 1;
2435 if (context->map_cache()->IsUndefined()) { 2439 if (context->map_cache()->IsUndefined()) {
2436 // Allocate the new map cache for the native context. 2440 // Allocate the new map cache for the native context.
2437 Handle<MapCache> new_cache = MapCache::New(isolate(), 24); 2441 Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED);
2438 context->set_map_cache(*new_cache); 2442 context->set_map_cache(*new_cache);
2439 } 2443 }
2440 // Check to see whether there is a matching element in the cache. 2444 // Check to see whether there is a matching element in the cache.
2441 Handle<MapCache> cache = 2445 Handle<FixedArray> cache(FixedArray::cast(context->map_cache()));
2442 Handle<MapCache>(MapCache::cast(context->map_cache())); 2446 {
2443 Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); 2447 Object* result = cache->get(cache_index);
2444 if (result->IsMap()) return Handle<Map>::cast(result); 2448 if (result->IsWeakCell()) {
2445 int length = keys->length(); 2449 WeakCell* cell = WeakCell::cast(result);
2446 // Create a new map and add it to the cache. Reuse the initial map of the 2450 if (!cell->cleared()) {
2447 // Object function if the literal has no predeclared properties. 2451 return handle(Map::cast(cell->value()), isolate());
2448 Handle<Map> map = length == 0 2452 }
2449 ? handle(context->object_function()->initial_map()) 2453 }
2450 : Map::Create(isolate(), length); 2454 }
2451 AddToMapCache(context, keys, map); 2455 // Create a new map and add it to the cache.
2456 Handle<Map> map = Map::Create(isolate(), number_of_properties);
2457 Handle<WeakCell> cell = NewWeakCell(map);
2458 cache->set(cache_index, *cell);
2452 return map; 2459 return map;
2453 } 2460 }
2454 2461
2455 2462
2456 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, 2463 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
2457 JSRegExp::Type type, 2464 JSRegExp::Type type,
2458 Handle<String> source, 2465 Handle<String> source,
2459 JSRegExp::Flags flags, 2466 JSRegExp::Flags flags,
2460 Handle<Object> data) { 2467 Handle<Object> data) {
2461 Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize); 2468 Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize);
2462 2469
2463 store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); 2470 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
2464 store->set(JSRegExp::kSourceIndex, *source); 2471 store->set(JSRegExp::kSourceIndex, *source);
2465 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); 2472 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
2466 store->set(JSRegExp::kAtomPatternIndex, *data); 2473 store->set(JSRegExp::kAtomPatternIndex, *data);
2467 regexp->set_data(*store); 2474 regexp->set_data(*store);
2468 } 2475 }
2469 2476
2477
2470 void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp, 2478 void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp,
2471 JSRegExp::Type type, 2479 JSRegExp::Type type,
2472 Handle<String> source, 2480 Handle<String> source,
2473 JSRegExp::Flags flags, 2481 JSRegExp::Flags flags,
2474 int capture_count) { 2482 int capture_count) {
2475 Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize); 2483 Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
2476 Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue); 2484 Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
2477 store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); 2485 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
2478 store->set(JSRegExp::kSourceIndex, *source); 2486 store->set(JSRegExp::kSourceIndex, *source);
2479 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); 2487 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
2480 store->set(JSRegExp::kIrregexpLatin1CodeIndex, uninitialized); 2488 store->set(JSRegExp::kIrregexpLatin1CodeIndex, uninitialized);
2481 store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized); 2489 store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
2482 store->set(JSRegExp::kIrregexpLatin1CodeSavedIndex, uninitialized); 2490 store->set(JSRegExp::kIrregexpLatin1CodeSavedIndex, uninitialized);
2483 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); 2491 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized);
2484 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0)); 2492 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0));
2485 store->set(JSRegExp::kIrregexpCaptureCountIndex, 2493 store->set(JSRegExp::kIrregexpCaptureCountIndex,
2486 Smi::FromInt(capture_count)); 2494 Smi::FromInt(capture_count));
2487 regexp->set_data(*store); 2495 regexp->set_data(*store);
2488 } 2496 }
2489 2497
2490 2498
2491
2492 MaybeHandle<FunctionTemplateInfo> Factory::ConfigureInstance( 2499 MaybeHandle<FunctionTemplateInfo> Factory::ConfigureInstance(
2493 Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance) { 2500 Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance) {
2494 // Configure the instance by adding the properties specified by the 2501 // Configure the instance by adding the properties specified by the
2495 // instance template. 2502 // instance template.
2496 Handle<Object> instance_template(desc->instance_template(), isolate()); 2503 Handle<Object> instance_template(desc->instance_template(), isolate());
2497 if (!instance_template->IsUndefined()) { 2504 if (!instance_template->IsUndefined()) {
2498 RETURN_ON_EXCEPTION( 2505 RETURN_ON_EXCEPTION(
2499 isolate(), 2506 isolate(),
2500 Execution::ConfigureInstance(isolate(), instance, instance_template), 2507 Execution::ConfigureInstance(isolate(), instance, instance_template),
2501 FunctionTemplateInfo); 2508 FunctionTemplateInfo);
2502 } 2509 }
2503 return desc; 2510 return desc;
2504 } 2511 }
2505 2512
2506 2513
2507 Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { 2514 Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
2508 if (String::Equals(name, undefined_string())) return undefined_value(); 2515 if (String::Equals(name, undefined_string())) return undefined_value();
2509 if (String::Equals(name, nan_string())) return nan_value(); 2516 if (String::Equals(name, nan_string())) return nan_value();
2510 if (String::Equals(name, infinity_string())) return infinity_value(); 2517 if (String::Equals(name, infinity_string())) return infinity_value();
2511 return Handle<Object>::null(); 2518 return Handle<Object>::null();
2512 } 2519 }
2513 2520
2514 2521
2515 Handle<Object> Factory::ToBoolean(bool value) { 2522 Handle<Object> Factory::ToBoolean(bool value) {
2516 return value ? true_value() : false_value(); 2523 return value ? true_value() : false_value();
2517 } 2524 }
2518 2525
2519 2526
2520 } } // namespace v8::internal 2527 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698