| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(Heap* heap, |
| 2792 FixedArray* cache, String* string, String* pattern) { | 2799 String* key_string, |
| 2793 if (!string->IsSymbol() || !pattern->IsSymbol()) return Smi::FromInt(0); | 2800 Object* key_pattern, |
| 2794 uint32_t hash = string->Hash(); | 2801 ResultsCacheType type) { |
| 2795 uint32_t index = ((hash & (kStringSplitCacheSize - 1)) & | 2802 FixedArray* cache; |
| 2803 if (!key_string->IsSymbol()) return Smi::FromInt(0); |
| 2804 if (type == STRING_SPLIT_SUBSTRINGS) { |
| 2805 ASSERT(key_pattern->IsString()); |
| 2806 if (!key_pattern->IsSymbol()) return Smi::FromInt(0); |
| 2807 cache = heap->string_split_cache(); |
| 2808 } else { |
| 2809 ASSERT(type == REGEXP_MULTIPLE_INDICES); |
| 2810 ASSERT(key_pattern->IsFixedArray()); |
| 2811 cache = heap->regexp_multiple_cache(); |
| 2812 } |
| 2813 |
| 2814 uint32_t hash = key_string->Hash(); |
| 2815 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
| 2796 ~(kArrayEntriesPerCacheEntry - 1)); | 2816 ~(kArrayEntriesPerCacheEntry - 1)); |
| 2797 if (cache->get(index + kStringOffset) == string && | 2817 if (cache->get(index + kStringOffset) == key_string && |
| 2798 cache->get(index + kPatternOffset) == pattern) { | 2818 cache->get(index + kPatternOffset) == key_pattern) { |
| 2799 return cache->get(index + kArrayOffset); | 2819 return cache->get(index + kArrayOffset); |
| 2800 } | 2820 } |
| 2801 index = ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1)); | 2821 index = |
| 2802 if (cache->get(index + kStringOffset) == string && | 2822 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
| 2803 cache->get(index + kPatternOffset) == pattern) { | 2823 if (cache->get(index + kStringOffset) == key_string && |
| 2824 cache->get(index + kPatternOffset) == key_pattern) { |
| 2804 return cache->get(index + kArrayOffset); | 2825 return cache->get(index + kArrayOffset); |
| 2805 } | 2826 } |
| 2806 return Smi::FromInt(0); | 2827 return Smi::FromInt(0); |
| 2807 } | 2828 } |
| 2808 | 2829 |
| 2809 | 2830 |
| 2810 void StringSplitCache::Enter(Heap* heap, | 2831 void RegExpResultsCache::Enter(Heap* heap, |
| 2811 FixedArray* cache, | 2832 String* key_string, |
| 2812 String* string, | 2833 Object* key_pattern, |
| 2813 String* pattern, | 2834 FixedArray* value_array, |
| 2814 FixedArray* array) { | 2835 ResultsCacheType type) { |
| 2815 if (!string->IsSymbol() || !pattern->IsSymbol()) return; | 2836 FixedArray* cache; |
| 2816 uint32_t hash = string->Hash(); | 2837 if (!key_string->IsSymbol()) return; |
| 2817 uint32_t index = ((hash & (kStringSplitCacheSize - 1)) & | 2838 if (type == STRING_SPLIT_SUBSTRINGS) { |
| 2839 ASSERT(key_pattern->IsString()); |
| 2840 if (!key_pattern->IsSymbol()) return; |
| 2841 cache = heap->string_split_cache(); |
| 2842 } else { |
| 2843 ASSERT(type == REGEXP_MULTIPLE_INDICES); |
| 2844 ASSERT(key_pattern->IsFixedArray()); |
| 2845 cache = heap->regexp_multiple_cache(); |
| 2846 } |
| 2847 |
| 2848 uint32_t hash = key_string->Hash(); |
| 2849 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
| 2818 ~(kArrayEntriesPerCacheEntry - 1)); | 2850 ~(kArrayEntriesPerCacheEntry - 1)); |
| 2819 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { | 2851 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { |
| 2820 cache->set(index + kStringOffset, string); | 2852 cache->set(index + kStringOffset, key_string); |
| 2821 cache->set(index + kPatternOffset, pattern); | 2853 cache->set(index + kPatternOffset, key_pattern); |
| 2822 cache->set(index + kArrayOffset, array); | 2854 cache->set(index + kArrayOffset, value_array); |
| 2823 } else { | 2855 } else { |
| 2824 uint32_t index2 = | 2856 uint32_t index2 = |
| 2825 ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1)); | 2857 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
| 2826 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { | 2858 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { |
| 2827 cache->set(index2 + kStringOffset, string); | 2859 cache->set(index2 + kStringOffset, key_string); |
| 2828 cache->set(index2 + kPatternOffset, pattern); | 2860 cache->set(index2 + kPatternOffset, key_pattern); |
| 2829 cache->set(index2 + kArrayOffset, array); | 2861 cache->set(index2 + kArrayOffset, value_array); |
| 2830 } else { | 2862 } else { |
| 2831 cache->set(index2 + kStringOffset, Smi::FromInt(0)); | 2863 cache->set(index2 + kStringOffset, Smi::FromInt(0)); |
| 2832 cache->set(index2 + kPatternOffset, Smi::FromInt(0)); | 2864 cache->set(index2 + kPatternOffset, Smi::FromInt(0)); |
| 2833 cache->set(index2 + kArrayOffset, Smi::FromInt(0)); | 2865 cache->set(index2 + kArrayOffset, Smi::FromInt(0)); |
| 2834 cache->set(index + kStringOffset, string); | 2866 cache->set(index + kStringOffset, key_string); |
| 2835 cache->set(index + kPatternOffset, pattern); | 2867 cache->set(index + kPatternOffset, key_pattern); |
| 2836 cache->set(index + kArrayOffset, array); | 2868 cache->set(index + kArrayOffset, value_array); |
| 2837 } | 2869 } |
| 2838 } | 2870 } |
| 2839 if (array->length() < 100) { // Limit how many new symbols we want to make. | 2871 // If the array is a reasonably short list of substrings, convert it into a |
| 2840 for (int i = 0; i < array->length(); i++) { | 2872 // list of symbols. |
| 2841 String* str = String::cast(array->get(i)); | 2873 if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) { |
| 2874 for (int i = 0; i < value_array->length(); i++) { |
| 2875 String* str = String::cast(value_array->get(i)); |
| 2842 Object* symbol; | 2876 Object* symbol; |
| 2843 MaybeObject* maybe_symbol = heap->LookupSymbol(str); | 2877 MaybeObject* maybe_symbol = heap->LookupSymbol(str); |
| 2844 if (maybe_symbol->ToObject(&symbol)) { | 2878 if (maybe_symbol->ToObject(&symbol)) { |
| 2845 array->set(i, symbol); | 2879 value_array->set(i, symbol); |
| 2846 } | 2880 } |
| 2847 } | 2881 } |
| 2848 } | 2882 } |
| 2849 array->set_map_no_write_barrier(heap->fixed_cow_array_map()); | 2883 // Convert backing store to a copy-on-write array. |
| 2884 value_array->set_map_no_write_barrier(heap->fixed_cow_array_map()); |
| 2850 } | 2885 } |
| 2851 | 2886 |
| 2852 | 2887 |
| 2853 void StringSplitCache::Clear(FixedArray* cache) { | 2888 void RegExpResultsCache::Clear(FixedArray* cache) { |
| 2854 for (int i = 0; i < kStringSplitCacheSize; i++) { | 2889 for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
| 2855 cache->set(i, Smi::FromInt(0)); | 2890 cache->set(i, Smi::FromInt(0)); |
| 2856 } | 2891 } |
| 2857 } | 2892 } |
| 2858 | 2893 |
| 2859 | 2894 |
| 2860 MaybeObject* Heap::AllocateInitialNumberStringCache() { | 2895 MaybeObject* Heap::AllocateInitialNumberStringCache() { |
| 2861 MaybeObject* maybe_obj = | 2896 MaybeObject* maybe_obj = |
| 2862 AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED); | 2897 AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED); |
| 2863 return maybe_obj; | 2898 return maybe_obj; |
| 2864 } | 2899 } |
| (...skipping 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7262 static_cast<int>(object_sizes_last_time_[index])); | 7297 static_cast<int>(object_sizes_last_time_[index])); |
| 7263 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7298 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7264 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7299 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7265 | 7300 |
| 7266 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7301 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7267 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7302 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7268 ClearObjectStats(); | 7303 ClearObjectStats(); |
| 7269 } | 7304 } |
| 7270 | 7305 |
| 7271 } } // namespace v8::internal | 7306 } } // namespace v8::internal |
| OLD | NEW |