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

Side by Side Diff: src/objects.cc

Issue 2065453002: [module] Track script "module code" status Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Extend compilation cache to recognize module code Created 4 years, 6 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
OLDNEW
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
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) {}
15752 StringSharedKey(Handle<String> source, Handle<SharedFunctionInfo> shared,
15753 LanguageMode language_mode, int scope_position)
15754 : StringSharedKey(source, shared, language_mode, false, scope_position) {}
vogelheim 2016/06/23 14:53:19 I'd prefer if this constructor was removed... It m
mike3 2016/06/25 19:31:45 Acknowledged.
15750 15755
15751 bool IsMatch(Object* other) override { 15756 bool IsMatch(Object* other) override {
15752 DisallowHeapAllocation no_allocation; 15757 DisallowHeapAllocation no_allocation;
15753 if (!other->IsFixedArray()) { 15758 if (!other->IsFixedArray()) {
15754 if (!other->IsNumber()) return false; 15759 if (!other->IsNumber()) return false;
15755 uint32_t other_hash = static_cast<uint32_t>(other->Number()); 15760 uint32_t other_hash = static_cast<uint32_t>(other->Number());
15756 return Hash() == other_hash; 15761 return Hash() == other_hash;
15757 } 15762 }
15758 FixedArray* other_array = FixedArray::cast(other); 15763 FixedArray* other_array = FixedArray::cast(other);
15759 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); 15764 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0));
15760 if (shared != *shared_) return false; 15765 if (shared != *shared_) return false;
15761 int language_unchecked = Smi::cast(other_array->get(2))->value(); 15766 int language_unchecked = Smi::cast(other_array->get(2))->value();
15762 DCHECK(is_valid_language_mode(language_unchecked)); 15767 DCHECK(is_valid_language_mode(language_unchecked));
15763 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); 15768 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked);
15764 if (language_mode != language_mode_) return false; 15769 if (language_mode != language_mode_) return false;
15765 int scope_position = Smi::cast(other_array->get(3))->value(); 15770 bool is_module =
15771 Smi::cast(other_array->get(3))->value() == 1 ? true : false;
vogelheim 2016/06/23 14:53:19 nit: drop "? true : false". The result of == is al
mike3 2016/06/25 19:31:45 Acknowledged.
15772 if (is_module != is_module_) return false;
15773 int scope_position = Smi::cast(other_array->get(4))->value();
15766 if (scope_position != scope_position_) return false; 15774 if (scope_position != scope_position_) return false;
15767 String* source = String::cast(other_array->get(1)); 15775 String* source = String::cast(other_array->get(1));
15768 return source->Equals(*source_); 15776 return source->Equals(*source_);
15769 } 15777 }
15770 15778
15771 static uint32_t StringSharedHashHelper(String* source, 15779 static uint32_t StringSharedHashHelper(String* source,
15772 SharedFunctionInfo* shared, 15780 SharedFunctionInfo* shared,
15773 LanguageMode language_mode, 15781 LanguageMode language_mode,
15774 int scope_position) { 15782 bool is_module, int scope_position) {
15775 uint32_t hash = source->Hash(); 15783 uint32_t hash = source->Hash();
15776 if (shared->HasSourceCode()) { 15784 if (shared->HasSourceCode()) {
15777 // Instead of using the SharedFunctionInfo pointer in the hash 15785 // Instead of using the SharedFunctionInfo pointer in the hash
15778 // code computation, we use a combination of the hash of the 15786 // code computation, we use a combination of the hash of the
15779 // script source code and the start position of the calling scope. 15787 // script source code and the start position of the calling scope.
15780 // We do this to ensure that the cache entries can survive garbage 15788 // We do this to ensure that the cache entries can survive garbage
15781 // collection. 15789 // collection.
15782 Script* script(Script::cast(shared->script())); 15790 Script* script(Script::cast(shared->script()));
15783 hash ^= String::cast(script->source())->Hash(); 15791 hash ^= String::cast(script->source())->Hash();
15784 STATIC_ASSERT(LANGUAGE_END == 3); 15792 STATIC_ASSERT(LANGUAGE_END == 3);
15785 if (is_strict(language_mode)) hash ^= 0x8000; 15793 if (is_strict(language_mode)) hash ^= 0x8000;
15794 if (is_module) hash ^= 0x4000;
mike3 2016/06/19 17:11:41 Would it be better to preserve the current bits fo
vogelheim 2016/06/23 14:53:20 No, I don't think so. The whole point of a hash is
mike3 2016/06/25 19:31:45 Acknowledged.
15786 hash += scope_position; 15795 hash += scope_position;
15787 } 15796 }
15788 return hash; 15797 return hash;
15789 } 15798 }
15790 15799
15791 uint32_t Hash() override { 15800 uint32_t Hash() override {
15792 return StringSharedHashHelper(*source_, *shared_, language_mode_, 15801 return StringSharedHashHelper(*source_, *shared_, language_mode_,
15793 scope_position_); 15802 is_module_, scope_position_);
15794 } 15803 }
15795 15804
15796 uint32_t HashForObject(Object* obj) override { 15805 uint32_t HashForObject(Object* obj) override {
15797 DisallowHeapAllocation no_allocation; 15806 DisallowHeapAllocation no_allocation;
15798 if (obj->IsNumber()) { 15807 if (obj->IsNumber()) {
15799 return static_cast<uint32_t>(obj->Number()); 15808 return static_cast<uint32_t>(obj->Number());
15800 } 15809 }
15801 FixedArray* other_array = FixedArray::cast(obj); 15810 FixedArray* other_array = FixedArray::cast(obj);
15802 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); 15811 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0));
15803 String* source = String::cast(other_array->get(1)); 15812 String* source = String::cast(other_array->get(1));
15804 int language_unchecked = Smi::cast(other_array->get(2))->value(); 15813 int language_unchecked = Smi::cast(other_array->get(2))->value();
15805 DCHECK(is_valid_language_mode(language_unchecked)); 15814 DCHECK(is_valid_language_mode(language_unchecked));
15806 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); 15815 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked);
15807 int scope_position = Smi::cast(other_array->get(3))->value(); 15816 bool is_module =
15808 return StringSharedHashHelper(source, shared, language_mode, 15817 Smi::cast(other_array->get(3))->value() == 1 ? true : false;
15818 int scope_position = Smi::cast(other_array->get(4))->value();
15819 return StringSharedHashHelper(source, shared, language_mode, is_module,
15809 scope_position); 15820 scope_position);
15810 } 15821 }
15811 15822
15812 15823
15813 Handle<Object> AsHandle(Isolate* isolate) override { 15824 Handle<Object> AsHandle(Isolate* isolate) override {
15814 Handle<FixedArray> array = isolate->factory()->NewFixedArray(4); 15825 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5);
15815 array->set(0, *shared_); 15826 array->set(0, *shared_);
15816 array->set(1, *source_); 15827 array->set(1, *source_);
15817 array->set(2, Smi::FromInt(language_mode_)); 15828 array->set(2, Smi::FromInt(language_mode_));
15818 array->set(3, Smi::FromInt(scope_position_)); 15829 array->set(3, Smi::FromInt(is_module_ ? 1 : 0));
mike3 2016/06/19 17:11:41 I looked for Smi::FromBool, but no dice. This is m
15830 array->set(4, Smi::FromInt(scope_position_));
15819 return array; 15831 return array;
15820 } 15832 }
15821 15833
15822 private: 15834 private:
15823 Handle<String> source_; 15835 Handle<String> source_;
15824 Handle<SharedFunctionInfo> shared_; 15836 Handle<SharedFunctionInfo> shared_;
15825 LanguageMode language_mode_; 15837 LanguageMode language_mode_;
15838 bool is_module_;
15826 int scope_position_; 15839 int scope_position_;
15827 }; 15840 };
15828 15841
15829 15842
15830 namespace { 15843 namespace {
15831 15844
15832 JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) { 15845 JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) {
15833 JSRegExp::Flags value = JSRegExp::kNone; 15846 JSRegExp::Flags value = JSRegExp::kNone;
15834 int length = flags->length(); 15847 int length = flags->length();
15835 // A longer flags string cannot be valid. 15848 // A longer flags string cannot be valid.
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
17038 } 17051 }
17039 return stringset; 17052 return stringset;
17040 } 17053 }
17041 17054
17042 bool StringSet::Has(Handle<String> name) { 17055 bool StringSet::Has(Handle<String> name) {
17043 return FindEntry(*name) != kNotFound; 17056 return FindEntry(*name) != kNotFound;
17044 } 17057 }
17045 17058
17046 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, 17059 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src,
17047 Handle<Context> context, 17060 Handle<Context> context,
17048 LanguageMode language_mode) { 17061 LanguageMode language_mode,
17062 bool is_module) {
17049 Isolate* isolate = GetIsolate(); 17063 Isolate* isolate = GetIsolate();
17050 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 17064 Handle<SharedFunctionInfo> shared(context->closure()->shared());
17051 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); 17065 StringSharedKey key(src, shared, language_mode, is_module,
17066 RelocInfo::kNoPosition);
17052 int entry = FindEntry(&key); 17067 int entry = FindEntry(&key);
17053 if (entry == kNotFound) return isolate->factory()->undefined_value(); 17068 if (entry == kNotFound) return isolate->factory()->undefined_value();
17054 int index = EntryToIndex(entry); 17069 int index = EntryToIndex(entry);
17055 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); 17070 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value();
17056 return Handle<Object>(get(index + 1), isolate); 17071 return Handle<Object>(get(index + 1), isolate);
17057 } 17072 }
17058 17073
17059 17074
17060 Handle<Object> CompilationCacheTable::LookupEval( 17075 Handle<Object> CompilationCacheTable::LookupEval(
17061 Handle<String> src, Handle<SharedFunctionInfo> outer_info, 17076 Handle<String> src, Handle<SharedFunctionInfo> outer_info,
(...skipping 13 matching lines...) Expand all
17075 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, 17090 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src,
17076 JSRegExp::Flags flags) { 17091 JSRegExp::Flags flags) {
17077 Isolate* isolate = GetIsolate(); 17092 Isolate* isolate = GetIsolate();
17078 DisallowHeapAllocation no_allocation; 17093 DisallowHeapAllocation no_allocation;
17079 RegExpKey key(src, flags); 17094 RegExpKey key(src, flags);
17080 int entry = FindEntry(&key); 17095 int entry = FindEntry(&key);
17081 if (entry == kNotFound) return isolate->factory()->undefined_value(); 17096 if (entry == kNotFound) return isolate->factory()->undefined_value();
17082 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); 17097 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate);
17083 } 17098 }
17084 17099
17085
17086 Handle<CompilationCacheTable> CompilationCacheTable::Put( 17100 Handle<CompilationCacheTable> CompilationCacheTable::Put(
17087 Handle<CompilationCacheTable> cache, Handle<String> src, 17101 Handle<CompilationCacheTable> cache, Handle<String> src,
17088 Handle<Context> context, LanguageMode language_mode, Handle<Object> value) { 17102 Handle<Context> context, LanguageMode language_mode, bool is_module,
17103 Handle<Object> value) {
17089 Isolate* isolate = cache->GetIsolate(); 17104 Isolate* isolate = cache->GetIsolate();
17090 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 17105 Handle<SharedFunctionInfo> shared(context->closure()->shared());
17091 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); 17106 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition);
vogelheim 2016/06/23 14:53:19 Shouldn't key depend on is_module?
mike3 2016/06/25 19:31:45 Acknowledged.
17092 Handle<Object> k = key.AsHandle(isolate); 17107 Handle<Object> k = key.AsHandle(isolate);
17093 cache = EnsureCapacity(cache, 1, &key); 17108 cache = EnsureCapacity(cache, 1, &key);
17094 int entry = cache->FindInsertionEntry(key.Hash()); 17109 int entry = cache->FindInsertionEntry(key.Hash());
17095 cache->set(EntryToIndex(entry), *k); 17110 cache->set(EntryToIndex(entry), *k);
17096 cache->set(EntryToIndex(entry) + 1, *value); 17111 cache->set(EntryToIndex(entry) + 1, *value);
17097 cache->ElementAdded(); 17112 cache->ElementAdded();
17098 return cache; 17113 return cache;
17099 } 17114 }
17100 17115
17101 17116
(...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after
18858 if (cell->value() != *new_value) { 18873 if (cell->value() != *new_value) {
18859 cell->set_value(*new_value); 18874 cell->set_value(*new_value);
18860 Isolate* isolate = cell->GetIsolate(); 18875 Isolate* isolate = cell->GetIsolate();
18861 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18876 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18862 isolate, DependentCode::kPropertyCellChangedGroup); 18877 isolate, DependentCode::kPropertyCellChangedGroup);
18863 } 18878 }
18864 } 18879 }
18865 18880
18866 } // namespace internal 18881 } // namespace internal
18867 } // namespace v8 18882 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | test/cctest/heap/test-heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698