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

Side by Side Diff: src/heap.cc

Issue 10837290: Cache results in SearchRegExpMultiple. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Actually set a limit. Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 isolate_->set_context_exit_happened(false); 995 isolate_->set_context_exit_happened(false);
996 } 996 }
997 997
998 998
999 void Heap::MarkCompactPrologue() { 999 void Heap::MarkCompactPrologue() {
1000 // At any old GC clear the keyed lookup cache to enable collection of unused 1000 // At any old GC clear the keyed lookup cache to enable collection of unused
1001 // maps. 1001 // maps.
1002 isolate_->keyed_lookup_cache()->Clear(); 1002 isolate_->keyed_lookup_cache()->Clear();
1003 isolate_->context_slot_cache()->Clear(); 1003 isolate_->context_slot_cache()->Clear();
1004 isolate_->descriptor_lookup_cache()->Clear(); 1004 isolate_->descriptor_lookup_cache()->Clear();
1005 StringSplitCache::Clear(string_split_cache()); 1005 RegExpResultsCache::Clear(string_split_cache());
1006 RegExpResultsCache::Clear(regexp_multiple_cache());
1006 1007
1007 isolate_->compilation_cache()->MarkCompactPrologue(); 1008 isolate_->compilation_cache()->MarkCompactPrologue();
1008 1009
1009 CompletelyClearInstanceofCache(); 1010 CompletelyClearInstanceofCache();
1010 1011
1011 FlushNumberStringCache(); 1012 FlushNumberStringCache();
1012 if (FLAG_cleanup_code_caches_at_gc) { 1013 if (FLAG_cleanup_code_caches_at_gc) {
1013 polymorphic_code_cache()->set_cache(undefined_value()); 1014 polymorphic_code_cache()->set_cache(undefined_value());
1014 } 1015 }
1015 1016
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 set_number_string_cache(FixedArray::cast(obj)); 2751 set_number_string_cache(FixedArray::cast(obj));
2751 2752
2752 // Allocate cache for single character ASCII strings. 2753 // Allocate cache for single character ASCII strings.
2753 { MaybeObject* maybe_obj = 2754 { MaybeObject* maybe_obj =
2754 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); 2755 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
2755 if (!maybe_obj->ToObject(&obj)) return false; 2756 if (!maybe_obj->ToObject(&obj)) return false;
2756 } 2757 }
2757 set_single_character_string_cache(FixedArray::cast(obj)); 2758 set_single_character_string_cache(FixedArray::cast(obj));
2758 2759
2759 // Allocate cache for string split. 2760 // Allocate cache for string split.
2760 { MaybeObject* maybe_obj = 2761 { MaybeObject* maybe_obj = AllocateFixedArray(
2761 AllocateFixedArray(StringSplitCache::kStringSplitCacheSize, TENURED); 2762 RegExpResultsCache::kRegExpResultsCacheSize, TENURED);
2762 if (!maybe_obj->ToObject(&obj)) return false; 2763 if (!maybe_obj->ToObject(&obj)) return false;
2763 } 2764 }
2764 set_string_split_cache(FixedArray::cast(obj)); 2765 set_string_split_cache(FixedArray::cast(obj));
2765 2766
2767 { MaybeObject* maybe_obj = AllocateFixedArray(
2768 RegExpResultsCache::kRegExpResultsCacheSize, TENURED);
2769 if (!maybe_obj->ToObject(&obj)) return false;
2770 }
2771 set_regexp_multiple_cache(FixedArray::cast(obj));
2772
2766 // Allocate cache for external strings pointing to native source code. 2773 // Allocate cache for external strings pointing to native source code.
2767 { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount()); 2774 { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount());
2768 if (!maybe_obj->ToObject(&obj)) return false; 2775 if (!maybe_obj->ToObject(&obj)) return false;
2769 } 2776 }
2770 set_natives_source_cache(FixedArray::cast(obj)); 2777 set_natives_source_cache(FixedArray::cast(obj));
2771 2778
2772 // Handling of script id generation is in FACTORY->NewScript. 2779 // Handling of script id generation is in FACTORY->NewScript.
2773 set_last_script_id(undefined_value()); 2780 set_last_script_id(undefined_value());
2774 2781
2775 // Initialize keyed lookup cache. 2782 // Initialize keyed lookup cache.
2776 isolate_->keyed_lookup_cache()->Clear(); 2783 isolate_->keyed_lookup_cache()->Clear();
2777 2784
2778 // Initialize context slot cache. 2785 // Initialize context slot cache.
2779 isolate_->context_slot_cache()->Clear(); 2786 isolate_->context_slot_cache()->Clear();
2780 2787
2781 // Initialize descriptor cache. 2788 // Initialize descriptor cache.
2782 isolate_->descriptor_lookup_cache()->Clear(); 2789 isolate_->descriptor_lookup_cache()->Clear();
2783 2790
2784 // Initialize compilation cache. 2791 // Initialize compilation cache.
2785 isolate_->compilation_cache()->Clear(); 2792 isolate_->compilation_cache()->Clear();
2786 2793
2787 return true; 2794 return true;
2788 } 2795 }
2789 2796
2790 2797
2791 Object* StringSplitCache::Lookup( 2798 Object* RegExpResultsCache::Lookup(
2792 FixedArray* cache, String* string, String* pattern) { 2799 FixedArray* cache, String* string, Object* pattern) {
2793 if (!string->IsSymbol() || !pattern->IsSymbol()) return Smi::FromInt(0); 2800 if (!string->IsSymbol() || (pattern->IsString() && !pattern->IsSymbol())) {
2801 return Smi::FromInt(0);
2802 }
2794 uint32_t hash = string->Hash(); 2803 uint32_t hash = string->Hash();
2795 uint32_t index = ((hash & (kStringSplitCacheSize - 1)) & 2804 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
2796 ~(kArrayEntriesPerCacheEntry - 1)); 2805 ~(kArrayEntriesPerCacheEntry - 1));
2797 if (cache->get(index + kStringOffset) == string && 2806 if (cache->get(index + kStringOffset) == string &&
2798 cache->get(index + kPatternOffset) == pattern) { 2807 cache->get(index + kPatternOffset) == pattern) {
2799 return cache->get(index + kArrayOffset); 2808 return cache->get(index + kArrayOffset);
2800 } 2809 }
2801 index = ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1)); 2810 index =
2811 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1));
2802 if (cache->get(index + kStringOffset) == string && 2812 if (cache->get(index + kStringOffset) == string &&
2803 cache->get(index + kPatternOffset) == pattern) { 2813 cache->get(index + kPatternOffset) == pattern) {
2804 return cache->get(index + kArrayOffset); 2814 return cache->get(index + kArrayOffset);
2805 } 2815 }
2806 return Smi::FromInt(0); 2816 return Smi::FromInt(0);
2807 } 2817 }
2808 2818
2809 2819
2810 void StringSplitCache::Enter(Heap* heap, 2820 void RegExpResultsCache::Enter(Heap* heap,
2811 FixedArray* cache, 2821 FixedArray* cache,
2812 String* string, 2822 String* string,
2813 String* pattern, 2823 Object* pattern,
2814 FixedArray* array) { 2824 FixedArray* array) {
2815 if (!string->IsSymbol() || !pattern->IsSymbol()) return; 2825 if (!string->IsSymbol() || (pattern->IsString() && !pattern->IsSymbol())) {
2826 return;
2827 }
2816 uint32_t hash = string->Hash(); 2828 uint32_t hash = string->Hash();
2817 uint32_t index = ((hash & (kStringSplitCacheSize - 1)) & 2829 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
2818 ~(kArrayEntriesPerCacheEntry - 1)); 2830 ~(kArrayEntriesPerCacheEntry - 1));
2819 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { 2831 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) {
2820 cache->set(index + kStringOffset, string); 2832 cache->set(index + kStringOffset, string);
2821 cache->set(index + kPatternOffset, pattern); 2833 cache->set(index + kPatternOffset, pattern);
2822 cache->set(index + kArrayOffset, array); 2834 cache->set(index + kArrayOffset, array);
2823 } else { 2835 } else {
2824 uint32_t index2 = 2836 uint32_t index2 =
2825 ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1)); 2837 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1));
2826 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { 2838 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) {
2827 cache->set(index2 + kStringOffset, string); 2839 cache->set(index2 + kStringOffset, string);
2828 cache->set(index2 + kPatternOffset, pattern); 2840 cache->set(index2 + kPatternOffset, pattern);
2829 cache->set(index2 + kArrayOffset, array); 2841 cache->set(index2 + kArrayOffset, array);
2830 } else { 2842 } else {
2831 cache->set(index2 + kStringOffset, Smi::FromInt(0)); 2843 cache->set(index2 + kStringOffset, Smi::FromInt(0));
2832 cache->set(index2 + kPatternOffset, Smi::FromInt(0)); 2844 cache->set(index2 + kPatternOffset, Smi::FromInt(0));
2833 cache->set(index2 + kArrayOffset, Smi::FromInt(0)); 2845 cache->set(index2 + kArrayOffset, Smi::FromInt(0));
2834 cache->set(index + kStringOffset, string); 2846 cache->set(index + kStringOffset, string);
2835 cache->set(index + kPatternOffset, pattern); 2847 cache->set(index + kPatternOffset, pattern);
2836 cache->set(index + kArrayOffset, array); 2848 cache->set(index + kArrayOffset, array);
2837 } 2849 }
2838 } 2850 }
2839 if (array->length() < 100) { // Limit how many new symbols we want to make. 2851 if (pattern->IsString() && array->length() < 100) {
2852 // Limit how many new symbols we want to make, when used on a list only
2853 // consisting of strings.
2840 for (int i = 0; i < array->length(); i++) { 2854 for (int i = 0; i < array->length(); i++) {
2841 String* str = String::cast(array->get(i)); 2855 String* str = String::cast(array->get(i));
2842 Object* symbol; 2856 Object* symbol;
2843 MaybeObject* maybe_symbol = heap->LookupSymbol(str); 2857 MaybeObject* maybe_symbol = heap->LookupSymbol(str);
2844 if (maybe_symbol->ToObject(&symbol)) { 2858 if (maybe_symbol->ToObject(&symbol)) {
2845 array->set(i, symbol); 2859 array->set(i, symbol);
2846 } 2860 }
2847 } 2861 }
2848 } 2862 }
2849 array->set_map_no_write_barrier(heap->fixed_cow_array_map()); 2863 array->set_map_no_write_barrier(heap->fixed_cow_array_map());
2850 } 2864 }
2851 2865
2852 2866
2853 void StringSplitCache::Clear(FixedArray* cache) { 2867 void RegExpResultsCache::Clear(FixedArray* cache) {
2854 for (int i = 0; i < kStringSplitCacheSize; i++) { 2868 for (int i = 0; i < kRegExpResultsCacheSize; i++) {
2855 cache->set(i, Smi::FromInt(0)); 2869 cache->set(i, Smi::FromInt(0));
2856 } 2870 }
2857 } 2871 }
2858 2872
2859 2873
2860 MaybeObject* Heap::AllocateInitialNumberStringCache() { 2874 MaybeObject* Heap::AllocateInitialNumberStringCache() {
2861 MaybeObject* maybe_obj = 2875 MaybeObject* maybe_obj =
2862 AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED); 2876 AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED);
2863 return maybe_obj; 2877 return maybe_obj;
2864 } 2878 }
(...skipping 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after
7262 static_cast<int>(object_sizes_last_time_[index])); 7276 static_cast<int>(object_sizes_last_time_[index]));
7263 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7277 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7264 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7278 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7265 7279
7266 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7280 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7267 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7281 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7268 ClearObjectStats(); 7282 ClearObjectStats();
7269 } 7283 }
7270 7284
7271 } } // namespace v8::internal 7285 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698