| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 ICU(StoreInterceptorProperty) \ | 59 ICU(StoreInterceptorProperty) \ |
| 60 ICU(UnaryOp_Patch) \ | 60 ICU(UnaryOp_Patch) \ |
| 61 ICU(BinaryOp_Patch) \ | 61 ICU(BinaryOp_Patch) \ |
| 62 ICU(CompareIC_Miss) | 62 ICU(CompareIC_Miss) |
| 63 // | 63 // |
| 64 // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, | 64 // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, |
| 65 // and KeyedStoreIC. | 65 // and KeyedStoreIC. |
| 66 // | 66 // |
| 67 class IC { | 67 class IC { |
| 68 public: | 68 public: |
| 69 | |
| 70 // The ids for utility called from the generated code. | 69 // The ids for utility called from the generated code. |
| 71 enum UtilityId { | 70 enum UtilityId { |
| 72 #define CONST_NAME(name) k##name, | 71 #define CONST_NAME(name) k##name, |
| 73 IC_UTIL_LIST(CONST_NAME) | 72 IC_UTIL_LIST(CONST_NAME) |
| 74 #undef CONST_NAME | 73 #undef CONST_NAME |
| 75 kUtilityCount | 74 kUtilityCount |
| 76 }; | 75 }; |
| 77 | 76 |
| 78 // Looks up the address of the named utility. | 77 // Looks up the address of the named utility. |
| 79 static Address AddressFromUtilityId(UtilityId id); | 78 static Address AddressFromUtilityId(UtilityId id); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 Handle<Object> object, | 276 Handle<Object> object, |
| 278 Handle<Object> key); | 277 Handle<Object> key); |
| 279 | 278 |
| 280 // Code generator routines. | 279 // Code generator routines. |
| 281 static void GenerateInitialize(MacroAssembler* masm, int argc) { | 280 static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 282 GenerateMiss(masm, argc); | 281 GenerateMiss(masm, argc); |
| 283 } | 282 } |
| 284 static void GenerateMiss(MacroAssembler* masm, int argc); | 283 static void GenerateMiss(MacroAssembler* masm, int argc); |
| 285 static void GenerateMegamorphic(MacroAssembler* masm, int argc); | 284 static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 286 static void GenerateNormal(MacroAssembler* masm, int argc); | 285 static void GenerateNormal(MacroAssembler* masm, int argc); |
| 286 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 | 289 |
| 290 class LoadIC: public IC { | 290 class LoadIC: public IC { |
| 291 public: | 291 public: |
| 292 explicit LoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { | 292 explicit LoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 293 ASSERT(target()->is_load_stub()); | 293 ASSERT(target()->is_load_stub()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 MUST_USE_RESULT MaybeObject* Load(State state, | 296 MUST_USE_RESULT MaybeObject* Load(State state, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 338 |
| 339 friend class IC; | 339 friend class IC; |
| 340 }; | 340 }; |
| 341 | 341 |
| 342 | 342 |
| 343 class KeyedIC: public IC { | 343 class KeyedIC: public IC { |
| 344 public: | 344 public: |
| 345 explicit KeyedIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {} | 345 explicit KeyedIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {} |
| 346 virtual ~KeyedIC() {} | 346 virtual ~KeyedIC() {} |
| 347 | 347 |
| 348 static const int kMaxKeyedPolymorphism = 4; | 348 virtual MaybeObject* GetElementStubWithoutMapCheck( |
| 349 | 349 bool is_js_array, |
| 350 virtual MaybeObject* GetFastElementStubWithoutMapCheck( | 350 JSObject::ElementsKind elements_kind) = 0; |
| 351 bool is_js_array) = 0; | |
| 352 | |
| 353 virtual MaybeObject* GetExternalArrayStubWithoutMapCheck( | |
| 354 ExternalArrayType array_type) = 0; | |
| 355 | 351 |
| 356 protected: | 352 protected: |
| 357 virtual Code* string_stub() { | 353 virtual Code* string_stub() { |
| 358 return NULL; | 354 return NULL; |
| 359 } | 355 } |
| 360 | 356 |
| 361 virtual Code::Kind kind() const = 0; | 357 virtual Code::Kind kind() const = 0; |
| 362 | 358 |
| 363 virtual String* GetStubNameForCache(IC::State ic_state) = 0; | |
| 364 | |
| 365 MaybeObject* ComputeStub(JSObject* receiver, | 359 MaybeObject* ComputeStub(JSObject* receiver, |
| 366 bool is_store, | 360 bool is_store, |
| 367 StrictModeFlag strict_mode, | 361 StrictModeFlag strict_mode, |
| 368 Code* default_stub); | 362 Code* default_stub); |
| 369 | 363 |
| 370 virtual MaybeObject* ConstructMegamorphicStub( | 364 virtual MaybeObject* ConstructMegamorphicStub( |
| 371 MapList* receiver_maps, | 365 MapList* receiver_maps, |
| 372 CodeList* targets, | 366 CodeList* targets, |
| 373 StrictModeFlag strict_mode) = 0; | 367 StrictModeFlag strict_mode) = 0; |
| 374 | 368 |
| 375 private: | 369 private: |
| 376 void GetReceiverMapsForStub(Code* stub, MapList* result); | 370 void GetReceiverMapsForStub(Code* stub, MapList* result); |
| 377 | 371 |
| 378 MaybeObject* ComputeMonomorphicStubWithoutMapCheck( | 372 MaybeObject* ComputeMonomorphicStubWithoutMapCheck( |
| 379 Map* receiver_map, | 373 Map* receiver_map, |
| 380 StrictModeFlag strict_mode, | 374 StrictModeFlag strict_mode); |
| 381 Code* generic_stub); | |
| 382 | 375 |
| 383 MaybeObject* ComputeMonomorphicStub(JSObject* receiver, | 376 MaybeObject* ComputeMonomorphicStub(JSObject* receiver, |
| 384 bool is_store, | 377 bool is_store, |
| 385 StrictModeFlag strict_mode, | 378 StrictModeFlag strict_mode, |
| 386 Code* default_stub); | 379 Code* default_stub); |
| 387 }; | 380 }; |
| 388 | 381 |
| 389 | 382 |
| 390 class KeyedLoadIC: public KeyedIC { | 383 class KeyedLoadIC: public KeyedIC { |
| 391 public: | 384 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 402 static void GenerateMiss(MacroAssembler* masm, bool force_generic); | 395 static void GenerateMiss(MacroAssembler* masm, bool force_generic); |
| 403 static void GenerateRuntimeGetProperty(MacroAssembler* masm); | 396 static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 404 static void GenerateInitialize(MacroAssembler* masm) { | 397 static void GenerateInitialize(MacroAssembler* masm) { |
| 405 GenerateMiss(masm, false); | 398 GenerateMiss(masm, false); |
| 406 } | 399 } |
| 407 static void GeneratePreMonomorphic(MacroAssembler* masm) { | 400 static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 408 GenerateMiss(masm, false); | 401 GenerateMiss(masm, false); |
| 409 } | 402 } |
| 410 static void GenerateGeneric(MacroAssembler* masm); | 403 static void GenerateGeneric(MacroAssembler* masm); |
| 411 static void GenerateString(MacroAssembler* masm); | 404 static void GenerateString(MacroAssembler* masm); |
| 412 | |
| 413 static void GenerateIndexedInterceptor(MacroAssembler* masm); | 405 static void GenerateIndexedInterceptor(MacroAssembler* masm); |
| 406 static void GenerateNonStrictArguments(MacroAssembler* masm); |
| 414 | 407 |
| 415 // Bit mask to be tested against bit field for the cases when | 408 // Bit mask to be tested against bit field for the cases when |
| 416 // generic stub should go into slow case. | 409 // generic stub should go into slow case. |
| 417 // Access check is necessary explicitly since generic stub does not perform | 410 // Access check is necessary explicitly since generic stub does not perform |
| 418 // map checks. | 411 // map checks. |
| 419 static const int kSlowCaseBitFieldMask = | 412 static const int kSlowCaseBitFieldMask = |
| 420 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); | 413 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 421 | 414 |
| 422 virtual MaybeObject* GetFastElementStubWithoutMapCheck( | 415 virtual MaybeObject* GetElementStubWithoutMapCheck( |
| 423 bool is_js_array); | 416 bool is_js_array, |
| 424 | 417 JSObject::ElementsKind elements_kind); |
| 425 virtual MaybeObject* GetExternalArrayStubWithoutMapCheck( | |
| 426 ExternalArrayType array_type); | |
| 427 | 418 |
| 428 protected: | 419 protected: |
| 429 virtual Code::Kind kind() const { return Code::KEYED_LOAD_IC; } | 420 virtual Code::Kind kind() const { return Code::KEYED_LOAD_IC; } |
| 430 | 421 |
| 431 virtual String* GetStubNameForCache(IC::State ic_state); | |
| 432 | |
| 433 virtual MaybeObject* ConstructMegamorphicStub( | 422 virtual MaybeObject* ConstructMegamorphicStub( |
| 434 MapList* receiver_maps, | 423 MapList* receiver_maps, |
| 435 CodeList* targets, | 424 CodeList* targets, |
| 436 StrictModeFlag strict_mode); | 425 StrictModeFlag strict_mode); |
| 437 | 426 |
| 438 virtual Code* string_stub() { | 427 virtual Code* string_stub() { |
| 439 return isolate()->builtins()->builtin( | 428 return isolate()->builtins()->builtin( |
| 440 Builtins::kKeyedLoadIC_String); | 429 Builtins::kKeyedLoadIC_String); |
| 441 } | 430 } |
| 442 | 431 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 461 Builtins::kKeyedLoadIC_Generic); | 450 Builtins::kKeyedLoadIC_Generic); |
| 462 } | 451 } |
| 463 Code* pre_monomorphic_stub() { | 452 Code* pre_monomorphic_stub() { |
| 464 return isolate()->builtins()->builtin( | 453 return isolate()->builtins()->builtin( |
| 465 Builtins::kKeyedLoadIC_PreMonomorphic); | 454 Builtins::kKeyedLoadIC_PreMonomorphic); |
| 466 } | 455 } |
| 467 Code* indexed_interceptor_stub() { | 456 Code* indexed_interceptor_stub() { |
| 468 return isolate()->builtins()->builtin( | 457 return isolate()->builtins()->builtin( |
| 469 Builtins::kKeyedLoadIC_IndexedInterceptor); | 458 Builtins::kKeyedLoadIC_IndexedInterceptor); |
| 470 } | 459 } |
| 460 Code* non_strict_arguments_stub() { |
| 461 return isolate()->builtins()->builtin( |
| 462 Builtins::kKeyedLoadIC_NonStrictArguments); |
| 463 } |
| 471 | 464 |
| 472 static void Clear(Address address, Code* target); | 465 static void Clear(Address address, Code* target); |
| 473 | 466 |
| 474 friend class IC; | 467 friend class IC; |
| 475 }; | 468 }; |
| 476 | 469 |
| 477 | 470 |
| 478 class StoreIC: public IC { | 471 class StoreIC: public IC { |
| 479 public: | 472 public: |
| 480 explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { | 473 explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 | 554 |
| 562 // Code generators for stub routines. Only called once at startup. | 555 // Code generators for stub routines. Only called once at startup. |
| 563 static void GenerateInitialize(MacroAssembler* masm) { | 556 static void GenerateInitialize(MacroAssembler* masm) { |
| 564 GenerateMiss(masm, false); | 557 GenerateMiss(masm, false); |
| 565 } | 558 } |
| 566 static void GenerateMiss(MacroAssembler* masm, bool force_generic); | 559 static void GenerateMiss(MacroAssembler* masm, bool force_generic); |
| 567 static void GenerateSlow(MacroAssembler* masm); | 560 static void GenerateSlow(MacroAssembler* masm); |
| 568 static void GenerateRuntimeSetProperty(MacroAssembler* masm, | 561 static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 569 StrictModeFlag strict_mode); | 562 StrictModeFlag strict_mode); |
| 570 static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); | 563 static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
| 564 static void GenerateNonStrictArguments(MacroAssembler* masm); |
| 571 | 565 |
| 572 virtual MaybeObject* GetFastElementStubWithoutMapCheck( | 566 virtual MaybeObject* GetElementStubWithoutMapCheck( |
| 573 bool is_js_array); | 567 bool is_js_array, |
| 574 | 568 JSObject::ElementsKind elements_kind); |
| 575 virtual MaybeObject* GetExternalArrayStubWithoutMapCheck( | |
| 576 ExternalArrayType array_type); | |
| 577 | 569 |
| 578 protected: | 570 protected: |
| 579 virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } | 571 virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } |
| 580 | 572 |
| 581 virtual String* GetStubNameForCache(IC::State ic_state); | |
| 582 | |
| 583 virtual MaybeObject* ConstructMegamorphicStub( | 573 virtual MaybeObject* ConstructMegamorphicStub( |
| 584 MapList* receiver_maps, | 574 MapList* receiver_maps, |
| 585 CodeList* targets, | 575 CodeList* targets, |
| 586 StrictModeFlag strict_mode); | 576 StrictModeFlag strict_mode); |
| 587 | 577 |
| 588 private: | 578 private: |
| 589 // Update the inline cache. | 579 // Update the inline cache. |
| 590 void UpdateCaches(LookupResult* lookup, | 580 void UpdateCaches(LookupResult* lookup, |
| 591 State state, | 581 State state, |
| 592 StrictModeFlag strict_mode, | 582 StrictModeFlag strict_mode, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 619 Builtins::kKeyedStoreIC_Generic_Strict); | 609 Builtins::kKeyedStoreIC_Generic_Strict); |
| 620 } | 610 } |
| 621 Code* generic_stub() { | 611 Code* generic_stub() { |
| 622 return isolate()->builtins()->builtin( | 612 return isolate()->builtins()->builtin( |
| 623 Builtins::kKeyedStoreIC_Generic); | 613 Builtins::kKeyedStoreIC_Generic); |
| 624 } | 614 } |
| 625 Code* generic_stub_strict() { | 615 Code* generic_stub_strict() { |
| 626 return isolate()->builtins()->builtin( | 616 return isolate()->builtins()->builtin( |
| 627 Builtins::kKeyedStoreIC_Generic_Strict); | 617 Builtins::kKeyedStoreIC_Generic_Strict); |
| 628 } | 618 } |
| 619 Code* non_strict_arguments_stub() { |
| 620 return isolate()->builtins()->builtin( |
| 621 Builtins::kKeyedStoreIC_NonStrictArguments); |
| 622 } |
| 629 | 623 |
| 630 static void Clear(Address address, Code* target); | 624 static void Clear(Address address, Code* target); |
| 631 | 625 |
| 632 friend class IC; | 626 friend class IC; |
| 633 }; | 627 }; |
| 634 | 628 |
| 635 | 629 |
| 636 class UnaryOpIC: public IC { | 630 class UnaryOpIC: public IC { |
| 637 public: | 631 public: |
| 638 | |
| 639 // sorted: increasingly more unspecific (ignoring UNINITIALIZED) | 632 // sorted: increasingly more unspecific (ignoring UNINITIALIZED) |
| 640 // TODO(svenpanne) Using enums+switch is an antipattern, use a class instead. | 633 // TODO(svenpanne) Using enums+switch is an antipattern, use a class instead. |
| 641 enum TypeInfo { | 634 enum TypeInfo { |
| 642 UNINITIALIZED, | 635 UNINITIALIZED, |
| 643 SMI, | 636 SMI, |
| 644 HEAP_NUMBER, | 637 HEAP_NUMBER, |
| 645 GENERIC | 638 GENERIC |
| 646 }; | 639 }; |
| 647 | 640 |
| 648 explicit UnaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } | 641 explicit UnaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
| 649 | 642 |
| 650 void patch(Code* code); | 643 void patch(Code* code); |
| 651 | 644 |
| 652 static const char* GetName(TypeInfo type_info); | 645 static const char* GetName(TypeInfo type_info); |
| 653 | 646 |
| 654 static State ToState(TypeInfo type_info); | 647 static State ToState(TypeInfo type_info); |
| 655 | 648 |
| 656 static TypeInfo GetTypeInfo(Handle<Object> operand); | 649 static TypeInfo GetTypeInfo(Handle<Object> operand); |
| 657 | 650 |
| 658 static TypeInfo ComputeNewType(TypeInfo type, TypeInfo previous); | 651 static TypeInfo ComputeNewType(TypeInfo type, TypeInfo previous); |
| 659 }; | 652 }; |
| 660 | 653 |
| 661 | 654 |
| 662 // Type Recording BinaryOpIC, that records the types of the inputs and outputs. | 655 // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
| 663 class BinaryOpIC: public IC { | 656 class BinaryOpIC: public IC { |
| 664 public: | 657 public: |
| 665 | |
| 666 enum TypeInfo { | 658 enum TypeInfo { |
| 667 UNINITIALIZED, | 659 UNINITIALIZED, |
| 668 SMI, | 660 SMI, |
| 669 INT32, | 661 INT32, |
| 670 HEAP_NUMBER, | 662 HEAP_NUMBER, |
| 671 ODDBALL, | 663 ODDBALL, |
| 672 BOTH_STRING, // Only used for addition operation. | 664 BOTH_STRING, // Only used for addition operation. |
| 673 STRING, // Only used for addition operation. At least one string operand. | 665 STRING, // Only used for addition operation. At least one string operand. |
| 674 GENERIC | 666 GENERIC |
| 675 }; | 667 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 719 |
| 728 Token::Value op_; | 720 Token::Value op_; |
| 729 }; | 721 }; |
| 730 | 722 |
| 731 // Helper for BinaryOpIC and CompareIC. | 723 // Helper for BinaryOpIC and CompareIC. |
| 732 void PatchInlinedSmiCode(Address address); | 724 void PatchInlinedSmiCode(Address address); |
| 733 | 725 |
| 734 } } // namespace v8::internal | 726 } } // namespace v8::internal |
| 735 | 727 |
| 736 #endif // V8_IC_H_ | 728 #endif // V8_IC_H_ |
| OLD | NEW |