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

Side by Side Diff: src/heap.cc

Issue 140953002: Refactor string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: whitespace Created 6 years, 11 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
« no previous file with comments | « src/heap.h ('k') | src/objects.h » ('j') | src/objects-inl.h » ('J')
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 // 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 3820 matching lines...) Expand 10 before | Expand all | Expand 10 after
3831 3831
3832 3832
3833 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { 3833 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) {
3834 if (code <= String::kMaxOneByteCharCode) { 3834 if (code <= String::kMaxOneByteCharCode) {
3835 Object* value = single_character_string_cache()->get(code); 3835 Object* value = single_character_string_cache()->get(code);
3836 if (value != undefined_value()) return value; 3836 if (value != undefined_value()) return value;
3837 3837
3838 uint8_t buffer[1]; 3838 uint8_t buffer[1];
3839 buffer[0] = static_cast<uint8_t>(code); 3839 buffer[0] = static_cast<uint8_t>(code);
3840 Object* result; 3840 Object* result;
3841 MaybeObject* maybe_result = 3841 OneByteStringKey key(Vector<const uint8_t>(buffer, 1), HashSeed());
3842 InternalizeOneByteString(Vector<const uint8_t>(buffer, 1)); 3842 MaybeObject* maybe_result = InternalizeStringWithKey(&key);
3843 3843
3844 if (!maybe_result->ToObject(&result)) return maybe_result; 3844 if (!maybe_result->ToObject(&result)) return maybe_result;
3845 single_character_string_cache()->set(code, result); 3845 single_character_string_cache()->set(code, result);
3846 return result; 3846 return result;
3847 } 3847 }
3848 3848
3849 SeqTwoByteString* result; 3849 SeqTwoByteString* result;
3850 { MaybeObject* maybe_result = AllocateRawTwoByteString(1); 3850 { MaybeObject* maybe_result = AllocateRawTwoByteString(1);
3851 if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result; 3851 if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result;
3852 } 3852 }
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
4715 // Allocate the backing storage for the properties. 4715 // Allocate the backing storage for the properties.
4716 int prop_size = map->unused_property_fields() - map->inobject_properties(); 4716 int prop_size = map->unused_property_fields() - map->inobject_properties();
4717 Object* properties; 4717 Object* properties;
4718 maybe = AllocateFixedArray(prop_size, TENURED); 4718 maybe = AllocateFixedArray(prop_size, TENURED);
4719 if (!maybe->ToObject(&properties)) return maybe; 4719 if (!maybe->ToObject(&properties)) return maybe;
4720 4720
4721 // Functions require some allocation, which might fail here. 4721 // Functions require some allocation, which might fail here.
4722 SharedFunctionInfo* shared = NULL; 4722 SharedFunctionInfo* shared = NULL;
4723 if (type == JS_FUNCTION_TYPE) { 4723 if (type == JS_FUNCTION_TYPE) {
4724 String* name; 4724 String* name;
4725 maybe = 4725 OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"),
4726 InternalizeOneByteString(STATIC_ASCII_VECTOR("<freezing call trap>")); 4726 HashSeed());
4727 maybe = InternalizeStringWithKey(&key);
4727 if (!maybe->To<String>(&name)) return maybe; 4728 if (!maybe->To<String>(&name)) return maybe;
4728 maybe = AllocateSharedFunctionInfo(name); 4729 maybe = AllocateSharedFunctionInfo(name);
4729 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; 4730 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe;
4730 } 4731 }
4731 4732
4732 // Because of possible retries of this function after failure, 4733 // Because of possible retries of this function after failure,
4733 // we must NOT fail after this point, where we have changed the type! 4734 // we must NOT fail after this point, where we have changed the type!
4734 4735
4735 // Reset the map for the object. 4736 // Reset the map for the object.
4736 object->set_map(map); 4737 object->set_map(map);
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
5849 code_space_->Verify(&no_dirty_regions_visitor); 5850 code_space_->Verify(&no_dirty_regions_visitor);
5850 cell_space_->Verify(&no_dirty_regions_visitor); 5851 cell_space_->Verify(&no_dirty_regions_visitor);
5851 property_cell_space_->Verify(&no_dirty_regions_visitor); 5852 property_cell_space_->Verify(&no_dirty_regions_visitor);
5852 5853
5853 lo_space_->Verify(); 5854 lo_space_->Verify();
5854 } 5855 }
5855 #endif 5856 #endif
5856 5857
5857 5858
5858 MaybeObject* Heap::InternalizeUtf8String(Vector<const char> string) { 5859 MaybeObject* Heap::InternalizeUtf8String(Vector<const char> string) {
5860 Utf8StringKey key(string, HashSeed());
5861 return InternalizeStringWithKey(&key);
5862 }
5863
5864
5865 MaybeObject* Heap::InternalizeString(String* string) {
5866 if (string->IsInternalizedString()) return string;
5859 Object* result = NULL; 5867 Object* result = NULL;
5860 Object* new_table; 5868 Object* new_table;
5861 { MaybeObject* maybe_new_table = 5869 { MaybeObject* maybe_new_table =
5862 string_table()->LookupUtf8String(string, &result); 5870 string_table()->LookupString(string, &result);
5863 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; 5871 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
5864 } 5872 }
5865 // Can't use set_string_table because StringTable::cast knows that 5873 // Can't use set_string_table because StringTable::cast knows that
5866 // StringTable is a singleton and checks for identity.
5867 roots_[kStringTableRootIndex] = new_table;
5868 ASSERT(result != NULL);
5869 return result;
5870 }
5871
5872
5873 MaybeObject* Heap::InternalizeOneByteString(Vector<const uint8_t> string) {
5874 Object* result = NULL;
5875 Object* new_table;
5876 { MaybeObject* maybe_new_table =
5877 string_table()->LookupOneByteString(string, &result);
5878 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
5879 }
5880 // Can't use set_string_table because StringTable::cast knows that
5881 // StringTable is a singleton and checks for identity.
5882 roots_[kStringTableRootIndex] = new_table;
5883 ASSERT(result != NULL);
5884 return result;
5885 }
5886
5887
5888 MaybeObject* Heap::InternalizeOneByteString(Handle<SeqOneByteString> string,
5889 int from,
5890 int length) {
5891 Object* result = NULL;
5892 Object* new_table;
5893 { MaybeObject* maybe_new_table =
5894 string_table()->LookupSubStringOneByteString(string,
5895 from,
5896 length,
5897 &result);
5898 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
5899 }
5900 // Can't use set_string_table because StringTable::cast knows that
5901 // StringTable is a singleton and checks for identity. 5874 // StringTable is a singleton and checks for identity.
5902 roots_[kStringTableRootIndex] = new_table; 5875 roots_[kStringTableRootIndex] = new_table;
5903 ASSERT(result != NULL); 5876 ASSERT(result != NULL);
5904 return result; 5877 return result;
5905 } 5878 }
5906 5879
5907 5880
5908 MaybeObject* Heap::InternalizeTwoByteString(Vector<const uc16> string) { 5881 bool Heap::InternalizeStringIfExists(String* string, String** result) {
5882 if (string->IsInternalizedString()) {
5883 *result = string;
5884 return true;
5885 }
5886 return string_table()->LookupStringIfExists(string, result);
5887 }
5888
5889
5890 MaybeObject* Heap::InternalizeStringWithKey(HashTableKey* key) {
5909 Object* result = NULL; 5891 Object* result = NULL;
5910 Object* new_table; 5892 Object* new_table;
5911 { MaybeObject* maybe_new_table = 5893 { MaybeObject* maybe_new_table =
5912 string_table()->LookupTwoByteString(string, &result); 5894 string_table()->LookupKey(key, &result);
5913 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; 5895 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
5914 } 5896 }
5915 // Can't use set_string_table because StringTable::cast knows that 5897 // Can't use set_string_table because StringTable::cast knows that
5916 // StringTable is a singleton and checks for identity.
5917 roots_[kStringTableRootIndex] = new_table;
5918 ASSERT(result != NULL);
5919 return result;
5920 }
5921
5922
5923 MaybeObject* Heap::InternalizeString(String* string) {
5924 if (string->IsInternalizedString()) return string;
5925 Object* result = NULL;
5926 Object* new_table;
5927 { MaybeObject* maybe_new_table =
5928 string_table()->LookupString(string, &result);
5929 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
5930 }
5931 // Can't use set_string_table because StringTable::cast knows that
5932 // StringTable is a singleton and checks for identity. 5898 // StringTable is a singleton and checks for identity.
5933 roots_[kStringTableRootIndex] = new_table; 5899 roots_[kStringTableRootIndex] = new_table;
5934 ASSERT(result != NULL); 5900 ASSERT(result != NULL);
5935 return result; 5901 return result;
5936 } 5902 }
5937 5903
5938 5904
5939 bool Heap::InternalizeStringIfExists(String* string, String** result) {
5940 if (string->IsInternalizedString()) {
5941 *result = string;
5942 return true;
5943 }
5944 return string_table()->LookupStringIfExists(string, result);
5945 }
5946
5947
5948 void Heap::ZapFromSpace() { 5905 void Heap::ZapFromSpace() {
5949 NewSpacePageIterator it(new_space_.FromSpaceStart(), 5906 NewSpacePageIterator it(new_space_.FromSpaceStart(),
5950 new_space_.FromSpaceEnd()); 5907 new_space_.FromSpaceEnd());
5951 while (it.has_next()) { 5908 while (it.has_next()) {
5952 NewSpacePage* page = it.next(); 5909 NewSpacePage* page = it.next();
5953 for (Address cursor = page->area_start(), limit = page->area_end(); 5910 for (Address cursor = page->area_start(), limit = page->area_end();
5954 cursor < limit; 5911 cursor < limit;
5955 cursor += kPointerSize) { 5912 cursor += kPointerSize) {
5956 Memory::Address_at(cursor) = kFromSpaceZapValue; 5913 Memory::Address_at(cursor) = kFromSpaceZapValue;
5957 } 5914 }
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after
7760 static_cast<int>(object_sizes_last_time_[index])); 7717 static_cast<int>(object_sizes_last_time_[index]));
7761 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7718 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7762 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7719 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7763 7720
7764 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7721 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7765 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7722 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7766 ClearObjectStats(); 7723 ClearObjectStats();
7767 } 7724 }
7768 7725
7769 } } // namespace v8::internal 7726 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/objects.h » ('j') | src/objects-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698