Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: src/heap.h

Issue 247263003: Hide heap methods where possible. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 return old_pointer_space_->allocation_limit_address(); 698 return old_pointer_space_->allocation_limit_address();
699 } 699 }
700 700
701 Address* OldDataSpaceAllocationTopAddress() { 701 Address* OldDataSpaceAllocationTopAddress() {
702 return old_data_space_->allocation_top_address(); 702 return old_data_space_->allocation_top_address();
703 } 703 }
704 Address* OldDataSpaceAllocationLimitAddress() { 704 Address* OldDataSpaceAllocationLimitAddress() {
705 return old_data_space_->allocation_limit_address(); 705 return old_data_space_->allocation_limit_address();
706 } 706 }
707 707
708 // Allocates and initializes a new JavaScript object based on a
709 // constructor.
710 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
711 // failed.
712 // If allocation_site is non-null, then a memento is emitted after the object
713 // that points to the site.
714 // Please note this does not perform a garbage collection.
715 MUST_USE_RESULT MaybeObject* AllocateJSObject(
716 JSFunction* constructor,
717 PretenureFlag pretenure = NOT_TENURED,
718 AllocationSite* allocation_site = NULL);
719
720 // Returns a deep copy of the JavaScript object. 708 // Returns a deep copy of the JavaScript object.
721 // Properties and elements are copied too. 709 // Properties and elements are copied too.
722 // Returns failure if allocation failed. 710 // Returns failure if allocation failed.
723 // Optionally takes an AllocationSite to be appended in an AllocationMemento. 711 // Optionally takes an AllocationSite to be appended in an AllocationMemento.
724 MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source, 712 MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source,
725 AllocationSite* site = NULL); 713 AllocationSite* site = NULL);
726 714
727 // Allocates and initializes a new JavaScript object based on a map.
728 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
729 // failed.
730 // Passing an allocation site means that a memento will be created that
731 // points to the site.
732 // Please note this does not perform a garbage collection.
733 MUST_USE_RESULT MaybeObject* AllocateJSObjectFromMap(
734 Map* map,
735 PretenureFlag pretenure = NOT_TENURED,
736 bool alloc_props = true,
737 AllocationSite* allocation_site = NULL);
738
739 // Allocates a heap object based on the map.
740 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
741 // failed.
742 // Please note this function does not perform a garbage collection.
743 MUST_USE_RESULT MaybeObject* Allocate(Map* map, AllocationSpace space,
744 AllocationSite* allocation_site = NULL);
745
746 // Allocates a JS Map in the heap.
747 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
748 // failed.
749 // Please note this function does not perform a garbage collection.
750 MUST_USE_RESULT MaybeObject* AllocateMap(
751 InstanceType instance_type,
752 int instance_size,
753 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
754
755 // Allocates a partial map for bootstrapping.
756 MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type,
757 int instance_size);
758
759 // Allocate a block of memory in the given space (filled with a filler).
760 // Used as a fall-back for generated code when the space is full.
761 MUST_USE_RESULT MaybeObject* AllocateFillerObject(int size,
762 bool double_align,
763 AllocationSpace space);
764
765 // Allocates an empty PolymorphicCodeCache.
766 MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache();
767
768 // Clear the Instanceof cache (used when a prototype changes). 715 // Clear the Instanceof cache (used when a prototype changes).
769 inline void ClearInstanceofCache(); 716 inline void ClearInstanceofCache();
770 717
771 // Iterates the whole code space to clear all ICs of the given kind. 718 // Iterates the whole code space to clear all ICs of the given kind.
772 void ClearAllICsByKind(Code::Kind kind); 719 void ClearAllICsByKind(Code::Kind kind);
773 720
774 // For use during bootup. 721 // For use during bootup.
775 void RepairFreeListsAfterBoot(); 722 void RepairFreeListsAfterBoot();
776 723
777 // Allocates and fully initializes a String. There are two String
778 // encodings: ASCII and two byte. One should choose between the three string
779 // allocation functions based on the encoding of the string buffer used to
780 // initialized the string.
781 // - ...FromAscii initializes the string from a buffer that is ASCII
782 // encoded (it does not check that the buffer is ASCII encoded) and the
783 // result will be ASCII encoded.
784 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
785 // encoded. If the characters are all single-byte characters, the
786 // result will be ASCII encoded, otherwise it will converted to two
787 // byte.
788 // - ...FromTwoByte initializes the string from a buffer that is two-byte
789 // encoded. If the characters are all single-byte characters, the
790 // result will be converted to ASCII, otherwise it will be left as
791 // two-byte.
792 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
793 // failed.
794 // Please note this does not perform a garbage collection.
795 MUST_USE_RESULT MaybeObject* AllocateStringFromUtf8Slow(
796 Vector<const char> str,
797 int non_ascii_start,
798 PretenureFlag pretenure = NOT_TENURED);
799 MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte(
800 Vector<const uc16> str,
801 PretenureFlag pretenure = NOT_TENURED);
802
803 // Allocates an internalized string in old space based on the character 724 // Allocates an internalized string in old space based on the character
804 // stream. Returns Failure::RetryAfterGC(requested_bytes, space) if the 725 // stream. Returns Failure::RetryAfterGC(requested_bytes, space) if the
805 // allocation failed. 726 // allocation failed.
806 // Please note this function does not perform a garbage collection. 727 // Please note this function does not perform a garbage collection.
807 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringFromUtf8( 728 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringFromUtf8(
808 Vector<const char> str, 729 Vector<const char> str,
809 int chars, 730 int chars,
810 uint32_t hash_field); 731 uint32_t hash_field);
811 732
812 MUST_USE_RESULT inline MaybeObject* AllocateOneByteInternalizedString( 733 MUST_USE_RESULT inline MaybeObject* AllocateOneByteInternalizedString(
813 Vector<const uint8_t> str, 734 Vector<const uint8_t> str,
814 uint32_t hash_field); 735 uint32_t hash_field);
815 736
816 MUST_USE_RESULT inline MaybeObject* AllocateTwoByteInternalizedString( 737 MUST_USE_RESULT inline MaybeObject* AllocateTwoByteInternalizedString(
817 Vector<const uc16> str, 738 Vector<const uc16> str,
818 uint32_t hash_field); 739 uint32_t hash_field);
819 740
820 template<typename T> 741 template<typename T>
821 static inline bool IsOneByte(T t, int chars); 742 static inline bool IsOneByte(T t, int chars);
822 743
823 template<typename T> 744 template<typename T>
824 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringImpl( 745 MUST_USE_RESULT inline MaybeObject* AllocateInternalizedStringImpl(
825 T t, int chars, uint32_t hash_field); 746 T t, int chars, uint32_t hash_field);
826 747
827 template<bool is_one_byte, typename T>
828 MUST_USE_RESULT MaybeObject* AllocateInternalizedStringImpl(
829 T t, int chars, uint32_t hash_field);
830
831 // Computes a single character string where the character has code.
832 // A cache is used for ASCII codes.
833 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
834 // failed. Please note this does not perform a garbage collection.
835 MUST_USE_RESULT MaybeObject* LookupSingleCharacterStringFromCode(
836 uint16_t code);
837
838 // Allocate a byte array of the specified length
839 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
840 // failed.
841 // Please note this does not perform a garbage collection.
842 MUST_USE_RESULT MaybeObject* AllocateByteArray(
843 int length,
844 PretenureFlag pretenure = NOT_TENURED);
845
846 // Allocates an external array of the specified length and type.
847 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
848 // failed.
849 // Please note this does not perform a garbage collection.
850 MUST_USE_RESULT MaybeObject* AllocateExternalArray(
851 int length,
852 ExternalArrayType array_type,
853 void* external_pointer,
854 PretenureFlag pretenure);
855
856 // Allocates a fixed typed array of the specified length and type.
857 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
858 // failed.
859 // Please note this does not perform a garbage collection.
860 MUST_USE_RESULT MaybeObject* AllocateFixedTypedArray(
861 int length,
862 ExternalArrayType array_type,
863 PretenureFlag pretenure);
864
865 // Allocate a symbol in old space.
866 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
867 // failed.
868 // Please note this does not perform a garbage collection.
869 MUST_USE_RESULT MaybeObject* AllocateSymbol();
870 MUST_USE_RESULT MaybeObject* AllocatePrivateSymbol();
871
872 // Allocates a fixed array initialized with undefined values 748 // Allocates a fixed array initialized with undefined values
873 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 749 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
874 // failed. 750 // failed.
875 // Please note this does not perform a garbage collection. 751 // Please note this does not perform a garbage collection.
876 MUST_USE_RESULT MaybeObject* AllocateFixedArray( 752 MUST_USE_RESULT MaybeObject* AllocateFixedArray(
877 int length, 753 int length,
878 PretenureFlag pretenure = NOT_TENURED); 754 PretenureFlag pretenure = NOT_TENURED);
879 755
880 // Allocates an uninitialized fixed array. It must be filled by the caller. 756 // Allocates an uninitialized fixed array. It must be filled by the caller.
881 // 757 //
882 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 758 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
883 // failed. 759 // failed.
884 // Please note this does not perform a garbage collection. 760 // Please note this does not perform a garbage collection.
885 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length); 761 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedArray(int length);
886 762
887 // Move len elements within a given array from src_index index to dst_index 763 // Move len elements within a given array from src_index index to dst_index
888 // index. 764 // index.
889 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); 765 void MoveElements(FixedArray* array, int dst_index, int src_index, int len);
890 766
891 // Make a copy of src and return it. Returns 767 // Make a copy of src and return it. Returns
892 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 768 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
893 MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src); 769 MUST_USE_RESULT inline MaybeObject* CopyFixedArray(FixedArray* src);
894 770
895 // Make a copy of src and return it. Returns
896 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
897 MUST_USE_RESULT MaybeObject* CopyAndTenureFixedCOWArray(FixedArray* src);
898
899 // Make a copy of src, set the map, and return the copy. Returns 771 // Make a copy of src, set the map, and return the copy. Returns
900 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 772 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
901 MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map); 773 MUST_USE_RESULT MaybeObject* CopyFixedArrayWithMap(FixedArray* src, Map* map);
902 774
903 // Make a copy of src and return it. Returns 775 // Make a copy of src and return it. Returns
904 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 776 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
905 MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray( 777 MUST_USE_RESULT inline MaybeObject* CopyFixedDoubleArray(
906 FixedDoubleArray* src); 778 FixedDoubleArray* src);
907 779
908 // Make a copy of src, set the map, and return the copy. Returns
909 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
910 MUST_USE_RESULT MaybeObject* CopyFixedDoubleArrayWithMap(
911 FixedDoubleArray* src, Map* map);
912
913 // Make a copy of src and return it. Returns 780 // Make a copy of src and return it. Returns
914 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed. 781 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
915 MUST_USE_RESULT inline MaybeObject* CopyConstantPoolArray( 782 MUST_USE_RESULT inline MaybeObject* CopyConstantPoolArray(
916 ConstantPoolArray* src); 783 ConstantPoolArray* src);
917 784
918 // Make a copy of src, set the map, and return the copy. Returns
919 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
920 MUST_USE_RESULT MaybeObject* CopyConstantPoolArrayWithMap(
921 ConstantPoolArray* src, Map* map);
922
923 MUST_USE_RESULT MaybeObject* AllocateConstantPoolArray(
924 int number_of_int64_entries,
925 int number_of_code_ptr_entries,
926 int number_of_heap_ptr_entries,
927 int number_of_int32_entries);
928
929 // Allocates a fixed double array with uninitialized values. Returns
930 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
931 // Please note this does not perform a garbage collection.
932 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedDoubleArray(
933 int length,
934 PretenureFlag pretenure = NOT_TENURED);
935
936 // AllocateHashTable is identical to AllocateFixedArray except 785 // AllocateHashTable is identical to AllocateFixedArray except
937 // that the resulting object has hash_table_map as map. 786 // that the resulting object has hash_table_map as map.
938 MUST_USE_RESULT MaybeObject* AllocateHashTable( 787 MUST_USE_RESULT MaybeObject* AllocateHashTable(
939 int length, PretenureFlag pretenure = NOT_TENURED); 788 int length, PretenureFlag pretenure = NOT_TENURED);
940 789
941 // Allocates a new utility object in the old generation.
942 MUST_USE_RESULT MaybeObject* AllocateStruct(InstanceType type);
943
944 // Sloppy mode arguments object size. 790 // Sloppy mode arguments object size.
945 static const int kSloppyArgumentsObjectSize = 791 static const int kSloppyArgumentsObjectSize =
946 JSObject::kHeaderSize + 2 * kPointerSize; 792 JSObject::kHeaderSize + 2 * kPointerSize;
947 // Strict mode arguments has no callee so it is smaller. 793 // Strict mode arguments has no callee so it is smaller.
948 static const int kStrictArgumentsObjectSize = 794 static const int kStrictArgumentsObjectSize =
949 JSObject::kHeaderSize + 1 * kPointerSize; 795 JSObject::kHeaderSize + 1 * kPointerSize;
950 // Indicies for direct access into argument objects. 796 // Indicies for direct access into argument objects.
951 static const int kArgumentsLengthIndex = 0; 797 static const int kArgumentsLengthIndex = 0;
952 // callee is only valid in sloppy mode. 798 // callee is only valid in sloppy mode.
953 static const int kArgumentsCalleeIndex = 1; 799 static const int kArgumentsCalleeIndex = 1;
954 800
955 // Allocates an arguments object - optionally with an elements array.
956 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
957 // failed.
958 // Please note this does not perform a garbage collection.
959 MUST_USE_RESULT MaybeObject* AllocateArgumentsObject(
960 Object* callee, int length);
961
962 // Allocated a HeapNumber from value.
963 MUST_USE_RESULT MaybeObject* AllocateHeapNumber(
964 double value, PretenureFlag pretenure = NOT_TENURED);
965
966 // Converts an int into either a Smi or a HeapNumber object. 801 // Converts an int into either a Smi or a HeapNumber object.
967 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation 802 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
968 // failed. 803 // failed.
969 // Please note this does not perform a garbage collection. 804 // Please note this does not perform a garbage collection.
970 MUST_USE_RESULT inline MaybeObject* NumberFromUint32( 805 MUST_USE_RESULT inline MaybeObject* NumberFromUint32(
971 uint32_t value, PretenureFlag pretenure = NOT_TENURED); 806 uint32_t value, PretenureFlag pretenure = NOT_TENURED);
972 807
973 // Allocates a new foreign object.
974 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
975 // failed.
976 // Please note this does not perform a garbage collection.
977 MUST_USE_RESULT MaybeObject* AllocateForeign(
978 Address address, PretenureFlag pretenure = NOT_TENURED);
979
980 // Finalizes an external string by deleting the associated external 808 // Finalizes an external string by deleting the associated external
981 // data and clearing the resource pointer. 809 // data and clearing the resource pointer.
982 inline void FinalizeExternalString(String* string); 810 inline void FinalizeExternalString(String* string);
983 811
984 // Initialize a filler object to keep the ability to iterate over the heap 812 // Initialize a filler object to keep the ability to iterate over the heap
985 // when shortening objects. 813 // when shortening objects.
986 void CreateFillerObjectAt(Address addr, int size); 814 void CreateFillerObjectAt(Address addr, int size);
987 815
988 bool CanMoveObjectStart(HeapObject* object); 816 bool CanMoveObjectStart(HeapObject* object);
989 817
990 enum InvocationMode { FROM_GC, FROM_MUTATOR }; 818 enum InvocationMode { FROM_GC, FROM_MUTATOR };
991 819
992 // Maintain marking consistency for IncrementalMarking. 820 // Maintain marking consistency for IncrementalMarking.
993 void AdjustLiveBytes(Address address, int by, InvocationMode mode); 821 void AdjustLiveBytes(Address address, int by, InvocationMode mode);
994 822
995 MUST_USE_RESULT MaybeObject* AllocateCode(int object_size, bool immovable);
996
997 MUST_USE_RESULT MaybeObject* CopyCode(Code* code);
998
999 // Copy the code and scope info part of the code object, but insert
1000 // the provided data as the relocation information.
1001 MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info);
1002
1003 // Finds the internalized copy for string in the string table.
1004 // If not found, a new string is added to the table and returned.
1005 // Returns Failure::RetryAfterGC(requested_bytes, space) if allocation
1006 // failed.
1007 // Please note this function does not perform a garbage collection.
1008 MUST_USE_RESULT MaybeObject* InternalizeUtf8String(const char* str) {
1009 return InternalizeUtf8String(CStrVector(str));
1010 }
1011 MUST_USE_RESULT MaybeObject* InternalizeUtf8String(Vector<const char> str);
1012
1013 MUST_USE_RESULT MaybeObject* InternalizeString(String* str);
1014 MUST_USE_RESULT MaybeObject* InternalizeStringWithKey(HashTableKey* key);
1015
1016 bool InternalizeStringIfExists(String* str, String** result); 823 bool InternalizeStringIfExists(String* str, String** result);
1017 bool InternalizeTwoCharsStringIfExists(String* str, String** result); 824 bool InternalizeTwoCharsStringIfExists(String* str, String** result);
1018 825
1019 // Compute the matching internalized string map for a string if possible. 826 // Compute the matching internalized string map for a string if possible.
1020 // NULL is returned if string is in new space or not flattened. 827 // NULL is returned if string is in new space or not flattened.
1021 Map* InternalizedStringMapForString(String* str); 828 Map* InternalizedStringMapForString(String* str);
1022 829
1023 // Converts the given boolean condition to JavaScript boolean value. 830 // Converts the given boolean condition to JavaScript boolean value.
1024 inline Object* ToBoolean(bool condition); 831 inline Object* ToBoolean(bool condition);
1025 832
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 1529
1723 void InitializeWeakObjectToCodeTable() { 1530 void InitializeWeakObjectToCodeTable() {
1724 set_weak_object_to_code_table(undefined_value()); 1531 set_weak_object_to_code_table(undefined_value());
1725 } 1532 }
1726 1533
1727 void EnsureWeakObjectToCodeTable(); 1534 void EnsureWeakObjectToCodeTable();
1728 1535
1729 static void FatalProcessOutOfMemory(const char* location, 1536 static void FatalProcessOutOfMemory(const char* location,
1730 bool take_snapshot = false); 1537 bool take_snapshot = false);
1731 1538
1539 protected:
1540 // Methods made available to tests.
1541
1542 // Allocates a JS Map in the heap.
1543 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1544 // failed.
1545 // Please note this function does not perform a garbage collection.
Michael Starzinger 2014/04/29 13:15:09 nit: I never was sure of the value of duplicating
Yang 2014/04/29 13:55:13 Done.
1546 MUST_USE_RESULT MaybeObject* AllocateMap(
1547 InstanceType instance_type,
1548 int instance_size,
1549 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
1550
1551 // Allocates and initializes a new JavaScript object based on a
1552 // constructor.
1553 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1554 // failed.
1555 // If allocation_site is non-null, then a memento is emitted after the object
1556 // that points to the site.
1557 // Please note this does not perform a garbage collection.
1558 MUST_USE_RESULT MaybeObject* AllocateJSObject(
1559 JSFunction* constructor,
1560 PretenureFlag pretenure = NOT_TENURED,
1561 AllocationSite* allocation_site = NULL);
1562
1563 // Allocates and initializes a new JavaScript object based on a map.
1564 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1565 // failed.
1566 // Passing an allocation site means that a memento will be created that
1567 // points to the site.
1568 // Please note this does not perform a garbage collection.
1569 MUST_USE_RESULT MaybeObject* AllocateJSObjectFromMap(
1570 Map* map,
1571 PretenureFlag pretenure = NOT_TENURED,
1572 bool alloc_props = true,
1573 AllocationSite* allocation_site = NULL);
1574
1575 // Allocated a HeapNumber from value.
1576 MUST_USE_RESULT MaybeObject* AllocateHeapNumber(
1577 double value, PretenureFlag pretenure = NOT_TENURED);
1578
1579 // Allocate a byte array of the specified length
1580 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1581 // failed.
1582 // Please note this does not perform a garbage collection.
1583 MUST_USE_RESULT MaybeObject* AllocateByteArray(
1584 int length,
1585 PretenureFlag pretenure = NOT_TENURED);
1586
1587 // Allocates an arguments object - optionally with an elements array.
1588 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1589 // failed.
1590 // Please note this does not perform a garbage collection.
1591 MUST_USE_RESULT MaybeObject* AllocateArgumentsObject(
1592 Object* callee, int length);
1593
1594 // Copy the code and scope info part of the code object, but insert
1595 // the provided data as the relocation information.
1596 MUST_USE_RESULT MaybeObject* CopyCode(Code* code, Vector<byte> reloc_info);
1597
1598 MUST_USE_RESULT MaybeObject* CopyCode(Code* code);
1599
1600 MUST_USE_RESULT MaybeObject* InternalizeString(String* str);
1601
1732 private: 1602 private:
1733 Heap(); 1603 Heap();
1734 1604
1735 // This can be calculated directly from a pointer to the heap; however, it is 1605 // This can be calculated directly from a pointer to the heap; however, it is
1736 // more expedient to get at the isolate directly from within Heap methods. 1606 // more expedient to get at the isolate directly from within Heap methods.
1737 Isolate* isolate_; 1607 Isolate* isolate_;
1738 1608
1739 Object* roots_[kRootListLength]; 1609 Object* roots_[kRootListLength];
1740 1610
1741 intptr_t code_range_size_; 1611 intptr_t code_range_size_;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 } 1848 }
1979 1849
1980 // Allocate an uninitialized object. The memory is non-executable if the 1850 // Allocate an uninitialized object. The memory is non-executable if the
1981 // hardware and OS allow. This is the single choke-point for allocations 1851 // hardware and OS allow. This is the single choke-point for allocations
1982 // performed by the runtime and should not be bypassed (to extend this to 1852 // performed by the runtime and should not be bypassed (to extend this to
1983 // inlined allocations, use the Heap::DisableInlineAllocation() support). 1853 // inlined allocations, use the Heap::DisableInlineAllocation() support).
1984 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes, 1854 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes,
1985 AllocationSpace space, 1855 AllocationSpace space,
1986 AllocationSpace retry_space); 1856 AllocationSpace retry_space);
1987 1857
1858 // Allocates a heap object based on the map.
1859 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1860 // failed.
1861 // Please note this function does not perform a garbage collection.
1862 MUST_USE_RESULT MaybeObject* Allocate(Map* map, AllocationSpace space,
1863 AllocationSite* allocation_site = NULL);
1864
1865 // Allocates a partial map for bootstrapping.
1866 MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type,
1867 int instance_size);
1868
1869 // Initializes a JSObject based on its map.
1870 void InitializeJSObjectFromMap(JSObject* obj,
1871 FixedArray* properties,
1872 Map* map);
1873 void InitializeAllocationMemento(AllocationMemento* memento,
1874 AllocationSite* allocation_site);
1875
1876 bool CreateInitialMaps();
1877 bool CreateInitialObjects();
1878
1879 // Allocate a block of memory in the given space (filled with a filler).
1880 // Used as a fall-back for generated code when the space is full.
1881 MUST_USE_RESULT MaybeObject* AllocateFillerObject(int size,
1882 bool double_align,
1883 AllocationSpace space);
1884
1988 // Allocate an uninitialized fixed array. 1885 // Allocate an uninitialized fixed array.
1989 MUST_USE_RESULT MaybeObject* AllocateRawFixedArray( 1886 MUST_USE_RESULT MaybeObject* AllocateRawFixedArray(
1990 int length, PretenureFlag pretenure); 1887 int length, PretenureFlag pretenure);
1991 1888
1992 // Allocate an uninitialized fixed double array. 1889 // Allocate an uninitialized fixed double array.
1993 MUST_USE_RESULT MaybeObject* AllocateRawFixedDoubleArray( 1890 MUST_USE_RESULT MaybeObject* AllocateRawFixedDoubleArray(
1994 int length, PretenureFlag pretenure); 1891 int length, PretenureFlag pretenure);
1995 1892
1996 // Allocate an initialized fixed array with the given filler value. 1893 // Allocate an initialized fixed array with the given filler value.
1997 MUST_USE_RESULT MaybeObject* AllocateFixedArrayWithFiller( 1894 MUST_USE_RESULT MaybeObject* AllocateFixedArrayWithFiller(
1998 int length, PretenureFlag pretenure, Object* filler); 1895 int length, PretenureFlag pretenure, Object* filler);
1999 1896
2000 // Allocate and partially initializes a String. There are two String 1897 // Allocate and partially initializes a String. There are two String
2001 // encodings: ASCII and two byte. These functions allocate a string of the 1898 // encodings: ASCII and two byte. These functions allocate a string of the
2002 // given length and set its map and length fields. The characters of the 1899 // given length and set its map and length fields. The characters of the
2003 // string are uninitialized. 1900 // string are uninitialized.
2004 MUST_USE_RESULT MaybeObject* AllocateRawOneByteString( 1901 MUST_USE_RESULT MaybeObject* AllocateRawOneByteString(
2005 int length, PretenureFlag pretenure); 1902 int length, PretenureFlag pretenure);
2006 MUST_USE_RESULT MaybeObject* AllocateRawTwoByteString( 1903 MUST_USE_RESULT MaybeObject* AllocateRawTwoByteString(
2007 int length, PretenureFlag pretenure); 1904 int length, PretenureFlag pretenure);
2008 1905
2009 // Initializes a JSObject based on its map. 1906 // Allocates and fully initializes a String. There are two String
2010 void InitializeJSObjectFromMap(JSObject* obj, 1907 // encodings: ASCII and two byte. One should choose between the three string
2011 FixedArray* properties, 1908 // allocation functions based on the encoding of the string buffer used to
2012 Map* map); 1909 // initialized the string.
2013 void InitializeAllocationMemento(AllocationMemento* memento, 1910 // - ...FromAscii initializes the string from a buffer that is ASCII
2014 AllocationSite* allocation_site); 1911 // encoded (it does not check that the buffer is ASCII encoded) and the
1912 // result will be ASCII encoded.
1913 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
1914 // encoded. If the characters are all single-byte characters, the
1915 // result will be ASCII encoded, otherwise it will converted to two
1916 // byte.
1917 // - ...FromTwoByte initializes the string from a buffer that is two-byte
1918 // encoded. If the characters are all single-byte characters, the
1919 // result will be converted to ASCII, otherwise it will be left as
1920 // two-byte.
1921 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1922 // failed.
1923 // Please note this does not perform a garbage collection.
1924 MUST_USE_RESULT MaybeObject* AllocateStringFromUtf8Slow(
1925 Vector<const char> str,
1926 int non_ascii_start,
1927 PretenureFlag pretenure = NOT_TENURED);
1928 MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte(
1929 Vector<const uc16> str,
1930 PretenureFlag pretenure = NOT_TENURED);
2015 1931
2016 bool CreateInitialMaps(); 1932 template<bool is_one_byte, typename T>
2017 bool CreateInitialObjects(); 1933 MUST_USE_RESULT MaybeObject* AllocateInternalizedStringImpl(
1934 T t, int chars, uint32_t hash_field);
1935
1936 // Computes a single character string where the character has code.
1937 // A cache is used for ASCII codes.
1938 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1939 // failed. Please note this does not perform a garbage collection.
1940 MUST_USE_RESULT MaybeObject* LookupSingleCharacterStringFromCode(
1941 uint16_t code);
1942
1943 // Allocate a symbol in old space.
1944 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1945 // failed.
1946 // Please note this does not perform a garbage collection.
1947 MUST_USE_RESULT MaybeObject* AllocateSymbol();
1948 MUST_USE_RESULT MaybeObject* AllocatePrivateSymbol();
1949
1950 // Allocates an empty PolymorphicCodeCache.
1951 MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache();
1952
1953 // Make a copy of src, set the map, and return the copy. Returns
1954 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
1955 MUST_USE_RESULT MaybeObject* CopyConstantPoolArrayWithMap(
1956 ConstantPoolArray* src, Map* map);
1957
1958 MUST_USE_RESULT MaybeObject* AllocateConstantPoolArray(
1959 int number_of_int64_entries,
1960 int number_of_code_ptr_entries,
1961 int number_of_heap_ptr_entries,
1962 int number_of_int32_entries);
1963
1964 // Allocates an external array of the specified length and type.
1965 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1966 // failed.
1967 // Please note this does not perform a garbage collection.
1968 MUST_USE_RESULT MaybeObject* AllocateExternalArray(
1969 int length,
1970 ExternalArrayType array_type,
1971 void* external_pointer,
1972 PretenureFlag pretenure);
1973
1974 // Allocates a fixed typed array of the specified length and type.
1975 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
1976 // failed.
1977 // Please note this does not perform a garbage collection.
1978 MUST_USE_RESULT MaybeObject* AllocateFixedTypedArray(
1979 int length,
1980 ExternalArrayType array_type,
1981 PretenureFlag pretenure);
1982
1983 // Make a copy of src and return it. Returns
1984 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
1985 MUST_USE_RESULT MaybeObject* CopyAndTenureFixedCOWArray(FixedArray* src);
1986
1987 // Make a copy of src, set the map, and return the copy. Returns
1988 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
1989 MUST_USE_RESULT MaybeObject* CopyFixedDoubleArrayWithMap(
1990 FixedDoubleArray* src, Map* map);
1991
1992 // Allocates a fixed double array with uninitialized values. Returns
1993 // Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
1994 // Please note this does not perform a garbage collection.
1995 MUST_USE_RESULT MaybeObject* AllocateUninitializedFixedDoubleArray(
1996 int length,
1997 PretenureFlag pretenure = NOT_TENURED);
2018 1998
2019 // These five Create*EntryStub functions are here and forced to not be inlined 1999 // These five Create*EntryStub functions are here and forced to not be inlined
2020 // because of a gcc-4.4 bug that assigns wrong vtable entries. 2000 // because of a gcc-4.4 bug that assigns wrong vtable entries.
2021 NO_INLINE(void CreateJSEntryStub()); 2001 NO_INLINE(void CreateJSEntryStub());
2022 NO_INLINE(void CreateJSConstructEntryStub()); 2002 NO_INLINE(void CreateJSConstructEntryStub());
2023 2003
2024 void CreateFixedStubs(); 2004 void CreateFixedStubs();
2025 2005
2026 // Allocate empty fixed array. 2006 // Allocate empty fixed array.
2027 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray(); 2007 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray();
2028 2008
2029 // Allocate empty external array of given type. 2009 // Allocate empty external array of given type.
2030 MUST_USE_RESULT MaybeObject* AllocateEmptyExternalArray( 2010 MUST_USE_RESULT MaybeObject* AllocateEmptyExternalArray(
2031 ExternalArrayType array_type); 2011 ExternalArrayType array_type);
2032 2012
2033 // Allocate empty fixed typed array of given type. 2013 // Allocate empty fixed typed array of given type.
2034 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedTypedArray( 2014 MUST_USE_RESULT MaybeObject* AllocateEmptyFixedTypedArray(
2035 ExternalArrayType array_type); 2015 ExternalArrayType array_type);
2036 2016
2037 // Allocate empty constant pool array. 2017 // Allocate empty constant pool array.
2038 MUST_USE_RESULT MaybeObject* AllocateEmptyConstantPoolArray(); 2018 MUST_USE_RESULT MaybeObject* AllocateEmptyConstantPoolArray();
2039 2019
2040 // Allocate a tenured simple cell. 2020 // Allocate a tenured simple cell.
2041 MUST_USE_RESULT MaybeObject* AllocateCell(Object* value); 2021 MUST_USE_RESULT MaybeObject* AllocateCell(Object* value);
2042 2022
2043 // Allocate a tenured JS global property cell initialized with the hole. 2023 // Allocate a tenured JS global property cell initialized with the hole.
2044 MUST_USE_RESULT MaybeObject* AllocatePropertyCell(); 2024 MUST_USE_RESULT MaybeObject* AllocatePropertyCell();
2045 2025
2026 // Allocates a new utility object in the old generation.
2027 MUST_USE_RESULT MaybeObject* AllocateStruct(InstanceType type);
2028
2029 // Allocates a new foreign object.
2030 // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
2031 // failed.
2032 // Please note this does not perform a garbage collection.
2033 MUST_USE_RESULT MaybeObject* AllocateForeign(
2034 Address address, PretenureFlag pretenure = NOT_TENURED);
2035
2036 MUST_USE_RESULT MaybeObject* AllocateCode(int object_size, bool immovable);
2037
2038 MUST_USE_RESULT MaybeObject* InternalizeStringWithKey(HashTableKey* key);
2039
2046 // Performs a minor collection in new generation. 2040 // Performs a minor collection in new generation.
2047 void Scavenge(); 2041 void Scavenge();
2048 2042
2049 // Commits from space if it is uncommitted. 2043 // Commits from space if it is uncommitted.
2050 void EnsureFromSpaceIsCommitted(); 2044 void EnsureFromSpaceIsCommitted();
2051 2045
2052 // Uncommit unused semi space. 2046 // Uncommit unused semi space.
2053 bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); } 2047 bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); }
2054 2048
2055 // Fill in bogus values in from space 2049 // Fill in bogus values in from space
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
2919 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. 2913 DisallowHeapAllocation no_allocation; // i.e. no gc allowed.
2920 2914
2921 private: 2915 private:
2922 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); 2916 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer);
2923 }; 2917 };
2924 #endif // DEBUG 2918 #endif // DEBUG
2925 2919
2926 } } // namespace v8::internal 2920 } } // namespace v8::internal
2927 2921
2928 #endif // V8_HEAP_H_ 2922 #endif // V8_HEAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698