| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // Recording of type feedback | 587 // Recording of type feedback |
| 588 | 588 |
| 589 // TODO(rossberg): all RecordTypeFeedback functions should disappear | 589 // TODO(rossberg): all RecordTypeFeedback functions should disappear |
| 590 // once we use the common type field in the AST consistently. | 590 // once we use the common type field in the AST consistently. |
| 591 | 591 |
| 592 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { | 592 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { |
| 593 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); | 593 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 | 596 |
| 597 int Call::GetFeedbackSlotCount(Isolate* isolate) { |
| 598 CallType call_type = GetCallType(isolate); |
| 599 if (call_type == LOOKUP_SLOT_CALL || call_type == OTHER_CALL) { |
| 600 // Call only uses a slot in some cases. |
| 601 return 1; |
| 602 } |
| 603 |
| 604 return 0; |
| 605 } |
| 606 |
| 607 |
| 597 Call::CallType Call::GetCallType(Isolate* isolate) const { | 608 Call::CallType Call::GetCallType(Isolate* isolate) const { |
| 598 VariableProxy* proxy = expression()->AsVariableProxy(); | 609 VariableProxy* proxy = expression()->AsVariableProxy(); |
| 599 if (proxy != NULL) { | 610 if (proxy != NULL) { |
| 600 if (proxy->var()->is_possibly_eval(isolate)) { | 611 if (proxy->var()->is_possibly_eval(isolate)) { |
| 601 return POSSIBLY_EVAL_CALL; | 612 return POSSIBLY_EVAL_CALL; |
| 602 } else if (proxy->var()->IsUnallocated()) { | 613 } else if (proxy->var()->IsUnallocated()) { |
| 603 return GLOBAL_CALL; | 614 return GLOBAL_CALL; |
| 604 } else if (proxy->var()->IsLookupSlot()) { | 615 } else if (proxy->var()->IsLookupSlot()) { |
| 605 return LOOKUP_SLOT_CALL; | 616 return LOOKUP_SLOT_CALL; |
| 606 } | 617 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 case BOOLEAN_CHECK: | 716 case BOOLEAN_CHECK: |
| 706 function = native_context->boolean_function(); | 717 function = native_context->boolean_function(); |
| 707 break; | 718 break; |
| 708 } | 719 } |
| 709 ASSERT(function != NULL); | 720 ASSERT(function != NULL); |
| 710 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 721 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 711 } | 722 } |
| 712 | 723 |
| 713 | 724 |
| 714 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 725 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 715 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackId()); | 726 if (CallFeedbackSlot() >= 0) { |
| 716 Property* property = expression()->AsProperty(); | 727 // We stored feedback in the type vector. |
| 717 if (property == NULL) { | 728 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackSlot()); |
| 718 // Function call. Specialize for monomorphic calls. | 729 ASSERT(expression()->AsProperty() == NULL); |
| 719 if (is_monomorphic_) target_ = oracle->GetCallTarget(CallFeedbackId()); | 730 if (is_monomorphic_) target_ = oracle->GetCallTarget(CallFeedbackSlot()); |
| 720 } else if (property->key()->IsPropertyName()) { | 731 } else { |
| 721 // Method call. Specialize for the receiver types seen at runtime. | 732 // We stored feedback in an IC. |
| 722 Literal* key = property->key()->AsLiteral(); | 733 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackId()); |
| 723 ASSERT(key != NULL && key->value()->IsString()); | 734 Property* property = expression()->AsProperty(); |
| 724 Handle<String> name = Handle<String>::cast(key->value()); | 735 if (property != NULL) { |
| 725 check_type_ = oracle->GetCallCheckType(CallFeedbackId()); | 736 if (property->key()->IsPropertyName()) { |
| 726 receiver_types_.Clear(); | 737 // Method call. Specialize for the receiver types seen at runtime. |
| 727 if (check_type_ == RECEIVER_MAP_CHECK) { | 738 Literal* key = property->key()->AsLiteral(); |
| 728 oracle->CallReceiverTypes(CallFeedbackId(), | 739 ASSERT(key != NULL && key->value()->IsString()); |
| 729 name, arguments()->length(), &receiver_types_); | 740 Handle<String> name = Handle<String>::cast(key->value()); |
| 730 is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0; | 741 check_type_ = oracle->GetCallCheckType(CallFeedbackId()); |
| 731 } else { | 742 receiver_types_.Clear(); |
| 732 holder_ = GetPrototypeForPrimitiveCheck(check_type_, oracle->isolate()); | 743 if (check_type_ == RECEIVER_MAP_CHECK) { |
| 733 receiver_types_.Add(handle(holder_->map()), oracle->zone()); | 744 oracle->CallReceiverTypes(CallFeedbackId(), |
| 734 } | 745 name, arguments()->length(), |
| 746 &receiver_types_); |
| 747 is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0; |
| 748 } else { |
| 749 holder_ = GetPrototypeForPrimitiveCheck(check_type_, |
| 750 oracle->isolate()); |
| 751 receiver_types_.Add(handle(holder_->map()), oracle->zone()); |
| 752 } |
| 735 #ifdef ENABLE_SLOW_ASSERTS | 753 #ifdef ENABLE_SLOW_ASSERTS |
| 736 if (FLAG_enable_slow_asserts) { | 754 if (FLAG_enable_slow_asserts) { |
| 737 int length = receiver_types_.length(); | 755 int length = receiver_types_.length(); |
| 738 for (int i = 0; i < length; i++) { | 756 for (int i = 0; i < length; i++) { |
| 739 Handle<Map> map = receiver_types_.at(i); | 757 Handle<Map> map = receiver_types_.at(i); |
| 740 ASSERT(!map.is_null() && *map != NULL); | 758 ASSERT(!map.is_null() && *map != NULL); |
| 759 } |
| 760 } |
| 761 #endif |
| 762 if (is_monomorphic_) { |
| 763 Handle<Map> map = receiver_types_.first(); |
| 764 is_monomorphic_ = ComputeTarget(map, name); |
| 765 } |
| 766 } else { |
| 767 if (is_monomorphic_) { |
| 768 keyed_array_call_is_holey_ = |
| 769 oracle->KeyedArrayCallIsHoley(CallFeedbackId()); |
| 770 } |
| 741 } | 771 } |
| 742 } | 772 } |
| 743 #endif | |
| 744 if (is_monomorphic_) { | |
| 745 Handle<Map> map = receiver_types_.first(); | |
| 746 is_monomorphic_ = ComputeTarget(map, name); | |
| 747 } | |
| 748 } else { | |
| 749 if (is_monomorphic_) { | |
| 750 keyed_array_call_is_holey_ = | |
| 751 oracle->KeyedArrayCallIsHoley(CallFeedbackId()); | |
| 752 } | |
| 753 } | 773 } |
| 754 } | 774 } |
| 755 | 775 |
| 756 | 776 |
| 757 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 777 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 758 allocation_site_ = | 778 allocation_site_ = |
| 759 oracle->GetCallNewAllocationSite(CallNewFeedbackId()); | 779 oracle->GetCallNewAllocationSite(CallNewFeedbackSlot()); |
| 760 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackId()); | 780 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackSlot()); |
| 761 if (is_monomorphic_) { | 781 if (is_monomorphic_) { |
| 762 target_ = oracle->GetCallNewTarget(CallNewFeedbackId()); | 782 target_ = oracle->GetCallNewTarget(CallNewFeedbackSlot()); |
| 763 if (!allocation_site_.is_null()) { | 783 if (!allocation_site_.is_null()) { |
| 764 elements_kind_ = allocation_site_->GetElementsKind(); | 784 elements_kind_ = allocation_site_->GetElementsKind(); |
| 765 } | 785 } |
| 766 } | 786 } |
| 767 } | 787 } |
| 768 | 788 |
| 769 | 789 |
| 770 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 790 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 771 TypeFeedbackId id = key()->LiteralFeedbackId(); | 791 TypeFeedbackId id = key()->LiteralFeedbackId(); |
| 772 SmallMapList maps; | 792 SmallMapList maps; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 statements_(statements), | 1174 statements_(statements), |
| 1155 compare_type_(Type::None(zone)), | 1175 compare_type_(Type::None(zone)), |
| 1156 compare_id_(AstNode::GetNextId(zone)), | 1176 compare_id_(AstNode::GetNextId(zone)), |
| 1157 entry_id_(AstNode::GetNextId(zone)) { | 1177 entry_id_(AstNode::GetNextId(zone)) { |
| 1158 } | 1178 } |
| 1159 | 1179 |
| 1160 | 1180 |
| 1161 #define REGULAR_NODE(NodeType) \ | 1181 #define REGULAR_NODE(NodeType) \ |
| 1162 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1182 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1163 increase_node_count(); \ | 1183 increase_node_count(); \ |
| 1184 AddFeedbackSlotInterface(node->SupportsFeedbackSlots()); \ |
| 1164 } | 1185 } |
| 1165 #define DONT_OPTIMIZE_NODE(NodeType) \ | 1186 #define DONT_OPTIMIZE_NODE(NodeType) \ |
| 1166 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1187 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1167 increase_node_count(); \ | 1188 increase_node_count(); \ |
| 1189 AddFeedbackSlotInterface(node->SupportsFeedbackSlots()); \ |
| 1168 set_dont_optimize_reason(k##NodeType); \ | 1190 set_dont_optimize_reason(k##NodeType); \ |
| 1169 add_flag(kDontInline); \ | 1191 add_flag(kDontInline); \ |
| 1170 add_flag(kDontSelfOptimize); \ | 1192 add_flag(kDontSelfOptimize); \ |
| 1171 } | 1193 } |
| 1172 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ | 1194 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ |
| 1173 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1195 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1174 increase_node_count(); \ | 1196 increase_node_count(); \ |
| 1197 AddFeedbackSlotInterface(node->SupportsFeedbackSlots()); \ |
| 1175 add_flag(kDontSelfOptimize); \ | 1198 add_flag(kDontSelfOptimize); \ |
| 1176 } | 1199 } |
| 1177 #define DONT_CACHE_NODE(NodeType) \ | 1200 #define DONT_CACHE_NODE(NodeType) \ |
| 1178 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1201 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1179 increase_node_count(); \ | 1202 increase_node_count(); \ |
| 1203 AddFeedbackSlotInterface(node->SupportsFeedbackSlots()); \ |
| 1180 set_dont_optimize_reason(k##NodeType); \ | 1204 set_dont_optimize_reason(k##NodeType); \ |
| 1181 add_flag(kDontInline); \ | 1205 add_flag(kDontInline); \ |
| 1182 add_flag(kDontSelfOptimize); \ | 1206 add_flag(kDontSelfOptimize); \ |
| 1183 add_flag(kDontCache); \ | 1207 add_flag(kDontCache); \ |
| 1184 } | 1208 } |
| 1185 | 1209 |
| 1186 REGULAR_NODE(VariableDeclaration) | 1210 REGULAR_NODE(VariableDeclaration) |
| 1187 REGULAR_NODE(FunctionDeclaration) | 1211 REGULAR_NODE(FunctionDeclaration) |
| 1188 REGULAR_NODE(Block) | 1212 REGULAR_NODE(Block) |
| 1189 REGULAR_NODE(ExpressionStatement) | 1213 REGULAR_NODE(ExpressionStatement) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) | 1258 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) |
| 1235 DONT_SELFOPTIMIZE_NODE(WhileStatement) | 1259 DONT_SELFOPTIMIZE_NODE(WhileStatement) |
| 1236 DONT_SELFOPTIMIZE_NODE(ForStatement) | 1260 DONT_SELFOPTIMIZE_NODE(ForStatement) |
| 1237 DONT_SELFOPTIMIZE_NODE(ForInStatement) | 1261 DONT_SELFOPTIMIZE_NODE(ForInStatement) |
| 1238 DONT_SELFOPTIMIZE_NODE(ForOfStatement) | 1262 DONT_SELFOPTIMIZE_NODE(ForOfStatement) |
| 1239 | 1263 |
| 1240 DONT_CACHE_NODE(ModuleLiteral) | 1264 DONT_CACHE_NODE(ModuleLiteral) |
| 1241 | 1265 |
| 1242 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { | 1266 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
| 1243 increase_node_count(); | 1267 increase_node_count(); |
| 1268 AddFeedbackSlotInterface(node->SupportsFeedbackSlots()); |
| 1244 if (node->is_jsruntime()) { | 1269 if (node->is_jsruntime()) { |
| 1245 // Don't try to inline JS runtime calls because we don't (currently) even | 1270 // Don't try to inline JS runtime calls because we don't (currently) even |
| 1246 // optimize them. | 1271 // optimize them. |
| 1247 add_flag(kDontInline); | 1272 add_flag(kDontInline); |
| 1248 } else if (node->function()->intrinsic_type == Runtime::INLINE && | 1273 } else if (node->function()->intrinsic_type == Runtime::INLINE && |
| 1249 (node->name()->IsOneByteEqualTo( | 1274 (node->name()->IsOneByteEqualTo( |
| 1250 STATIC_ASCII_VECTOR("_ArgumentsLength")) || | 1275 STATIC_ASCII_VECTOR("_ArgumentsLength")) || |
| 1251 node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) { | 1276 node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) { |
| 1252 // Don't inline the %_ArgumentsLength or %_Arguments because their | 1277 // Don't inline the %_ArgumentsLength or %_Arguments because their |
| 1253 // implementation will not work. There is no stack frame to get them | 1278 // implementation will not work. There is no stack frame to get them |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1273 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); | 1298 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); |
| 1274 str = arr; | 1299 str = arr; |
| 1275 } else { | 1300 } else { |
| 1276 str = DoubleToCString(value_->Number(), buffer); | 1301 str = DoubleToCString(value_->Number(), buffer); |
| 1277 } | 1302 } |
| 1278 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); | 1303 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); |
| 1279 } | 1304 } |
| 1280 | 1305 |
| 1281 | 1306 |
| 1282 } } // namespace v8::internal | 1307 } } // namespace v8::internal |
| OLD | NEW |