Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 ExternalReference ref = | 419 ExternalReference ref = |
| 420 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly)); | 420 ExternalReference(IC_Utility(IC::kLoadPropertyWithInterceptorOnly)); |
| 421 __ mov(r0, Operand(5)); | 421 __ mov(r0, Operand(5)); |
| 422 __ mov(r1, Operand(ref)); | 422 __ mov(r1, Operand(ref)); |
| 423 | 423 |
| 424 CEntryStub stub(1); | 424 CEntryStub stub(1); |
| 425 __ CallStub(&stub); | 425 __ CallStub(&stub); |
| 426 } | 426 } |
| 427 | 427 |
| 428 | 428 |
| 429 class LoadInterceptorCompiler BASE_EMBEDDED { | |
| 430 public: | |
| 431 explicit LoadInterceptorCompiler(Register name) : name_(name) {} | |
| 432 | |
| 433 void CompileCacheable(MacroAssembler* masm, | |
| 434 StubCompiler* stub_compiler, | |
| 435 Register receiver, | |
| 436 Register holder, | |
| 437 Register scratch1, | |
| 438 Register scratch2, | |
| 439 JSObject* interceptor_holder, | |
| 440 LookupResult* lookup, | |
| 441 String* name, | |
| 442 Label* miss_label) { | |
| 443 AccessorInfo* callback = NULL; | |
| 444 bool optimize = false; | |
| 445 // So far the most popular follow ups for interceptor loads are FIELD | |
| 446 // and CALLBACKS, so inline only them, other cases may be added | |
| 447 // later. | |
| 448 if (lookup->type() == FIELD) { | |
| 449 optimize = true; | |
| 450 } else if (lookup->type() == CALLBACKS) { | |
| 451 Object* callback_object = lookup->GetCallbackObject(); | |
| 452 if (callback_object->IsAccessorInfo()) { | |
| 453 callback = AccessorInfo::cast(callback_object); | |
| 454 optimize = callback->getter() != NULL; | |
| 455 } | |
| 456 } | |
| 457 | |
| 458 if (!optimize) { | |
| 459 CompileRegular(masm, receiver, holder, scratch2, interceptor_holder, | |
| 460 miss_label); | |
| 461 return; | |
| 462 } | |
| 463 | |
| 464 // Save necessary data before invoking an interceptor. | |
| 465 // Requires a frame to make GC aware of pushed pointers. | |
| 466 __ EnterInternalFrame(); | |
| 467 | |
| 468 if (lookup->type() == CALLBACKS && !receiver.is(holder)) { | |
| 469 // CALLBACKS case needs a receiver to be passed into C++ callback. | |
| 470 __ Push(receiver, holder, name_); | |
| 471 } else { | |
| 472 __ Push(holder, name_); | |
| 473 } | |
| 474 | |
| 475 // Invoke an interceptor. Note: map checks from receiver to | |
| 476 // interceptor's holder has been compiled before (see a caller | |
| 477 // of this method.) | |
| 478 CompileCallLoadPropertyWithInterceptor(masm, | |
| 479 receiver, | |
| 480 holder, | |
| 481 name_, | |
| 482 interceptor_holder); | |
| 483 | |
| 484 // Check if interceptor provided a value for property. If it's | |
| 485 // the case, return immediately. | |
| 486 Label interceptor_failed; | |
| 487 __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex); | |
| 488 __ cmp(r0, scratch1); | |
| 489 __ b(eq, &interceptor_failed); | |
| 490 __ LeaveInternalFrame(); | |
| 491 __ Ret(); | |
| 492 | |
| 493 __ bind(&interceptor_failed); | |
| 494 __ pop(name_); | |
| 495 __ pop(holder); | |
| 496 if (lookup->type() == CALLBACKS && !receiver.is(holder)) { | |
| 497 __ pop(receiver); | |
| 498 } | |
| 499 | |
| 500 __ LeaveInternalFrame(); | |
| 501 | |
| 502 // Check that the maps from interceptor's holder to lookup's holder | |
| 503 // haven't changed. And load lookup's holder into |holder| register. | |
| 504 if (interceptor_holder != lookup->holder()) { | |
| 505 holder = stub_compiler->CheckPrototypes(interceptor_holder, holder, | |
| 506 lookup->holder(), scratch1, | |
| 507 scratch2, | |
| 508 name, | |
| 509 miss_label); | |
| 510 } | |
| 511 | |
| 512 if (lookup->type() == FIELD) { | |
| 513 // We found FIELD property in prototype chain of interceptor's holder. | |
| 514 // Retrieve a field from field's holder. | |
| 515 stub_compiler->GenerateFastPropertyLoad(masm, | |
| 516 r0, | |
| 517 holder, | |
| 518 lookup->holder(), | |
| 519 lookup->GetFieldIndex()); | |
| 520 __ Ret(); | |
| 521 } else { | |
| 522 // We found CALLBACKS property in prototype chain of interceptor's | |
| 523 // holder. | |
| 524 ASSERT(lookup->type() == CALLBACKS); | |
| 525 ASSERT(lookup->GetCallbackObject()->IsAccessorInfo()); | |
| 526 ASSERT(callback != NULL); | |
| 527 ASSERT(callback->getter() != NULL); | |
| 528 | |
| 529 // Tail call to runtime. | |
| 530 // Important invariant in CALLBACKS case: the code above must be | |
| 531 // structured to never clobber |receiver| register. | |
| 532 __ Move(scratch2, Handle<AccessorInfo>(callback)); | |
| 533 // holder is either receiver or scratch1. | |
| 534 if (!receiver.is(holder)) { | |
| 535 ASSERT(scratch1.is(holder)); | |
| 536 __ Push(receiver, holder, scratch2); | |
| 537 __ ldr(scratch1, FieldMemOperand(holder, AccessorInfo::kDataOffset)); | |
| 538 __ Push(scratch1, name_); | |
| 539 } else { | |
| 540 __ push(receiver); | |
| 541 __ ldr(scratch1, FieldMemOperand(holder, AccessorInfo::kDataOffset)); | |
| 542 __ Push(holder, scratch2, scratch1, name_); | |
| 543 } | |
| 544 | |
| 545 ExternalReference ref = | |
| 546 ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); | |
| 547 __ TailCallExternalReference(ref, 5, 1); | |
| 548 } | |
| 549 } | |
| 550 | |
| 551 | |
| 552 void CompileRegular(MacroAssembler* masm, | |
| 553 Register receiver, | |
| 554 Register holder, | |
| 555 Register scratch, | |
| 556 JSObject* interceptor_holder, | |
| 557 Label* miss_label) { | |
| 558 PushInterceptorArguments(masm, receiver, holder, name_, interceptor_holder); | |
| 559 | |
| 560 ExternalReference ref = ExternalReference( | |
| 561 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); | |
| 562 __ TailCallExternalReference(ref, 5, 1); | |
| 563 } | |
| 564 | |
| 565 private: | |
| 566 Register name_; | |
| 567 }; | |
| 568 | |
| 569 | |
| 570 static void CompileLoadInterceptor(LoadInterceptorCompiler* compiler, | |
| 571 StubCompiler* stub_compiler, | |
| 572 MacroAssembler* masm, | |
| 573 JSObject* object, | |
| 574 JSObject* holder, | |
| 575 String* name, | |
| 576 LookupResult* lookup, | |
| 577 Register receiver, | |
| 578 Register scratch1, | |
| 579 Register scratch2, | |
| 580 Label* miss) { | |
| 581 ASSERT(holder->HasNamedInterceptor()); | |
| 582 ASSERT(!holder->GetNamedInterceptor()->getter()->IsUndefined()); | |
| 583 | |
| 584 // Check that the receiver isn't a smi. | |
| 585 __ BranchOnSmi(receiver, miss); | |
| 586 | |
| 587 // Check that the maps haven't changed. | |
| 588 Register reg = | |
| 589 stub_compiler->CheckPrototypes(object, receiver, holder, | |
| 590 scratch1, scratch2, name, miss); | |
| 591 | |
| 592 if (lookup->IsProperty() && lookup->IsCacheable()) { | |
| 593 compiler->CompileCacheable(masm, | |
| 594 stub_compiler, | |
| 595 receiver, | |
| 596 reg, | |
| 597 scratch1, | |
| 598 scratch2, | |
| 599 holder, | |
| 600 lookup, | |
| 601 name, | |
| 602 miss); | |
| 603 } else { | |
| 604 compiler->CompileRegular(masm, | |
| 605 receiver, | |
| 606 reg, | |
| 607 scratch2, | |
| 608 holder, | |
| 609 miss); | |
| 610 } | |
| 611 } | |
| 612 | |
| 613 | |
| 614 // Reserves space for the extra arguments to FastHandleApiCall in the | 429 // Reserves space for the extra arguments to FastHandleApiCall in the |
| 615 // caller's frame. | 430 // caller's frame. |
| 616 // | 431 // |
| 617 // These arguments are set by CheckPrototypes and GenerateFastApiCall. | 432 // These arguments are set by CheckPrototypes and GenerateFastApiCall. |
| 618 static void ReserveSpaceForFastApiCall(MacroAssembler* masm, | 433 static void ReserveSpaceForFastApiCall(MacroAssembler* masm, |
| 619 Register scratch) { | 434 Register scratch) { |
| 620 __ mov(scratch, Operand(Smi::FromInt(0))); | 435 __ mov(scratch, Operand(Smi::FromInt(0))); |
| 621 __ push(scratch); | 436 __ push(scratch); |
| 622 __ push(scratch); | 437 __ push(scratch); |
| 623 __ push(scratch); | 438 __ push(scratch); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 // Do tail-call to the runtime system. | 830 // Do tail-call to the runtime system. |
| 1016 ExternalReference load_callback_property = | 831 ExternalReference load_callback_property = |
| 1017 ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); | 832 ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); |
| 1018 __ TailCallExternalReference(load_callback_property, 5, 1); | 833 __ TailCallExternalReference(load_callback_property, 5, 1); |
| 1019 | 834 |
| 1020 return true; | 835 return true; |
| 1021 } | 836 } |
| 1022 | 837 |
| 1023 | 838 |
| 1024 void StubCompiler::GenerateLoadInterceptor(JSObject* object, | 839 void StubCompiler::GenerateLoadInterceptor(JSObject* object, |
| 1025 JSObject* holder, | 840 JSObject* interceptor_holder, |
| 1026 LookupResult* lookup, | 841 LookupResult* lookup, |
| 1027 Register receiver, | 842 Register receiver, |
| 1028 Register name_reg, | 843 Register name_reg, |
| 1029 Register scratch1, | 844 Register scratch1, |
| 1030 Register scratch2, | 845 Register scratch2, |
| 1031 String* name, | 846 String* name, |
| 1032 Label* miss) { | 847 Label* miss) { |
| 1033 LoadInterceptorCompiler compiler(name_reg); | 848 ASSERT(interceptor_holder->HasNamedInterceptor()); |
| 1034 CompileLoadInterceptor(&compiler, | 849 ASSERT(!interceptor_holder->GetNamedInterceptor()->getter()->IsUndefined()); |
| 1035 this, | 850 |
| 1036 masm(), | 851 // Check that the receiver isn't a smi. |
| 1037 object, | 852 __ BranchOnSmi(receiver, miss); |
| 1038 holder, | 853 |
| 1039 name, | 854 // So far the most popular follow ups for interceptor loads are FIELD |
| 1040 lookup, | 855 // and CALLBACKS, so inline only them, other cases may be added |
| 1041 receiver, | 856 // later. |
| 1042 scratch1, | 857 bool compile_followup_inline = false; |
| 1043 scratch2, | 858 if (lookup->IsProperty() && lookup->IsCacheable()) { |
| 1044 miss); | 859 if (lookup->type() == FIELD) { |
| 860 compile_followup_inline = true; | |
| 861 } else if (lookup->type() == CALLBACKS && | |
| 862 lookup->GetCallbackObject()->IsAccessorInfo() && | |
| 863 AccessorInfo::cast(lookup->GetCallbackObject())->getter() != NULL) { | |
| 864 compile_followup_inline = true; | |
| 865 } | |
| 866 } | |
| 867 | |
| 868 if (compile_followup_inline) { | |
| 869 // Compile the interceptor call, followed by inline code to load the | |
| 870 // property from further up the prototype chain if the call fails. | |
| 871 // Check that the maps haven't changed. | |
| 872 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder, | |
| 873 scratch1, scratch2, name, miss); | |
| 874 ASSERT(holder_reg.is(receiver) || holder_reg.is(scratch1)); | |
| 875 | |
| 876 // Save necessary data before invoking an interceptor. | |
| 877 // Requires a frame to make GC aware of pushed pointers. | |
| 878 __ EnterInternalFrame(); | |
| 879 | |
| 880 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) { | |
| 881 // CALLBACKS case needs a receiver to be passed into C++ callback. | |
| 882 __ Push(receiver, holder_reg, name_reg); | |
| 883 } else { | |
| 884 __ Push(holder_reg, name_reg); | |
| 885 } | |
| 886 | |
| 887 // Invoke an interceptor. Note: map checks from receiver to | |
| 888 // interceptor's holder has been compiled before (see a caller | |
| 889 // of this method.) | |
| 890 CompileCallLoadPropertyWithInterceptor(masm(), | |
| 891 receiver, | |
| 892 holder_reg, | |
| 893 name_reg, | |
| 894 interceptor_holder); | |
| 895 | |
| 896 // Check if interceptor provided a value for property. If it's | |
| 897 // the case, return immediately. | |
| 898 Label interceptor_failed; | |
| 899 __ LoadRoot(scratch1, Heap::kNoInterceptorResultSentinelRootIndex); | |
| 900 __ cmp(r0, scratch1); | |
| 901 __ b(eq, &interceptor_failed); | |
| 902 __ LeaveInternalFrame(); | |
| 903 __ Ret(); | |
| 904 | |
| 905 __ bind(&interceptor_failed); | |
| 906 __ pop(name_reg); | |
| 907 __ pop(holder_reg); | |
| 908 if (lookup->type() == CALLBACKS && !receiver.is(holder_reg)) { | |
| 909 __ pop(receiver); | |
| 910 } | |
| 911 | |
| 912 __ LeaveInternalFrame(); | |
| 913 | |
| 914 // Check that the maps from interceptor's holder to lookup's holder | |
| 915 // haven't changed. And load lookup's holder into |holder| register. | |
| 916 if (interceptor_holder != lookup->holder()) { | |
| 917 holder_reg = CheckPrototypes(interceptor_holder, | |
| 918 holder_reg, | |
| 919 lookup->holder(), | |
| 920 scratch1, | |
| 921 scratch2, | |
| 922 name, | |
| 923 miss); | |
| 924 } | |
|
antonm
2010/05/27 13:39:40
Please, restore ASSERT added in http://codereview.
| |
| 925 | |
| 926 if (lookup->type() == FIELD) { | |
| 927 // We found FIELD property in prototype chain of interceptor's holder. | |
| 928 // Retrieve a field from field's holder. | |
| 929 GenerateFastPropertyLoad(masm(), r0, holder_reg, | |
| 930 lookup->holder(), lookup->GetFieldIndex()); | |
| 931 __ Ret(); | |
| 932 } else { | |
| 933 // We found CALLBACKS property in prototype chain of interceptor's | |
| 934 // holder. | |
| 935 ASSERT(lookup->type() == CALLBACKS); | |
| 936 ASSERT(lookup->GetCallbackObject()->IsAccessorInfo()); | |
| 937 AccessorInfo* callback = AccessorInfo::cast(lookup->GetCallbackObject()); | |
| 938 ASSERT(callback != NULL); | |
| 939 ASSERT(callback->getter() != NULL); | |
| 940 | |
| 941 // Tail call to runtime. | |
| 942 // Important invariant in CALLBACKS case: the code above must be | |
| 943 // structured to never clobber |receiver| register. | |
| 944 __ Move(scratch2, Handle<AccessorInfo>(callback)); | |
| 945 // holder_reg is either receiver or scratch1. | |
| 946 if (!receiver.is(holder_reg)) { | |
| 947 ASSERT(scratch1.is(holder_reg)); | |
| 948 __ Push(receiver, holder_reg, scratch2); | |
| 949 __ ldr(scratch1, | |
| 950 FieldMemOperand(holder_reg, AccessorInfo::kDataOffset)); | |
| 951 __ Push(scratch1, name_reg); | |
| 952 } else { | |
| 953 __ push(receiver); | |
| 954 __ ldr(scratch1, | |
| 955 FieldMemOperand(holder_reg, AccessorInfo::kDataOffset)); | |
| 956 __ Push(holder_reg, scratch2, scratch1, name_reg); | |
| 957 } | |
| 958 | |
| 959 ExternalReference ref = | |
| 960 ExternalReference(IC_Utility(IC::kLoadCallbackProperty)); | |
| 961 __ TailCallExternalReference(ref, 5, 1); | |
| 962 } | |
| 963 } else { // !compile_followup_inline | |
| 964 // Call the runtime system to load the interceptor. | |
| 965 // Check that the maps haven't changed. | |
| 966 Register holder_reg = CheckPrototypes(object, receiver, interceptor_holder, | |
| 967 scratch1, scratch2, name, miss); | |
| 968 PushInterceptorArguments(masm(), receiver, holder_reg, | |
| 969 name_reg, interceptor_holder); | |
| 970 | |
| 971 ExternalReference ref = ExternalReference( | |
| 972 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); | |
| 973 __ TailCallExternalReference(ref, 5, 1); | |
| 974 } | |
| 1045 } | 975 } |
| 1046 | 976 |
| 1047 | 977 |
| 1048 Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { | 978 Object* StubCompiler::CompileLazyCompile(Code::Flags flags) { |
| 1049 // ----------- S t a t e ------------- | 979 // ----------- S t a t e ------------- |
| 1050 // -- r1: function | 980 // -- r1: function |
| 1051 // -- lr: return address | 981 // -- lr: return address |
| 1052 // ----------------------------------- | 982 // ----------------------------------- |
| 1053 | 983 |
| 1054 // Enter an internal frame. | 984 // Enter an internal frame. |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2191 // Return the generated code. | 2121 // Return the generated code. |
| 2192 return GetCode(); | 2122 return GetCode(); |
| 2193 } | 2123 } |
| 2194 | 2124 |
| 2195 | 2125 |
| 2196 #undef __ | 2126 #undef __ |
| 2197 | 2127 |
| 2198 } } // namespace v8::internal | 2128 } } // namespace v8::internal |
| 2199 | 2129 |
| 2200 #endif // V8_TARGET_ARCH_ARM | 2130 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |