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

Side by Side Diff: src/objects.cc

Issue 675013004: Changing the aging mechanism for script and eval caches. (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/objects.h ('k') | test/cctest/test-heap.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 <sstream> 5 #include <sstream>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/allocation-site-scopes.h" 10 #include "src/allocation-site-scopes.h"
(...skipping 13625 matching lines...) Expand 10 before | Expand all | Expand 10 after
13636 Handle<SharedFunctionInfo> shared, 13636 Handle<SharedFunctionInfo> shared,
13637 StrictMode strict_mode, 13637 StrictMode strict_mode,
13638 int scope_position) 13638 int scope_position)
13639 : source_(source), 13639 : source_(source),
13640 shared_(shared), 13640 shared_(shared),
13641 strict_mode_(strict_mode), 13641 strict_mode_(strict_mode),
13642 scope_position_(scope_position) { } 13642 scope_position_(scope_position) { }
13643 13643
13644 bool IsMatch(Object* other) OVERRIDE { 13644 bool IsMatch(Object* other) OVERRIDE {
13645 DisallowHeapAllocation no_allocation; 13645 DisallowHeapAllocation no_allocation;
13646 if (!other->IsFixedArray()) return false; 13646 if (!other->IsFixedArray()) {
13647 if (!other->IsNumber()) return false;
13648 uint32_t other_hash = static_cast<uint32_t>(other->Number());
13649 return Hash() == other_hash;
13650 }
13647 FixedArray* other_array = FixedArray::cast(other); 13651 FixedArray* other_array = FixedArray::cast(other);
13648 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); 13652 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0));
13649 if (shared != *shared_) return false; 13653 if (shared != *shared_) return false;
13650 int strict_unchecked = Smi::cast(other_array->get(2))->value(); 13654 int strict_unchecked = Smi::cast(other_array->get(2))->value();
13651 DCHECK(strict_unchecked == SLOPPY || strict_unchecked == STRICT); 13655 DCHECK(strict_unchecked == SLOPPY || strict_unchecked == STRICT);
13652 StrictMode strict_mode = static_cast<StrictMode>(strict_unchecked); 13656 StrictMode strict_mode = static_cast<StrictMode>(strict_unchecked);
13653 if (strict_mode != strict_mode_) return false; 13657 if (strict_mode != strict_mode_) return false;
13654 int scope_position = Smi::cast(other_array->get(3))->value(); 13658 int scope_position = Smi::cast(other_array->get(3))->value();
13655 if (scope_position != scope_position_) return false; 13659 if (scope_position != scope_position_) return false;
13656 String* source = String::cast(other_array->get(1)); 13660 String* source = String::cast(other_array->get(1));
(...skipping 19 matching lines...) Expand all
13676 return hash; 13680 return hash;
13677 } 13681 }
13678 13682
13679 uint32_t Hash() OVERRIDE { 13683 uint32_t Hash() OVERRIDE {
13680 return StringSharedHashHelper(*source_, *shared_, strict_mode_, 13684 return StringSharedHashHelper(*source_, *shared_, strict_mode_,
13681 scope_position_); 13685 scope_position_);
13682 } 13686 }
13683 13687
13684 uint32_t HashForObject(Object* obj) OVERRIDE { 13688 uint32_t HashForObject(Object* obj) OVERRIDE {
13685 DisallowHeapAllocation no_allocation; 13689 DisallowHeapAllocation no_allocation;
13690 if (obj->IsNumber()) {
13691 return static_cast<uint32_t>(obj->Number());
13692 }
13686 FixedArray* other_array = FixedArray::cast(obj); 13693 FixedArray* other_array = FixedArray::cast(obj);
13687 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); 13694 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0));
13688 String* source = String::cast(other_array->get(1)); 13695 String* source = String::cast(other_array->get(1));
13689 int strict_unchecked = Smi::cast(other_array->get(2))->value(); 13696 int strict_unchecked = Smi::cast(other_array->get(2))->value();
13690 DCHECK(strict_unchecked == SLOPPY || strict_unchecked == STRICT); 13697 DCHECK(strict_unchecked == SLOPPY || strict_unchecked == STRICT);
13691 StrictMode strict_mode = static_cast<StrictMode>(strict_unchecked); 13698 StrictMode strict_mode = static_cast<StrictMode>(strict_unchecked);
13692 int scope_position = Smi::cast(other_array->get(3))->value(); 13699 int scope_position = Smi::cast(other_array->get(3))->value();
13693 return StringSharedHashHelper( 13700 return StringSharedHashHelper(
13694 source, shared, strict_mode, scope_position); 13701 source, shared, strict_mode, scope_position);
13695 } 13702 }
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
14834 14841
14835 14842
14836 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, 14843 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src,
14837 Handle<Context> context) { 14844 Handle<Context> context) {
14838 Isolate* isolate = GetIsolate(); 14845 Isolate* isolate = GetIsolate();
14839 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 14846 Handle<SharedFunctionInfo> shared(context->closure()->shared());
14840 StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY, 14847 StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY,
14841 RelocInfo::kNoPosition); 14848 RelocInfo::kNoPosition);
14842 int entry = FindEntry(&key); 14849 int entry = FindEntry(&key);
14843 if (entry == kNotFound) return isolate->factory()->undefined_value(); 14850 if (entry == kNotFound) return isolate->factory()->undefined_value();
14844 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); 14851 int index = EntryToIndex(entry);
14852 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value();
14853 return Handle<Object>(get(index + 1), isolate);
14845 } 14854 }
14846 14855
14847 14856
14848 Handle<Object> CompilationCacheTable::LookupEval( 14857 Handle<Object> CompilationCacheTable::LookupEval(
14849 Handle<String> src, Handle<SharedFunctionInfo> outer_info, 14858 Handle<String> src, Handle<SharedFunctionInfo> outer_info,
14850 StrictMode strict_mode, int scope_position) { 14859 StrictMode strict_mode, int scope_position) {
14851 Isolate* isolate = GetIsolate(); 14860 Isolate* isolate = GetIsolate();
14852 // Cache key is the tuple (source, outer shared function info, scope position) 14861 // Cache key is the tuple (source, outer shared function info, scope position)
14853 // to unambiguously identify the context chain the cached eval code assumes. 14862 // to unambiguously identify the context chain the cached eval code assumes.
14854 StringSharedKey key(src, outer_info, strict_mode, scope_position); 14863 StringSharedKey key(src, outer_info, strict_mode, scope_position);
14855 int entry = FindEntry(&key); 14864 int entry = FindEntry(&key);
14856 if (entry == kNotFound) return isolate->factory()->undefined_value(); 14865 if (entry == kNotFound) return isolate->factory()->undefined_value();
14866 int index = EntryToIndex(entry);
14867 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value();
14857 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); 14868 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate);
14858 } 14869 }
14859 14870
14860 14871
14861 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, 14872 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src,
14862 JSRegExp::Flags flags) { 14873 JSRegExp::Flags flags) {
14863 Isolate* isolate = GetIsolate(); 14874 Isolate* isolate = GetIsolate();
14864 DisallowHeapAllocation no_allocation; 14875 DisallowHeapAllocation no_allocation;
14865 RegExpKey key(src, flags); 14876 RegExpKey key(src, flags);
14866 int entry = FindEntry(&key); 14877 int entry = FindEntry(&key);
14867 if (entry == kNotFound) return isolate->factory()->undefined_value(); 14878 if (entry == kNotFound) return isolate->factory()->undefined_value();
14868 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); 14879 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate);
14869 } 14880 }
14870 14881
14871 14882
14872 Handle<CompilationCacheTable> CompilationCacheTable::Put( 14883 Handle<CompilationCacheTable> CompilationCacheTable::Put(
14873 Handle<CompilationCacheTable> cache, Handle<String> src, 14884 Handle<CompilationCacheTable> cache, Handle<String> src,
14874 Handle<Context> context, Handle<Object> value) { 14885 Handle<Context> context, Handle<Object> value) {
14875 Isolate* isolate = cache->GetIsolate(); 14886 Isolate* isolate = cache->GetIsolate();
14876 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 14887 Handle<SharedFunctionInfo> shared(context->closure()->shared());
14877 StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY, 14888 StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY,
14878 RelocInfo::kNoPosition); 14889 RelocInfo::kNoPosition);
14890 int entry = cache->FindEntry(&key);
14891 if (entry != kNotFound) {
14892 Handle<Object> k = key.AsHandle(isolate);
14893 cache->set(EntryToIndex(entry), *k);
14894 cache->set(EntryToIndex(entry) + 1, *value);
14895 return cache;
14896 }
14897
14879 cache = EnsureCapacity(cache, 1, &key); 14898 cache = EnsureCapacity(cache, 1, &key);
14880 Handle<Object> k = key.AsHandle(isolate); 14899 entry = cache->FindInsertionEntry(key.Hash());
14881 int entry = cache->FindInsertionEntry(key.Hash()); 14900 Handle<Object> k =
14901 isolate->factory()->NewNumber(static_cast<double>(key.Hash()));
14882 cache->set(EntryToIndex(entry), *k); 14902 cache->set(EntryToIndex(entry), *k);
14883 cache->set(EntryToIndex(entry) + 1, *value); 14903 cache->set(EntryToIndex(entry) + 1, Smi::FromInt(kHashGenerations));
14884 cache->ElementAdded(); 14904 cache->ElementAdded();
14885 return cache; 14905 return cache;
14886 } 14906 }
14887 14907
14888 14908
14889 Handle<CompilationCacheTable> CompilationCacheTable::PutEval( 14909 Handle<CompilationCacheTable> CompilationCacheTable::PutEval(
14890 Handle<CompilationCacheTable> cache, Handle<String> src, 14910 Handle<CompilationCacheTable> cache, Handle<String> src,
14891 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value, 14911 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value,
14892 int scope_position) { 14912 int scope_position) {
14893 Isolate* isolate = cache->GetIsolate(); 14913 Isolate* isolate = cache->GetIsolate();
14894 StringSharedKey key(src, outer_info, value->strict_mode(), scope_position); 14914 StringSharedKey key(src, outer_info, value->strict_mode(), scope_position);
14915 int entry = cache->FindEntry(&key);
14916 if (entry != kNotFound) {
14917 Handle<Object> k = key.AsHandle(isolate);
14918 cache->set(EntryToIndex(entry), *k);
14919 cache->set(EntryToIndex(entry) + 1, *value);
14920 return cache;
14921 }
14922
14895 cache = EnsureCapacity(cache, 1, &key); 14923 cache = EnsureCapacity(cache, 1, &key);
14896 Handle<Object> k = key.AsHandle(isolate); 14924 entry = cache->FindInsertionEntry(key.Hash());
14897 int entry = cache->FindInsertionEntry(key.Hash()); 14925 Handle<Object> k =
14926 isolate->factory()->NewNumber(static_cast<double>(key.Hash()));
14898 cache->set(EntryToIndex(entry), *k); 14927 cache->set(EntryToIndex(entry), *k);
14899 cache->set(EntryToIndex(entry) + 1, *value); 14928 cache->set(EntryToIndex(entry) + 1, Smi::FromInt(kHashGenerations));
14900 cache->ElementAdded(); 14929 cache->ElementAdded();
14901 return cache; 14930 return cache;
14902 } 14931 }
14903 14932
14904 14933
14905 Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp( 14934 Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
14906 Handle<CompilationCacheTable> cache, Handle<String> src, 14935 Handle<CompilationCacheTable> cache, Handle<String> src,
14907 JSRegExp::Flags flags, Handle<FixedArray> value) { 14936 JSRegExp::Flags flags, Handle<FixedArray> value) {
14908 RegExpKey key(src, flags); 14937 RegExpKey key(src, flags);
14909 cache = EnsureCapacity(cache, 1, &key); 14938 cache = EnsureCapacity(cache, 1, &key);
14910 int entry = cache->FindInsertionEntry(key.Hash()); 14939 int entry = cache->FindInsertionEntry(key.Hash());
14911 // We store the value in the key slot, and compare the search key 14940 // We store the value in the key slot, and compare the search key
14912 // to the stored value with a custon IsMatch function during lookups. 14941 // to the stored value with a custon IsMatch function during lookups.
14913 cache->set(EntryToIndex(entry), *value); 14942 cache->set(EntryToIndex(entry), *value);
14914 cache->set(EntryToIndex(entry) + 1, *value); 14943 cache->set(EntryToIndex(entry) + 1, *value);
14915 cache->ElementAdded(); 14944 cache->ElementAdded();
14916 return cache; 14945 return cache;
14917 } 14946 }
14918 14947
14919 14948
14949 void CompilationCacheTable::Age() {
14950 DisallowHeapAllocation no_allocation;
14951 Object* the_hole_value = GetHeap()->the_hole_value();
14952 for (int entry = 0, size = Capacity(); entry < size; entry++) {
14953 int entry_index = EntryToIndex(entry);
14954 int value_index = entry_index + 1;
14955
14956 if (get(entry_index)->IsNumber()) {
14957 Smi* count = Smi::cast(get(value_index));
14958 count = Smi::FromInt(count->value() - 1);
14959 if (count->value() == 0) {
14960 NoWriteBarrierSet(this, entry_index, the_hole_value);
14961 NoWriteBarrierSet(this, value_index, the_hole_value);
14962 ElementRemoved();
14963 } else {
14964 NoWriteBarrierSet(this, value_index, count);
14965 }
14966 } else if (get(entry_index)->IsFixedArray()) {
14967 SharedFunctionInfo* info = SharedFunctionInfo::cast(get(value_index));
14968 if (info->code()->kind() != Code::FUNCTION || info->code()->IsOld()) {
14969 NoWriteBarrierSet(this, entry_index, the_hole_value);
14970 NoWriteBarrierSet(this, value_index, the_hole_value);
14971 ElementRemoved();
14972 }
14973 }
14974 }
14975 }
14976
14977
14920 void CompilationCacheTable::Remove(Object* value) { 14978 void CompilationCacheTable::Remove(Object* value) {
14921 DisallowHeapAllocation no_allocation; 14979 DisallowHeapAllocation no_allocation;
14922 Object* the_hole_value = GetHeap()->the_hole_value(); 14980 Object* the_hole_value = GetHeap()->the_hole_value();
14923 for (int entry = 0, size = Capacity(); entry < size; entry++) { 14981 for (int entry = 0, size = Capacity(); entry < size; entry++) {
14924 int entry_index = EntryToIndex(entry); 14982 int entry_index = EntryToIndex(entry);
14925 int value_index = entry_index + 1; 14983 int value_index = entry_index + 1;
14926 if (get(value_index) == value) { 14984 if (get(value_index) == value) {
14927 NoWriteBarrierSet(this, entry_index, the_hole_value); 14985 NoWriteBarrierSet(this, entry_index, the_hole_value);
14928 NoWriteBarrierSet(this, value_index, the_hole_value); 14986 NoWriteBarrierSet(this, value_index, the_hole_value);
14929 ElementRemoved(); 14987 ElementRemoved();
(...skipping 1565 matching lines...) Expand 10 before | Expand all | Expand 10 after
16495 Handle<DependentCode> codes = 16553 Handle<DependentCode> codes =
16496 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), 16554 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()),
16497 DependentCode::kPropertyCellChangedGroup, 16555 DependentCode::kPropertyCellChangedGroup,
16498 info->object_wrapper()); 16556 info->object_wrapper());
16499 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); 16557 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes);
16500 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( 16558 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add(
16501 cell, info->zone()); 16559 cell, info->zone());
16502 } 16560 }
16503 16561
16504 } } // namespace v8::internal 16562 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698