| 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 #include "ast.h" | 28 #include "ast.h" |
| 29 | 29 |
| 30 #include <cmath> // For isfinite. | 30 #include <cmath> // For isfinite. |
| 31 #include "builtins.h" | 31 #include "builtins.h" |
| 32 #include "code-stubs.h" | 32 #include "code-stubs.h" |
| 33 #include "contexts.h" |
| 33 #include "conversions.h" | 34 #include "conversions.h" |
| 34 #include "hashmap.h" | 35 #include "hashmap.h" |
| 35 #include "parser.h" | 36 #include "parser.h" |
| 36 #include "property-details.h" | 37 #include "property-details.h" |
| 37 #include "property.h" | 38 #include "property.h" |
| 38 #include "scopes.h" | 39 #include "scopes.h" |
| 39 #include "string-stream.h" | 40 #include "string-stream.h" |
| 40 #include "type-info.h" | 41 #include "type-info.h" |
| 41 | 42 |
| 42 namespace v8 { | 43 namespace v8 { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 int FunctionLiteral::end_position() const { | 175 int FunctionLiteral::end_position() const { |
| 175 return scope()->end_position(); | 176 return scope()->end_position(); |
| 176 } | 177 } |
| 177 | 178 |
| 178 | 179 |
| 179 LanguageMode FunctionLiteral::language_mode() const { | 180 LanguageMode FunctionLiteral::language_mode() const { |
| 180 return scope()->language_mode(); | 181 return scope()->language_mode(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 | 184 |
| 184 ObjectLiteral::Property::Property(Literal* key, | 185 ObjectLiteralProperty::ObjectLiteralProperty(Literal* key, |
| 185 Expression* value, | 186 Expression* value, |
| 186 Isolate* isolate) { | 187 Isolate* isolate) { |
| 187 emit_store_ = true; | 188 emit_store_ = true; |
| 188 key_ = key; | 189 key_ = key; |
| 189 value_ = value; | 190 value_ = value; |
| 190 Object* k = *key->handle(); | 191 Object* k = *key->handle(); |
| 191 if (k->IsInternalizedString() && | 192 if (k->IsInternalizedString() && |
| 192 isolate->heap()->proto_string()->Equals(String::cast(k))) { | 193 isolate->heap()->proto_string()->Equals(String::cast(k))) { |
| 193 kind_ = PROTOTYPE; | 194 kind_ = PROTOTYPE; |
| 194 } else if (value_->AsMaterializedLiteral() != NULL) { | 195 } else if (value_->AsMaterializedLiteral() != NULL) { |
| 195 kind_ = MATERIALIZED_LITERAL; | 196 kind_ = MATERIALIZED_LITERAL; |
| 196 } else if (value_->AsLiteral() != NULL) { | 197 } else if (value_->AsLiteral() != NULL) { |
| 197 kind_ = CONSTANT; | 198 kind_ = CONSTANT; |
| 198 } else { | 199 } else { |
| 199 kind_ = COMPUTED; | 200 kind_ = COMPUTED; |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 | 204 |
| 204 ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) { | 205 ObjectLiteralProperty::ObjectLiteralProperty(bool is_getter, |
| 206 FunctionLiteral* value) { |
| 205 emit_store_ = true; | 207 emit_store_ = true; |
| 206 value_ = value; | 208 value_ = value; |
| 207 kind_ = is_getter ? GETTER : SETTER; | 209 kind_ = is_getter ? GETTER : SETTER; |
| 208 } | 210 } |
| 209 | 211 |
| 210 | 212 |
| 211 bool ObjectLiteral::Property::IsCompileTimeValue() { | 213 bool ObjectLiteral::Property::IsCompileTimeValue() { |
| 212 return kind_ == CONSTANT || | 214 return kind_ == CONSTANT || |
| 213 (kind_ == MATERIALIZED_LITERAL && | 215 (kind_ == MATERIALIZED_LITERAL && |
| 214 CompileTimeValue::IsCompileTimeValue(value_)); | 216 CompileTimeValue::IsCompileTimeValue(value_)); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 410 } |
| 409 | 411 |
| 410 bool FunctionDeclaration::IsInlineable() const { | 412 bool FunctionDeclaration::IsInlineable() const { |
| 411 return false; | 413 return false; |
| 412 } | 414 } |
| 413 | 415 |
| 414 | 416 |
| 415 // ---------------------------------------------------------------------------- | 417 // ---------------------------------------------------------------------------- |
| 416 // Recording of type feedback | 418 // Recording of type feedback |
| 417 | 419 |
| 420 void ForInStatement::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 421 for_in_type_ = static_cast<ForInType>(oracle->ForInType(this)); |
| 422 } |
| 423 |
| 424 |
| 425 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { |
| 426 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); |
| 427 } |
| 428 |
| 429 |
| 418 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, | 430 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 419 Zone* zone) { | 431 Zone* zone) { |
| 420 // Record type feedback from the oracle in the AST. | 432 // Record type feedback from the oracle in the AST. |
| 421 is_uninitialized_ = oracle->LoadIsUninitialized(this); | 433 is_uninitialized_ = oracle->LoadIsUninitialized(this); |
| 422 if (is_uninitialized_) return; | 434 if (is_uninitialized_) return; |
| 423 | 435 |
| 424 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); | 436 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); |
| 425 receiver_types_.Clear(); | 437 receiver_types_.Clear(); |
| 426 if (key()->IsPropertyName()) { | 438 if (key()->IsPropertyName()) { |
| 427 FunctionPrototypeStub proto_stub(Code::LOAD_IC); | 439 FunctionPrototypeStub proto_stub(Code::LOAD_IC); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 receiver_types_.Clear(); | 491 receiver_types_.Clear(); |
| 480 if (is_monomorphic_) { | 492 if (is_monomorphic_) { |
| 481 // Record receiver type for monomorphic keyed stores. | 493 // Record receiver type for monomorphic keyed stores. |
| 482 receiver_types_.Add( | 494 receiver_types_.Add( |
| 483 oracle->StoreMonomorphicReceiverType(id), zone); | 495 oracle->StoreMonomorphicReceiverType(id), zone); |
| 484 } else if (oracle->StoreIsPolymorphic(id)) { | 496 } else if (oracle->StoreIsPolymorphic(id)) { |
| 485 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); | 497 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
| 486 oracle->CollectKeyedReceiverTypes(id, &receiver_types_); | 498 oracle->CollectKeyedReceiverTypes(id, &receiver_types_); |
| 487 } | 499 } |
| 488 store_mode_ = oracle->GetStoreMode(id); | 500 store_mode_ = oracle->GetStoreMode(id); |
| 501 type_ = oracle->IncrementType(this); |
| 489 } | 502 } |
| 490 | 503 |
| 491 | 504 |
| 492 void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 505 void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 493 TypeInfo info = oracle->SwitchType(this); | 506 TypeInfo info = oracle->SwitchType(this); |
| 494 if (info.IsUninitialized()) info = TypeInfo::Unknown(); | 507 if (info.IsUninitialized()) info = TypeInfo::Unknown(); |
| 495 if (info.IsSmi()) { | 508 if (info.IsSmi()) { |
| 496 compare_type_ = SMI_ONLY; | 509 compare_type_ = SMI_ONLY; |
| 497 } else if (info.IsInternalizedString()) { | 510 } else if (info.IsInternalizedString()) { |
| 498 compare_type_ = NAME_ONLY; | 511 compare_type_ = NAME_ONLY; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 // change and thus prefer the general IC code. | 581 // change and thus prefer the general IC code. |
| 569 if (!HEAP->InNewSpace(*candidate)) { | 582 if (!HEAP->InNewSpace(*candidate)) { |
| 570 target_ = candidate; | 583 target_ = candidate; |
| 571 return true; | 584 return true; |
| 572 } | 585 } |
| 573 } | 586 } |
| 574 return false; | 587 return false; |
| 575 } | 588 } |
| 576 | 589 |
| 577 | 590 |
| 591 Handle<JSObject> Call::GetPrototypeForPrimitiveCheck( |
| 592 CheckType check, Isolate* isolate) { |
| 593 v8::internal::Context* native_context = isolate->context()->native_context(); |
| 594 JSFunction* function = NULL; |
| 595 switch (check) { |
| 596 case RECEIVER_MAP_CHECK: |
| 597 UNREACHABLE(); |
| 598 break; |
| 599 case STRING_CHECK: |
| 600 function = native_context->string_function(); |
| 601 break; |
| 602 case SYMBOL_CHECK: |
| 603 function = native_context->symbol_function(); |
| 604 break; |
| 605 case NUMBER_CHECK: |
| 606 function = native_context->number_function(); |
| 607 break; |
| 608 case BOOLEAN_CHECK: |
| 609 function = native_context->boolean_function(); |
| 610 break; |
| 611 } |
| 612 ASSERT(function != NULL); |
| 613 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 614 } |
| 615 |
| 616 |
| 578 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, | 617 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 579 CallKind call_kind) { | 618 CallKind call_kind) { |
| 580 is_monomorphic_ = oracle->CallIsMonomorphic(this); | 619 is_monomorphic_ = oracle->CallIsMonomorphic(this); |
| 581 Property* property = expression()->AsProperty(); | 620 Property* property = expression()->AsProperty(); |
| 582 if (property == NULL) { | 621 if (property == NULL) { |
| 583 // Function call. Specialize for monomorphic calls. | 622 // Function call. Specialize for monomorphic calls. |
| 584 if (is_monomorphic_) target_ = oracle->GetCallTarget(this); | 623 if (is_monomorphic_) target_ = oracle->GetCallTarget(this); |
| 585 } else { | 624 } else { |
| 586 // Method call. Specialize for the receiver types seen at runtime. | 625 // Method call. Specialize for the receiver types seen at runtime. |
| 587 Literal* key = property->key()->AsLiteral(); | 626 Literal* key = property->key()->AsLiteral(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 599 } | 638 } |
| 600 #endif | 639 #endif |
| 601 check_type_ = oracle->GetCallCheckType(this); | 640 check_type_ = oracle->GetCallCheckType(this); |
| 602 if (is_monomorphic_) { | 641 if (is_monomorphic_) { |
| 603 Handle<Map> map; | 642 Handle<Map> map; |
| 604 if (receiver_types_.length() > 0) { | 643 if (receiver_types_.length() > 0) { |
| 605 ASSERT(check_type_ == RECEIVER_MAP_CHECK); | 644 ASSERT(check_type_ == RECEIVER_MAP_CHECK); |
| 606 map = receiver_types_.at(0); | 645 map = receiver_types_.at(0); |
| 607 } else { | 646 } else { |
| 608 ASSERT(check_type_ != RECEIVER_MAP_CHECK); | 647 ASSERT(check_type_ != RECEIVER_MAP_CHECK); |
| 609 holder_ = Handle<JSObject>( | 648 holder_ = GetPrototypeForPrimitiveCheck(check_type_, oracle->isolate()); |
| 610 oracle->GetPrototypeForPrimitiveCheck(check_type_)); | |
| 611 map = Handle<Map>(holder_->map()); | 649 map = Handle<Map>(holder_->map()); |
| 612 } | 650 } |
| 613 is_monomorphic_ = ComputeTarget(map, name); | 651 is_monomorphic_ = ComputeTarget(map, name); |
| 614 } | 652 } |
| 615 } | 653 } |
| 616 } | 654 } |
| 617 | 655 |
| 618 | 656 |
| 619 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 657 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 620 is_monomorphic_ = oracle->CallNewIsMonomorphic(this); | 658 is_monomorphic_ = oracle->CallNewIsMonomorphic(this); |
| 621 if (is_monomorphic_) { | 659 if (is_monomorphic_) { |
| 622 target_ = oracle->GetCallNewTarget(this); | 660 target_ = oracle->GetCallNewTarget(this); |
| 623 elements_kind_ = oracle->GetCallNewElementsKind(this); | 661 elements_kind_ = oracle->GetCallNewElementsKind(this); |
| 662 } else { |
| 663 Handle<Object> alloc_elements_kind = oracle->GetInfo(CallNewFeedbackId()); |
| 664 if (alloc_elements_kind->IsSmi()) |
| 665 alloc_elements_kind_ = Handle<Smi>::cast(alloc_elements_kind); |
| 624 } | 666 } |
| 625 } | 667 } |
| 626 | 668 |
| 627 | 669 |
| 628 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 670 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 629 receiver_type_ = oracle->ObjectLiteralStoreIsMonomorphic(this) | 671 receiver_type_ = oracle->ObjectLiteralStoreIsMonomorphic(this) |
| 630 ? oracle->GetObjectLiteralStoreMap(this) | 672 ? oracle->GetObjectLiteralStoreMap(this) |
| 631 : Handle<Map>::null(); | 673 : Handle<Map>::null(); |
| 632 } | 674 } |
| 633 | 675 |
| 634 | 676 |
| 677 void UnaryOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 678 type_ = oracle->UnaryType(this); |
| 679 } |
| 680 |
| 681 |
| 682 void BinaryOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 683 oracle->BinaryType(this, &left_type_, &right_type_, &result_type_); |
| 684 } |
| 685 |
| 686 |
| 687 void CompareOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 688 oracle->CompareType(this, &left_type_, &right_type_, &overall_type_); |
| 689 if (!overall_type_.IsUninitialized() && overall_type_.IsNonPrimitive() && |
| 690 (op_ == Token::EQ || op_ == Token::EQ_STRICT)) { |
| 691 map_ = oracle->GetCompareMap(this); |
| 692 } else { |
| 693 // May be a compare to nil. |
| 694 map_ = oracle->CompareNilMonomorphicReceiverType(this); |
| 695 if (op_ != Token::EQ_STRICT) |
| 696 compare_nil_types_ = oracle->CompareNilTypes(this); |
| 697 } |
| 698 } |
| 699 |
| 700 |
| 635 // ---------------------------------------------------------------------------- | 701 // ---------------------------------------------------------------------------- |
| 636 // Implementation of AstVisitor | 702 // Implementation of AstVisitor |
| 637 | 703 |
| 638 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 704 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
| 639 for (int i = 0; i < declarations->length(); i++) { | 705 for (int i = 0; i < declarations->length(); i++) { |
| 640 Visit(declarations->at(i)); | 706 Visit(declarations->at(i)); |
| 641 } | 707 } |
| 642 } | 708 } |
| 643 | 709 |
| 644 | 710 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); | 1190 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
| 1125 str = arr; | 1191 str = arr; |
| 1126 } else { | 1192 } else { |
| 1127 str = DoubleToCString(handle_->Number(), buffer); | 1193 str = DoubleToCString(handle_->Number(), buffer); |
| 1128 } | 1194 } |
| 1129 return FACTORY->NewStringFromAscii(CStrVector(str)); | 1195 return FACTORY->NewStringFromAscii(CStrVector(str)); |
| 1130 } | 1196 } |
| 1131 | 1197 |
| 1132 | 1198 |
| 1133 } } // namespace v8::internal | 1199 } } // namespace v8::internal |
| OLD | NEW |