OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 15724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15735 os << " (" << PrivateSymbolToName() << ")"; | 15735 os << " (" << PrivateSymbolToName() << ")"; |
15736 } | 15736 } |
15737 os << ">"; | 15737 os << ">"; |
15738 } | 15738 } |
15739 | 15739 |
15740 | 15740 |
15741 // StringSharedKeys are used as keys in the eval cache. | 15741 // StringSharedKeys are used as keys in the eval cache. |
15742 class StringSharedKey : public HashTableKey { | 15742 class StringSharedKey : public HashTableKey { |
15743 public: | 15743 public: |
15744 StringSharedKey(Handle<String> source, Handle<SharedFunctionInfo> shared, | 15744 StringSharedKey(Handle<String> source, Handle<SharedFunctionInfo> shared, |
15745 LanguageMode language_mode, int scope_position) | 15745 LanguageMode language_mode, bool is_module, |
15746 int scope_position) | |
15746 : source_(source), | 15747 : source_(source), |
15747 shared_(shared), | 15748 shared_(shared), |
15748 language_mode_(language_mode), | 15749 language_mode_(language_mode), |
15750 is_module_(is_module), | |
15749 scope_position_(scope_position) {} | 15751 scope_position_(scope_position) {} |
15750 | 15752 |
15751 bool IsMatch(Object* other) override { | 15753 bool IsMatch(Object* other) override { |
15752 DisallowHeapAllocation no_allocation; | 15754 DisallowHeapAllocation no_allocation; |
15753 if (!other->IsFixedArray()) { | 15755 if (!other->IsFixedArray()) { |
15754 if (!other->IsNumber()) return false; | 15756 if (!other->IsNumber()) return false; |
15755 uint32_t other_hash = static_cast<uint32_t>(other->Number()); | 15757 uint32_t other_hash = static_cast<uint32_t>(other->Number()); |
15756 return Hash() == other_hash; | 15758 return Hash() == other_hash; |
15757 } | 15759 } |
15758 FixedArray* other_array = FixedArray::cast(other); | 15760 FixedArray* other_array = FixedArray::cast(other); |
15759 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); | 15761 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); |
15760 if (shared != *shared_) return false; | 15762 if (shared != *shared_) return false; |
15761 int language_unchecked = Smi::cast(other_array->get(2))->value(); | 15763 int language_unchecked = Smi::cast(other_array->get(2))->value(); |
15762 DCHECK(is_valid_language_mode(language_unchecked)); | 15764 DCHECK(is_valid_language_mode(language_unchecked)); |
15763 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); | 15765 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); |
15764 if (language_mode != language_mode_) return false; | 15766 if (language_mode != language_mode_) return false; |
15765 int scope_position = Smi::cast(other_array->get(3))->value(); | 15767 bool is_module = Smi::cast(other_array->get(3))->value() == 1; |
15768 if (is_module != is_module_) return false; | |
15769 int scope_position = Smi::cast(other_array->get(4))->value(); | |
15766 if (scope_position != scope_position_) return false; | 15770 if (scope_position != scope_position_) return false; |
15767 String* source = String::cast(other_array->get(1)); | 15771 String* source = String::cast(other_array->get(1)); |
15768 return source->Equals(*source_); | 15772 return source->Equals(*source_); |
15769 } | 15773 } |
15770 | 15774 |
15771 static uint32_t StringSharedHashHelper(String* source, | 15775 static uint32_t StringSharedHashHelper(String* source, |
15772 SharedFunctionInfo* shared, | 15776 SharedFunctionInfo* shared, |
15773 LanguageMode language_mode, | 15777 LanguageMode language_mode, |
15774 int scope_position) { | 15778 bool is_module, int scope_position) { |
15775 uint32_t hash = source->Hash(); | 15779 uint32_t hash = source->Hash(); |
15776 if (shared->HasSourceCode()) { | 15780 if (shared->HasSourceCode()) { |
15777 // Instead of using the SharedFunctionInfo pointer in the hash | 15781 // Instead of using the SharedFunctionInfo pointer in the hash |
15778 // code computation, we use a combination of the hash of the | 15782 // code computation, we use a combination of the hash of the |
15779 // script source code and the start position of the calling scope. | 15783 // script source code and the start position of the calling scope. |
15780 // We do this to ensure that the cache entries can survive garbage | 15784 // We do this to ensure that the cache entries can survive garbage |
15781 // collection. | 15785 // collection. |
15782 Script* script(Script::cast(shared->script())); | 15786 Script* script(Script::cast(shared->script())); |
15783 hash ^= String::cast(script->source())->Hash(); | 15787 hash ^= String::cast(script->source())->Hash(); |
15784 STATIC_ASSERT(LANGUAGE_END == 3); | 15788 STATIC_ASSERT(LANGUAGE_END == 3); |
15785 if (is_strict(language_mode)) hash ^= 0x8000; | 15789 if (is_strict(language_mode)) hash ^= 0x8000; |
15790 if (is_module) hash ^= 0x4000; | |
adamk
2016/06/28 17:03:53
Curious how you decided to tweak the hash code her
mike3
2016/07/02 22:17:59
I just needed a place to store this bit, so I foll
| |
15786 hash += scope_position; | 15791 hash += scope_position; |
15787 } | 15792 } |
15788 return hash; | 15793 return hash; |
15789 } | 15794 } |
15790 | 15795 |
15791 uint32_t Hash() override { | 15796 uint32_t Hash() override { |
15792 return StringSharedHashHelper(*source_, *shared_, language_mode_, | 15797 return StringSharedHashHelper(*source_, *shared_, language_mode_, |
15793 scope_position_); | 15798 is_module_, scope_position_); |
15794 } | 15799 } |
15795 | 15800 |
15796 uint32_t HashForObject(Object* obj) override { | 15801 uint32_t HashForObject(Object* obj) override { |
15797 DisallowHeapAllocation no_allocation; | 15802 DisallowHeapAllocation no_allocation; |
15798 if (obj->IsNumber()) { | 15803 if (obj->IsNumber()) { |
15799 return static_cast<uint32_t>(obj->Number()); | 15804 return static_cast<uint32_t>(obj->Number()); |
15800 } | 15805 } |
15801 FixedArray* other_array = FixedArray::cast(obj); | 15806 FixedArray* other_array = FixedArray::cast(obj); |
15802 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); | 15807 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); |
15803 String* source = String::cast(other_array->get(1)); | 15808 String* source = String::cast(other_array->get(1)); |
15804 int language_unchecked = Smi::cast(other_array->get(2))->value(); | 15809 int language_unchecked = Smi::cast(other_array->get(2))->value(); |
15805 DCHECK(is_valid_language_mode(language_unchecked)); | 15810 DCHECK(is_valid_language_mode(language_unchecked)); |
15806 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); | 15811 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); |
15807 int scope_position = Smi::cast(other_array->get(3))->value(); | 15812 bool is_module = |
15808 return StringSharedHashHelper(source, shared, language_mode, | 15813 Smi::cast(other_array->get(3))->value() == 1 ? true : false; |
vogelheim
2016/06/28 16:41:27
Please also drop "? true : false" here.
mike3
2016/07/02 22:17:59
Acknowledged.
| |
15814 int scope_position = Smi::cast(other_array->get(4))->value(); | |
15815 return StringSharedHashHelper(source, shared, language_mode, is_module, | |
15809 scope_position); | 15816 scope_position); |
15810 } | 15817 } |
15811 | 15818 |
15812 | 15819 |
15813 Handle<Object> AsHandle(Isolate* isolate) override { | 15820 Handle<Object> AsHandle(Isolate* isolate) override { |
15814 Handle<FixedArray> array = isolate->factory()->NewFixedArray(4); | 15821 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); |
15815 array->set(0, *shared_); | 15822 array->set(0, *shared_); |
15816 array->set(1, *source_); | 15823 array->set(1, *source_); |
15817 array->set(2, Smi::FromInt(language_mode_)); | 15824 array->set(2, Smi::FromInt(language_mode_)); |
15818 array->set(3, Smi::FromInt(scope_position_)); | 15825 array->set(3, Smi::FromInt(is_module_ ? 1 : 0)); |
15826 array->set(4, Smi::FromInt(scope_position_)); | |
15819 return array; | 15827 return array; |
15820 } | 15828 } |
15821 | 15829 |
15822 private: | 15830 private: |
15823 Handle<String> source_; | 15831 Handle<String> source_; |
15824 Handle<SharedFunctionInfo> shared_; | 15832 Handle<SharedFunctionInfo> shared_; |
15825 LanguageMode language_mode_; | 15833 LanguageMode language_mode_; |
15834 bool is_module_; | |
15826 int scope_position_; | 15835 int scope_position_; |
15827 }; | 15836 }; |
15828 | 15837 |
15829 | 15838 |
15830 namespace { | 15839 namespace { |
15831 | 15840 |
15832 JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) { | 15841 JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) { |
15833 JSRegExp::Flags value = JSRegExp::kNone; | 15842 JSRegExp::Flags value = JSRegExp::kNone; |
15834 int length = flags->length(); | 15843 int length = flags->length(); |
15835 // A longer flags string cannot be valid. | 15844 // A longer flags string cannot be valid. |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17038 } | 17047 } |
17039 return stringset; | 17048 return stringset; |
17040 } | 17049 } |
17041 | 17050 |
17042 bool StringSet::Has(Handle<String> name) { | 17051 bool StringSet::Has(Handle<String> name) { |
17043 return FindEntry(*name) != kNotFound; | 17052 return FindEntry(*name) != kNotFound; |
17044 } | 17053 } |
17045 | 17054 |
17046 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, | 17055 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, |
17047 Handle<Context> context, | 17056 Handle<Context> context, |
17048 LanguageMode language_mode) { | 17057 LanguageMode language_mode, |
17058 bool is_module) { | |
17049 Isolate* isolate = GetIsolate(); | 17059 Isolate* isolate = GetIsolate(); |
17050 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 17060 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
17051 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); | 17061 StringSharedKey key(src, shared, language_mode, is_module, |
17062 RelocInfo::kNoPosition); | |
17052 int entry = FindEntry(&key); | 17063 int entry = FindEntry(&key); |
17053 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17064 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17054 int index = EntryToIndex(entry); | 17065 int index = EntryToIndex(entry); |
17055 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); | 17066 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); |
17056 return Handle<Object>(get(index + 1), isolate); | 17067 return Handle<Object>(get(index + 1), isolate); |
17057 } | 17068 } |
17058 | 17069 |
17059 | 17070 |
17060 Handle<Object> CompilationCacheTable::LookupEval( | 17071 Handle<Object> CompilationCacheTable::LookupEval( |
17061 Handle<String> src, Handle<SharedFunctionInfo> outer_info, | 17072 Handle<String> src, Handle<SharedFunctionInfo> outer_info, |
17062 LanguageMode language_mode, int scope_position) { | 17073 LanguageMode language_mode, int scope_position) { |
17063 Isolate* isolate = GetIsolate(); | 17074 Isolate* isolate = GetIsolate(); |
17064 // Cache key is the tuple (source, outer shared function info, scope position) | 17075 // Cache key is the tuple (source, outer shared function info, scope position) |
17065 // to unambiguously identify the context chain the cached eval code assumes. | 17076 // to unambiguously identify the context chain the cached eval code assumes. |
17066 StringSharedKey key(src, outer_info, language_mode, scope_position); | 17077 StringSharedKey key(src, outer_info, language_mode, false, scope_position); |
17067 int entry = FindEntry(&key); | 17078 int entry = FindEntry(&key); |
17068 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17079 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17069 int index = EntryToIndex(entry); | 17080 int index = EntryToIndex(entry); |
17070 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); | 17081 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); |
17071 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); | 17082 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); |
17072 } | 17083 } |
17073 | 17084 |
17074 | 17085 |
17075 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, | 17086 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, |
17076 JSRegExp::Flags flags) { | 17087 JSRegExp::Flags flags) { |
17077 Isolate* isolate = GetIsolate(); | 17088 Isolate* isolate = GetIsolate(); |
17078 DisallowHeapAllocation no_allocation; | 17089 DisallowHeapAllocation no_allocation; |
17079 RegExpKey key(src, flags); | 17090 RegExpKey key(src, flags); |
17080 int entry = FindEntry(&key); | 17091 int entry = FindEntry(&key); |
17081 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17092 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17082 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); | 17093 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); |
17083 } | 17094 } |
17084 | 17095 |
17085 | |
17086 Handle<CompilationCacheTable> CompilationCacheTable::Put( | 17096 Handle<CompilationCacheTable> CompilationCacheTable::Put( |
17087 Handle<CompilationCacheTable> cache, Handle<String> src, | 17097 Handle<CompilationCacheTable> cache, Handle<String> src, |
17088 Handle<Context> context, LanguageMode language_mode, Handle<Object> value) { | 17098 Handle<Context> context, LanguageMode language_mode, bool is_module, |
17099 Handle<Object> value) { | |
17089 Isolate* isolate = cache->GetIsolate(); | 17100 Isolate* isolate = cache->GetIsolate(); |
17090 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 17101 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
17091 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); | 17102 StringSharedKey key(src, shared, language_mode, is_module, |
17103 RelocInfo::kNoPosition); | |
17092 Handle<Object> k = key.AsHandle(isolate); | 17104 Handle<Object> k = key.AsHandle(isolate); |
17093 cache = EnsureCapacity(cache, 1, &key); | 17105 cache = EnsureCapacity(cache, 1, &key); |
17094 int entry = cache->FindInsertionEntry(key.Hash()); | 17106 int entry = cache->FindInsertionEntry(key.Hash()); |
17095 cache->set(EntryToIndex(entry), *k); | 17107 cache->set(EntryToIndex(entry), *k); |
17096 cache->set(EntryToIndex(entry) + 1, *value); | 17108 cache->set(EntryToIndex(entry) + 1, *value); |
17097 cache->ElementAdded(); | 17109 cache->ElementAdded(); |
17098 return cache; | 17110 return cache; |
17099 } | 17111 } |
17100 | 17112 |
17101 | 17113 |
17102 Handle<CompilationCacheTable> CompilationCacheTable::PutEval( | 17114 Handle<CompilationCacheTable> CompilationCacheTable::PutEval( |
17103 Handle<CompilationCacheTable> cache, Handle<String> src, | 17115 Handle<CompilationCacheTable> cache, Handle<String> src, |
17104 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value, | 17116 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value, |
17105 int scope_position) { | 17117 int scope_position) { |
17106 Isolate* isolate = cache->GetIsolate(); | 17118 Isolate* isolate = cache->GetIsolate(); |
17107 StringSharedKey key(src, outer_info, value->language_mode(), scope_position); | 17119 StringSharedKey key(src, outer_info, value->language_mode(), false, |
17120 scope_position); | |
17108 { | 17121 { |
17109 Handle<Object> k = key.AsHandle(isolate); | 17122 Handle<Object> k = key.AsHandle(isolate); |
17110 DisallowHeapAllocation no_allocation_scope; | 17123 DisallowHeapAllocation no_allocation_scope; |
17111 int entry = cache->FindEntry(&key); | 17124 int entry = cache->FindEntry(&key); |
17112 if (entry != kNotFound) { | 17125 if (entry != kNotFound) { |
17113 cache->set(EntryToIndex(entry), *k); | 17126 cache->set(EntryToIndex(entry), *k); |
17114 cache->set(EntryToIndex(entry) + 1, *value); | 17127 cache->set(EntryToIndex(entry) + 1, *value); |
17115 return cache; | 17128 return cache; |
17116 } | 17129 } |
17117 } | 17130 } |
(...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18858 if (cell->value() != *new_value) { | 18871 if (cell->value() != *new_value) { |
18859 cell->set_value(*new_value); | 18872 cell->set_value(*new_value); |
18860 Isolate* isolate = cell->GetIsolate(); | 18873 Isolate* isolate = cell->GetIsolate(); |
18861 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18874 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18862 isolate, DependentCode::kPropertyCellChangedGroup); | 18875 isolate, DependentCode::kPropertyCellChangedGroup); |
18863 } | 18876 } |
18864 } | 18877 } |
18865 | 18878 |
18866 } // namespace internal | 18879 } // namespace internal |
18867 } // namespace v8 | 18880 } // namespace v8 |
OLD | NEW |