| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_HEAP_H_ | 5 #ifndef V8_HEAP_H_ |
| 6 #define V8_HEAP_H_ | 6 #define V8_HEAP_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "allocation.h" | 10 #include "allocation.h" |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 return old_pointer_space_->allocation_limit_address(); | 675 return old_pointer_space_->allocation_limit_address(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 Address* OldDataSpaceAllocationTopAddress() { | 678 Address* OldDataSpaceAllocationTopAddress() { |
| 679 return old_data_space_->allocation_top_address(); | 679 return old_data_space_->allocation_top_address(); |
| 680 } | 680 } |
| 681 Address* OldDataSpaceAllocationLimitAddress() { | 681 Address* OldDataSpaceAllocationLimitAddress() { |
| 682 return old_data_space_->allocation_limit_address(); | 682 return old_data_space_->allocation_limit_address(); |
| 683 } | 683 } |
| 684 | 684 |
| 685 // Allocates and initializes a new JavaScript object based on a | |
| 686 // constructor. | |
| 687 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 688 // failed. | |
| 689 // If allocation_site is non-null, then a memento is emitted after the object | |
| 690 // that points to the site. | |
| 691 // Please note this does not perform a garbage collection. | |
| 692 MUST_USE_RESULT MaybeObject* AllocateJSObject( | |
| 693 JSFunction* constructor, | |
| 694 PretenureFlag pretenure = NOT_TENURED, | |
| 695 AllocationSite* allocation_site = NULL); | |
| 696 | |
| 697 // Returns a deep copy of the JavaScript object. | 685 // Returns a deep copy of the JavaScript object. |
| 698 // Properties and elements are copied too. | 686 // Properties and elements are copied too. |
| 699 // Returns failure if allocation failed. | 687 // Returns failure if allocation failed. |
| 700 // Optionally takes an AllocationSite to be appended in an AllocationMemento. | 688 // Optionally takes an AllocationSite to be appended in an AllocationMemento. |
| 701 MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source, | 689 MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source, |
| 702 AllocationSite* site = NULL); | 690 AllocationSite* site = NULL); |
| 703 | 691 |
| 704 // Allocates and initializes a new JavaScript object based on a map. | |
| 705 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 706 // failed. | |
| 707 // Passing an allocation site means that a memento will be created that | |
| 708 // points to the site. | |
| 709 // Please note this does not perform a garbage collection. | |
| 710 MUST_USE_RESULT MaybeObject* AllocateJSObjectFromMap( | |
| 711 Map* map, | |
| 712 PretenureFlag pretenure = NOT_TENURED, | |
| 713 bool alloc_props = true, | |
| 714 AllocationSite* allocation_site = NULL); | |
| 715 | |
| 716 // Allocates a heap object based on the map. | |
| 717 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 718 // failed. | |
| 719 // Please note this function does not perform a garbage collection. | |
| 720 MUST_USE_RESULT MaybeObject* Allocate(Map* map, AllocationSpace space, | |
| 721 AllocationSite* allocation_site = NULL); | |
| 722 | |
| 723 // Allocates a JS Map in the heap. | |
| 724 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 725 // failed. | |
| 726 // Please note this function does not perform a garbage collection. | |
| 727 MUST_USE_RESULT MaybeObject* AllocateMap( | |
| 728 InstanceType instance_type, | |
| 729 int instance_size, | |
| 730 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); | |
| 731 | |
| 732 // Allocates a partial map for bootstrapping. | |
| 733 MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type, | |
| 734 int instance_size); | |
| 735 | |
| 736 // Allocate a block of memory in the given space (filled with a filler). | |
| 737 // Used as a fall-back for generated code when the space is full. | |
| 738 MUST_USE_RESULT MaybeObject* AllocateFillerObject(int size, | |
| 739 bool double_align, | |
| 740 AllocationSpace space); | |
| 741 | |
| 742 // Clear the Instanceof cache (used when a prototype changes). | 692 // Clear the Instanceof cache (used when a prototype changes). |
| 743 inline void ClearInstanceofCache(); | 693 inline void ClearInstanceofCache(); |
| 744 | 694 |
| 745 // Iterates the whole code space to clear all ICs of the given kind. | 695 // Iterates the whole code space to clear all ICs of the given kind. |
| 746 void ClearAllICsByKind(Code::Kind kind); | 696 void ClearAllICsByKind(Code::Kind kind); |
| 747 | 697 |
| 748 // For use during bootup. | 698 // For use during bootup. |
| 749 void RepairFreeListsAfterBoot(); | 699 void RepairFreeListsAfterBoot(); |
| 750 | 700 |
| 751 // Allocates and fully initializes a String. There are two String | |
| 752 // encodings: ASCII and two byte. One should choose between the three string | |
| 753 // allocation functions based on the encoding of the string buffer used to | |
| 754 // initialized the string. | |
| 755 // - ...FromAscii initializes the string from a buffer that is ASCII | |
| 756 // encoded (it does not check that the buffer is ASCII encoded) and the | |
| 757 // result will be ASCII encoded. | |
| 758 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 | |
| 759 // encoded. If the characters are all single-byte characters, the | |
| 760 // result will be ASCII encoded, otherwise it will converted to two | |
| 761 // byte. | |
| 762 // - ...FromTwoByte initializes the string from a buffer that is two-byte | |
| 763 // encoded. If the characters are all single-byte characters, the | |
| 764 // result will be converted to ASCII, otherwise it will be left as | |
| 765 // two-byte. | |
| 766 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 767 // failed. | |
| 768 // Please note this does not perform a garbage collection. | |
| 769 MUST_USE_RESULT MaybeObject* AllocateStringFromUtf8Slow( | |
| 770 Vector<const char> str, | |
| 771 int non_ascii_start, | |
| 772 PretenureFlag pretenure = NOT_TENURED); | |
| 773 MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte( | |
| 774 Vector<const uc16> str, | |
| 775 PretenureFlag pretenure = NOT_TENURED); | |
| 776 | |
| 777 // Allocates an internalized string in old space based on the character | 701 // Allocates an internalized string in old space based on the character |
| 778 // stream. Returns Failure::RetryAfterGC(requested_bytes, space) if the | 702 // stream. Returns Failure::RetryAfterGC(requested_bytes, space) if the |
| 779 // allocation failed. | 703 // allocation failed. |
| 780 // Please note this function does not perform a garbage collection. | 704 // Please note this function does not perform a garbage collection. |
| 781 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringFromUtf8( | 705 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringFromUtf8( |
| 782 Vector<const char> str, | 706 Vector<const char> str, |
| 783 int chars, | 707 int chars, |
| 784 uint32_t hash_field); | 708 uint32_t hash_field); |
| 785 | 709 |
| 786 MUST_USE_RESULT inline MaybeObject* AllocateOneByteInternalizedString( | 710 MUST_USE_RESULT inline MaybeObject* AllocateOneByteInternalizedString( |
| 787 Vector<const uint8_t> str, | 711 Vector<const uint8_t> str, |
| 788 uint32_t hash_field); | 712 uint32_t hash_field); |
| 789 | 713 |
| 790 MUST_USE_RESULT inline MaybeObject* AllocateTwoByteInternalizedString( | 714 MUST_USE_RESULT inline MaybeObject* AllocateTwoByteInternalizedString( |
| 791 Vector<const uc16> str, | 715 Vector<const uc16> str, |
| 792 uint32_t hash_field); | 716 uint32_t hash_field); |
| 793 | 717 |
| 794 template<typename T> | 718 template<typename T> |
| 795 static inline bool IsOneByte(T t, int chars); | 719 static inline bool IsOneByte(T t, int chars); |
| 796 | 720 |
| 797 template<typename T> | 721 template<typename T> |
| 798 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringImpl( | 722 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringImpl( |
| 799 T t, int chars, uint32_t hash_field); | 723 T t, int chars, uint32_t hash_field); |
| 800 | 724 |
| 801 template<bool is_one_byte, typename T> | |
| 802 MUST_USE_RESULT MaybeObject* AllocateInternalizedStringImpl( | |
| 803 T t, int chars, uint32_t hash_field); | |
| 804 | |
| 805 // Allocate a byte array of the specified length | |
| 806 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 807 // failed. | |
| 808 // Please note this does not perform a garbage collection. | |
| 809 MUST_USE_RESULT MaybeObject* AllocateByteArray( | |
| 810 int length, | |
| 811 PretenureFlag pretenure = NOT_TENURED); | |
| 812 | |
| 813 // Allocates an external array of the specified length and type. | |
| 814 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 815 // failed. | |
| 816 // Please note this does not perform a garbage collection. | |
| 817 MUST_USE_RESULT MaybeObject* AllocateExternalArray( | |
| 818 int length, | |
| 819 ExternalArrayType array_type, | |
| 820 void* external_pointer, | |
| 821 PretenureFlag pretenure); | |
| 822 | |
| 823 // Allocates a fixed typed array of the specified length and type. | |
| 824 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 825 // failed. | |
| 826 // Please note this does not perform a garbage collection. | |
| 827 MUST_USE_RESULT MaybeObject* AllocateFixedTypedArray( | |
| 828 int length, | |
| 829 ExternalArrayType array_type, | |
| 830 PretenureFlag pretenure); | |
| 831 | |
| 832 // Allocate a symbol in old space. | |
| 833 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 834 // failed. | |
| 835 // Please note this does not perform a garbage collection. | |
| 836 MUST_USE_RESULT MaybeObject* AllocateSymbol(); | |
| 837 MUST_USE_RESULT MaybeObject* AllocatePrivateSymbol(); | |
| 838 | |
| 839 // Allocates a fixed array initialized with undefined values | 725 // Allocates a fixed array initialized with undefined values |
| 840 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | 726 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 841 // failed. | 727 // failed. |
| 842 // Please note this does not perform a garbage collection. | 728 // Please note this does not perform a garbage collection. |
| 843 MUST_USE_RESULT MaybeObject* AllocateFixedArray( | 729 MUST_USE_RESULT MaybeObject* AllocateFixedArray( |
| 844 int length, | 730 int length, |
| 845 PretenureFlag pretenure = NOT_TENURED); | 731 PretenureFlag pretenure = NOT_TENURED); |
| 846 | 732 |
| 847 // Allocates an uninitialized fixed array. It must be filled by the caller. | 733 // Allocates an uninitialized fixed array. It must be filled by the caller. |
| 848 // | 734 // |
| 849 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | 735 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 850 // failed. | 736 // failed. |
| 851 // Please note this does not perform a garbage collection. | 737 // Please note this does not perform a garbage collection. |
| 852 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length); | 738 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length); |
| 853 | 739 |
| 854 // Move len elements within a given array from src_index index to dst_index | 740 // Move len elements within a given array from src_index index to dst_index |
| 855 // index. | 741 // index. |
| 856 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); | 742 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); |
| 857 | 743 |
| 858 // Make a copy of src and return it. Returns | 744 // Make a copy of src and return it. Returns |
| 859 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | 745 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 860 MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src); | 746 MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src); |
| 861 | 747 |
| 862 // Make a copy of src and return it. Returns | |
| 863 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
| 864 MUST_USE_RESULT MaybeObject* CopyAndTenureFixedCOWArray(FixedArray* src); | |
| 865 | |
| 866 // Make a copy of src, set the map, and return the copy. Returns | 748 // Make a copy of src, set the map, and return the copy. Returns |
| 867 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | 749 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 868 MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map); | 750 MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map); |
| 869 | 751 |
| 870 // Make a copy of src and return it. Returns | 752 // Make a copy of src and return it. Returns |
| 871 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | 753 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 872 MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray( | 754 MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray( |
| 873 FixedDoubleArray* src); | 755 FixedDoubleArray* src); |
| 874 | 756 |
| 875 // Make a copy of src, set the map, and return the copy. Returns | |
| 876 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
| 877 MUST_USE_RESULT MaybeObject* CopyFixedDoubleArrayWithMap( | |
| 878 FixedDoubleArray* src, Map* map); | |
| 879 | |
| 880 // Make a copy of src and return it. Returns | 757 // Make a copy of src and return it. Returns |
| 881 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | 758 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 882 MUST_USE_RESULT inline MaybeObject* CopyConstantPoolArray( | 759 MUST_USE_RESULT inline MaybeObject* CopyConstantPoolArray( |
| 883 ConstantPoolArray* src); | 760 ConstantPoolArray* src); |
| 884 | 761 |
| 885 // Make a copy of src, set the map, and return the copy. Returns | |
| 886 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
| 887 MUST_USE_RESULT MaybeObject* CopyConstantPoolArrayWithMap( | |
| 888 ConstantPoolArray* src, Map* map); | |
| 889 | |
| 890 MUST_USE_RESULT MaybeObject* AllocateConstantPoolArray( | |
| 891 int number_of_int64_entries, | |
| 892 int number_of_code_ptr_entries, | |
| 893 int number_of_heap_ptr_entries, | |
| 894 int number_of_int32_entries); | |
| 895 | |
| 896 // Allocates a fixed double array with uninitialized values. Returns | |
| 897 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
| 898 // Please note this does not perform a garbage collection. | |
| 899 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedDoubleArray( | |
| 900 int length, | |
| 901 PretenureFlag pretenure = NOT_TENURED); | |
| 902 | |
| 903 // AllocateHashTable is identical to AllocateFixedArray except | 762 // AllocateHashTable is identical to AllocateFixedArray except |
| 904 // that the resulting object has hash_table_map as map. | 763 // that the resulting object has hash_table_map as map. |
| 905 MUST_USE_RESULT MaybeObject* AllocateHashTable( | 764 MUST_USE_RESULT MaybeObject* AllocateHashTable( |
| 906 int length, PretenureFlag pretenure = NOT_TENURED); | 765 int length, PretenureFlag pretenure = NOT_TENURED); |
| 907 | 766 |
| 908 // Allocates a new utility object in the old generation. | |
| 909 MUST_USE_RESULT MaybeObject* AllocateStruct(InstanceType type); | |
| 910 | |
| 911 // Sloppy mode arguments object size. | 767 // Sloppy mode arguments object size. |
| 912 static const int kSloppyArgumentsObjectSize = | 768 static const int kSloppyArgumentsObjectSize = |
| 913 JSObject::kHeaderSize + 2 * kPointerSize; | 769 JSObject::kHeaderSize + 2 * kPointerSize; |
| 914 // Strict mode arguments has no callee so it is smaller. | 770 // Strict mode arguments has no callee so it is smaller. |
| 915 static const int kStrictArgumentsObjectSize = | 771 static const int kStrictArgumentsObjectSize = |
| 916 JSObject::kHeaderSize + 1 * kPointerSize; | 772 JSObject::kHeaderSize + 1 * kPointerSize; |
| 917 // Indicies for direct access into argument objects. | 773 // Indicies for direct access into argument objects. |
| 918 static const int kArgumentsLengthIndex = 0; | 774 static const int kArgumentsLengthIndex = 0; |
| 919 // callee is only valid in sloppy mode. | 775 // callee is only valid in sloppy mode. |
| 920 static const int kArgumentsCalleeIndex = 1; | 776 static const int kArgumentsCalleeIndex = 1; |
| 921 | 777 |
| 922 // Allocates an arguments object - optionally with an elements array. | |
| 923 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 924 // failed. | |
| 925 // Please note this does not perform a garbage collection. | |
| 926 MUST_USE_RESULT MaybeObject* AllocateArgumentsObject( | |
| 927 Object* callee, int length); | |
| 928 | |
| 929 // Allocated a HeapNumber from value. | |
| 930 MUST_USE_RESULT MaybeObject* AllocateHeapNumber( | |
| 931 double value, PretenureFlag pretenure = NOT_TENURED); | |
| 932 | |
| 933 // Converts an int into either a Smi or a HeapNumber object. | 778 // Converts an int into either a Smi or a HeapNumber object. |
| 934 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | 779 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation |
| 935 // failed. | 780 // failed. |
| 936 // Please note this does not perform a garbage collection. | 781 // Please note this does not perform a garbage collection. |
| 937 MUST_USE_RESULT inline MaybeObject* NumberFromUint32( | 782 MUST_USE_RESULT inline MaybeObject* NumberFromUint32( |
| 938 uint32_t value, PretenureFlag pretenure = NOT_TENURED); | 783 uint32_t value, PretenureFlag pretenure = NOT_TENURED); |
| 939 | 784 |
| 940 // Allocates a new foreign object. | |
| 941 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
| 942 // failed. | |
| 943 // Please note this does not perform a garbage collection. | |
| 944 MUST_USE_RESULT MaybeObject* AllocateForeign( | |
| 945 Address address, PretenureFlag pretenure = NOT_TENURED); | |
| 946 | |
| 947 // Finalizes an external string by deleting the associated external | 785 // Finalizes an external string by deleting the associated external |
| 948 // data and clearing the resource pointer. | 786 // data and clearing the resource pointer. |
| 949 inline void FinalizeExternalString(String* string); | 787 inline void FinalizeExternalString(String* string); |
| 950 | 788 |
| 951 // Initialize a filler object to keep the ability to iterate over the heap | 789 // Initialize a filler object to keep the ability to iterate over the heap |
| 952 // when shortening objects. | 790 // when shortening objects. |
| 953 void CreateFillerObjectAt(Address addr, int size); | 791 void CreateFillerObjectAt(Address addr, int size); |
| 954 | 792 |
| 955 bool CanMoveObjectStart(HeapObject* object); | 793 bool CanMoveObjectStart(HeapObject* object); |
| 956 | 794 |
| 957 enum InvocationMode { FROM_GC, FROM_MUTATOR }; | 795 enum InvocationMode { FROM_GC, FROM_MUTATOR }; |
| 958 | 796 |
| 959 // Maintain marking consistency for IncrementalMarking. | 797 // Maintain marking consistency for IncrementalMarking. |
| 960 void AdjustLiveBytes(Address address, int by, InvocationMode mode); | 798 void AdjustLiveBytes(Address address, int by, InvocationMode mode); |
| 961 | 799 |
| 962 MUST_USE_RESULT MaybeObject* AllocateCode(int object_size, bool immovable); | |
| 963 | |
| 964 MUST_USE_RESULT MaybeObject* CopyCode(Code* code); | |
| 965 | |
| 966 // Copy the code and scope info part of the code object, but insert | |
| 967 // the provided data as the relocation information. | |
| 968 MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info); | |
| 969 | |
| 970 // Finds the internalized copy for string in the string table. | |
| 971 // If not found, a new string is added to the table and returned. | |
| 972 // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation | |
| 973 // failed. | |
| 974 // Please note this function does not perform a garbage collection. | |
| 975 MUST_USE_RESULT MaybeObject* InternalizeStringWithKey(HashTableKey* key); | |
| 976 | |
| 977 bool InternalizeStringIfExists(String* str, String** result); | 800 bool InternalizeStringIfExists(String* str, String** result); |
| 978 bool InternalizeTwoCharsStringIfExists(String* str, String** result); | 801 bool InternalizeTwoCharsStringIfExists(String* str, String** result); |
| 979 | 802 |
| 980 // Converts the given boolean condition to JavaScript boolean value. | 803 // Converts the given boolean condition to JavaScript boolean value. |
| 981 inline Object* ToBoolean(bool condition); | 804 inline Object* ToBoolean(bool condition); |
| 982 | 805 |
| 983 // Performs garbage collection operation. | 806 // Performs garbage collection operation. |
| 984 // Returns whether there is a chance that another major GC could | 807 // Returns whether there is a chance that another major GC could |
| 985 // collect more garbage. | 808 // collect more garbage. |
| 986 inline bool CollectGarbage( | 809 inline bool CollectGarbage( |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 | 1489 |
| 1667 void InitializeWeakObjectToCodeTable() { | 1490 void InitializeWeakObjectToCodeTable() { |
| 1668 set_weak_object_to_code_table(undefined_value()); | 1491 set_weak_object_to_code_table(undefined_value()); |
| 1669 } | 1492 } |
| 1670 | 1493 |
| 1671 void EnsureWeakObjectToCodeTable(); | 1494 void EnsureWeakObjectToCodeTable(); |
| 1672 | 1495 |
| 1673 static void FatalProcessOutOfMemory(const char* location, | 1496 static void FatalProcessOutOfMemory(const char* location, |
| 1674 bool take_snapshot = false); | 1497 bool take_snapshot = false); |
| 1675 | 1498 |
| 1499 protected: |
| 1500 // Methods made available to tests. |
| 1501 |
| 1502 // Allocates a JS Map in the heap. |
| 1503 MUST_USE_RESULT MaybeObject* AllocateMap( |
| 1504 InstanceType instance_type, |
| 1505 int instance_size, |
| 1506 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); |
| 1507 |
| 1508 // Allocates and initializes a new JavaScript object based on a |
| 1509 // constructor. |
| 1510 // If allocation_site is non-null, then a memento is emitted after the object |
| 1511 // that points to the site. |
| 1512 MUST_USE_RESULT MaybeObject* AllocateJSObject( |
| 1513 JSFunction* constructor, |
| 1514 PretenureFlag pretenure = NOT_TENURED, |
| 1515 AllocationSite* allocation_site = NULL); |
| 1516 |
| 1517 // Allocates and initializes a new JavaScript object based on a map. |
| 1518 // Passing an allocation site means that a memento will be created that |
| 1519 // points to the site. |
| 1520 MUST_USE_RESULT MaybeObject* AllocateJSObjectFromMap( |
| 1521 Map* map, |
| 1522 PretenureFlag pretenure = NOT_TENURED, |
| 1523 bool alloc_props = true, |
| 1524 AllocationSite* allocation_site = NULL); |
| 1525 |
| 1526 // Allocated a HeapNumber from value. |
| 1527 MUST_USE_RESULT MaybeObject* AllocateHeapNumber( |
| 1528 double value, PretenureFlag pretenure = NOT_TENURED); |
| 1529 |
| 1530 // Allocate a byte array of the specified length |
| 1531 MUST_USE_RESULT MaybeObject* AllocateByteArray( |
| 1532 int length, |
| 1533 PretenureFlag pretenure = NOT_TENURED); |
| 1534 |
| 1535 // Allocates an arguments object - optionally with an elements array. |
| 1536 MUST_USE_RESULT MaybeObject* AllocateArgumentsObject( |
| 1537 Object* callee, int length); |
| 1538 |
| 1539 // Copy the code and scope info part of the code object, but insert |
| 1540 // the provided data as the relocation information. |
| 1541 MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info); |
| 1542 |
| 1543 MUST_USE_RESULT MaybeObject* CopyCode(Code* code); |
| 1544 |
| 1676 private: | 1545 private: |
| 1677 Heap(); | 1546 Heap(); |
| 1678 | 1547 |
| 1679 // This can be calculated directly from a pointer to the heap; however, it is | 1548 // This can be calculated directly from a pointer to the heap; however, it is |
| 1680 // more expedient to get at the isolate directly from within Heap methods. | 1549 // more expedient to get at the isolate directly from within Heap methods. |
| 1681 Isolate* isolate_; | 1550 Isolate* isolate_; |
| 1682 | 1551 |
| 1683 Object* roots_[kRootListLength]; | 1552 Object* roots_[kRootListLength]; |
| 1684 | 1553 |
| 1685 intptr_t code_range_size_; | 1554 intptr_t code_range_size_; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 } | 1791 } |
| 1923 | 1792 |
| 1924 // Allocate an uninitialized object. The memory is non-executable if the | 1793 // Allocate an uninitialized object. The memory is non-executable if the |
| 1925 // hardware and OS allow. This is the single choke-point for allocations | 1794 // hardware and OS allow. This is the single choke-point for allocations |
| 1926 // performed by the runtime and should not be bypassed (to extend this to | 1795 // performed by the runtime and should not be bypassed (to extend this to |
| 1927 // inlined allocations, use the Heap::DisableInlineAllocation() support). | 1796 // inlined allocations, use the Heap::DisableInlineAllocation() support). |
| 1928 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes, | 1797 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes, |
| 1929 AllocationSpace space, | 1798 AllocationSpace space, |
| 1930 AllocationSpace retry_space); | 1799 AllocationSpace retry_space); |
| 1931 | 1800 |
| 1801 // Allocates a heap object based on the map. |
| 1802 MUST_USE_RESULT MaybeObject* Allocate(Map* map, AllocationSpace space, |
| 1803 AllocationSite* allocation_site = NULL); |
| 1804 |
| 1805 // Allocates a partial map for bootstrapping. |
| 1806 MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type, |
| 1807 int instance_size); |
| 1808 |
| 1809 // Initializes a JSObject based on its map. |
| 1810 void InitializeJSObjectFromMap(JSObject* obj, |
| 1811 FixedArray* properties, |
| 1812 Map* map); |
| 1813 void InitializeAllocationMemento(AllocationMemento* memento, |
| 1814 AllocationSite* allocation_site); |
| 1815 |
| 1816 // Allocate a block of memory in the given space (filled with a filler). |
| 1817 // Used as a fall-back for generated code when the space is full. |
| 1818 MUST_USE_RESULT MaybeObject* AllocateFillerObject(int size, |
| 1819 bool double_align, |
| 1820 AllocationSpace space); |
| 1821 |
| 1932 // Allocate an uninitialized fixed array. | 1822 // Allocate an uninitialized fixed array. |
| 1933 MUST_USE_RESULT MaybeObject* AllocateRawFixedArray( | 1823 MUST_USE_RESULT MaybeObject* AllocateRawFixedArray( |
| 1934 int length, PretenureFlag pretenure); | 1824 int length, PretenureFlag pretenure); |
| 1935 | 1825 |
| 1936 // Allocate an uninitialized fixed double array. | 1826 // Allocate an uninitialized fixed double array. |
| 1937 MUST_USE_RESULT MaybeObject* AllocateRawFixedDoubleArray( | 1827 MUST_USE_RESULT MaybeObject* AllocateRawFixedDoubleArray( |
| 1938 int length, PretenureFlag pretenure); | 1828 int length, PretenureFlag pretenure); |
| 1939 | 1829 |
| 1940 // Allocate an initialized fixed array with the given filler value. | 1830 // Allocate an initialized fixed array with the given filler value. |
| 1941 MUST_USE_RESULT MaybeObject* AllocateFixedArrayWithFiller( | 1831 MUST_USE_RESULT MaybeObject* AllocateFixedArrayWithFiller( |
| 1942 int length, PretenureFlag pretenure, Object* filler); | 1832 int length, PretenureFlag pretenure, Object* filler); |
| 1943 | 1833 |
| 1944 // Allocate and partially initializes a String. There are two String | 1834 // Allocate and partially initializes a String. There are two String |
| 1945 // encodings: ASCII and two byte. These functions allocate a string of the | 1835 // encodings: ASCII and two byte. These functions allocate a string of the |
| 1946 // given length and set its map and length fields. The characters of the | 1836 // given length and set its map and length fields. The characters of the |
| 1947 // string are uninitialized. | 1837 // string are uninitialized. |
| 1948 MUST_USE_RESULT MaybeObject* AllocateRawOneByteString( | 1838 MUST_USE_RESULT MaybeObject* AllocateRawOneByteString( |
| 1949 int length, PretenureFlag pretenure); | 1839 int length, PretenureFlag pretenure); |
| 1950 MUST_USE_RESULT MaybeObject* AllocateRawTwoByteString( | 1840 MUST_USE_RESULT MaybeObject* AllocateRawTwoByteString( |
| 1951 int length, PretenureFlag pretenure); | 1841 int length, PretenureFlag pretenure); |
| 1952 | 1842 |
| 1953 // Initializes a JSObject based on its map. | 1843 // Allocates and fully initializes a String. There are two String |
| 1954 void InitializeJSObjectFromMap(JSObject* obj, | 1844 // encodings: ASCII and two byte. One should choose between the three string |
| 1955 FixedArray* properties, | 1845 // allocation functions based on the encoding of the string buffer used to |
| 1956 Map* map); | 1846 // initialized the string. |
| 1957 void InitializeAllocationMemento(AllocationMemento* memento, | 1847 // - ...FromAscii initializes the string from a buffer that is ASCII |
| 1958 AllocationSite* allocation_site); | 1848 // encoded (it does not check that the buffer is ASCII encoded) and the |
| 1849 // result will be ASCII encoded. |
| 1850 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
| 1851 // encoded. If the characters are all single-byte characters, the |
| 1852 // result will be ASCII encoded, otherwise it will converted to two |
| 1853 // byte. |
| 1854 // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 1855 // encoded. If the characters are all single-byte characters, the |
| 1856 // result will be converted to ASCII, otherwise it will be left as |
| 1857 // two-byte. |
| 1858 MUST_USE_RESULT MaybeObject* AllocateStringFromUtf8Slow( |
| 1859 Vector<const char> str, |
| 1860 int non_ascii_start, |
| 1861 PretenureFlag pretenure = NOT_TENURED); |
| 1862 MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte( |
| 1863 Vector<const uc16> str, |
| 1864 PretenureFlag pretenure = NOT_TENURED); |
| 1959 | 1865 |
| 1960 bool CreateInitialMaps(); | 1866 bool CreateInitialMaps(); |
| 1961 void CreateInitialObjects(); | 1867 void CreateInitialObjects(); |
| 1962 | 1868 |
| 1869 template<bool is_one_byte, typename T> |
| 1870 MUST_USE_RESULT MaybeObject* AllocateInternalizedStringImpl( |
| 1871 T t, int chars, uint32_t hash_field); |
| 1872 |
| 1873 // Computes a single character string where the character has code. |
| 1874 // A cache is used for ASCII codes. |
| 1875 MUST_USE_RESULT MaybeObject* LookupSingleCharacterStringFromCode( |
| 1876 uint16_t code); |
| 1877 |
| 1878 // Allocate a symbol in old space. |
| 1879 MUST_USE_RESULT MaybeObject* AllocateSymbol(); |
| 1880 |
| 1881 // Make a copy of src, set the map, and return the copy. |
| 1882 MUST_USE_RESULT MaybeObject* CopyConstantPoolArrayWithMap( |
| 1883 ConstantPoolArray* src, Map* map); |
| 1884 |
| 1885 MUST_USE_RESULT MaybeObject* AllocateConstantPoolArray( |
| 1886 int number_of_int64_entries, |
| 1887 int number_of_code_ptr_entries, |
| 1888 int number_of_heap_ptr_entries, |
| 1889 int number_of_int32_entries); |
| 1890 |
| 1891 // Allocates an external array of the specified length and type. |
| 1892 MUST_USE_RESULT MaybeObject* AllocateExternalArray( |
| 1893 int length, |
| 1894 ExternalArrayType array_type, |
| 1895 void* external_pointer, |
| 1896 PretenureFlag pretenure); |
| 1897 |
| 1898 // Allocates a fixed typed array of the specified length and type. |
| 1899 MUST_USE_RESULT MaybeObject* AllocateFixedTypedArray( |
| 1900 int length, |
| 1901 ExternalArrayType array_type, |
| 1902 PretenureFlag pretenure); |
| 1903 |
| 1904 // Make a copy of src and return it. |
| 1905 MUST_USE_RESULT MaybeObject* CopyAndTenureFixedCOWArray(FixedArray* src); |
| 1906 |
| 1907 // Make a copy of src, set the map, and return the copy. |
| 1908 MUST_USE_RESULT MaybeObject* CopyFixedDoubleArrayWithMap( |
| 1909 FixedDoubleArray* src, Map* map); |
| 1910 |
| 1911 // Allocates a fixed double array with uninitialized values. Returns |
| 1912 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedDoubleArray( |
| 1913 int length, |
| 1914 PretenureFlag pretenure = NOT_TENURED); |
| 1915 |
| 1963 // These five Create*EntryStub functions are here and forced to not be inlined | 1916 // These five Create*EntryStub functions are here and forced to not be inlined |
| 1964 // because of a gcc-4.4 bug that assigns wrong vtable entries. | 1917 // because of a gcc-4.4 bug that assigns wrong vtable entries. |
| 1965 NO_INLINE(void CreateJSEntryStub()); | 1918 NO_INLINE(void CreateJSEntryStub()); |
| 1966 NO_INLINE(void CreateJSConstructEntryStub()); | 1919 NO_INLINE(void CreateJSConstructEntryStub()); |
| 1967 | 1920 |
| 1968 void CreateFixedStubs(); | 1921 void CreateFixedStubs(); |
| 1969 | 1922 |
| 1970 // Allocate empty fixed array. | 1923 // Allocate empty fixed array. |
| 1971 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray(); | 1924 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray(); |
| 1972 | 1925 |
| 1973 // Allocate empty external array of given type. | 1926 // Allocate empty external array of given type. |
| 1974 MUST_USE_RESULT MaybeObject* AllocateEmptyExternalArray( | 1927 MUST_USE_RESULT MaybeObject* AllocateEmptyExternalArray( |
| 1975 ExternalArrayType array_type); | 1928 ExternalArrayType array_type); |
| 1976 | 1929 |
| 1977 // Allocate empty fixed typed array of given type. | 1930 // Allocate empty fixed typed array of given type. |
| 1978 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedTypedArray( | 1931 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedTypedArray( |
| 1979 ExternalArrayType array_type); | 1932 ExternalArrayType array_type); |
| 1980 | 1933 |
| 1981 // Allocate empty constant pool array. | 1934 // Allocate empty constant pool array. |
| 1982 MUST_USE_RESULT MaybeObject* AllocateEmptyConstantPoolArray(); | 1935 MUST_USE_RESULT MaybeObject* AllocateEmptyConstantPoolArray(); |
| 1983 | 1936 |
| 1984 // Allocate a tenured simple cell. | 1937 // Allocate a tenured simple cell. |
| 1985 MUST_USE_RESULT MaybeObject* AllocateCell(Object* value); | 1938 MUST_USE_RESULT MaybeObject* AllocateCell(Object* value); |
| 1986 | 1939 |
| 1987 // Allocate a tenured JS global property cell initialized with the hole. | 1940 // Allocate a tenured JS global property cell initialized with the hole. |
| 1988 MUST_USE_RESULT MaybeObject* AllocatePropertyCell(); | 1941 MUST_USE_RESULT MaybeObject* AllocatePropertyCell(); |
| 1989 | 1942 |
| 1943 // Allocates a new utility object in the old generation. |
| 1944 MUST_USE_RESULT MaybeObject* AllocateStruct(InstanceType type); |
| 1945 |
| 1946 // Allocates a new foreign object. |
| 1947 MUST_USE_RESULT MaybeObject* AllocateForeign( |
| 1948 Address address, PretenureFlag pretenure = NOT_TENURED); |
| 1949 |
| 1950 MUST_USE_RESULT MaybeObject* AllocateCode(int object_size, bool immovable); |
| 1951 |
| 1952 MUST_USE_RESULT MaybeObject* InternalizeStringWithKey(HashTableKey* key); |
| 1953 |
| 1954 MUST_USE_RESULT MaybeObject* InternalizeString(String* str); |
| 1955 |
| 1990 // Performs a minor collection in new generation. | 1956 // Performs a minor collection in new generation. |
| 1991 void Scavenge(); | 1957 void Scavenge(); |
| 1992 | 1958 |
| 1993 // Commits from space if it is uncommitted. | 1959 // Commits from space if it is uncommitted. |
| 1994 void EnsureFromSpaceIsCommitted(); | 1960 void EnsureFromSpaceIsCommitted(); |
| 1995 | 1961 |
| 1996 // Uncommit unused semi space. | 1962 // Uncommit unused semi space. |
| 1997 bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); } | 1963 bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); } |
| 1998 | 1964 |
| 1999 // Fill in bogus values in from space | 1965 // Fill in bogus values in from space |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2858 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2824 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
| 2859 | 2825 |
| 2860 private: | 2826 private: |
| 2861 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2827 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2862 }; | 2828 }; |
| 2863 #endif // DEBUG | 2829 #endif // DEBUG |
| 2864 | 2830 |
| 2865 } } // namespace v8::internal | 2831 } } // namespace v8::internal |
| 2866 | 2832 |
| 2867 #endif // V8_HEAP_H_ | 2833 #endif // V8_HEAP_H_ |
| OLD | NEW |