| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 VariableProxy* var_proxy = AsVariableProxy(); | 75 VariableProxy* var_proxy = AsVariableProxy(); |
| 76 if (var_proxy == NULL) return false; | 76 if (var_proxy == NULL) return false; |
| 77 Variable* var = var_proxy->var(); | 77 Variable* var = var_proxy->var(); |
| 78 // The global identifier "undefined" is immutable. Everything | 78 // The global identifier "undefined" is immutable. Everything |
| 79 // else could be reassigned. | 79 // else could be reassigned. |
| 80 return var != NULL && var->location() == Variable::UNALLOCATED && | 80 return var != NULL && var->location() == Variable::UNALLOCATED && |
| 81 var_proxy->name()->Equals(isolate->heap()->undefined_string()); | 81 var_proxy->name()->Equals(isolate->heap()->undefined_string()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 | 84 |
| 85 VariableProxy::VariableProxy(Isolate* isolate, Variable* var) | 85 VariableProxy::VariableProxy(Isolate* isolate, Variable* var, int position) |
| 86 : Expression(isolate), | 86 : Expression(isolate, position), |
| 87 name_(var->name()), | 87 name_(var->name()), |
| 88 var_(NULL), // Will be set by the call to BindTo. | 88 var_(NULL), // Will be set by the call to BindTo. |
| 89 is_this_(var->is_this()), | 89 is_this_(var->is_this()), |
| 90 is_trivial_(false), | 90 is_trivial_(false), |
| 91 is_lvalue_(false), | 91 is_lvalue_(false), |
| 92 position_(RelocInfo::kNoPosition), | |
| 93 interface_(var->interface()) { | 92 interface_(var->interface()) { |
| 94 BindTo(var); | 93 BindTo(var); |
| 95 } | 94 } |
| 96 | 95 |
| 97 | 96 |
| 98 VariableProxy::VariableProxy(Isolate* isolate, | 97 VariableProxy::VariableProxy(Isolate* isolate, |
| 99 Handle<String> name, | 98 Handle<String> name, |
| 100 bool is_this, | 99 bool is_this, |
| 101 Interface* interface, | 100 Interface* interface, |
| 102 int position) | 101 int position) |
| 103 : Expression(isolate), | 102 : Expression(isolate, position), |
| 104 name_(name), | 103 name_(name), |
| 105 var_(NULL), | 104 var_(NULL), |
| 106 is_this_(is_this), | 105 is_this_(is_this), |
| 107 is_trivial_(false), | 106 is_trivial_(false), |
| 108 is_lvalue_(false), | 107 is_lvalue_(false), |
| 109 position_(position), | |
| 110 interface_(interface) { | 108 interface_(interface) { |
| 111 // Names must be canonicalized for fast equality checks. | 109 // Names must be canonicalized for fast equality checks. |
| 112 ASSERT(name->IsInternalizedString()); | 110 ASSERT(name->IsInternalizedString()); |
| 113 } | 111 } |
| 114 | 112 |
| 115 | 113 |
| 116 void VariableProxy::BindTo(Variable* var) { | 114 void VariableProxy::BindTo(Variable* var) { |
| 117 ASSERT(var_ == NULL); // must be bound only once | 115 ASSERT(var_ == NULL); // must be bound only once |
| 118 ASSERT(var != NULL); // must bind | 116 ASSERT(var != NULL); // must bind |
| 119 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); | 117 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); |
| 120 ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name())); | 118 ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name())); |
| 121 // Ideally CONST-ness should match. However, this is very hard to achieve | 119 // Ideally CONST-ness should match. However, this is very hard to achieve |
| 122 // because we don't know the exact semantics of conflicting (const and | 120 // because we don't know the exact semantics of conflicting (const and |
| 123 // non-const) multiple variable declarations, const vars introduced via | 121 // non-const) multiple variable declarations, const vars introduced via |
| 124 // eval() etc. Const-ness and variable declarations are a complete mess | 122 // eval() etc. Const-ness and variable declarations are a complete mess |
| 125 // in JS. Sigh... | 123 // in JS. Sigh... |
| 126 var_ = var; | 124 var_ = var; |
| 127 var->set_is_used(true); | 125 var->set_is_used(true); |
| 128 } | 126 } |
| 129 | 127 |
| 130 | 128 |
| 131 Assignment::Assignment(Isolate* isolate, | 129 Assignment::Assignment(Isolate* isolate, |
| 132 Token::Value op, | 130 Token::Value op, |
| 133 Expression* target, | 131 Expression* target, |
| 134 Expression* value, | 132 Expression* value, |
| 135 int pos) | 133 int pos) |
| 136 : Expression(isolate), | 134 : Expression(isolate, pos), |
| 137 op_(op), | 135 op_(op), |
| 138 target_(target), | 136 target_(target), |
| 139 value_(value), | 137 value_(value), |
| 140 pos_(pos), | |
| 141 binary_operation_(NULL), | 138 binary_operation_(NULL), |
| 142 assignment_id_(GetNextId(isolate)), | 139 assignment_id_(GetNextId(isolate)), |
| 143 is_monomorphic_(false), | 140 is_monomorphic_(false), |
| 144 is_uninitialized_(false), | 141 is_uninitialized_(false), |
| 142 is_pre_monomorphic_(false), |
| 145 store_mode_(STANDARD_STORE) { } | 143 store_mode_(STANDARD_STORE) { } |
| 146 | 144 |
| 147 | 145 |
| 148 Token::Value Assignment::binary_op() const { | 146 Token::Value Assignment::binary_op() const { |
| 149 switch (op_) { | 147 switch (op_) { |
| 150 case Token::ASSIGN_BIT_OR: return Token::BIT_OR; | 148 case Token::ASSIGN_BIT_OR: return Token::BIT_OR; |
| 151 case Token::ASSIGN_BIT_XOR: return Token::BIT_XOR; | 149 case Token::ASSIGN_BIT_XOR: return Token::BIT_XOR; |
| 152 case Token::ASSIGN_BIT_AND: return Token::BIT_AND; | 150 case Token::ASSIGN_BIT_AND: return Token::BIT_AND; |
| 153 case Token::ASSIGN_SHL: return Token::SHL; | 151 case Token::ASSIGN_SHL: return Token::SHL; |
| 154 case Token::ASSIGN_SAR: return Token::SAR; | 152 case Token::ASSIGN_SAR: return Token::SAR; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void ObjectLiteral::Property::set_emit_store(bool emit_store) { | 225 void ObjectLiteral::Property::set_emit_store(bool emit_store) { |
| 228 emit_store_ = emit_store; | 226 emit_store_ = emit_store; |
| 229 } | 227 } |
| 230 | 228 |
| 231 | 229 |
| 232 bool ObjectLiteral::Property::emit_store() { | 230 bool ObjectLiteral::Property::emit_store() { |
| 233 return emit_store_; | 231 return emit_store_; |
| 234 } | 232 } |
| 235 | 233 |
| 236 | 234 |
| 237 bool IsEqualString(void* first, void* second) { | |
| 238 ASSERT((*reinterpret_cast<String**>(first))->IsString()); | |
| 239 ASSERT((*reinterpret_cast<String**>(second))->IsString()); | |
| 240 Handle<String> h1(reinterpret_cast<String**>(first)); | |
| 241 Handle<String> h2(reinterpret_cast<String**>(second)); | |
| 242 return (*h1)->Equals(*h2); | |
| 243 } | |
| 244 | |
| 245 | |
| 246 bool IsEqualNumber(void* first, void* second) { | |
| 247 ASSERT((*reinterpret_cast<Object**>(first))->IsNumber()); | |
| 248 ASSERT((*reinterpret_cast<Object**>(second))->IsNumber()); | |
| 249 | |
| 250 Handle<Object> h1(reinterpret_cast<Object**>(first)); | |
| 251 Handle<Object> h2(reinterpret_cast<Object**>(second)); | |
| 252 if (h1->IsSmi()) { | |
| 253 return h2->IsSmi() && *h1 == *h2; | |
| 254 } | |
| 255 if (h2->IsSmi()) return false; | |
| 256 Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1); | |
| 257 Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2); | |
| 258 ASSERT(std::isfinite(n1->value())); | |
| 259 ASSERT(std::isfinite(n2->value())); | |
| 260 return n1->value() == n2->value(); | |
| 261 } | |
| 262 | |
| 263 | |
| 264 void ObjectLiteral::CalculateEmitStore(Zone* zone) { | 235 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
| 265 ZoneAllocationPolicy allocator(zone); | 236 ZoneAllocationPolicy allocator(zone); |
| 266 | 237 |
| 267 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, | 238 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, |
| 268 allocator); | 239 allocator); |
| 269 for (int i = properties()->length() - 1; i >= 0; i--) { | 240 for (int i = properties()->length() - 1; i >= 0; i--) { |
| 270 ObjectLiteral::Property* property = properties()->at(i); | 241 ObjectLiteral::Property* property = properties()->at(i); |
| 271 Literal* literal = property->key(); | 242 Literal* literal = property->key(); |
| 272 if (literal->value()->IsNull()) continue; | 243 if (literal->value()->IsNull()) continue; |
| 273 uint32_t hash = literal->Hash(); | 244 uint32_t hash = literal->Hash(); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); | 420 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); |
| 450 } | 421 } |
| 451 | 422 |
| 452 | 423 |
| 453 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, | 424 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 454 Zone* zone) { | 425 Zone* zone) { |
| 455 // Record type feedback from the oracle in the AST. | 426 // Record type feedback from the oracle in the AST. |
| 456 is_uninitialized_ = oracle->LoadIsUninitialized(this); | 427 is_uninitialized_ = oracle->LoadIsUninitialized(this); |
| 457 if (is_uninitialized_) return; | 428 if (is_uninitialized_) return; |
| 458 | 429 |
| 430 is_pre_monomorphic_ = oracle->LoadIsPreMonomorphic(this); |
| 459 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); | 431 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); |
| 432 ASSERT(!is_pre_monomorphic_ || !is_monomorphic_); |
| 460 receiver_types_.Clear(); | 433 receiver_types_.Clear(); |
| 461 if (key()->IsPropertyName()) { | 434 if (key()->IsPropertyName()) { |
| 462 FunctionPrototypeStub proto_stub(Code::LOAD_IC); | 435 FunctionPrototypeStub proto_stub(Code::LOAD_IC); |
| 463 if (oracle->LoadIsStub(this, &proto_stub)) { | 436 if (oracle->LoadIsStub(this, &proto_stub)) { |
| 464 is_function_prototype_ = true; | 437 is_function_prototype_ = true; |
| 465 } else { | 438 } else { |
| 466 Literal* lit_key = key()->AsLiteral(); | 439 Literal* lit_key = key()->AsLiteral(); |
| 467 ASSERT(lit_key != NULL && lit_key->value()->IsString()); | 440 ASSERT(lit_key != NULL && lit_key->value()->IsString()); |
| 468 Handle<String> name = Handle<String>::cast(lit_key->value()); | 441 Handle<String> name = Handle<String>::cast(lit_key->value()); |
| 469 oracle->LoadReceiverTypes(this, name, &receiver_types_); | 442 oracle->LoadReceiverTypes(this, name, &receiver_types_); |
| 470 } | 443 } |
| 471 } else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) { | 444 } else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) { |
| 472 is_string_access_ = true; | 445 is_string_access_ = true; |
| 473 } else if (is_monomorphic_) { | 446 } else if (is_monomorphic_) { |
| 474 receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this), | 447 receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this), zone); |
| 475 zone); | |
| 476 } else if (oracle->LoadIsPolymorphic(this)) { | 448 } else if (oracle->LoadIsPolymorphic(this)) { |
| 477 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); | 449 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
| 478 oracle->CollectKeyedReceiverTypes(PropertyFeedbackId(), &receiver_types_); | 450 oracle->CollectKeyedReceiverTypes(PropertyFeedbackId(), &receiver_types_); |
| 479 } | 451 } |
| 480 } | 452 } |
| 481 | 453 |
| 482 | 454 |
| 483 void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle, | 455 void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 484 Zone* zone) { | 456 Zone* zone) { |
| 485 Property* prop = target()->AsProperty(); | 457 Property* prop = target()->AsProperty(); |
| 486 ASSERT(prop != NULL); | 458 ASSERT(prop != NULL); |
| 487 TypeFeedbackId id = AssignmentFeedbackId(); | 459 TypeFeedbackId id = AssignmentFeedbackId(); |
| 488 is_uninitialized_ = oracle->StoreIsUninitialized(id); | 460 is_uninitialized_ = oracle->StoreIsUninitialized(id); |
| 489 if (is_uninitialized_) return; | 461 if (is_uninitialized_) return; |
| 462 |
| 463 is_pre_monomorphic_ = oracle->StoreIsPreMonomorphic(id); |
| 490 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id); | 464 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id); |
| 465 ASSERT(!is_pre_monomorphic_ || !is_monomorphic_); |
| 491 receiver_types_.Clear(); | 466 receiver_types_.Clear(); |
| 492 if (prop->key()->IsPropertyName()) { | 467 if (prop->key()->IsPropertyName()) { |
| 493 Literal* lit_key = prop->key()->AsLiteral(); | 468 Literal* lit_key = prop->key()->AsLiteral(); |
| 494 ASSERT(lit_key != NULL && lit_key->value()->IsString()); | 469 ASSERT(lit_key != NULL && lit_key->value()->IsString()); |
| 495 Handle<String> name = Handle<String>::cast(lit_key->value()); | 470 Handle<String> name = Handle<String>::cast(lit_key->value()); |
| 496 oracle->StoreReceiverTypes(this, name, &receiver_types_); | 471 oracle->StoreReceiverTypes(this, name, &receiver_types_); |
| 497 } else if (is_monomorphic_) { | 472 } else if (is_monomorphic_) { |
| 498 // Record receiver type for monomorphic keyed stores. | 473 // Record receiver type for monomorphic keyed stores. |
| 499 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(id), zone); | 474 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(id), zone); |
| 500 store_mode_ = oracle->GetStoreMode(id); | 475 store_mode_ = oracle->GetStoreMode(id); |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 int node_max_match = node->max_match(); | 1032 int node_max_match = node->max_match(); |
| 1058 max_match_ = IncreaseBy(max_match_, node_max_match); | 1033 max_match_ = IncreaseBy(max_match_, node_max_match); |
| 1059 } | 1034 } |
| 1060 } | 1035 } |
| 1061 | 1036 |
| 1062 | 1037 |
| 1063 CaseClause::CaseClause(Isolate* isolate, | 1038 CaseClause::CaseClause(Isolate* isolate, |
| 1064 Expression* label, | 1039 Expression* label, |
| 1065 ZoneList<Statement*>* statements, | 1040 ZoneList<Statement*>* statements, |
| 1066 int pos) | 1041 int pos) |
| 1067 : label_(label), | 1042 : AstNode(pos), |
| 1043 label_(label), |
| 1068 statements_(statements), | 1044 statements_(statements), |
| 1069 position_(pos), | |
| 1070 compare_type_(Type::None(), isolate), | 1045 compare_type_(Type::None(), isolate), |
| 1071 compare_id_(AstNode::GetNextId(isolate)), | 1046 compare_id_(AstNode::GetNextId(isolate)), |
| 1072 entry_id_(AstNode::GetNextId(isolate)) { | 1047 entry_id_(AstNode::GetNextId(isolate)) { |
| 1073 } | 1048 } |
| 1074 | 1049 |
| 1075 | 1050 |
| 1076 #define REGULAR_NODE(NodeType) \ | 1051 #define REGULAR_NODE(NodeType) \ |
| 1077 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ | 1052 void AstConstructionVisitor::Visit##NodeType(NodeType* node) { \ |
| 1078 increase_node_count(); \ | 1053 increase_node_count(); \ |
| 1079 } | 1054 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1101 REGULAR_NODE(VariableDeclaration) | 1076 REGULAR_NODE(VariableDeclaration) |
| 1102 REGULAR_NODE(FunctionDeclaration) | 1077 REGULAR_NODE(FunctionDeclaration) |
| 1103 REGULAR_NODE(Block) | 1078 REGULAR_NODE(Block) |
| 1104 REGULAR_NODE(ExpressionStatement) | 1079 REGULAR_NODE(ExpressionStatement) |
| 1105 REGULAR_NODE(EmptyStatement) | 1080 REGULAR_NODE(EmptyStatement) |
| 1106 REGULAR_NODE(IfStatement) | 1081 REGULAR_NODE(IfStatement) |
| 1107 REGULAR_NODE(ContinueStatement) | 1082 REGULAR_NODE(ContinueStatement) |
| 1108 REGULAR_NODE(BreakStatement) | 1083 REGULAR_NODE(BreakStatement) |
| 1109 REGULAR_NODE(ReturnStatement) | 1084 REGULAR_NODE(ReturnStatement) |
| 1110 REGULAR_NODE(SwitchStatement) | 1085 REGULAR_NODE(SwitchStatement) |
| 1086 REGULAR_NODE(CaseClause) |
| 1111 REGULAR_NODE(Conditional) | 1087 REGULAR_NODE(Conditional) |
| 1112 REGULAR_NODE(Literal) | 1088 REGULAR_NODE(Literal) |
| 1113 REGULAR_NODE(ArrayLiteral) | 1089 REGULAR_NODE(ArrayLiteral) |
| 1114 REGULAR_NODE(ObjectLiteral) | 1090 REGULAR_NODE(ObjectLiteral) |
| 1115 REGULAR_NODE(RegExpLiteral) | 1091 REGULAR_NODE(RegExpLiteral) |
| 1116 REGULAR_NODE(FunctionLiteral) | 1092 REGULAR_NODE(FunctionLiteral) |
| 1117 REGULAR_NODE(Assignment) | 1093 REGULAR_NODE(Assignment) |
| 1118 REGULAR_NODE(Throw) | 1094 REGULAR_NODE(Throw) |
| 1119 REGULAR_NODE(Property) | 1095 REGULAR_NODE(Property) |
| 1120 REGULAR_NODE(UnaryOperation) | 1096 REGULAR_NODE(UnaryOperation) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); | 1163 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); |
| 1188 str = arr; | 1164 str = arr; |
| 1189 } else { | 1165 } else { |
| 1190 str = DoubleToCString(value_->Number(), buffer); | 1166 str = DoubleToCString(value_->Number(), buffer); |
| 1191 } | 1167 } |
| 1192 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); | 1168 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); |
| 1193 } | 1169 } |
| 1194 | 1170 |
| 1195 | 1171 |
| 1196 } } // namespace v8::internal | 1172 } } // namespace v8::internal |
| OLD | NEW |