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

Side by Side Diff: src/transitions.cc

Issue 1163073002: Replace ad-hoc weakness in prototype transitions with WeakCell. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix crash Created 5 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
« no previous file with comments | « src/transitions.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
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 // 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/objects.h" 7 #include "src/objects.h"
8 #include "src/transitions-inl.h" 8 #include "src/transitions-inl.h"
9 #include "src/utils.h" 9 #include "src/utils.h"
10 10
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 Object* raw_transitions = map->raw_transitions(); 226 Object* raw_transitions = map->raw_transitions();
227 if (IsFullTransitionArray(raw_transitions)) { 227 if (IsFullTransitionArray(raw_transitions)) {
228 TransitionArray* transitions = TransitionArray::cast(raw_transitions); 228 TransitionArray* transitions = TransitionArray::cast(raw_transitions);
229 return transitions->number_of_transitions() < kMaxNumberOfTransitions; 229 return transitions->number_of_transitions() < kMaxNumberOfTransitions;
230 } 230 }
231 return true; 231 return true;
232 } 232 }
233 233
234 234
235 // static 235 // static
236 Handle<Map> TransitionArray::PutPrototypeTransition(Handle<Map> map, 236 void TransitionArray::PutPrototypeTransition(Handle<Map> map,
237 Handle<Object> prototype, 237 Handle<Object> prototype,
238 Handle<Map> target_map) { 238 Handle<Map> target_map) {
239 DCHECK(HeapObject::cast(*prototype)->map()->IsMap()); 239 DCHECK(HeapObject::cast(*prototype)->map()->IsMap());
240 // Don't cache prototype transition if this map is either shared, or a map of 240 // Don't cache prototype transition if this map is either shared, or a map of
241 // a prototype. 241 // a prototype.
242 if (map->is_prototype_map()) return map; 242 if (map->is_prototype_map()) return;
243 if (map->is_dictionary_map() || !FLAG_cache_prototype_transitions) return map; 243 if (map->is_dictionary_map() || !FLAG_cache_prototype_transitions) return;
244 244
245 const int header = kProtoTransitionHeaderSize; 245 const int header = kProtoTransitionHeaderSize;
246 246
247 Handle<WeakCell> target_cell = Map::WeakCellForMap(target_map);
248
247 Handle<FixedArray> cache(GetPrototypeTransitions(*map)); 249 Handle<FixedArray> cache(GetPrototypeTransitions(*map));
248 int capacity = cache->length() - header; 250 int capacity = cache->length() - header;
249 int transitions = NumberOfPrototypeTransitions(*cache) + 1; 251 int transitions = NumberOfPrototypeTransitions(*cache) + 1;
250 252
251 if (transitions > capacity) { 253 if (transitions > capacity) {
252 // Grow array by factor 2 up to MaxCachedPrototypeTransitions. 254 // Grow array by factor 2 up to MaxCachedPrototypeTransitions.
253 int new_capacity = Min(kMaxCachedPrototypeTransitions, transitions * 2); 255 int new_capacity = Min(kMaxCachedPrototypeTransitions, transitions * 2);
254 if (new_capacity == capacity) return map; 256 if (new_capacity == capacity) return;
255 257
256 cache = FixedArray::CopySize(cache, header + new_capacity); 258 cache = FixedArray::CopySize(cache, header + new_capacity);
257 if (capacity < 0) { 259 if (capacity < 0) {
258 // There was no prototype transitions array before, so the size 260 // There was no prototype transitions array before, so the size
259 // couldn't be copied. Initialize it explicitly. 261 // couldn't be copied. Initialize it explicitly.
260 SetNumberOfPrototypeTransitions(*cache, 0); 262 SetNumberOfPrototypeTransitions(*cache, 0);
261 } 263 }
262 264
263 SetPrototypeTransitions(map, cache); 265 SetPrototypeTransitions(map, cache);
264 } 266 }
265 267
266 // Reload number of transitions as GC might shrink them. 268 // Reload number of transitions as GC might shrink them.
267 int last = NumberOfPrototypeTransitions(*cache); 269 int last = NumberOfPrototypeTransitions(*cache);
268 int entry = header + last; 270 int entry = header + last;
269 271
270 cache->set(entry, *target_map); 272 cache->set(entry, *target_cell);
271 SetNumberOfPrototypeTransitions(*cache, last + 1); 273 SetNumberOfPrototypeTransitions(*cache, last + 1);
272
273 return map;
274 } 274 }
275 275
276 276
277 // static 277 // static
278 Handle<Map> TransitionArray::GetPrototypeTransition(Handle<Map> map, 278 Handle<Map> TransitionArray::GetPrototypeTransition(Handle<Map> map,
279 Handle<Object> prototype) { 279 Handle<Object> prototype) {
280 DisallowHeapAllocation no_gc; 280 DisallowHeapAllocation no_gc;
281 FixedArray* cache = GetPrototypeTransitions(*map); 281 FixedArray* cache = GetPrototypeTransitions(*map);
282 int number_of_transitions = NumberOfPrototypeTransitions(cache); 282 int number_of_transitions = NumberOfPrototypeTransitions(cache);
283 for (int i = 0; i < number_of_transitions; i++) { 283 for (int i = 0; i < number_of_transitions; i++) {
284 Map* target = Map::cast(cache->get(kProtoTransitionHeaderSize + i)); 284 WeakCell* target_cell =
285 if (target->prototype() == *prototype) return handle(target); 285 WeakCell::cast(cache->get(kProtoTransitionHeaderSize + i));
286 if (!target_cell->cleared() &&
287 Map::cast(target_cell->value())->prototype() == *prototype) {
288 return handle(Map::cast(target_cell->value()));
289 }
286 } 290 }
287 return Handle<Map>(); 291 return Handle<Map>();
288 } 292 }
289 293
290 294
291 // static 295 // static
292 FixedArray* TransitionArray::GetPrototypeTransitions(Map* map) { 296 FixedArray* TransitionArray::GetPrototypeTransitions(Map* map) {
293 Object* raw_transitions = map->raw_transitions(); 297 Object* raw_transitions = map->raw_transitions();
294 Heap* heap = map->GetHeap(); 298 Heap* heap = map->GetHeap();
295 if (!IsFullTransitionArray(raw_transitions)) { 299 if (!IsFullTransitionArray(raw_transitions)) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 void TransitionArray::TraverseTransitionTreeInternal(Map* map, 433 void TransitionArray::TraverseTransitionTreeInternal(Map* map,
430 TraverseCallback callback, 434 TraverseCallback callback,
431 void* data) { 435 void* data) {
432 Object* raw_transitions = map->raw_transitions(); 436 Object* raw_transitions = map->raw_transitions();
433 if (IsFullTransitionArray(raw_transitions)) { 437 if (IsFullTransitionArray(raw_transitions)) {
434 TransitionArray* transitions = TransitionArray::cast(raw_transitions); 438 TransitionArray* transitions = TransitionArray::cast(raw_transitions);
435 if (transitions->HasPrototypeTransitions()) { 439 if (transitions->HasPrototypeTransitions()) {
436 FixedArray* proto_trans = transitions->GetPrototypeTransitions(); 440 FixedArray* proto_trans = transitions->GetPrototypeTransitions();
437 for (int i = 0; i < NumberOfPrototypeTransitions(proto_trans); ++i) { 441 for (int i = 0; i < NumberOfPrototypeTransitions(proto_trans); ++i) {
438 int index = TransitionArray::kProtoTransitionHeaderSize + i; 442 int index = TransitionArray::kProtoTransitionHeaderSize + i;
439 TraverseTransitionTreeInternal(Map::cast(proto_trans->get(index)), 443 WeakCell* cell = WeakCell::cast(proto_trans->get(index));
440 callback, data); 444 TraverseTransitionTreeInternal(Map::cast(cell->value()), callback,
445 data);
441 } 446 }
442 } 447 }
443 for (int i = 0; i < transitions->number_of_transitions(); ++i) { 448 for (int i = 0; i < transitions->number_of_transitions(); ++i) {
444 TraverseTransitionTreeInternal(transitions->GetTarget(i), callback, data); 449 TraverseTransitionTreeInternal(transitions->GetTarget(i), callback, data);
445 } 450 }
446 } else if (IsSimpleTransition(raw_transitions)) { 451 } else if (IsSimpleTransition(raw_transitions)) {
447 TraverseTransitionTreeInternal(GetSimpleTransition(raw_transitions), 452 TraverseTransitionTreeInternal(GetSimpleTransition(raw_transitions),
448 callback, data); 453 callback, data);
449 } 454 }
450 callback(map, data); 455 callback(map, data);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 PropertyAttributes attributes, 513 PropertyAttributes attributes,
509 int* out_insertion_index) { 514 int* out_insertion_index) {
510 int transition = SearchName(name, out_insertion_index); 515 int transition = SearchName(name, out_insertion_index);
511 if (transition == kNotFound) { 516 if (transition == kNotFound) {
512 return kNotFound; 517 return kNotFound;
513 } 518 }
514 return SearchDetails(transition, kind, attributes, out_insertion_index); 519 return SearchDetails(transition, kind, attributes, out_insertion_index);
515 } 520 }
516 } // namespace internal 521 } // namespace internal
517 } // namespace v8 522 } // namespace v8
OLDNEW
« no previous file with comments | « src/transitions.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698