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

Side by Side Diff: src/heap/heap.cc

Issue 1306053003: [heap] Move RegExpResultCache out of the heap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « src/heap/heap.h ('k') | src/regexp/jsregexp.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/heap/heap.h" 5 #include "src/heap/heap.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 3408 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 } 3419 }
3420 } 3420 }
3421 3421
3422 3422
3423 bool Heap::RootCanBeTreatedAsConstant(RootListIndex root_index) { 3423 bool Heap::RootCanBeTreatedAsConstant(RootListIndex root_index) {
3424 return !RootCanBeWrittenAfterInitialization(root_index) && 3424 return !RootCanBeWrittenAfterInitialization(root_index) &&
3425 !InNewSpace(roots_array_start()[root_index]); 3425 !InNewSpace(roots_array_start()[root_index]);
3426 } 3426 }
3427 3427
3428 3428
3429 Object* RegExpResultsCache::Lookup(Heap* heap, String* key_string,
3430 Object* key_pattern, ResultsCacheType type) {
3431 FixedArray* cache;
3432 if (!key_string->IsInternalizedString()) return Smi::FromInt(0);
3433 if (type == STRING_SPLIT_SUBSTRINGS) {
3434 DCHECK(key_pattern->IsString());
3435 if (!key_pattern->IsInternalizedString()) return Smi::FromInt(0);
3436 cache = heap->string_split_cache();
3437 } else {
3438 DCHECK(type == REGEXP_MULTIPLE_INDICES);
3439 DCHECK(key_pattern->IsFixedArray());
3440 cache = heap->regexp_multiple_cache();
3441 }
3442
3443 uint32_t hash = key_string->Hash();
3444 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
3445 ~(kArrayEntriesPerCacheEntry - 1));
3446 if (cache->get(index + kStringOffset) == key_string &&
3447 cache->get(index + kPatternOffset) == key_pattern) {
3448 return cache->get(index + kArrayOffset);
3449 }
3450 index =
3451 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1));
3452 if (cache->get(index + kStringOffset) == key_string &&
3453 cache->get(index + kPatternOffset) == key_pattern) {
3454 return cache->get(index + kArrayOffset);
3455 }
3456 return Smi::FromInt(0);
3457 }
3458
3459
3460 void RegExpResultsCache::Enter(Isolate* isolate, Handle<String> key_string,
3461 Handle<Object> key_pattern,
3462 Handle<FixedArray> value_array,
3463 ResultsCacheType type) {
3464 Factory* factory = isolate->factory();
3465 Handle<FixedArray> cache;
3466 if (!key_string->IsInternalizedString()) return;
3467 if (type == STRING_SPLIT_SUBSTRINGS) {
3468 DCHECK(key_pattern->IsString());
3469 if (!key_pattern->IsInternalizedString()) return;
3470 cache = factory->string_split_cache();
3471 } else {
3472 DCHECK(type == REGEXP_MULTIPLE_INDICES);
3473 DCHECK(key_pattern->IsFixedArray());
3474 cache = factory->regexp_multiple_cache();
3475 }
3476
3477 uint32_t hash = key_string->Hash();
3478 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
3479 ~(kArrayEntriesPerCacheEntry - 1));
3480 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) {
3481 cache->set(index + kStringOffset, *key_string);
3482 cache->set(index + kPatternOffset, *key_pattern);
3483 cache->set(index + kArrayOffset, *value_array);
3484 } else {
3485 uint32_t index2 =
3486 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1));
3487 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) {
3488 cache->set(index2 + kStringOffset, *key_string);
3489 cache->set(index2 + kPatternOffset, *key_pattern);
3490 cache->set(index2 + kArrayOffset, *value_array);
3491 } else {
3492 cache->set(index2 + kStringOffset, Smi::FromInt(0));
3493 cache->set(index2 + kPatternOffset, Smi::FromInt(0));
3494 cache->set(index2 + kArrayOffset, Smi::FromInt(0));
3495 cache->set(index + kStringOffset, *key_string);
3496 cache->set(index + kPatternOffset, *key_pattern);
3497 cache->set(index + kArrayOffset, *value_array);
3498 }
3499 }
3500 // If the array is a reasonably short list of substrings, convert it into a
3501 // list of internalized strings.
3502 if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) {
3503 for (int i = 0; i < value_array->length(); i++) {
3504 Handle<String> str(String::cast(value_array->get(i)), isolate);
3505 Handle<String> internalized_str = factory->InternalizeString(str);
3506 value_array->set(i, *internalized_str);
3507 }
3508 }
3509 // Convert backing store to a copy-on-write array.
3510 value_array->set_map_no_write_barrier(*factory->fixed_cow_array_map());
3511 }
3512
3513
3514 void RegExpResultsCache::Clear(FixedArray* cache) {
3515 for (int i = 0; i < kRegExpResultsCacheSize; i++) {
3516 cache->set(i, Smi::FromInt(0));
3517 }
3518 }
3519
3520
3521 int Heap::FullSizeNumberStringCacheLength() { 3429 int Heap::FullSizeNumberStringCacheLength() {
3522 // Compute the size of the number string cache based on the max newspace size. 3430 // Compute the size of the number string cache based on the max newspace size.
3523 // The number string cache has a minimum size based on twice the initial cache 3431 // The number string cache has a minimum size based on twice the initial cache
3524 // size to ensure that it is bigger after being made 'full size'. 3432 // size to ensure that it is bigger after being made 'full size'.
3525 int number_string_cache_size = max_semi_space_size_ / 512; 3433 int number_string_cache_size = max_semi_space_size_ / 512;
3526 number_string_cache_size = Max(kInitialNumberStringCacheSize * 2, 3434 number_string_cache_size = Max(kInitialNumberStringCacheSize * 2,
3527 Min(0x4000, number_string_cache_size)); 3435 Min(0x4000, number_string_cache_size));
3528 // There is a string and a number per entry so the length is twice the number 3436 // There is a string and a number per entry so the length is twice the number
3529 // of entries. 3437 // of entries.
3530 return number_string_cache_size * 2; 3438 return number_string_cache_size * 2;
(...skipping 3346 matching lines...) Expand 10 before | Expand all | Expand 10 after
6877 *object_type = "CODE_TYPE"; \ 6785 *object_type = "CODE_TYPE"; \
6878 *object_sub_type = "CODE_AGE/" #name; \ 6786 *object_sub_type = "CODE_AGE/" #name; \
6879 return true; 6787 return true;
6880 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) 6788 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME)
6881 #undef COMPARE_AND_RETURN_NAME 6789 #undef COMPARE_AND_RETURN_NAME
6882 } 6790 }
6883 return false; 6791 return false;
6884 } 6792 }
6885 } // namespace internal 6793 } // namespace internal
6886 } // namespace v8 6794 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/regexp/jsregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698