OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 // collection. Only valid during a scavenge collection (specifically, | 923 // collection. Only valid during a scavenge collection (specifically, |
924 // when all map words are heap object pointers, ie. not during a full GC). | 924 // when all map words are heap object pointers, ie. not during a full GC). |
925 inline bool IsForwardingAddress(); | 925 inline bool IsForwardingAddress(); |
926 | 926 |
927 // Create a map word from a forwarding address. | 927 // Create a map word from a forwarding address. |
928 static inline MapWord FromForwardingAddress(HeapObject* object); | 928 static inline MapWord FromForwardingAddress(HeapObject* object); |
929 | 929 |
930 // View this map word as a forwarding address. | 930 // View this map word as a forwarding address. |
931 inline HeapObject* ToForwardingAddress(); | 931 inline HeapObject* ToForwardingAddress(); |
932 | 932 |
933 // Marking phase of full collection: the map word of live objects is | 933 static inline MapWord FromRawValue(uintptr_t value) { |
934 // marked, and may be marked as overflowed (eg, the object is live, its | 934 return MapWord(value); |
935 // children have not been visited, and it does not fit in the marking | 935 } |
936 // stack). | |
937 | 936 |
938 // True if this map word's mark bit is set. | 937 inline uintptr_t ToRawValue() { |
939 inline bool IsMarked(); | 938 return value_; |
940 | 939 } |
941 // Return this map word but with its mark bit set. | |
942 inline void SetMark(); | |
943 | |
944 // Return this map word but with its mark bit cleared. | |
945 inline void ClearMark(); | |
946 | |
947 // True if this map word's overflow bit is set. | |
948 inline bool IsOverflowed(); | |
949 | |
950 // Return this map word but with its overflow bit set. | |
951 inline void SetOverflow(); | |
952 | |
953 // Return this map word but with its overflow bit cleared. | |
954 inline void ClearOverflow(); | |
955 | |
956 // Bits used by the marking phase of the garbage collector. | |
957 // | |
958 // The first word of a heap object is normally a map pointer. The last two | |
959 // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to | |
960 // mark an object as live and/or overflowed: | |
961 // last bit = 0, marked as alive | |
962 // second bit = 1, overflowed | |
963 // An object is only marked as overflowed when it is marked as live while | |
964 // the marking stack is overflowed. | |
965 static const int kMarkingBit = 0; // marking bit | |
966 static const int kMarkingMask = (1 << kMarkingBit); // marking mask | |
967 static const int kOverflowBit = 1; // overflow bit | |
968 static const int kOverflowMask = (1 << kOverflowBit); // overflow mask | |
969 | 940 |
970 private: | 941 private: |
971 // HeapObject calls the private constructor and directly reads the value. | 942 // HeapObject calls the private constructor and directly reads the value. |
972 friend class HeapObject; | 943 friend class HeapObject; |
973 | 944 |
974 explicit MapWord(uintptr_t value) : value_(value) {} | 945 explicit MapWord(uintptr_t value) : value_(value) {} |
975 | 946 |
976 uintptr_t value_; | 947 uintptr_t value_; |
977 }; | 948 }; |
978 | 949 |
(...skipping 28 matching lines...) Expand all Loading... |
1007 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); | 978 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
1008 | 979 |
1009 // Returns the heap object's size in bytes | 980 // Returns the heap object's size in bytes |
1010 inline int Size(); | 981 inline int Size(); |
1011 | 982 |
1012 // Given a heap object's map pointer, returns the heap size in bytes | 983 // Given a heap object's map pointer, returns the heap size in bytes |
1013 // Useful when the map pointer field is used for other purposes. | 984 // Useful when the map pointer field is used for other purposes. |
1014 // GC internal. | 985 // GC internal. |
1015 inline int SizeFromMap(Map* map); | 986 inline int SizeFromMap(Map* map); |
1016 | 987 |
1017 // Support for the marking heap objects during the marking phase of GC. | |
1018 // True if the object is marked live. | |
1019 inline bool IsMarked(); | |
1020 | |
1021 // Mutate this object's map pointer to indicate that the object is live. | |
1022 inline void SetMark(); | |
1023 | |
1024 // Mutate this object's map pointer to remove the indication that the | |
1025 // object is live (ie, partially restore the map pointer). | |
1026 inline void ClearMark(); | |
1027 | |
1028 // True if this object is marked as overflowed. Overflowed objects have | 988 // True if this object is marked as overflowed. Overflowed objects have |
1029 // been reached and marked during marking of the heap, but their children | 989 // been reached and marked during marking of the heap, but their children |
1030 // have not necessarily been marked and they have not been pushed on the | 990 // have not necessarily been marked and they have not been pushed on the |
1031 // marking stack. | 991 // marking stack. |
1032 inline bool IsOverflowed(); | 992 inline bool IsOverflowed() { return false; } |
1033 | 993 |
1034 // Mutate this object's map pointer to indicate that the object is | 994 // Mutate this object's map pointer to indicate that the object is |
1035 // overflowed. | 995 // overflowed. |
1036 inline void SetOverflow(); | 996 inline void SetOverflow() {} |
1037 | 997 |
1038 // Mutate this object's map pointer to remove the indication that the | 998 // Mutate this object's map pointer to remove the indication that the |
1039 // object is overflowed (ie, partially restore the map pointer). | 999 // object is overflowed (ie, partially restore the map pointer). |
1040 inline void ClearOverflow(); | 1000 inline void ClearOverflow() {} |
1041 | 1001 |
1042 // Returns the field at offset in obj, as a read/write Object* reference. | 1002 // Returns the field at offset in obj, as a read/write Object* reference. |
1043 // Does no checking, and is safe to use during GC, while maps are invalid. | 1003 // Does no checking, and is safe to use during GC, while maps are invalid. |
1044 // Does not invoke write barrier, so should only be assigned to | 1004 // Does not invoke write barrier, so should only be assigned to |
1045 // during marking GC. | 1005 // during marking GC. |
1046 static inline Object** RawField(HeapObject* obj, int offset); | 1006 static inline Object** RawField(HeapObject* obj, int offset); |
1047 | 1007 |
1048 // Casting. | 1008 // Casting. |
1049 static inline HeapObject* cast(Object* obj); | 1009 static inline HeapObject* cast(Object* obj); |
1050 | 1010 |
(...skipping 5279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6330 } else { | 6290 } else { |
6331 value &= ~(1 << bit_position); | 6291 value &= ~(1 << bit_position); |
6332 } | 6292 } |
6333 return value; | 6293 return value; |
6334 } | 6294 } |
6335 }; | 6295 }; |
6336 | 6296 |
6337 } } // namespace v8::internal | 6297 } } // namespace v8::internal |
6338 | 6298 |
6339 #endif // V8_OBJECTS_H_ | 6299 #endif // V8_OBJECTS_H_ |
OLD | NEW |