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

Side by Side Diff: src/objects.cc

Issue 1840193003: Speed up accessing default code caches in maps. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « src/ic/ic.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10105 matching lines...) Expand 10 before | Expand all | Expand 10 after
10116 UpdateNormalTypeCache(code_cache, name, code); 10116 UpdateNormalTypeCache(code_cache, name, code);
10117 } else { 10117 } else {
10118 DCHECK(code_cache->default_cache()->IsFixedArray()); 10118 DCHECK(code_cache->default_cache()->IsFixedArray());
10119 UpdateDefaultCache(code_cache, name, code); 10119 UpdateDefaultCache(code_cache, name, code);
10120 } 10120 }
10121 } 10121 }
10122 10122
10123 10123
10124 void CodeCache::UpdateDefaultCache( 10124 void CodeCache::UpdateDefaultCache(
10125 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) { 10125 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code) {
10126 Isolate* isolate = code_cache->GetIsolate();
10126 // When updating the default code cache we disregard the type encoded in the 10127 // When updating the default code cache we disregard the type encoded in the
10127 // flags. This allows call constant stubs to overwrite call field 10128 // flags. This allows call constant stubs to overwrite call field
10128 // stubs, etc. 10129 // stubs, etc.
10129 Code::Flags flags = Code::RemoveTypeFromFlags(code->flags()); 10130 Code::Flags flags = Code::RemoveTypeFromFlags(code->flags());
10130 10131
10131 // First check whether we can update existing code cache without 10132 // First check whether we can update existing code cache without
10132 // extending it. 10133 // extending it.
10133 Handle<FixedArray> cache = handle(code_cache->default_cache()); 10134 Handle<FixedArray> cache = handle(code_cache->default_cache());
10134 int length = cache->length(); 10135 int length = cache->length();
10135 { 10136 {
10136 DisallowHeapAllocation no_alloc; 10137 DisallowHeapAllocation no_alloc;
10137 int deleted_index = -1; 10138 int deleted_index = -1;
10139 Object* null = isolate->heap()->null_value();
10140 Object* undefined = isolate->heap()->undefined_value();
10141 DCHECK(name->IsUniqueName());
10138 for (int i = 0; i < length; i += kCodeCacheEntrySize) { 10142 for (int i = 0; i < length; i += kCodeCacheEntrySize) {
10139 Object* key = cache->get(i); 10143 Object* key = cache->get(i);
10140 if (key->IsNull()) { 10144 if (key == null) {
10141 if (deleted_index < 0) deleted_index = i; 10145 if (deleted_index < 0) deleted_index = i;
10142 continue; 10146 continue;
10143 } 10147 }
10144 if (key->IsUndefined()) { 10148 if (key == undefined) {
10145 if (deleted_index >= 0) i = deleted_index; 10149 if (deleted_index >= 0) i = deleted_index;
10146 cache->set(i + kCodeCacheEntryNameOffset, *name); 10150 cache->set(i + kCodeCacheEntryNameOffset, *name);
10147 cache->set(i + kCodeCacheEntryCodeOffset, *code); 10151 cache->set(i + kCodeCacheEntryCodeOffset, *code);
10148 return; 10152 return;
10149 } 10153 }
10150 if (name->Equals(Name::cast(key))) { 10154 DCHECK(key->IsUniqueName());
10155 if (*name == key) {
10151 Code::Flags found = 10156 Code::Flags found =
10152 Code::cast(cache->get(i + kCodeCacheEntryCodeOffset))->flags(); 10157 Code::cast(cache->get(i + kCodeCacheEntryCodeOffset))->flags();
10153 if (Code::RemoveTypeFromFlags(found) == flags) { 10158 if (Code::RemoveTypeFromFlags(found) == flags) {
10154 cache->set(i + kCodeCacheEntryCodeOffset, *code); 10159 cache->set(i + kCodeCacheEntryCodeOffset, *code);
10155 return; 10160 return;
10156 } 10161 }
10157 } 10162 }
10158 } 10163 }
10159 10164
10160 // Reached the end of the code cache. If there were deleted 10165 // Reached the end of the code cache. If there were deleted
10161 // elements, reuse the space for the first of them. 10166 // elements, reuse the space for the first of them.
10162 if (deleted_index >= 0) { 10167 if (deleted_index >= 0) {
10163 cache->set(deleted_index + kCodeCacheEntryNameOffset, *name); 10168 cache->set(deleted_index + kCodeCacheEntryNameOffset, *name);
10164 cache->set(deleted_index + kCodeCacheEntryCodeOffset, *code); 10169 cache->set(deleted_index + kCodeCacheEntryCodeOffset, *code);
10165 return; 10170 return;
10166 } 10171 }
10167 } 10172 }
10168 10173
10169 // Extend the code cache with some new entries (at least one). Must be a 10174 // Extend the code cache with some new entries (at least one). Must be a
10170 // multiple of the entry size. 10175 // multiple of the entry size.
10171 Isolate* isolate = cache->GetIsolate();
10172 int new_length = length + (length >> 1) + kCodeCacheEntrySize; 10176 int new_length = length + (length >> 1) + kCodeCacheEntrySize;
10173 new_length = new_length - new_length % kCodeCacheEntrySize; 10177 new_length = new_length - new_length % kCodeCacheEntrySize;
10174 DCHECK((new_length % kCodeCacheEntrySize) == 0); 10178 DCHECK((new_length % kCodeCacheEntrySize) == 0);
10175 cache = isolate->factory()->CopyFixedArrayAndGrow(cache, new_length - length); 10179 cache = isolate->factory()->CopyFixedArrayAndGrow(cache, new_length - length);
10176 10180
10177 // Add the (name, code) pair to the new cache. 10181 // Add the (name, code) pair to the new cache.
10178 cache->set(length + kCodeCacheEntryNameOffset, *name); 10182 cache->set(length + kCodeCacheEntryNameOffset, *name);
10179 cache->set(length + kCodeCacheEntryCodeOffset, *code); 10183 cache->set(length + kCodeCacheEntryCodeOffset, *code);
10180 code_cache->set_default_cache(*cache); 10184 code_cache->set_default_cache(*cache);
10181 } 10185 }
(...skipping 14 matching lines...) Expand all
10196 if (result->IsCode()) { 10200 if (result->IsCode()) {
10197 if (Code::cast(result)->flags() == flags) return result; 10201 if (Code::cast(result)->flags() == flags) return result;
10198 return GetHeap()->undefined_value(); 10202 return GetHeap()->undefined_value();
10199 } 10203 }
10200 return LookupNormalTypeCache(name, flags); 10204 return LookupNormalTypeCache(name, flags);
10201 } 10205 }
10202 10206
10203 10207
10204 Object* CodeCache::LookupDefaultCache(Name* name, Code::Flags flags) { 10208 Object* CodeCache::LookupDefaultCache(Name* name, Code::Flags flags) {
10205 FixedArray* cache = default_cache(); 10209 FixedArray* cache = default_cache();
10210 Heap* heap = GetHeap();
10211 Object* null = heap->null_value();
10212 Object* undefined = heap->undefined_value();
10206 int length = cache->length(); 10213 int length = cache->length();
10214 DCHECK(name->IsUniqueName());
10207 for (int i = 0; i < length; i += kCodeCacheEntrySize) { 10215 for (int i = 0; i < length; i += kCodeCacheEntrySize) {
10208 Object* key = cache->get(i + kCodeCacheEntryNameOffset); 10216 Object* key = cache->get(i + kCodeCacheEntryNameOffset);
10209 // Skip deleted elements. 10217 // Skip deleted elements.
10210 if (key->IsNull()) continue; 10218 if (key == null) continue;
10211 if (key->IsUndefined()) return key; 10219 if (key == undefined) return key;
10212 if (name->Equals(Name::cast(key))) { 10220 DCHECK(key->IsUniqueName());
10221 if (name == key) {
10213 Code* code = Code::cast(cache->get(i + kCodeCacheEntryCodeOffset)); 10222 Code* code = Code::cast(cache->get(i + kCodeCacheEntryCodeOffset));
10214 if (Code::RemoveTypeFromFlags(code->flags()) == flags) { 10223 if (Code::RemoveTypeFromFlags(code->flags()) == flags) {
10215 return code; 10224 return code;
10216 } 10225 }
10217 } 10226 }
10218 } 10227 }
10219 return GetHeap()->undefined_value(); 10228 return GetHeap()->undefined_value();
10220 } 10229 }
10221 10230
10222 10231
(...skipping 9537 matching lines...) Expand 10 before | Expand all | Expand 10 after
19760 if (cell->value() != *new_value) { 19769 if (cell->value() != *new_value) {
19761 cell->set_value(*new_value); 19770 cell->set_value(*new_value);
19762 Isolate* isolate = cell->GetIsolate(); 19771 Isolate* isolate = cell->GetIsolate();
19763 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19772 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19764 isolate, DependentCode::kPropertyCellChangedGroup); 19773 isolate, DependentCode::kPropertyCellChangedGroup);
19765 } 19774 }
19766 } 19775 }
19767 19776
19768 } // namespace internal 19777 } // namespace internal
19769 } // namespace v8 19778 } // namespace v8
OLDNEW
« no previous file with comments | « src/ic/ic.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698