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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 691 |
692 // Clear the Instanceof cache (used when a prototype changes). | 692 // Clear the Instanceof cache (used when a prototype changes). |
693 inline void ClearInstanceofCache(); | 693 inline void ClearInstanceofCache(); |
694 | 694 |
695 // 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. |
696 void ClearAllICsByKind(Code::Kind kind); | 696 void ClearAllICsByKind(Code::Kind kind); |
697 | 697 |
698 // For use during bootup. | 698 // For use during bootup. |
699 void RepairFreeListsAfterBoot(); | 699 void RepairFreeListsAfterBoot(); |
700 | 700 |
701 // Allocates an internalized string in old space based on the character | |
702 // stream. Returns Failure::RetryAfterGC(requested_bytes, space) if the | |
703 // allocation failed. | |
704 // Please note this function does not perform a garbage collection. | |
705 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringFromUtf8( | |
706 Vector<const char> str, | |
707 int chars, | |
708 uint32_t hash_field); | |
709 | |
710 MUST_USE_RESULT inline MaybeObject* AllocateOneByteInternalizedString( | |
711 Vector<const uint8_t> str, | |
712 uint32_t hash_field); | |
713 | |
714 MUST_USE_RESULT inline MaybeObject* AllocateTwoByteInternalizedString( | |
715 Vector<const uc16> str, | |
716 uint32_t hash_field); | |
717 | |
718 template<typename T> | 701 template<typename T> |
719 static inline bool IsOneByte(T t, int chars); | 702 static inline bool IsOneByte(T t, int chars); |
720 | 703 |
721 template<typename T> | |
722 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringImpl( | |
723 T t, int chars, uint32_t hash_field); | |
724 | |
725 // Allocates a fixed array initialized with undefined values | |
726 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
727 // failed. | |
728 // Please note this does not perform a garbage collection. | |
729 MUST_USE_RESULT MaybeObject* AllocateFixedArray( | |
730 int length, | |
731 PretenureFlag pretenure = NOT_TENURED); | |
732 | |
733 // Allocates an uninitialized fixed array. It must be filled by the caller. | |
734 // | |
735 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation | |
736 // failed. | |
737 // Please note this does not perform a garbage collection. | |
738 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length); | |
739 | |
740 // Move len elements within a given array from src_index index to dst_index | 704 // Move len elements within a given array from src_index index to dst_index |
741 // index. | 705 // index. |
742 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); | 706 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); |
743 | 707 |
744 // Make a copy of src and return it. Returns | |
745 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
746 MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src); | |
747 | |
748 // Make a copy of src, set the map, and return the copy. Returns | |
749 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
750 MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map); | |
751 | |
752 // Make a copy of src and return it. Returns | |
753 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
754 MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray( | |
755 FixedDoubleArray* src); | |
756 | |
757 // Make a copy of src and return it. Returns | |
758 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. | |
759 MUST_USE_RESULT inline MaybeObject* CopyConstantPoolArray( | |
760 ConstantPoolArray* src); | |
761 | |
762 // AllocateHashTable is identical to AllocateFixedArray except | |
763 // that the resulting object has hash_table_map as map. | |
764 MUST_USE_RESULT MaybeObject* AllocateHashTable( | |
765 int length, PretenureFlag pretenure = NOT_TENURED); | |
766 | |
767 // Sloppy mode arguments object size. | 708 // Sloppy mode arguments object size. |
768 static const int kSloppyArgumentsObjectSize = | 709 static const int kSloppyArgumentsObjectSize = |
769 JSObject::kHeaderSize + 2 * kPointerSize; | 710 JSObject::kHeaderSize + 2 * kPointerSize; |
770 // Strict mode arguments has no callee so it is smaller. | 711 // Strict mode arguments has no callee so it is smaller. |
771 static const int kStrictArgumentsObjectSize = | 712 static const int kStrictArgumentsObjectSize = |
772 JSObject::kHeaderSize + 1 * kPointerSize; | 713 JSObject::kHeaderSize + 1 * kPointerSize; |
773 // Indicies for direct access into argument objects. | 714 // Indicies for direct access into argument objects. |
774 static const int kArgumentsLengthIndex = 0; | 715 static const int kArgumentsLengthIndex = 0; |
775 // callee is only valid in sloppy mode. | 716 // callee is only valid in sloppy mode. |
776 static const int kArgumentsCalleeIndex = 1; | 717 static const int kArgumentsCalleeIndex = 1; |
(...skipping 14 matching lines...) Expand all Loading... |
791 void CreateFillerObjectAt(Address addr, int size); | 732 void CreateFillerObjectAt(Address addr, int size); |
792 | 733 |
793 bool CanMoveObjectStart(HeapObject* object); | 734 bool CanMoveObjectStart(HeapObject* object); |
794 | 735 |
795 enum InvocationMode { FROM_GC, FROM_MUTATOR }; | 736 enum InvocationMode { FROM_GC, FROM_MUTATOR }; |
796 | 737 |
797 // Maintain marking consistency for IncrementalMarking. | 738 // Maintain marking consistency for IncrementalMarking. |
798 void AdjustLiveBytes(Address address, int by, InvocationMode mode); | 739 void AdjustLiveBytes(Address address, int by, InvocationMode mode); |
799 | 740 |
800 bool InternalizeStringIfExists(String* str, String** result); | 741 bool InternalizeStringIfExists(String* str, String** result); |
801 bool InternalizeTwoCharsStringIfExists(String* str, String** result); | |
802 | 742 |
803 // Converts the given boolean condition to JavaScript boolean value. | 743 // Converts the given boolean condition to JavaScript boolean value. |
804 inline Object* ToBoolean(bool condition); | 744 inline Object* ToBoolean(bool condition); |
805 | 745 |
806 // Performs garbage collection operation. | 746 // Performs garbage collection operation. |
807 // Returns whether there is a chance that another major GC could | 747 // Returns whether there is a chance that another major GC could |
808 // collect more garbage. | 748 // collect more garbage. |
809 inline bool CollectGarbage( | 749 inline bool CollectGarbage( |
810 AllocationSpace space, | 750 AllocationSpace space, |
811 const char* gc_reason = NULL, | 751 const char* gc_reason = NULL, |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 // Allocates an arguments object - optionally with an elements array. | 1475 // Allocates an arguments object - optionally with an elements array. |
1536 MUST_USE_RESULT MaybeObject* AllocateArgumentsObject( | 1476 MUST_USE_RESULT MaybeObject* AllocateArgumentsObject( |
1537 Object* callee, int length); | 1477 Object* callee, int length); |
1538 | 1478 |
1539 // Copy the code and scope info part of the code object, but insert | 1479 // Copy the code and scope info part of the code object, but insert |
1540 // the provided data as the relocation information. | 1480 // the provided data as the relocation information. |
1541 MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info); | 1481 MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info); |
1542 | 1482 |
1543 MUST_USE_RESULT MaybeObject* CopyCode(Code* code); | 1483 MUST_USE_RESULT MaybeObject* CopyCode(Code* code); |
1544 | 1484 |
| 1485 // Allocates a fixed array initialized with undefined values |
| 1486 MUST_USE_RESULT MaybeObject* AllocateFixedArray( |
| 1487 int length, |
| 1488 PretenureFlag pretenure = NOT_TENURED); |
| 1489 |
1545 private: | 1490 private: |
1546 Heap(); | 1491 Heap(); |
1547 | 1492 |
1548 // This can be calculated directly from a pointer to the heap; however, it is | 1493 // This can be calculated directly from a pointer to the heap; however, it is |
1549 // more expedient to get at the isolate directly from within Heap methods. | 1494 // more expedient to get at the isolate directly from within Heap methods. |
1550 Isolate* isolate_; | 1495 Isolate* isolate_; |
1551 | 1496 |
1552 Object* roots_[kRootListLength]; | 1497 Object* roots_[kRootListLength]; |
1553 | 1498 |
1554 intptr_t code_range_size_; | 1499 intptr_t code_range_size_; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 Vector<const char> str, | 1804 Vector<const char> str, |
1860 int non_ascii_start, | 1805 int non_ascii_start, |
1861 PretenureFlag pretenure = NOT_TENURED); | 1806 PretenureFlag pretenure = NOT_TENURED); |
1862 MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte( | 1807 MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte( |
1863 Vector<const uc16> str, | 1808 Vector<const uc16> str, |
1864 PretenureFlag pretenure = NOT_TENURED); | 1809 PretenureFlag pretenure = NOT_TENURED); |
1865 | 1810 |
1866 bool CreateInitialMaps(); | 1811 bool CreateInitialMaps(); |
1867 void CreateInitialObjects(); | 1812 void CreateInitialObjects(); |
1868 | 1813 |
| 1814 // Allocates an internalized string in old space based on the character |
| 1815 // stream. |
| 1816 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringFromUtf8( |
| 1817 Vector<const char> str, |
| 1818 int chars, |
| 1819 uint32_t hash_field); |
| 1820 |
| 1821 MUST_USE_RESULT inline MaybeObject* AllocateOneByteInternalizedString( |
| 1822 Vector<const uint8_t> str, |
| 1823 uint32_t hash_field); |
| 1824 |
| 1825 MUST_USE_RESULT inline MaybeObject* AllocateTwoByteInternalizedString( |
| 1826 Vector<const uc16> str, |
| 1827 uint32_t hash_field); |
| 1828 |
1869 template<bool is_one_byte, typename T> | 1829 template<bool is_one_byte, typename T> |
1870 MUST_USE_RESULT MaybeObject* AllocateInternalizedStringImpl( | 1830 MUST_USE_RESULT MaybeObject* AllocateInternalizedStringImpl( |
1871 T t, int chars, uint32_t hash_field); | 1831 T t, int chars, uint32_t hash_field); |
1872 | 1832 |
| 1833 template<typename T> |
| 1834 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringImpl( |
| 1835 T t, int chars, uint32_t hash_field); |
| 1836 |
| 1837 // Allocates an uninitialized fixed array. It must be filled by the caller. |
| 1838 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length); |
| 1839 |
| 1840 // Make a copy of src and return it. Returns |
| 1841 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 1842 MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src); |
| 1843 |
| 1844 // Make a copy of src, set the map, and return the copy. Returns |
| 1845 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 1846 MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map); |
| 1847 |
| 1848 // Make a copy of src and return it. Returns |
| 1849 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 1850 MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray( |
| 1851 FixedDoubleArray* src); |
| 1852 |
| 1853 // Make a copy of src and return it. Returns |
| 1854 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. |
| 1855 MUST_USE_RESULT inline MaybeObject* CopyConstantPoolArray( |
| 1856 ConstantPoolArray* src); |
| 1857 |
| 1858 |
1873 // Computes a single character string where the character has code. | 1859 // Computes a single character string where the character has code. |
1874 // A cache is used for ASCII codes. | 1860 // A cache is used for ASCII codes. |
1875 MUST_USE_RESULT MaybeObject* LookupSingleCharacterStringFromCode( | 1861 MUST_USE_RESULT MaybeObject* LookupSingleCharacterStringFromCode( |
1876 uint16_t code); | 1862 uint16_t code); |
1877 | 1863 |
1878 // Allocate a symbol in old space. | 1864 // Allocate a symbol in old space. |
1879 MUST_USE_RESULT MaybeObject* AllocateSymbol(); | 1865 MUST_USE_RESULT MaybeObject* AllocateSymbol(); |
1880 | 1866 |
1881 // Make a copy of src, set the map, and return the copy. | 1867 // Make a copy of src, set the map, and return the copy. |
1882 MUST_USE_RESULT MaybeObject* CopyConstantPoolArrayWithMap( | 1868 MUST_USE_RESULT MaybeObject* CopyConstantPoolArrayWithMap( |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2824 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2810 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2825 | 2811 |
2826 private: | 2812 private: |
2827 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2813 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2828 }; | 2814 }; |
2829 #endif // DEBUG | 2815 #endif // DEBUG |
2830 | 2816 |
2831 } } // namespace v8::internal | 2817 } } // namespace v8::internal |
2832 | 2818 |
2833 #endif // V8_HEAP_H_ | 2819 #endif // V8_HEAP_H_ |
OLD | NEW |