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

Side by Side Diff: src/type-info.cc

Issue 8892002: Filter out maps from different global context when collecting type feedback. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: addressed latest comments Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « src/type-info.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 isolate_->builtins()->builtin(Builtins::kStoreIC_GlobalProxy)) { 431 isolate_->builtins()->builtin(Builtins::kStoreIC_GlobalProxy)) {
432 // TODO(fschneider): We could collect the maps and signal that 432 // TODO(fschneider): We could collect the maps and signal that
433 // we need a generic store (or load) here. 433 // we need a generic store (or load) here.
434 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC); 434 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC);
435 } else if (object->IsMap()) { 435 } else if (object->IsMap()) {
436 types->Add(Handle<Map>::cast(object)); 436 types->Add(Handle<Map>::cast(object));
437 } else if (FLAG_collect_megamorphic_maps_from_stub_cache && 437 } else if (FLAG_collect_megamorphic_maps_from_stub_cache &&
438 Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) { 438 Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) {
439 types->Reserve(4); 439 types->Reserve(4);
440 ASSERT(object->IsCode()); 440 ASSERT(object->IsCode());
441 isolate_->stub_cache()->CollectMatchingMaps(types, *name, flags); 441 isolate_->stub_cache()->CollectMatchingMaps(types,
442 *name,
443 flags,
444 global_context_);
442 } 445 }
443 } 446 }
444 447
445 448
449 // Check if a map originates from a given global context. We use this
450 // information to filter out maps from different context to avoid
451 // retaining objects from different tabs in Chrome via optimized code.
452 bool TypeFeedbackOracle::CanRetainOtherContext(Map* map,
453 Context* global_context) {
454 Object* constructor = map->constructor();
455 ASSERT(constructor != NULL);
456 while (!constructor->IsJSFunction()) {
457 // If the constructor is not null or a JSFunction, we have to
458 // conservatively assume that it may retain a global context.
459 if (!constructor->IsNull()) return true;
460
461 // If both, constructor and prototype are null, we conclude
462 // that no global context will be retained by this map.
463 if (map->prototype()->IsNull()) return false;
464
465 map = JSObject::cast(map->prototype())->map();
466 constructor = map->constructor();
467 }
468 JSFunction* function = JSFunction::cast(constructor);
469 return CanRetainOtherContext(function, global_context);
470 }
471
472
473 bool TypeFeedbackOracle::CanRetainOtherContext(JSFunction* function,
474 Context* global_context) {
475 return function->context()->global() != global_context->global()
476 && function->context()->global() != global_context->builtins();
477 }
478
479
446 static void AddMapIfMissing(Handle<Map> map, SmallMapList* list) { 480 static void AddMapIfMissing(Handle<Map> map, SmallMapList* list) {
447 for (int i = 0; i < list->length(); ++i) { 481 for (int i = 0; i < list->length(); ++i) {
448 if (list->at(i).is_identical_to(map)) return; 482 if (list->at(i).is_identical_to(map)) return;
449 } 483 }
450 list->Add(map); 484 list->Add(map);
451 } 485 }
452 486
453 487
454 void TypeFeedbackOracle::CollectKeyedReceiverTypes(unsigned ast_id, 488 void TypeFeedbackOracle::CollectKeyedReceiverTypes(unsigned ast_id,
455 SmallMapList* types) { 489 SmallMapList* types) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 case Code::LOAD_IC: 566 case Code::LOAD_IC:
533 case Code::STORE_IC: 567 case Code::STORE_IC:
534 case Code::CALL_IC: 568 case Code::CALL_IC:
535 case Code::KEYED_CALL_IC: 569 case Code::KEYED_CALL_IC:
536 if (target->ic_state() == MONOMORPHIC) { 570 if (target->ic_state() == MONOMORPHIC) {
537 if (target->kind() == Code::CALL_IC && 571 if (target->kind() == Code::CALL_IC &&
538 target->check_type() != RECEIVER_MAP_CHECK) { 572 target->check_type() != RECEIVER_MAP_CHECK) {
539 SetInfo(ast_id, Smi::FromInt(target->check_type())); 573 SetInfo(ast_id, Smi::FromInt(target->check_type()));
540 } else { 574 } else {
541 Object* map = target->FindFirstMap(); 575 Object* map = target->FindFirstMap();
542 SetInfo(ast_id, map == NULL ? static_cast<Object*>(target) : map); 576 if (map == NULL) {
577 SetInfo(ast_id, static_cast<Object*>(target));
578 } else if (!CanRetainOtherContext(Map::cast(map),
579 *global_context_)) {
580 SetInfo(ast_id, map);
581 }
543 } 582 }
544 } else if (target->ic_state() == MEGAMORPHIC) { 583 } else if (target->ic_state() == MEGAMORPHIC) {
545 SetInfo(ast_id, target); 584 SetInfo(ast_id, target);
546 } 585 }
547 break; 586 break;
548 587
549 case Code::KEYED_LOAD_IC: 588 case Code::KEYED_LOAD_IC:
550 case Code::KEYED_STORE_IC: 589 case Code::KEYED_STORE_IC:
551 if (target->ic_state() == MONOMORPHIC || 590 if (target->ic_state() == MONOMORPHIC ||
552 target->ic_state() == MEGAMORPHIC) { 591 target->ic_state() == MEGAMORPHIC) {
553 SetInfo(ast_id, target); 592 SetInfo(ast_id, target);
554 } 593 }
555 break; 594 break;
556 595
557 case Code::UNARY_OP_IC: 596 case Code::UNARY_OP_IC:
558 case Code::BINARY_OP_IC: 597 case Code::BINARY_OP_IC:
559 case Code::COMPARE_IC: 598 case Code::COMPARE_IC:
560 case Code::TO_BOOLEAN_IC: 599 case Code::TO_BOOLEAN_IC:
561 SetInfo(ast_id, target); 600 SetInfo(ast_id, target);
562 break; 601 break;
563 602
564 case Code::STUB: 603 case Code::STUB:
565 if (target->major_key() == CodeStub::CallFunction && 604 if (target->major_key() == CodeStub::CallFunction &&
566 target->has_function_cache()) { 605 target->has_function_cache()) {
567 Object* value = CallFunctionStub::GetCachedValue(reloc_entry.pc()); 606 Object* value = CallFunctionStub::GetCachedValue(reloc_entry.pc());
568 if (value->IsJSFunction()) { 607 if (value->IsJSFunction() &&
608 !CanRetainOtherContext(JSFunction::cast(value),
609 *global_context_)) {
569 SetInfo(ast_id, value); 610 SetInfo(ast_id, value);
570 } 611 }
571 } 612 }
572 break; 613 break;
573 614
574 default: 615 default:
575 break; 616 break;
576 } 617 }
577 } 618 }
578 } 619 }
579 620
580 621
581 void TypeFeedbackOracle::SetInfo(unsigned ast_id, Object* target) { 622 void TypeFeedbackOracle::SetInfo(unsigned ast_id, Object* target) {
582 ASSERT(dictionary_->FindEntry(ast_id) == NumberDictionary::kNotFound); 623 ASSERT(dictionary_->FindEntry(ast_id) == NumberDictionary::kNotFound);
583 MaybeObject* maybe_result = dictionary_->AtNumberPut(ast_id, target); 624 MaybeObject* maybe_result = dictionary_->AtNumberPut(ast_id, target);
584 USE(maybe_result); 625 USE(maybe_result);
585 #ifdef DEBUG 626 #ifdef DEBUG
586 Object* result = NULL; 627 Object* result = NULL;
587 // Dictionary has been allocated with sufficient size for all elements. 628 // Dictionary has been allocated with sufficient size for all elements.
588 ASSERT(maybe_result->ToObject(&result)); 629 ASSERT(maybe_result->ToObject(&result));
589 ASSERT(*dictionary_ == result); 630 ASSERT(*dictionary_ == result);
590 #endif 631 #endif
591 } 632 }
592 633
593 } } // namespace v8::internal 634 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/type-info.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698