| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 virtual Statement* AsStatement() { return NULL; } | 160 virtual Statement* AsStatement() { return NULL; } |
| 161 virtual Expression* AsExpression() { return NULL; } | 161 virtual Expression* AsExpression() { return NULL; } |
| 162 virtual TargetCollector* AsTargetCollector() { return NULL; } | 162 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 163 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 163 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 164 virtual IterationStatement* AsIterationStatement() { return NULL; } | 164 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 165 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 165 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 166 | 166 |
| 167 // True if the node is simple enough for us to inline calls containing it. | 167 // True if the node is simple enough for us to inline calls containing it. |
| 168 virtual bool IsInlineable() const = 0; | 168 virtual bool IsInlineable() const = 0; |
| 169 | 169 |
| 170 static int Count() { return Isolate::Current()->ast_node_count(); } | |
| 171 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } | 170 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
| 172 | 171 |
| 173 protected: | 172 protected: |
| 174 static unsigned GetNextId(Isolate* isolate) { | 173 static unsigned GetNextId(Isolate* isolate) { |
| 175 return ReserveIdRange(isolate, 1); | 174 return ReserveIdRange(isolate, 1); |
| 176 } | 175 } |
| 177 | 176 |
| 178 static unsigned ReserveIdRange(Isolate* isolate, int n) { | 177 static unsigned ReserveIdRange(Isolate* isolate, int n) { |
| 179 unsigned tmp = isolate->ast_node_id(); | 178 unsigned tmp = isolate->ast_node_id(); |
| 180 isolate->set_ast_node_id(tmp + n); | 179 isolate->set_ast_node_id(tmp + n); |
| 181 return tmp; | 180 return tmp; |
| 182 } | 181 } |
| 183 | 182 |
| 183 // See comment of FunctionLiteral::is_primitive for definition of "primitive". |
| 184 void MarkFunctionAsNonPrimitive(Isolate* isolate) { |
| 185 isolate->set_is_function_primitive(false); |
| 186 } |
| 187 |
| 184 private: | 188 private: |
| 185 // Hidden to prevent accidental usage. It would have to load the | 189 // Hidden to prevent accidental usage. It would have to load the |
| 186 // current zone from the TLS. | 190 // current zone from the TLS. |
| 187 void* operator new(size_t size); | 191 void* operator new(size_t size); |
| 188 | 192 |
| 189 friend class CaseClause; // Generates AST IDs. | 193 friend class CaseClause; // Generates AST IDs. |
| 190 }; | 194 }; |
| 191 | 195 |
| 192 | 196 |
| 193 class Statement: public AstNode { | 197 class Statement: public AstNode { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 virtual int StackCheckId() const = 0; | 438 virtual int StackCheckId() const = 0; |
| 435 | 439 |
| 436 // Code generation | 440 // Code generation |
| 437 Label* continue_target() { return &continue_target_; } | 441 Label* continue_target() { return &continue_target_; } |
| 438 | 442 |
| 439 protected: | 443 protected: |
| 440 IterationStatement(Isolate* isolate, ZoneStringList* labels) | 444 IterationStatement(Isolate* isolate, ZoneStringList* labels) |
| 441 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), | 445 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), |
| 442 body_(NULL), | 446 body_(NULL), |
| 443 osr_entry_id_(GetNextId(isolate)) { | 447 osr_entry_id_(GetNextId(isolate)) { |
| 448 // Making the function non-primitive seems to give better performance. |
| 449 MarkFunctionAsNonPrimitive(isolate); |
| 444 } | 450 } |
| 445 | 451 |
| 446 void Initialize(Statement* body) { | 452 void Initialize(Statement* body) { |
| 447 body_ = body; | 453 body_ = body; |
| 448 } | 454 } |
| 449 | 455 |
| 450 private: | 456 private: |
| 451 Statement* body_; | 457 Statement* body_; |
| 452 Label continue_target_; | 458 Label continue_target_; |
| 453 int osr_entry_id_; | 459 int osr_entry_id_; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 Expression* expression() const { return expression_; } | 685 Expression* expression() const { return expression_; } |
| 680 virtual bool IsInlineable() const; | 686 virtual bool IsInlineable() const; |
| 681 | 687 |
| 682 private: | 688 private: |
| 683 Expression* expression_; | 689 Expression* expression_; |
| 684 }; | 690 }; |
| 685 | 691 |
| 686 | 692 |
| 687 class WithStatement: public Statement { | 693 class WithStatement: public Statement { |
| 688 public: | 694 public: |
| 689 WithStatement(Expression* expression, Statement* statement) | 695 WithStatement(Isolate* isolate, Expression* expression, Statement* statement) |
| 690 : expression_(expression), statement_(statement) { } | 696 : expression_(expression), statement_(statement) { |
| 697 // A "with" statement is not inlineable, |
| 698 // so a function containing it is not primitive. |
| 699 MarkFunctionAsNonPrimitive(isolate); |
| 700 } |
| 691 | 701 |
| 692 DECLARE_NODE_TYPE(WithStatement) | 702 DECLARE_NODE_TYPE(WithStatement) |
| 693 | 703 |
| 694 Expression* expression() const { return expression_; } | 704 Expression* expression() const { return expression_; } |
| 695 Statement* statement() const { return statement_; } | 705 Statement* statement() const { return statement_; } |
| 696 | 706 |
| 697 virtual bool IsInlineable() const; | 707 virtual bool IsInlineable() const; |
| 698 | 708 |
| 699 private: | 709 private: |
| 700 Expression* expression_; | 710 Expression* expression_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 int entry_id_; | 757 int entry_id_; |
| 748 }; | 758 }; |
| 749 | 759 |
| 750 | 760 |
| 751 class SwitchStatement: public BreakableStatement { | 761 class SwitchStatement: public BreakableStatement { |
| 752 public: | 762 public: |
| 753 SwitchStatement(Isolate* isolate, ZoneStringList* labels) | 763 SwitchStatement(Isolate* isolate, ZoneStringList* labels) |
| 754 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), | 764 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), |
| 755 tag_(NULL), | 765 tag_(NULL), |
| 756 cases_(NULL) { | 766 cases_(NULL) { |
| 767 // A "switch" statement is not inlineable, |
| 768 // so a function containing it is not primitive. |
| 769 MarkFunctionAsNonPrimitive(isolate); |
| 757 } | 770 } |
| 758 | 771 |
| 759 | 772 |
| 760 DECLARE_NODE_TYPE(SwitchStatement) | 773 DECLARE_NODE_TYPE(SwitchStatement) |
| 761 | 774 |
| 762 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { | 775 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
| 763 tag_ = tag; | 776 tag_ = tag; |
| 764 cases_ = cases; | 777 cases_ = cases; |
| 765 } | 778 } |
| 766 | 779 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 783 public: | 796 public: |
| 784 IfStatement(Isolate* isolate, | 797 IfStatement(Isolate* isolate, |
| 785 Expression* condition, | 798 Expression* condition, |
| 786 Statement* then_statement, | 799 Statement* then_statement, |
| 787 Statement* else_statement) | 800 Statement* else_statement) |
| 788 : condition_(condition), | 801 : condition_(condition), |
| 789 then_statement_(then_statement), | 802 then_statement_(then_statement), |
| 790 else_statement_(else_statement), | 803 else_statement_(else_statement), |
| 791 if_id_(GetNextId(isolate)), | 804 if_id_(GetNextId(isolate)), |
| 792 then_id_(GetNextId(isolate)), | 805 then_id_(GetNextId(isolate)), |
| 793 else_id_(GetNextId(isolate)) { | 806 else_id_(GetNextId(isolate)) { } |
| 794 } | |
| 795 | 807 |
| 796 DECLARE_NODE_TYPE(IfStatement) | 808 DECLARE_NODE_TYPE(IfStatement) |
| 797 | 809 |
| 798 virtual bool IsInlineable() const; | 810 virtual bool IsInlineable() const; |
| 799 | 811 |
| 800 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } | 812 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
| 801 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } | 813 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
| 802 | 814 |
| 803 Expression* condition() const { return condition_; } | 815 Expression* condition() const { return condition_; } |
| 804 Statement* then_statement() const { return then_statement_; } | 816 Statement* then_statement() const { return then_statement_; } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 ZoneList<Label*>* targets() { return &targets_; } | 848 ZoneList<Label*>* targets() { return &targets_; } |
| 837 virtual bool IsInlineable() const; | 849 virtual bool IsInlineable() const; |
| 838 | 850 |
| 839 private: | 851 private: |
| 840 ZoneList<Label*> targets_; | 852 ZoneList<Label*> targets_; |
| 841 }; | 853 }; |
| 842 | 854 |
| 843 | 855 |
| 844 class TryStatement: public Statement { | 856 class TryStatement: public Statement { |
| 845 public: | 857 public: |
| 846 explicit TryStatement(int index, Block* try_block) | 858 explicit TryStatement(Isolate* isolate, int index, Block* try_block) |
| 847 : index_(index), | 859 : index_(index), |
| 848 try_block_(try_block), | 860 try_block_(try_block), |
| 849 escaping_targets_(NULL) { | 861 escaping_targets_(NULL) { |
| 862 // A "try" statement is not inlineable, |
| 863 // so a function containing it is not primitive. |
| 864 MarkFunctionAsNonPrimitive(isolate); |
| 850 } | 865 } |
| 851 | 866 |
| 852 void set_escaping_targets(ZoneList<Label*>* targets) { | 867 void set_escaping_targets(ZoneList<Label*>* targets) { |
| 853 escaping_targets_ = targets; | 868 escaping_targets_ = targets; |
| 854 } | 869 } |
| 855 | 870 |
| 856 int index() const { return index_; } | 871 int index() const { return index_; } |
| 857 Block* try_block() const { return try_block_; } | 872 Block* try_block() const { return try_block_; } |
| 858 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } | 873 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } |
| 859 virtual bool IsInlineable() const; | 874 virtual bool IsInlineable() const; |
| 860 | 875 |
| 861 private: | 876 private: |
| 862 // Unique (per-function) index of this handler. This is not an AST ID. | 877 // Unique (per-function) index of this handler. This is not an AST ID. |
| 863 int index_; | 878 int index_; |
| 864 | 879 |
| 865 Block* try_block_; | 880 Block* try_block_; |
| 866 ZoneList<Label*>* escaping_targets_; | 881 ZoneList<Label*>* escaping_targets_; |
| 867 }; | 882 }; |
| 868 | 883 |
| 869 | 884 |
| 870 class TryCatchStatement: public TryStatement { | 885 class TryCatchStatement: public TryStatement { |
| 871 public: | 886 public: |
| 872 TryCatchStatement(int index, | 887 TryCatchStatement(Isolate* isolate, |
| 888 int index, |
| 873 Block* try_block, | 889 Block* try_block, |
| 874 Scope* scope, | 890 Scope* scope, |
| 875 Variable* variable, | 891 Variable* variable, |
| 876 Block* catch_block) | 892 Block* catch_block) |
| 877 : TryStatement(index, try_block), | 893 : TryStatement(isolate, index, try_block), |
| 878 scope_(scope), | 894 scope_(scope), |
| 879 variable_(variable), | 895 variable_(variable), |
| 880 catch_block_(catch_block) { | 896 catch_block_(catch_block) { } |
| 881 } | |
| 882 | 897 |
| 883 DECLARE_NODE_TYPE(TryCatchStatement) | 898 DECLARE_NODE_TYPE(TryCatchStatement) |
| 884 | 899 |
| 885 Scope* scope() { return scope_; } | 900 Scope* scope() { return scope_; } |
| 886 Variable* variable() { return variable_; } | 901 Variable* variable() { return variable_; } |
| 887 Block* catch_block() const { return catch_block_; } | 902 Block* catch_block() const { return catch_block_; } |
| 888 virtual bool IsInlineable() const; | 903 virtual bool IsInlineable() const; |
| 889 | 904 |
| 890 private: | 905 private: |
| 891 Scope* scope_; | 906 Scope* scope_; |
| 892 Variable* variable_; | 907 Variable* variable_; |
| 893 Block* catch_block_; | 908 Block* catch_block_; |
| 894 }; | 909 }; |
| 895 | 910 |
| 896 | 911 |
| 897 class TryFinallyStatement: public TryStatement { | 912 class TryFinallyStatement: public TryStatement { |
| 898 public: | 913 public: |
| 899 TryFinallyStatement(int index, Block* try_block, Block* finally_block) | 914 TryFinallyStatement(Isolate* isolate, |
| 900 : TryStatement(index, try_block), | 915 int index, |
| 916 Block* try_block, |
| 917 Block* finally_block) |
| 918 : TryStatement(isolate, index, try_block), |
| 901 finally_block_(finally_block) { } | 919 finally_block_(finally_block) { } |
| 902 | 920 |
| 903 DECLARE_NODE_TYPE(TryFinallyStatement) | 921 DECLARE_NODE_TYPE(TryFinallyStatement) |
| 904 | 922 |
| 905 Block* finally_block() const { return finally_block_; } | 923 Block* finally_block() const { return finally_block_; } |
| 906 virtual bool IsInlineable() const; | 924 virtual bool IsInlineable() const; |
| 907 | 925 |
| 908 private: | 926 private: |
| 909 Block* finally_block_; | 927 Block* finally_block_; |
| 910 }; | 928 }; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 // Base class for literals that needs space in the corresponding JSFunction. | 996 // Base class for literals that needs space in the corresponding JSFunction. |
| 979 class MaterializedLiteral: public Expression { | 997 class MaterializedLiteral: public Expression { |
| 980 public: | 998 public: |
| 981 MaterializedLiteral(Isolate* isolate, | 999 MaterializedLiteral(Isolate* isolate, |
| 982 int literal_index, | 1000 int literal_index, |
| 983 bool is_simple, | 1001 bool is_simple, |
| 984 int depth) | 1002 int depth) |
| 985 : Expression(isolate), | 1003 : Expression(isolate), |
| 986 literal_index_(literal_index), | 1004 literal_index_(literal_index), |
| 987 is_simple_(is_simple), | 1005 is_simple_(is_simple), |
| 988 depth_(depth) {} | 1006 depth_(depth) { |
| 1007 // A materialized literal is not inlineable, |
| 1008 // so a function containing it is not primitive. |
| 1009 MarkFunctionAsNonPrimitive(isolate); |
| 1010 } |
| 989 | 1011 |
| 990 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } | 1012 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
| 991 | 1013 |
| 992 int literal_index() { return literal_index_; } | 1014 int literal_index() { return literal_index_; } |
| 993 | 1015 |
| 994 // A materialized literal is simple if the values consist of only | 1016 // A materialized literal is simple if the values consist of only |
| 995 // constants and simple object and array literals. | 1017 // constants and simple object and array literals. |
| 996 bool is_simple() const { return is_simple_; } | 1018 bool is_simple() const { return is_simple_; } |
| 997 | 1019 |
| 998 int depth() const { return depth_; } | 1020 int depth() const { return depth_; } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 ZoneList<Property*>* properties, | 1068 ZoneList<Property*>* properties, |
| 1047 int literal_index, | 1069 int literal_index, |
| 1048 bool is_simple, | 1070 bool is_simple, |
| 1049 bool fast_elements, | 1071 bool fast_elements, |
| 1050 int depth, | 1072 int depth, |
| 1051 bool has_function) | 1073 bool has_function) |
| 1052 : MaterializedLiteral(isolate, literal_index, is_simple, depth), | 1074 : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
| 1053 constant_properties_(constant_properties), | 1075 constant_properties_(constant_properties), |
| 1054 properties_(properties), | 1076 properties_(properties), |
| 1055 fast_elements_(fast_elements), | 1077 fast_elements_(fast_elements), |
| 1056 has_function_(has_function) {} | 1078 has_function_(has_function) { } |
| 1057 | 1079 |
| 1058 DECLARE_NODE_TYPE(ObjectLiteral) | 1080 DECLARE_NODE_TYPE(ObjectLiteral) |
| 1059 | 1081 |
| 1060 Handle<FixedArray> constant_properties() const { | 1082 Handle<FixedArray> constant_properties() const { |
| 1061 return constant_properties_; | 1083 return constant_properties_; |
| 1062 } | 1084 } |
| 1063 ZoneList<Property*>* properties() const { return properties_; } | 1085 ZoneList<Property*>* properties() const { return properties_; } |
| 1064 | 1086 |
| 1065 bool fast_elements() const { return fast_elements_; } | 1087 bool fast_elements() const { return fast_elements_; } |
| 1066 | 1088 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 Expression* expression, | 1257 Expression* expression, |
| 1236 ZoneList<Expression*>* arguments, | 1258 ZoneList<Expression*>* arguments, |
| 1237 int pos) | 1259 int pos) |
| 1238 : Expression(isolate), | 1260 : Expression(isolate), |
| 1239 expression_(expression), | 1261 expression_(expression), |
| 1240 arguments_(arguments), | 1262 arguments_(arguments), |
| 1241 pos_(pos), | 1263 pos_(pos), |
| 1242 is_monomorphic_(false), | 1264 is_monomorphic_(false), |
| 1243 check_type_(RECEIVER_MAP_CHECK), | 1265 check_type_(RECEIVER_MAP_CHECK), |
| 1244 return_id_(GetNextId(isolate)) { | 1266 return_id_(GetNextId(isolate)) { |
| 1267 // Making the function non-primitive seems to give better performance. |
| 1268 MarkFunctionAsNonPrimitive(isolate); |
| 1245 } | 1269 } |
| 1246 | 1270 |
| 1247 DECLARE_NODE_TYPE(Call) | 1271 DECLARE_NODE_TYPE(Call) |
| 1248 | 1272 |
| 1249 virtual bool IsInlineable() const; | 1273 virtual bool IsInlineable() const; |
| 1250 | 1274 |
| 1251 Expression* expression() const { return expression_; } | 1275 Expression* expression() const { return expression_; } |
| 1252 ZoneList<Expression*>* arguments() const { return arguments_; } | 1276 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1253 virtual int position() const { return pos_; } | 1277 virtual int position() const { return pos_; } |
| 1254 | 1278 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 | 1314 |
| 1291 class CallNew: public Expression { | 1315 class CallNew: public Expression { |
| 1292 public: | 1316 public: |
| 1293 CallNew(Isolate* isolate, | 1317 CallNew(Isolate* isolate, |
| 1294 Expression* expression, | 1318 Expression* expression, |
| 1295 ZoneList<Expression*>* arguments, | 1319 ZoneList<Expression*>* arguments, |
| 1296 int pos) | 1320 int pos) |
| 1297 : Expression(isolate), | 1321 : Expression(isolate), |
| 1298 expression_(expression), | 1322 expression_(expression), |
| 1299 arguments_(arguments), | 1323 arguments_(arguments), |
| 1300 pos_(pos) { } | 1324 pos_(pos) { |
| 1325 // Making the function non-primitive seems to give better performance. |
| 1326 MarkFunctionAsNonPrimitive(isolate); |
| 1327 } |
| 1301 | 1328 |
| 1302 DECLARE_NODE_TYPE(CallNew) | 1329 DECLARE_NODE_TYPE(CallNew) |
| 1303 | 1330 |
| 1304 virtual bool IsInlineable() const; | 1331 virtual bool IsInlineable() const; |
| 1305 | 1332 |
| 1306 Expression* expression() const { return expression_; } | 1333 Expression* expression() const { return expression_; } |
| 1307 ZoneList<Expression*>* arguments() const { return arguments_; } | 1334 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1308 virtual int position() const { return pos_; } | 1335 virtual int position() const { return pos_; } |
| 1309 | 1336 |
| 1310 private: | 1337 private: |
| 1311 Expression* expression_; | 1338 Expression* expression_; |
| 1312 ZoneList<Expression*>* arguments_; | 1339 ZoneList<Expression*>* arguments_; |
| 1313 int pos_; | 1340 int pos_; |
| 1314 }; | 1341 }; |
| 1315 | 1342 |
| 1316 | 1343 |
| 1317 // The CallRuntime class does not represent any official JavaScript | 1344 // The CallRuntime class does not represent any official JavaScript |
| 1318 // language construct. Instead it is used to call a C or JS function | 1345 // language construct. Instead it is used to call a C or JS function |
| 1319 // with a set of arguments. This is used from the builtins that are | 1346 // with a set of arguments. This is used from the builtins that are |
| 1320 // implemented in JavaScript (see "v8natives.js"). | 1347 // implemented in JavaScript (see "v8natives.js"). |
| 1321 class CallRuntime: public Expression { | 1348 class CallRuntime: public Expression { |
| 1322 public: | 1349 public: |
| 1323 CallRuntime(Isolate* isolate, | 1350 CallRuntime(Isolate* isolate, |
| 1324 Handle<String> name, | 1351 Handle<String> name, |
| 1325 const Runtime::Function* function, | 1352 const Runtime::Function* function, |
| 1326 ZoneList<Expression*>* arguments) | 1353 ZoneList<Expression*>* arguments) |
| 1327 : Expression(isolate), | 1354 : Expression(isolate), |
| 1328 name_(name), | 1355 name_(name), |
| 1329 function_(function), | 1356 function_(function), |
| 1330 arguments_(arguments) { } | 1357 arguments_(arguments) { |
| 1358 // Making the function non-primitive seems to give better performance. |
| 1359 MarkFunctionAsNonPrimitive(isolate); |
| 1360 } |
| 1331 | 1361 |
| 1332 DECLARE_NODE_TYPE(CallRuntime) | 1362 DECLARE_NODE_TYPE(CallRuntime) |
| 1333 | 1363 |
| 1334 virtual bool IsInlineable() const; | 1364 virtual bool IsInlineable() const; |
| 1335 | 1365 |
| 1336 Handle<String> name() const { return name_; } | 1366 Handle<String> name() const { return name_; } |
| 1337 const Runtime::Function* function() const { return function_; } | 1367 const Runtime::Function* function() const { return function_; } |
| 1338 ZoneList<Expression*>* arguments() const { return arguments_; } | 1368 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1339 bool is_jsruntime() const { return function_ == NULL; } | 1369 bool is_jsruntime() const { return function_ == NULL; } |
| 1340 | 1370 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 Handle<String> name, | 1688 Handle<String> name, |
| 1659 Scope* scope, | 1689 Scope* scope, |
| 1660 ZoneList<Statement*>* body, | 1690 ZoneList<Statement*>* body, |
| 1661 int materialized_literal_count, | 1691 int materialized_literal_count, |
| 1662 int expected_property_count, | 1692 int expected_property_count, |
| 1663 int handler_count, | 1693 int handler_count, |
| 1664 bool has_only_simple_this_property_assignments, | 1694 bool has_only_simple_this_property_assignments, |
| 1665 Handle<FixedArray> this_property_assignments, | 1695 Handle<FixedArray> this_property_assignments, |
| 1666 int parameter_count, | 1696 int parameter_count, |
| 1667 Type type, | 1697 Type type, |
| 1668 bool has_duplicate_parameters) | 1698 bool has_duplicate_parameters, |
| 1699 int ast_node_count, |
| 1700 bool is_primitive) |
| 1669 : Expression(isolate), | 1701 : Expression(isolate), |
| 1670 name_(name), | 1702 name_(name), |
| 1671 scope_(scope), | 1703 scope_(scope), |
| 1672 body_(body), | 1704 body_(body), |
| 1673 this_property_assignments_(this_property_assignments), | 1705 this_property_assignments_(this_property_assignments), |
| 1674 inferred_name_(isolate->factory()->empty_string()), | 1706 inferred_name_(isolate->factory()->empty_string()), |
| 1675 materialized_literal_count_(materialized_literal_count), | 1707 materialized_literal_count_(materialized_literal_count), |
| 1676 expected_property_count_(expected_property_count), | 1708 expected_property_count_(expected_property_count), |
| 1677 handler_count_(handler_count), | 1709 handler_count_(handler_count), |
| 1678 parameter_count_(parameter_count), | 1710 parameter_count_(parameter_count), |
| 1679 function_token_position_(RelocInfo::kNoPosition) { | 1711 function_token_position_(RelocInfo::kNoPosition), |
| 1712 ast_node_count_(ast_node_count), |
| 1713 is_primitive_(is_primitive) { |
| 1680 bitfield_ = | 1714 bitfield_ = |
| 1681 HasOnlySimpleThisPropertyAssignments::encode( | 1715 HasOnlySimpleThisPropertyAssignments::encode( |
| 1682 has_only_simple_this_property_assignments) | | 1716 has_only_simple_this_property_assignments) | |
| 1683 IsExpression::encode(type != DECLARATION) | | 1717 IsExpression::encode(type != DECLARATION) | |
| 1684 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | | 1718 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | |
| 1685 Pretenure::encode(false) | | 1719 Pretenure::encode(false) | |
| 1686 HasDuplicateParameters::encode(has_duplicate_parameters); | 1720 HasDuplicateParameters::encode(has_duplicate_parameters); |
| 1721 // A function literal is not inlineable, |
| 1722 // so a function containing it is not primitive. |
| 1723 MarkFunctionAsNonPrimitive(isolate); |
| 1687 } | 1724 } |
| 1688 | 1725 |
| 1689 DECLARE_NODE_TYPE(FunctionLiteral) | 1726 DECLARE_NODE_TYPE(FunctionLiteral) |
| 1690 | 1727 |
| 1691 Handle<String> name() const { return name_; } | 1728 Handle<String> name() const { return name_; } |
| 1692 Scope* scope() const { return scope_; } | 1729 Scope* scope() const { return scope_; } |
| 1693 ZoneList<Statement*>* body() const { return body_; } | 1730 ZoneList<Statement*>* body() const { return body_; } |
| 1694 void set_function_token_position(int pos) { function_token_position_ = pos; } | 1731 void set_function_token_position(int pos) { function_token_position_ = pos; } |
| 1695 int function_token_position() const { return function_token_position_; } | 1732 int function_token_position() const { return function_token_position_; } |
| 1696 int start_position() const; | 1733 int start_position() const; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1724 } | 1761 } |
| 1725 | 1762 |
| 1726 bool pretenure() { return Pretenure::decode(bitfield_); } | 1763 bool pretenure() { return Pretenure::decode(bitfield_); } |
| 1727 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } | 1764 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } |
| 1728 virtual bool IsInlineable() const; | 1765 virtual bool IsInlineable() const; |
| 1729 | 1766 |
| 1730 bool has_duplicate_parameters() { | 1767 bool has_duplicate_parameters() { |
| 1731 return HasDuplicateParameters::decode(bitfield_); | 1768 return HasDuplicateParameters::decode(bitfield_); |
| 1732 } | 1769 } |
| 1733 | 1770 |
| 1771 // Returns the AST node count in the function if the function was parsed |
| 1772 // eagerly, otherwise returns 0. |
| 1773 int ast_node_count() { |
| 1774 return ast_node_count_; |
| 1775 } |
| 1776 |
| 1777 // Returns whether the function is primitive or not if the function was parsed |
| 1778 // eagerly, otherwise returns false. |
| 1779 // A function is primitive if it is inlinable and contains only |
| 1780 // simple statements: expression statement, assignment statement, |
| 1781 // "if" statement, "return" statement. |
| 1782 bool is_primitive() { |
| 1783 return is_primitive_; |
| 1784 } |
| 1785 |
| 1734 private: | 1786 private: |
| 1735 Handle<String> name_; | 1787 Handle<String> name_; |
| 1736 Scope* scope_; | 1788 Scope* scope_; |
| 1737 ZoneList<Statement*>* body_; | 1789 ZoneList<Statement*>* body_; |
| 1738 Handle<FixedArray> this_property_assignments_; | 1790 Handle<FixedArray> this_property_assignments_; |
| 1739 Handle<String> inferred_name_; | 1791 Handle<String> inferred_name_; |
| 1740 | 1792 |
| 1741 int materialized_literal_count_; | 1793 int materialized_literal_count_; |
| 1742 int expected_property_count_; | 1794 int expected_property_count_; |
| 1743 int handler_count_; | 1795 int handler_count_; |
| 1744 int parameter_count_; | 1796 int parameter_count_; |
| 1745 int function_token_position_; | 1797 int function_token_position_; |
| 1746 | 1798 |
| 1799 int ast_node_count_; |
| 1800 bool is_primitive_; |
| 1801 |
| 1747 unsigned bitfield_; | 1802 unsigned bitfield_; |
| 1748 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; | 1803 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; |
| 1749 class IsExpression: public BitField<bool, 1, 1> {}; | 1804 class IsExpression: public BitField<bool, 1, 1> {}; |
| 1750 class IsAnonymous: public BitField<bool, 2, 1> {}; | 1805 class IsAnonymous: public BitField<bool, 2, 1> {}; |
| 1751 class Pretenure: public BitField<bool, 3, 1> {}; | 1806 class Pretenure: public BitField<bool, 3, 1> {}; |
| 1752 class HasDuplicateParameters: public BitField<bool, 4, 1> {}; | 1807 class HasDuplicateParameters: public BitField<bool, 4, 1> {}; |
| 1753 }; | 1808 }; |
| 1754 | 1809 |
| 1755 | 1810 |
| 1756 class SharedFunctionInfoLiteral: public Expression { | 1811 class SharedFunctionInfoLiteral: public Expression { |
| 1757 public: | 1812 public: |
| 1758 SharedFunctionInfoLiteral( | 1813 SharedFunctionInfoLiteral( |
| 1759 Isolate* isolate, | 1814 Isolate* isolate, |
| 1760 Handle<SharedFunctionInfo> shared_function_info) | 1815 Handle<SharedFunctionInfo> shared_function_info) |
| 1761 : Expression(isolate), shared_function_info_(shared_function_info) { } | 1816 : Expression(isolate), shared_function_info_(shared_function_info) { |
| 1817 MarkFunctionAsNonPrimitive(isolate); |
| 1818 } |
| 1762 | 1819 |
| 1763 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) | 1820 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) |
| 1764 | 1821 |
| 1765 Handle<SharedFunctionInfo> shared_function_info() const { | 1822 Handle<SharedFunctionInfo> shared_function_info() const { |
| 1766 return shared_function_info_; | 1823 return shared_function_info_; |
| 1767 } | 1824 } |
| 1768 virtual bool IsInlineable() const; | 1825 virtual bool IsInlineable() const; |
| 1769 | 1826 |
| 1770 private: | 1827 private: |
| 1771 Handle<SharedFunctionInfo> shared_function_info_; | 1828 Handle<SharedFunctionInfo> shared_function_info_; |
| 1772 }; | 1829 }; |
| 1773 | 1830 |
| 1774 | 1831 |
| 1775 class ThisFunction: public Expression { | 1832 class ThisFunction: public Expression { |
| 1776 public: | 1833 public: |
| 1777 explicit ThisFunction(Isolate* isolate) : Expression(isolate) {} | 1834 explicit ThisFunction(Isolate* isolate) : Expression(isolate) { } |
| 1778 DECLARE_NODE_TYPE(ThisFunction) | 1835 DECLARE_NODE_TYPE(ThisFunction) |
| 1779 virtual bool IsInlineable() const; | 1836 virtual bool IsInlineable() const; |
| 1780 }; | 1837 }; |
| 1781 | 1838 |
| 1782 | 1839 |
| 1783 // ---------------------------------------------------------------------------- | 1840 // ---------------------------------------------------------------------------- |
| 1784 // Regular expressions | 1841 // Regular expressions |
| 1785 | 1842 |
| 1786 | 1843 |
| 1787 class RegExpVisitor BASE_EMBEDDED { | 1844 class RegExpVisitor BASE_EMBEDDED { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2176 | 2233 |
| 2177 private: | 2234 private: |
| 2178 Isolate* isolate_; | 2235 Isolate* isolate_; |
| 2179 bool stack_overflow_; | 2236 bool stack_overflow_; |
| 2180 }; | 2237 }; |
| 2181 | 2238 |
| 2182 | 2239 |
| 2183 } } // namespace v8::internal | 2240 } } // namespace v8::internal |
| 2184 | 2241 |
| 2185 #endif // V8_AST_H_ | 2242 #endif // V8_AST_H_ |
| OLD | NEW |