| 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 21 matching lines...) Expand all Loading... |
| 32 #include "code-stubs.h" | 32 #include "code-stubs.h" |
| 33 #include "contexts.h" | 33 #include "contexts.h" |
| 34 #include "conversions.h" | 34 #include "conversions.h" |
| 35 #include "hashmap.h" | 35 #include "hashmap.h" |
| 36 #include "parser.h" | 36 #include "parser.h" |
| 37 #include "property-details.h" | 37 #include "property-details.h" |
| 38 #include "property.h" | 38 #include "property.h" |
| 39 #include "scopes.h" | 39 #include "scopes.h" |
| 40 #include "string-stream.h" | 40 #include "string-stream.h" |
| 41 #include "type-info.h" | 41 #include "type-info.h" |
| 42 #include "third_party/loki/TypeManip.h" |
| 42 | 43 |
| 43 namespace v8 { | 44 namespace v8 { |
| 44 namespace internal { | 45 namespace internal { |
| 45 | 46 |
| 46 // ---------------------------------------------------------------------------- | 47 // ---------------------------------------------------------------------------- |
| 47 // All the Accept member functions for each syntax tree node type. | 48 // All the Accept member functions for each syntax tree node type. |
| 48 | 49 |
| 49 #define DECL_ACCEPT(type) \ | 50 #define DECL_ACCEPT(type) \ |
| 50 void type::Accept(AstVisitor* v) { v->Visit##type(this); } | 51 void type::Accept(AstVisitor* v) { v->Visit##type(this); } |
| 51 AST_NODE_LIST(DECL_ACCEPT) | 52 AST_NODE_LIST(DECL_ACCEPT) |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // Recording of type feedback | 588 // Recording of type feedback |
| 588 | 589 |
| 589 // TODO(rossberg): all RecordTypeFeedback functions should disappear | 590 // TODO(rossberg): all RecordTypeFeedback functions should disappear |
| 590 // once we use the common type field in the AST consistently. | 591 // once we use the common type field in the AST consistently. |
| 591 | 592 |
| 592 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { | 593 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { |
| 593 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); | 594 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); |
| 594 } | 595 } |
| 595 | 596 |
| 596 | 597 |
| 598 int Call::GetFeedbackSlotCount(Isolate* isolate) { |
| 599 CallType call_type = GetCallType(isolate); |
| 600 if (call_type == LOOKUP_SLOT_CALL || call_type == OTHER_CALL) { |
| 601 // Call only uses a slot in some cases. |
| 602 return 1; |
| 603 } |
| 604 |
| 605 return 0; |
| 606 } |
| 607 |
| 608 |
| 597 Call::CallType Call::GetCallType(Isolate* isolate) const { | 609 Call::CallType Call::GetCallType(Isolate* isolate) const { |
| 598 VariableProxy* proxy = expression()->AsVariableProxy(); | 610 VariableProxy* proxy = expression()->AsVariableProxy(); |
| 599 if (proxy != NULL) { | 611 if (proxy != NULL) { |
| 600 if (proxy->var()->is_possibly_eval(isolate)) { | 612 if (proxy->var()->is_possibly_eval(isolate)) { |
| 601 return POSSIBLY_EVAL_CALL; | 613 return POSSIBLY_EVAL_CALL; |
| 602 } else if (proxy->var()->IsUnallocated()) { | 614 } else if (proxy->var()->IsUnallocated()) { |
| 603 return GLOBAL_CALL; | 615 return GLOBAL_CALL; |
| 604 } else if (proxy->var()->IsLookupSlot()) { | 616 } else if (proxy->var()->IsLookupSlot()) { |
| 605 return LOOKUP_SLOT_CALL; | 617 return LOOKUP_SLOT_CALL; |
| 606 } | 618 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 case BOOLEAN_CHECK: | 717 case BOOLEAN_CHECK: |
| 706 function = native_context->boolean_function(); | 718 function = native_context->boolean_function(); |
| 707 break; | 719 break; |
| 708 } | 720 } |
| 709 ASSERT(function != NULL); | 721 ASSERT(function != NULL); |
| 710 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 722 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 711 } | 723 } |
| 712 | 724 |
| 713 | 725 |
| 714 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 726 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 715 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackId()); | 727 if (HasCallFeedbackSlot()) { |
| 716 Property* property = expression()->AsProperty(); | 728 // We stored feedback in the type vector. |
| 717 if (property == NULL) { | 729 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackSlot()); |
| 718 // Function call. Specialize for monomorphic calls. | 730 ASSERT(expression()->AsProperty() == NULL); |
| 719 if (is_monomorphic_) target_ = oracle->GetCallTarget(CallFeedbackId()); | 731 if (is_monomorphic_) target_ = oracle->GetCallTarget(CallFeedbackSlot()); |
| 720 } else if (property->key()->IsPropertyName()) { | 732 } else { |
| 721 // Method call. Specialize for the receiver types seen at runtime. | 733 // We stored feedback in an IC. |
| 722 Literal* key = property->key()->AsLiteral(); | 734 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackId()); |
| 723 ASSERT(key != NULL && key->value()->IsString()); | 735 Property* property = expression()->AsProperty(); |
| 724 Handle<String> name = Handle<String>::cast(key->value()); | 736 if (property != NULL) { |
| 725 check_type_ = oracle->GetCallCheckType(CallFeedbackId()); | 737 if (property->key()->IsPropertyName()) { |
| 726 receiver_types_.Clear(); | 738 // Method call. Specialize for the receiver types seen at runtime. |
| 727 if (check_type_ == RECEIVER_MAP_CHECK) { | 739 Literal* key = property->key()->AsLiteral(); |
| 728 oracle->CallReceiverTypes(CallFeedbackId(), | 740 ASSERT(key != NULL && key->value()->IsString()); |
| 729 name, arguments()->length(), &receiver_types_); | 741 Handle<String> name = Handle<String>::cast(key->value()); |
| 730 is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0; | 742 check_type_ = oracle->GetCallCheckType(CallFeedbackId()); |
| 731 } else { | 743 receiver_types_.Clear(); |
| 732 holder_ = GetPrototypeForPrimitiveCheck(check_type_, oracle->isolate()); | 744 if (check_type_ == RECEIVER_MAP_CHECK) { |
| 733 receiver_types_.Add(handle(holder_->map()), oracle->zone()); | 745 oracle->CallReceiverTypes(CallFeedbackId(), |
| 734 } | 746 name, arguments()->length(), |
| 747 &receiver_types_); |
| 748 is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0; |
| 749 } else { |
| 750 holder_ = GetPrototypeForPrimitiveCheck(check_type_, |
| 751 oracle->isolate()); |
| 752 receiver_types_.Add(handle(holder_->map()), oracle->zone()); |
| 753 } |
| 735 #ifdef ENABLE_SLOW_ASSERTS | 754 #ifdef ENABLE_SLOW_ASSERTS |
| 736 if (FLAG_enable_slow_asserts) { | 755 if (FLAG_enable_slow_asserts) { |
| 737 int length = receiver_types_.length(); | 756 int length = receiver_types_.length(); |
| 738 for (int i = 0; i < length; i++) { | 757 for (int i = 0; i < length; i++) { |
| 739 Handle<Map> map = receiver_types_.at(i); | 758 Handle<Map> map = receiver_types_.at(i); |
| 740 ASSERT(!map.is_null() && *map != NULL); | 759 ASSERT(!map.is_null() && *map != NULL); |
| 760 } |
| 761 } |
| 762 #endif |
| 763 if (is_monomorphic_) { |
| 764 Handle<Map> map = receiver_types_.first(); |
| 765 is_monomorphic_ = ComputeTarget(map, name); |
| 766 } |
| 767 } else { |
| 768 if (is_monomorphic_) { |
| 769 keyed_array_call_is_holey_ = |
| 770 oracle->KeyedArrayCallIsHoley(CallFeedbackId()); |
| 771 } |
| 741 } | 772 } |
| 742 } | 773 } |
| 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 } | 774 } |
| 754 } | 775 } |
| 755 | 776 |
| 756 | 777 |
| 757 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 778 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 758 allocation_site_ = | 779 allocation_site_ = |
| 759 oracle->GetCallNewAllocationSite(CallNewFeedbackId()); | 780 oracle->GetCallNewAllocationSite(CallNewFeedbackSlot()); |
| 760 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackId()); | 781 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackSlot()); |
| 761 if (is_monomorphic_) { | 782 if (is_monomorphic_) { |
| 762 target_ = oracle->GetCallNewTarget(CallNewFeedbackId()); | 783 target_ = oracle->GetCallNewTarget(CallNewFeedbackSlot()); |
| 763 if (!allocation_site_.is_null()) { | 784 if (!allocation_site_.is_null()) { |
| 764 elements_kind_ = allocation_site_->GetElementsKind(); | 785 elements_kind_ = allocation_site_->GetElementsKind(); |
| 765 } | 786 } |
| 766 } | 787 } |
| 767 } | 788 } |
| 768 | 789 |
| 769 | 790 |
| 770 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 791 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 771 TypeFeedbackId id = key()->LiteralFeedbackId(); | 792 TypeFeedbackId id = key()->LiteralFeedbackId(); |
| 772 SmallMapList maps; | 793 SmallMapList maps; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 int pos) | 1172 int pos) |
| 1152 : Expression(zone, pos), | 1173 : Expression(zone, pos), |
| 1153 label_(label), | 1174 label_(label), |
| 1154 statements_(statements), | 1175 statements_(statements), |
| 1155 compare_type_(Type::None(zone)), | 1176 compare_type_(Type::None(zone)), |
| 1156 compare_id_(AstNode::GetNextId(zone)), | 1177 compare_id_(AstNode::GetNextId(zone)), |
| 1157 entry_id_(AstNode::GetNextId(zone)) { | 1178 entry_id_(AstNode::GetNextId(zone)) { |
| 1158 } | 1179 } |
| 1159 | 1180 |
| 1160 | 1181 |
| 1182 // FeedbackSlotUpdater exists to avoid a C-style cast from AstNode subtypes to |
| 1183 // FeedbackSlotInterface. With partial template specialization, we allow Loki |
| 1184 // to determine whether or not it's safe to cast an AstNode to |
| 1185 // FeedbackSlotInterface, then make the cast and call add_slot_node() |
| 1186 // in a compile-safe way. |
| 1187 template<bool B, class N> |
| 1188 class FeedbackSlotUpdater { |
| 1189 public: |
| 1190 static void Update(AstConstructionVisitor* visitor, N* n) { |
| 1191 FeedbackSlotInterface* slot = static_cast<FeedbackSlotInterface*>(n); |
| 1192 visitor->add_slot_node(slot); |
| 1193 } |
| 1194 }; |
| 1195 |
| 1196 |
| 1197 template<class N> |
| 1198 class FeedbackSlotUpdater<false, N> { |
| 1199 public: |
| 1200 static void Update(AstConstructionVisitor* visitor, N* n) {} |
| 1201 }; |
| 1202 |
| 1203 |
| 1204 #define UPDATE_FEEDBACK_SLOTS(NodeType, node) \ |
| 1205 FeedbackSlotUpdater< \ |
| 1206 Loki::SuperSubclass<FeedbackSlotInterface, NodeType>::value, \ |
| 1207 NodeType>::Update(this, node) |
| 1208 |
| 1209 |
| 1161 #define REGULAR_NODE(NodeType) \ | 1210 #define REGULAR_NODE(NodeType) \ |
| 1162 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1211 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1163 increase_node_count(); \ | 1212 increase_node_count(); \ |
| 1213 UPDATE_FEEDBACK_SLOTS(NodeType, node); \ |
| 1164 } | 1214 } |
| 1165 #define DONT_OPTIMIZE_NODE(NodeType) \ | 1215 #define DONT_OPTIMIZE_NODE(NodeType) \ |
| 1166 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1216 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1167 increase_node_count(); \ | 1217 increase_node_count(); \ |
| 1218 UPDATE_FEEDBACK_SLOTS(NodeType, node); \ |
| 1168 set_dont_optimize_reason(k##NodeType); \ | 1219 set_dont_optimize_reason(k##NodeType); \ |
| 1169 add_flag(kDontInline); \ | 1220 add_flag(kDontInline); \ |
| 1170 add_flag(kDontSelfOptimize); \ | 1221 add_flag(kDontSelfOptimize); \ |
| 1171 } | 1222 } |
| 1172 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ | 1223 #define DONT_SELFOPTIMIZE_NODE(NodeType) \ |
| 1173 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1224 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1174 increase_node_count(); \ | 1225 increase_node_count(); \ |
| 1226 UPDATE_FEEDBACK_SLOTS(NodeType, node); \ |
| 1175 add_flag(kDontSelfOptimize); \ | 1227 add_flag(kDontSelfOptimize); \ |
| 1176 } | 1228 } |
| 1177 #define DONT_CACHE_NODE(NodeType) \ | 1229 #define DONT_CACHE_NODE(NodeType) \ |
| 1178 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1230 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1179 increase_node_count(); \ | 1231 increase_node_count(); \ |
| 1232 UPDATE_FEEDBACK_SLOTS(NodeType, node); \ |
| 1180 set_dont_optimize_reason(k##NodeType); \ | 1233 set_dont_optimize_reason(k##NodeType); \ |
| 1181 add_flag(kDontInline); \ | 1234 add_flag(kDontInline); \ |
| 1182 add_flag(kDontSelfOptimize); \ | 1235 add_flag(kDontSelfOptimize); \ |
| 1183 add_flag(kDontCache); \ | 1236 add_flag(kDontCache); \ |
| 1184 } | 1237 } |
| 1185 | 1238 |
| 1186 REGULAR_NODE(VariableDeclaration) | 1239 REGULAR_NODE(VariableDeclaration) |
| 1187 REGULAR_NODE(FunctionDeclaration) | 1240 REGULAR_NODE(FunctionDeclaration) |
| 1188 REGULAR_NODE(Block) | 1241 REGULAR_NODE(Block) |
| 1189 REGULAR_NODE(ExpressionStatement) | 1242 REGULAR_NODE(ExpressionStatement) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) | 1287 DONT_SELFOPTIMIZE_NODE(DoWhileStatement) |
| 1235 DONT_SELFOPTIMIZE_NODE(WhileStatement) | 1288 DONT_SELFOPTIMIZE_NODE(WhileStatement) |
| 1236 DONT_SELFOPTIMIZE_NODE(ForStatement) | 1289 DONT_SELFOPTIMIZE_NODE(ForStatement) |
| 1237 DONT_SELFOPTIMIZE_NODE(ForInStatement) | 1290 DONT_SELFOPTIMIZE_NODE(ForInStatement) |
| 1238 DONT_SELFOPTIMIZE_NODE(ForOfStatement) | 1291 DONT_SELFOPTIMIZE_NODE(ForOfStatement) |
| 1239 | 1292 |
| 1240 DONT_CACHE_NODE(ModuleLiteral) | 1293 DONT_CACHE_NODE(ModuleLiteral) |
| 1241 | 1294 |
| 1242 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { | 1295 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
| 1243 increase_node_count(); | 1296 increase_node_count(); |
| 1297 UPDATE_FEEDBACK_SLOTS(CallRuntime, node); |
| 1244 if (node->is_jsruntime()) { | 1298 if (node->is_jsruntime()) { |
| 1245 // Don't try to inline JS runtime calls because we don't (currently) even | 1299 // Don't try to inline JS runtime calls because we don't (currently) even |
| 1246 // optimize them. | 1300 // optimize them. |
| 1247 add_flag(kDontInline); | 1301 add_flag(kDontInline); |
| 1248 } else if (node->function()->intrinsic_type == Runtime::INLINE && | 1302 } else if (node->function()->intrinsic_type == Runtime::INLINE && |
| 1249 (node->name()->IsOneByteEqualTo( | 1303 (node->name()->IsOneByteEqualTo( |
| 1250 STATIC_ASCII_VECTOR("_ArgumentsLength")) || | 1304 STATIC_ASCII_VECTOR("_ArgumentsLength")) || |
| 1251 node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) { | 1305 node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) { |
| 1252 // Don't inline the %_ArgumentsLength or %_Arguments because their | 1306 // Don't inline the %_ArgumentsLength or %_Arguments because their |
| 1253 // implementation will not work. There is no stack frame to get them | 1307 // 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()); | 1327 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); |
| 1274 str = arr; | 1328 str = arr; |
| 1275 } else { | 1329 } else { |
| 1276 str = DoubleToCString(value_->Number(), buffer); | 1330 str = DoubleToCString(value_->Number(), buffer); |
| 1277 } | 1331 } |
| 1278 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); | 1332 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); |
| 1279 } | 1333 } |
| 1280 | 1334 |
| 1281 | 1335 |
| 1282 } } // namespace v8::internal | 1336 } } // namespace v8::internal |
| OLD | NEW |