| 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 *reinterpret_cast<Smi**>(cache->Cell(i)->ValueAddress()) = |
| 512 Smi::FromInt(0); |
| 513 } |
| 514 } |
| 515 |
| 516 return ret; |
| 517 } |
| 518 |
| 519 |
| 493 TypeInfo TypeFeedbackOracle::IncrementType(CountOperation* expr) { | 520 TypeInfo TypeFeedbackOracle::IncrementType(CountOperation* expr) { |
| 494 Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId()); | 521 Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId()); |
| 495 TypeInfo unknown = TypeInfo::Unknown(); | 522 TypeInfo unknown = TypeInfo::Unknown(); |
| 496 if (!object->IsCode()) return unknown; | 523 if (!object->IsCode()) return unknown; |
| 497 Handle<Code> code = Handle<Code>::cast(object); | 524 Handle<Code> code = Handle<Code>::cast(object); |
| 498 if (!code->is_binary_op_stub()) return unknown; | 525 if (!code->is_binary_op_stub()) return unknown; |
| 499 | 526 |
| 500 BinaryOpIC::TypeInfo left_type, right_type, unused_result_type; | 527 BinaryOpIC::TypeInfo left_type, right_type, unused_result_type; |
| 501 BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, | 528 BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, |
| 502 &right_type, &unused_result_type); | 529 &right_type, &unused_result_type); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 USE(maybe_result); | 785 USE(maybe_result); |
| 759 #ifdef DEBUG | 786 #ifdef DEBUG |
| 760 Object* result = NULL; | 787 Object* result = NULL; |
| 761 // Dictionary has been allocated with sufficient size for all elements. | 788 // Dictionary has been allocated with sufficient size for all elements. |
| 762 ASSERT(maybe_result->ToObject(&result)); | 789 ASSERT(maybe_result->ToObject(&result)); |
| 763 ASSERT(*dictionary_ == result); | 790 ASSERT(*dictionary_ == result); |
| 764 #endif | 791 #endif |
| 765 } | 792 } |
| 766 | 793 |
| 767 } } // namespace v8::internal | 794 } } // namespace v8::internal |
| OLD | NEW |