OLD | NEW |
---|---|
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 Loading... | |
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::InSameContext(Map* map, | |
Vyacheslav Egorov (Chromium)
2011/12/14 13:34:46
I would call it IsLikelyToRetainOtherContext.
It'
fschneider
2011/12/14 14:01:42
Done.
| |
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 false; | |
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 true; | |
464 | |
465 map = JSObject::cast(map->prototype())->map(); | |
466 constructor = map->constructor(); | |
467 } | |
468 JSFunction* function = JSFunction::cast(constructor); | |
469 return InSameContext(function, global_context); | |
470 } | |
471 | |
472 | |
473 bool TypeFeedbackOracle::InSameContext(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 Loading... | |
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 (InSameContext(Map::cast(map), *global_context_)) { | |
579 SetInfo(ast_id, map); | |
580 } | |
543 } | 581 } |
544 } else if (target->ic_state() == MEGAMORPHIC) { | 582 } else if (target->ic_state() == MEGAMORPHIC) { |
545 SetInfo(ast_id, target); | 583 SetInfo(ast_id, target); |
546 } | 584 } |
547 break; | 585 break; |
548 | 586 |
549 case Code::KEYED_LOAD_IC: | 587 case Code::KEYED_LOAD_IC: |
550 case Code::KEYED_STORE_IC: | 588 case Code::KEYED_STORE_IC: |
551 if (target->ic_state() == MONOMORPHIC || | 589 if (target->ic_state() == MONOMORPHIC || |
552 target->ic_state() == MEGAMORPHIC) { | 590 target->ic_state() == MEGAMORPHIC) { |
553 SetInfo(ast_id, target); | 591 SetInfo(ast_id, target); |
554 } | 592 } |
555 break; | 593 break; |
556 | 594 |
557 case Code::UNARY_OP_IC: | 595 case Code::UNARY_OP_IC: |
558 case Code::BINARY_OP_IC: | 596 case Code::BINARY_OP_IC: |
559 case Code::COMPARE_IC: | 597 case Code::COMPARE_IC: |
560 case Code::TO_BOOLEAN_IC: | 598 case Code::TO_BOOLEAN_IC: |
561 SetInfo(ast_id, target); | 599 SetInfo(ast_id, target); |
562 break; | 600 break; |
563 | 601 |
564 case Code::STUB: | 602 case Code::STUB: |
565 if (target->major_key() == CodeStub::CallFunction && | 603 if (target->major_key() == CodeStub::CallFunction && |
566 target->has_function_cache()) { | 604 target->has_function_cache()) { |
567 Object* value = CallFunctionStub::GetCachedValue(reloc_entry.pc()); | 605 Object* value = CallFunctionStub::GetCachedValue(reloc_entry.pc()); |
568 if (value->IsJSFunction()) { | 606 if (value->IsJSFunction() && |
607 InSameContext(JSFunction::cast(value), *global_context_)) { | |
569 SetInfo(ast_id, value); | 608 SetInfo(ast_id, value); |
570 } | 609 } |
571 } | 610 } |
572 break; | 611 break; |
573 | 612 |
574 default: | 613 default: |
575 break; | 614 break; |
576 } | 615 } |
577 } | 616 } |
578 } | 617 } |
579 | 618 |
580 | 619 |
581 void TypeFeedbackOracle::SetInfo(unsigned ast_id, Object* target) { | 620 void TypeFeedbackOracle::SetInfo(unsigned ast_id, Object* target) { |
582 ASSERT(dictionary_->FindEntry(ast_id) == NumberDictionary::kNotFound); | 621 ASSERT(dictionary_->FindEntry(ast_id) == NumberDictionary::kNotFound); |
583 MaybeObject* maybe_result = dictionary_->AtNumberPut(ast_id, target); | 622 MaybeObject* maybe_result = dictionary_->AtNumberPut(ast_id, target); |
584 USE(maybe_result); | 623 USE(maybe_result); |
585 #ifdef DEBUG | 624 #ifdef DEBUG |
586 Object* result = NULL; | 625 Object* result = NULL; |
587 // Dictionary has been allocated with sufficient size for all elements. | 626 // Dictionary has been allocated with sufficient size for all elements. |
588 ASSERT(maybe_result->ToObject(&result)); | 627 ASSERT(maybe_result->ToObject(&result)); |
589 ASSERT(*dictionary_ == result); | 628 ASSERT(*dictionary_ == result); |
590 #endif | 629 #endif |
591 } | 630 } |
592 | 631 |
593 } } // namespace v8::internal | 632 } } // namespace v8::internal |
OLD | NEW |