OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 info = TypeInfo::Unknown(); | 56 info = TypeInfo::Unknown(); |
57 } | 57 } |
58 return info; | 58 return info; |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, | 62 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, |
63 Handle<Context> native_context, | 63 Handle<Context> native_context, |
64 Isolate* isolate, | 64 Isolate* isolate, |
65 Zone* zone) | 65 Zone* zone) |
66 : native_context_(native_context), | 66 : code_(code), |
| 67 native_context_(native_context), |
67 isolate_(isolate), | 68 isolate_(isolate), |
68 zone_(zone) { | 69 zone_(zone) { |
69 BuildDictionary(code); | 70 BuildDictionary(code); |
70 ASSERT(dictionary_->IsDictionary()); | 71 ASSERT(dictionary_->IsDictionary()); |
71 } | 72 } |
72 | 73 |
73 | 74 |
74 static uint32_t IdToKey(TypeFeedbackId ast_id) { | 75 static uint32_t IdToKey(TypeFeedbackId ast_id) { |
75 return static_cast<uint32_t>(ast_id.ToInt()); | 76 return static_cast<uint32_t>(ast_id.ToInt()); |
76 } | 77 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 TypeInfo unknown = TypeInfo::Unknown(); | 484 TypeInfo unknown = TypeInfo::Unknown(); |
484 if (!object->IsCode()) return unknown; | 485 if (!object->IsCode()) return unknown; |
485 Handle<Code> code = Handle<Code>::cast(object); | 486 Handle<Code> code = Handle<Code>::cast(object); |
486 if (!code->is_compare_ic_stub()) return unknown; | 487 if (!code->is_compare_ic_stub()) return unknown; |
487 | 488 |
488 CompareIC::State state = ICCompareStub::CompareState(code->stub_info()); | 489 CompareIC::State state = ICCompareStub::CompareState(code->stub_info()); |
489 return TypeFromCompareType(state); | 490 return TypeFromCompareType(state); |
490 } | 491 } |
491 | 492 |
492 | 493 |
| 494 int TypeFeedbackOracle::SwitchHitCount(CaseClause* clause) { |
| 495 Handle<Object> object = GetInfo(clause->CounterId()); |
| 496 if (!object->IsSmi()) return 0; |
| 497 |
| 498 int ret = Smi::cast(*object)->value(); |
| 499 if (ret == 0) return ret; |
| 500 |
| 501 // Reset counter after observing it |
| 502 // XXX: O(n) for each hit counter |
| 503 Object* raw_info = code_->type_feedback_info(); |
| 504 if (raw_info->IsTypeFeedbackInfo()) { |
| 505 Handle<TypeFeedbackCells> cache( |
| 506 TypeFeedbackInfo::cast(raw_info)->type_feedback_cells()); |
| 507 for (int i = 0; i < cache->CellCount(); i++) { |
| 508 TypeFeedbackId ast_id = cache->AstId(i); |
| 509 if (ast_id.ToInt() != clause->CounterId().ToInt()) continue; |
| 510 |
| 511 cache->Cell(i)->set_value(Smi::FromInt(0)); |
| 512 } |
| 513 } |
| 514 |
| 515 return ret; |
| 516 } |
| 517 |
| 518 |
493 TypeInfo TypeFeedbackOracle::IncrementType(CountOperation* expr) { | 519 TypeInfo TypeFeedbackOracle::IncrementType(CountOperation* expr) { |
494 Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId()); | 520 Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId()); |
495 TypeInfo unknown = TypeInfo::Unknown(); | 521 TypeInfo unknown = TypeInfo::Unknown(); |
496 if (!object->IsCode()) return unknown; | 522 if (!object->IsCode()) return unknown; |
497 Handle<Code> code = Handle<Code>::cast(object); | 523 Handle<Code> code = Handle<Code>::cast(object); |
498 if (!code->is_binary_op_stub()) return unknown; | 524 if (!code->is_binary_op_stub()) return unknown; |
499 | 525 |
500 BinaryOpIC::TypeInfo left_type, right_type, unused_result_type; | 526 BinaryOpIC::TypeInfo left_type, right_type, unused_result_type; |
501 BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, | 527 BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, |
502 &right_type, &unused_result_type); | 528 &right_type, &unused_result_type); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 USE(maybe_result); | 784 USE(maybe_result); |
759 #ifdef DEBUG | 785 #ifdef DEBUG |
760 Object* result = NULL; | 786 Object* result = NULL; |
761 // Dictionary has been allocated with sufficient size for all elements. | 787 // Dictionary has been allocated with sufficient size for all elements. |
762 ASSERT(maybe_result->ToObject(&result)); | 788 ASSERT(maybe_result->ToObject(&result)); |
763 ASSERT(*dictionary_ == result); | 789 ASSERT(*dictionary_ == result); |
764 #endif | 790 #endif |
765 } | 791 } |
766 | 792 |
767 } } // namespace v8::internal | 793 } } // namespace v8::internal |
OLD | NEW |