Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/ast.h

Issue 7655017: Improve memory usage of receiver type feedback. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ReceiverTypeList -> SmallMapList Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_AST_H_ 28 #ifndef V8_AST_H_
29 #define V8_AST_H_ 29 #define V8_AST_H_
30 30
31 #include "allocation.h" 31 #include "allocation.h"
32 #include "execution.h" 32 #include "execution.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "jsregexp.h" 34 #include "jsregexp.h"
35 #include "runtime.h" 35 #include "runtime.h"
36 #include "small-pointer-list.h"
36 #include "token.h" 37 #include "token.h"
37 #include "variables.h" 38 #include "variables.h"
38 39
39 namespace v8 { 40 namespace v8 {
40 namespace internal { 41 namespace internal {
41 42
42 // The abstract syntax tree is an intermediate, light-weight 43 // The abstract syntax tree is an intermediate, light-weight
43 // representation of the parsed JavaScript code suitable for 44 // representation of the parsed JavaScript code suitable for
44 // compilation to native code. 45 // compilation to native code.
45 46
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 bool IsEmpty() { return AsEmptyStatement() != NULL; } 201 bool IsEmpty() { return AsEmptyStatement() != NULL; }
201 202
202 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } 203 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
203 int statement_pos() const { return statement_pos_; } 204 int statement_pos() const { return statement_pos_; }
204 205
205 private: 206 private:
206 int statement_pos_; 207 int statement_pos_;
207 }; 208 };
208 209
209 210
211 class SmallMapList {
212 public:
213 SmallMapList() {}
214 explicit SmallMapList(int capacity) : list_(capacity) {}
215
216 void Reserve(int capacty) { list_.Reserve(capacty); }
fschneider 2011/08/22 13:38:06 capacty -> capacity
217 void Clear() { list_.Clear(); }
218
219 bool is_empty() const { return list_.is_empty(); }
220 int length() const { return list_.length(); }
221
222 void Add(Handle<Map> handle) {
223 list_.Add(handle.location());
224 }
225
226 Handle<Map> at(int i) const {
227 return Handle<Map>(list_.at(i));
228 }
229
230 Handle<Map> first() const { return at(0); }
231 Handle<Map> last() const { return at(length() - 1); }
232
233 private:
234 SmallPointerList<Map*> list_;
235
236 DISALLOW_COPY_AND_ASSIGN(SmallMapList);
237 };
238
239
210 class Expression: public AstNode { 240 class Expression: public AstNode {
211 public: 241 public:
212 enum Context { 242 enum Context {
213 // Not assigned a context yet, or else will not be visited during 243 // Not assigned a context yet, or else will not be visited during
214 // code generation. 244 // code generation.
215 kUninitialized, 245 kUninitialized,
216 // Evaluated for its side effects. 246 // Evaluated for its side effects.
217 kEffect, 247 kEffect,
218 // Evaluated for its value (and side effects). 248 // Evaluated for its value (and side effects).
219 kValue, 249 kValue,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 288
259 // Type feedback information for assignments and properties. 289 // Type feedback information for assignments and properties.
260 virtual bool IsMonomorphic() { 290 virtual bool IsMonomorphic() {
261 UNREACHABLE(); 291 UNREACHABLE();
262 return false; 292 return false;
263 } 293 }
264 virtual bool IsArrayLength() { 294 virtual bool IsArrayLength() {
265 UNREACHABLE(); 295 UNREACHABLE();
266 return false; 296 return false;
267 } 297 }
268 virtual ZoneMapList* GetReceiverTypes() { 298 virtual SmallMapList* GetReceiverTypes() {
269 UNREACHABLE(); 299 UNREACHABLE();
270 return NULL; 300 return NULL;
271 } 301 }
272 virtual Handle<Map> GetMonomorphicReceiverType() { 302 Handle<Map> GetMonomorphicReceiverType() {
273 UNREACHABLE(); 303 ASSERT(IsMonomorphic());
274 return Handle<Map>(); 304 SmallMapList* types = GetReceiverTypes();
305 ASSERT(types != NULL && types->length() == 1);
306 return types->at(0);
275 } 307 }
276 308
277 unsigned id() const { return id_; } 309 unsigned id() const { return id_; }
278 unsigned test_id() const { return test_id_; } 310 unsigned test_id() const { return test_id_; }
279 311
280 private: 312 private:
281 unsigned id_; 313 unsigned id_;
282 unsigned test_id_; 314 unsigned test_id_;
283 }; 315 };
284 316
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 Property(Isolate* isolate, 1236 Property(Isolate* isolate,
1205 Expression* obj, 1237 Expression* obj,
1206 Expression* key, 1238 Expression* key,
1207 int pos, 1239 int pos,
1208 Type type = NORMAL) 1240 Type type = NORMAL)
1209 : Expression(isolate), 1241 : Expression(isolate),
1210 obj_(obj), 1242 obj_(obj),
1211 key_(key), 1243 key_(key),
1212 pos_(pos), 1244 pos_(pos),
1213 type_(type), 1245 type_(type),
1214 receiver_types_(NULL),
1215 is_monomorphic_(false), 1246 is_monomorphic_(false),
1216 is_array_length_(false), 1247 is_array_length_(false),
1217 is_string_length_(false), 1248 is_string_length_(false),
1218 is_string_access_(false), 1249 is_string_access_(false),
1219 is_function_prototype_(false) { } 1250 is_function_prototype_(false) { }
1220 1251
1221 DECLARE_NODE_TYPE(Property) 1252 DECLARE_NODE_TYPE(Property)
1222 1253
1223 virtual bool IsValidLeftHandSide() { return true; } 1254 virtual bool IsValidLeftHandSide() { return true; }
1224 virtual bool IsInlineable() const; 1255 virtual bool IsInlineable() const;
1225 1256
1226 Expression* obj() const { return obj_; } 1257 Expression* obj() const { return obj_; }
1227 Expression* key() const { return key_; } 1258 Expression* key() const { return key_; }
1228 virtual int position() const { return pos_; } 1259 virtual int position() const { return pos_; }
1229 bool is_synthetic() const { return type_ == SYNTHETIC; } 1260 bool is_synthetic() const { return type_ == SYNTHETIC; }
1230 1261
1231 bool IsStringLength() const { return is_string_length_; } 1262 bool IsStringLength() const { return is_string_length_; }
1232 bool IsStringAccess() const { return is_string_access_; } 1263 bool IsStringAccess() const { return is_string_access_; }
1233 bool IsFunctionPrototype() const { return is_function_prototype_; } 1264 bool IsFunctionPrototype() const { return is_function_prototype_; }
1234 1265
1235 // Type feedback information. 1266 // Type feedback information.
1236 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1267 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1237 virtual bool IsMonomorphic() { return is_monomorphic_; } 1268 virtual bool IsMonomorphic() { return is_monomorphic_; }
1238 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } 1269 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1239 virtual bool IsArrayLength() { return is_array_length_; } 1270 virtual bool IsArrayLength() { return is_array_length_; }
1240 virtual Handle<Map> GetMonomorphicReceiverType() {
1241 return monomorphic_receiver_type_;
1242 }
1243 1271
1244 private: 1272 private:
1245 Expression* obj_; 1273 Expression* obj_;
1246 Expression* key_; 1274 Expression* key_;
1247 int pos_; 1275 int pos_;
1248 Type type_; 1276 Type type_;
1249 1277
1250 ZoneMapList* receiver_types_; 1278 SmallMapList receiver_types_;
1251 bool is_monomorphic_ : 1; 1279 bool is_monomorphic_ : 1;
1252 bool is_array_length_ : 1; 1280 bool is_array_length_ : 1;
1253 bool is_string_length_ : 1; 1281 bool is_string_length_ : 1;
1254 bool is_string_access_ : 1; 1282 bool is_string_access_ : 1;
1255 bool is_function_prototype_ : 1; 1283 bool is_function_prototype_ : 1;
1256 Handle<Map> monomorphic_receiver_type_;
1257 }; 1284 };
1258 1285
1259 1286
1260 class Call: public Expression { 1287 class Call: public Expression {
1261 public: 1288 public:
1262 Call(Isolate* isolate, 1289 Call(Isolate* isolate,
1263 Expression* expression, 1290 Expression* expression,
1264 ZoneList<Expression*>* arguments, 1291 ZoneList<Expression*>* arguments,
1265 int pos) 1292 int pos)
1266 : Expression(isolate), 1293 : Expression(isolate),
1267 expression_(expression), 1294 expression_(expression),
1268 arguments_(arguments), 1295 arguments_(arguments),
1269 pos_(pos), 1296 pos_(pos),
1270 is_monomorphic_(false), 1297 is_monomorphic_(false),
1271 check_type_(RECEIVER_MAP_CHECK), 1298 check_type_(RECEIVER_MAP_CHECK),
1272 receiver_types_(NULL),
1273 return_id_(GetNextId(isolate)) { 1299 return_id_(GetNextId(isolate)) {
1274 } 1300 }
1275 1301
1276 DECLARE_NODE_TYPE(Call) 1302 DECLARE_NODE_TYPE(Call)
1277 1303
1278 virtual bool IsInlineable() const; 1304 virtual bool IsInlineable() const;
1279 1305
1280 Expression* expression() const { return expression_; } 1306 Expression* expression() const { return expression_; }
1281 ZoneList<Expression*>* arguments() const { return arguments_; } 1307 ZoneList<Expression*>* arguments() const { return arguments_; }
1282 virtual int position() const { return pos_; } 1308 virtual int position() const { return pos_; }
1283 1309
1284 void RecordTypeFeedback(TypeFeedbackOracle* oracle, 1310 void RecordTypeFeedback(TypeFeedbackOracle* oracle,
1285 CallKind call_kind); 1311 CallKind call_kind);
1286 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } 1312 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1287 virtual bool IsMonomorphic() { return is_monomorphic_; } 1313 virtual bool IsMonomorphic() { return is_monomorphic_; }
1288 CheckType check_type() const { return check_type_; } 1314 CheckType check_type() const { return check_type_; }
1289 Handle<JSFunction> target() { return target_; } 1315 Handle<JSFunction> target() { return target_; }
1290 Handle<JSObject> holder() { return holder_; } 1316 Handle<JSObject> holder() { return holder_; }
1291 Handle<JSGlobalPropertyCell> cell() { return cell_; } 1317 Handle<JSGlobalPropertyCell> cell() { return cell_; }
1292 1318
1293 bool ComputeTarget(Handle<Map> type, Handle<String> name); 1319 bool ComputeTarget(Handle<Map> type, Handle<String> name);
1294 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup); 1320 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup);
1295 1321
1296 // Bailout support. 1322 // Bailout support.
1297 int ReturnId() const { return return_id_; } 1323 int ReturnId() const { return return_id_; }
1298 1324
1299 #ifdef DEBUG 1325 #ifdef DEBUG
1300 // Used to assert that the FullCodeGenerator records the return site. 1326 // Used to assert that the FullCodeGenerator records the return site.
1301 bool return_is_recorded_; 1327 bool return_is_recorded_;
1302 #endif 1328 #endif
1303 1329
1304 private: 1330 private:
1305 Expression* expression_; 1331 Expression* expression_;
1306 ZoneList<Expression*>* arguments_; 1332 ZoneList<Expression*>* arguments_;
1307 int pos_; 1333 int pos_;
1308 1334
1309 bool is_monomorphic_; 1335 bool is_monomorphic_;
1310 CheckType check_type_; 1336 CheckType check_type_;
1311 ZoneMapList* receiver_types_; 1337 SmallMapList receiver_types_;
1312 Handle<JSFunction> target_; 1338 Handle<JSFunction> target_;
1313 Handle<JSObject> holder_; 1339 Handle<JSObject> holder_;
1314 Handle<JSGlobalPropertyCell> cell_; 1340 Handle<JSGlobalPropertyCell> cell_;
1315 1341
1316 int return_id_; 1342 int return_id_;
1317 }; 1343 };
1318 1344
1319 1345
1320 class AstSentinels { 1346 class AstSentinels {
1321 public: 1347 public:
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 Token::Value op, 1502 Token::Value op,
1477 bool is_prefix, 1503 bool is_prefix,
1478 Expression* expr, 1504 Expression* expr,
1479 int pos) 1505 int pos)
1480 : Expression(isolate), 1506 : Expression(isolate),
1481 op_(op), 1507 op_(op),
1482 is_prefix_(is_prefix), 1508 is_prefix_(is_prefix),
1483 expression_(expr), 1509 expression_(expr),
1484 pos_(pos), 1510 pos_(pos),
1485 assignment_id_(GetNextId(isolate)), 1511 assignment_id_(GetNextId(isolate)),
1486 count_id_(GetNextId(isolate)), 1512 count_id_(GetNextId(isolate)) {}
1487 receiver_types_(NULL) { }
1488 1513
1489 DECLARE_NODE_TYPE(CountOperation) 1514 DECLARE_NODE_TYPE(CountOperation)
1490 1515
1491 bool is_prefix() const { return is_prefix_; } 1516 bool is_prefix() const { return is_prefix_; }
1492 bool is_postfix() const { return !is_prefix_; } 1517 bool is_postfix() const { return !is_prefix_; }
1493 1518
1494 Token::Value op() const { return op_; } 1519 Token::Value op() const { return op_; }
1495 Token::Value binary_op() { 1520 Token::Value binary_op() {
1496 return (op() == Token::INC) ? Token::ADD : Token::SUB; 1521 return (op() == Token::INC) ? Token::ADD : Token::SUB;
1497 } 1522 }
1498 1523
1499 Expression* expression() const { return expression_; } 1524 Expression* expression() const { return expression_; }
1500 virtual int position() const { return pos_; } 1525 virtual int position() const { return pos_; }
1501 1526
1502 virtual void MarkAsStatement() { is_prefix_ = true; } 1527 virtual void MarkAsStatement() { is_prefix_ = true; }
1503 1528
1504 virtual bool IsInlineable() const; 1529 virtual bool IsInlineable() const;
1505 1530
1506 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1531 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1507 virtual bool IsMonomorphic() { return is_monomorphic_; } 1532 virtual bool IsMonomorphic() { return is_monomorphic_; }
1508 virtual Handle<Map> GetMonomorphicReceiverType() { 1533 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1509 return monomorphic_receiver_type_;
1510 }
1511 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
1512 1534
1513 // Bailout support. 1535 // Bailout support.
1514 int AssignmentId() const { return assignment_id_; } 1536 int AssignmentId() const { return assignment_id_; }
1515 int CountId() const { return count_id_; } 1537 int CountId() const { return count_id_; }
1516 1538
1517 private: 1539 private:
1518 Token::Value op_; 1540 Token::Value op_;
1519 bool is_prefix_; 1541 bool is_prefix_;
1520 bool is_monomorphic_; 1542 bool is_monomorphic_;
1521 Expression* expression_; 1543 Expression* expression_;
1522 int pos_; 1544 int pos_;
1523 int assignment_id_; 1545 int assignment_id_;
1524 int count_id_; 1546 int count_id_;
1525 Handle<Map> monomorphic_receiver_type_; 1547 SmallMapList receiver_types_;
1526 ZoneMapList* receiver_types_;
1527 }; 1548 };
1528 1549
1529 1550
1530 class CompareOperation: public Expression { 1551 class CompareOperation: public Expression {
1531 public: 1552 public:
1532 CompareOperation(Isolate* isolate, 1553 CompareOperation(Isolate* isolate,
1533 Token::Value op, 1554 Token::Value op,
1534 Expression* left, 1555 Expression* left,
1535 Expression* right, 1556 Expression* right,
1536 int pos) 1557 int pos)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 // ending of these blocks to allow for optimizations of initialization 1685 // ending of these blocks to allow for optimizations of initialization
1665 // blocks. 1686 // blocks.
1666 bool starts_initialization_block() { return block_start_; } 1687 bool starts_initialization_block() { return block_start_; }
1667 bool ends_initialization_block() { return block_end_; } 1688 bool ends_initialization_block() { return block_end_; }
1668 void mark_block_start() { block_start_ = true; } 1689 void mark_block_start() { block_start_ = true; }
1669 void mark_block_end() { block_end_ = true; } 1690 void mark_block_end() { block_end_ = true; }
1670 1691
1671 // Type feedback information. 1692 // Type feedback information.
1672 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1693 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1673 virtual bool IsMonomorphic() { return is_monomorphic_; } 1694 virtual bool IsMonomorphic() { return is_monomorphic_; }
1674 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } 1695 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
1675 virtual Handle<Map> GetMonomorphicReceiverType() {
1676 return monomorphic_receiver_type_;
1677 }
1678 1696
1679 // Bailout support. 1697 // Bailout support.
1680 int CompoundLoadId() const { return compound_load_id_; } 1698 int CompoundLoadId() const { return compound_load_id_; }
1681 int AssignmentId() const { return assignment_id_; } 1699 int AssignmentId() const { return assignment_id_; }
1682 1700
1683 private: 1701 private:
1684 Token::Value op_; 1702 Token::Value op_;
1685 Expression* target_; 1703 Expression* target_;
1686 Expression* value_; 1704 Expression* value_;
1687 int pos_; 1705 int pos_;
1688 BinaryOperation* binary_operation_; 1706 BinaryOperation* binary_operation_;
1689 int compound_load_id_; 1707 int compound_load_id_;
1690 int assignment_id_; 1708 int assignment_id_;
1691 1709
1692 bool block_start_; 1710 bool block_start_;
1693 bool block_end_; 1711 bool block_end_;
1694 1712
1695 bool is_monomorphic_; 1713 bool is_monomorphic_;
1696 ZoneMapList* receiver_types_; 1714 SmallMapList receiver_types_;
1697 Handle<Map> monomorphic_receiver_type_;
1698 }; 1715 };
1699 1716
1700 1717
1701 class Throw: public Expression { 1718 class Throw: public Expression {
1702 public: 1719 public:
1703 Throw(Isolate* isolate, Expression* exception, int pos) 1720 Throw(Isolate* isolate, Expression* exception, int pos)
1704 : Expression(isolate), exception_(exception), pos_(pos) {} 1721 : Expression(isolate), exception_(exception), pos_(pos) {}
1705 1722
1706 DECLARE_NODE_TYPE(Throw) 1723 DECLARE_NODE_TYPE(Throw)
1707 1724
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 2259
2243 private: 2260 private:
2244 Isolate* isolate_; 2261 Isolate* isolate_;
2245 bool stack_overflow_; 2262 bool stack_overflow_;
2246 }; 2263 };
2247 2264
2248 2265
2249 } } // namespace v8::internal 2266 } } // namespace v8::internal
2250 2267
2251 #endif // V8_AST_H_ 2268 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698