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 3840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3851 | 3851 |
3852 | 3852 |
3853 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { | 3853 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { |
3854 if (code <= String::kMaxOneByteCharCode) { | 3854 if (code <= String::kMaxOneByteCharCode) { |
3855 Object* value = single_character_string_cache()->get(code); | 3855 Object* value = single_character_string_cache()->get(code); |
3856 if (value != undefined_value()) return value; | 3856 if (value != undefined_value()) return value; |
3857 | 3857 |
3858 uint8_t buffer[1]; | 3858 uint8_t buffer[1]; |
3859 buffer[0] = static_cast<uint8_t>(code); | 3859 buffer[0] = static_cast<uint8_t>(code); |
3860 Object* result; | 3860 Object* result; |
3861 MaybeObject* maybe_result = | 3861 OneByteStringKey key(Vector<const uint8_t>(buffer, 1), HashSeed()); |
3862 InternalizeOneByteString(Vector<const uint8_t>(buffer, 1)); | 3862 MaybeObject* maybe_result = InternalizeStringWithKey(&key); |
3863 | 3863 |
3864 if (!maybe_result->ToObject(&result)) return maybe_result; | 3864 if (!maybe_result->ToObject(&result)) return maybe_result; |
3865 single_character_string_cache()->set(code, result); | 3865 single_character_string_cache()->set(code, result); |
3866 return result; | 3866 return result; |
3867 } | 3867 } |
3868 | 3868 |
3869 SeqTwoByteString* result; | 3869 SeqTwoByteString* result; |
3870 { MaybeObject* maybe_result = AllocateRawTwoByteString(1); | 3870 { MaybeObject* maybe_result = AllocateRawTwoByteString(1); |
3871 if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result; | 3871 if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result; |
3872 } | 3872 } |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4735 // Allocate the backing storage for the properties. | 4735 // Allocate the backing storage for the properties. |
4736 int prop_size = map->unused_property_fields() - map->inobject_properties(); | 4736 int prop_size = map->unused_property_fields() - map->inobject_properties(); |
4737 Object* properties; | 4737 Object* properties; |
4738 maybe = AllocateFixedArray(prop_size, TENURED); | 4738 maybe = AllocateFixedArray(prop_size, TENURED); |
4739 if (!maybe->ToObject(&properties)) return maybe; | 4739 if (!maybe->ToObject(&properties)) return maybe; |
4740 | 4740 |
4741 // Functions require some allocation, which might fail here. | 4741 // Functions require some allocation, which might fail here. |
4742 SharedFunctionInfo* shared = NULL; | 4742 SharedFunctionInfo* shared = NULL; |
4743 if (type == JS_FUNCTION_TYPE) { | 4743 if (type == JS_FUNCTION_TYPE) { |
4744 String* name; | 4744 String* name; |
4745 maybe = | 4745 OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"), |
4746 InternalizeOneByteString(STATIC_ASCII_VECTOR("<freezing call trap>")); | 4746 HashSeed()); |
| 4747 maybe = InternalizeStringWithKey(&key); |
4747 if (!maybe->To<String>(&name)) return maybe; | 4748 if (!maybe->To<String>(&name)) return maybe; |
4748 maybe = AllocateSharedFunctionInfo(name); | 4749 maybe = AllocateSharedFunctionInfo(name); |
4749 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; | 4750 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; |
4750 } | 4751 } |
4751 | 4752 |
4752 // Because of possible retries of this function after failure, | 4753 // Because of possible retries of this function after failure, |
4753 // we must NOT fail after this point, where we have changed the type! | 4754 // we must NOT fail after this point, where we have changed the type! |
4754 | 4755 |
4755 // Reset the map for the object. | 4756 // Reset the map for the object. |
4756 object->set_map(map); | 4757 object->set_map(map); |
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5869 code_space_->Verify(&no_dirty_regions_visitor); | 5870 code_space_->Verify(&no_dirty_regions_visitor); |
5870 cell_space_->Verify(&no_dirty_regions_visitor); | 5871 cell_space_->Verify(&no_dirty_regions_visitor); |
5871 property_cell_space_->Verify(&no_dirty_regions_visitor); | 5872 property_cell_space_->Verify(&no_dirty_regions_visitor); |
5872 | 5873 |
5873 lo_space_->Verify(); | 5874 lo_space_->Verify(); |
5874 } | 5875 } |
5875 #endif | 5876 #endif |
5876 | 5877 |
5877 | 5878 |
5878 MaybeObject* Heap::InternalizeUtf8String(Vector<const char> string) { | 5879 MaybeObject* Heap::InternalizeUtf8String(Vector<const char> string) { |
| 5880 Utf8StringKey key(string, HashSeed()); |
| 5881 return InternalizeStringWithKey(&key); |
| 5882 } |
| 5883 |
| 5884 |
| 5885 MaybeObject* Heap::InternalizeString(String* string) { |
| 5886 if (string->IsInternalizedString()) return string; |
5879 Object* result = NULL; | 5887 Object* result = NULL; |
5880 Object* new_table; | 5888 Object* new_table; |
5881 { MaybeObject* maybe_new_table = | 5889 { MaybeObject* maybe_new_table = |
5882 string_table()->LookupUtf8String(string, &result); | 5890 string_table()->LookupString(string, &result); |
5883 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; | 5891 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
5884 } | 5892 } |
5885 // Can't use set_string_table because StringTable::cast knows that | 5893 // Can't use set_string_table because StringTable::cast knows that |
5886 // StringTable is a singleton and checks for identity. | |
5887 roots_[kStringTableRootIndex] = new_table; | |
5888 ASSERT(result != NULL); | |
5889 return result; | |
5890 } | |
5891 | |
5892 | |
5893 MaybeObject* Heap::InternalizeOneByteString(Vector<const uint8_t> string) { | |
5894 Object* result = NULL; | |
5895 Object* new_table; | |
5896 { MaybeObject* maybe_new_table = | |
5897 string_table()->LookupOneByteString(string, &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. | |
5902 roots_[kStringTableRootIndex] = new_table; | |
5903 ASSERT(result != NULL); | |
5904 return result; | |
5905 } | |
5906 | |
5907 | |
5908 MaybeObject* Heap::InternalizeOneByteString(Handle<SeqOneByteString> string, | |
5909 int from, | |
5910 int length) { | |
5911 Object* result = NULL; | |
5912 Object* new_table; | |
5913 { MaybeObject* maybe_new_table = | |
5914 string_table()->LookupSubStringOneByteString(string, | |
5915 from, | |
5916 length, | |
5917 &result); | |
5918 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; | |
5919 } | |
5920 // Can't use set_string_table because StringTable::cast knows that | |
5921 // StringTable is a singleton and checks for identity. | 5894 // StringTable is a singleton and checks for identity. |
5922 roots_[kStringTableRootIndex] = new_table; | 5895 roots_[kStringTableRootIndex] = new_table; |
5923 ASSERT(result != NULL); | 5896 ASSERT(result != NULL); |
5924 return result; | 5897 return result; |
5925 } | 5898 } |
5926 | 5899 |
5927 | 5900 |
5928 MaybeObject* Heap::InternalizeTwoByteString(Vector<const uc16> string) { | 5901 bool Heap::InternalizeStringIfExists(String* string, String** result) { |
| 5902 if (string->IsInternalizedString()) { |
| 5903 *result = string; |
| 5904 return true; |
| 5905 } |
| 5906 return string_table()->LookupStringIfExists(string, result); |
| 5907 } |
| 5908 |
| 5909 |
| 5910 MaybeObject* Heap::InternalizeStringWithKey(HashTableKey* key) { |
5929 Object* result = NULL; | 5911 Object* result = NULL; |
5930 Object* new_table; | 5912 Object* new_table; |
5931 { MaybeObject* maybe_new_table = | 5913 { MaybeObject* maybe_new_table = |
5932 string_table()->LookupTwoByteString(string, &result); | 5914 string_table()->LookupKey(key, &result); |
5933 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; | 5915 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
5934 } | 5916 } |
5935 // Can't use set_string_table because StringTable::cast knows that | 5917 // Can't use set_string_table because StringTable::cast knows that |
5936 // StringTable is a singleton and checks for identity. | |
5937 roots_[kStringTableRootIndex] = new_table; | |
5938 ASSERT(result != NULL); | |
5939 return result; | |
5940 } | |
5941 | |
5942 | |
5943 MaybeObject* Heap::InternalizeString(String* string) { | |
5944 if (string->IsInternalizedString()) return string; | |
5945 Object* result = NULL; | |
5946 Object* new_table; | |
5947 { MaybeObject* maybe_new_table = | |
5948 string_table()->LookupString(string, &result); | |
5949 if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; | |
5950 } | |
5951 // Can't use set_string_table because StringTable::cast knows that | |
5952 // StringTable is a singleton and checks for identity. | 5918 // StringTable is a singleton and checks for identity. |
5953 roots_[kStringTableRootIndex] = new_table; | 5919 roots_[kStringTableRootIndex] = new_table; |
5954 ASSERT(result != NULL); | 5920 ASSERT(result != NULL); |
5955 return result; | 5921 return result; |
5956 } | 5922 } |
5957 | 5923 |
5958 | 5924 |
5959 bool Heap::InternalizeStringIfExists(String* string, String** result) { | |
5960 if (string->IsInternalizedString()) { | |
5961 *result = string; | |
5962 return true; | |
5963 } | |
5964 return string_table()->LookupStringIfExists(string, result); | |
5965 } | |
5966 | |
5967 | |
5968 void Heap::ZapFromSpace() { | 5925 void Heap::ZapFromSpace() { |
5969 NewSpacePageIterator it(new_space_.FromSpaceStart(), | 5926 NewSpacePageIterator it(new_space_.FromSpaceStart(), |
5970 new_space_.FromSpaceEnd()); | 5927 new_space_.FromSpaceEnd()); |
5971 while (it.has_next()) { | 5928 while (it.has_next()) { |
5972 NewSpacePage* page = it.next(); | 5929 NewSpacePage* page = it.next(); |
5973 for (Address cursor = page->area_start(), limit = page->area_end(); | 5930 for (Address cursor = page->area_start(), limit = page->area_end(); |
5974 cursor < limit; | 5931 cursor < limit; |
5975 cursor += kPointerSize) { | 5932 cursor += kPointerSize) { |
5976 Memory::Address_at(cursor) = kFromSpaceZapValue; | 5933 Memory::Address_at(cursor) = kFromSpaceZapValue; |
5977 } | 5934 } |
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7780 static_cast<int>(object_sizes_last_time_[index])); | 7737 static_cast<int>(object_sizes_last_time_[index])); |
7781 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7738 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
7782 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7739 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7783 | 7740 |
7784 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7741 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7785 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7742 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7786 ClearObjectStats(); | 7743 ClearObjectStats(); |
7787 } | 7744 } |
7788 | 7745 |
7789 } } // namespace v8::internal | 7746 } } // namespace v8::internal |
OLD | NEW |