| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 // TODO(gc) we are ignoring this flag | 906 // TODO(gc) we are ignoring this flag |
| 907 static const int kForceCompactionMask = 1; | 907 static const int kForceCompactionMask = 1; |
| 908 static const int kMakeHeapIterableMask = 2; | 908 static const int kMakeHeapIterableMask = 2; |
| 909 | 909 |
| 910 // Performs a full garbage collection. If (flags & kForceCompactionMask) is | 910 // Performs a full garbage collection. If (flags & kForceCompactionMask) is |
| 911 // non-zero then force compaction. If (flags & kMakeHeapIterableMask) is non- | 911 // non-zero then force compaction. If (flags & kMakeHeapIterableMask) is non- |
| 912 // zero, then the slower precise sweeper is used, which leaves the heap in a | 912 // zero, then the slower precise sweeper is used, which leaves the heap in a |
| 913 // state where we can iterate over the heap visiting all objects. | 913 // state where we can iterate over the heap visiting all objects. |
| 914 void CollectAllGarbage(int flags); | 914 void CollectAllGarbage(int flags); |
| 915 | 915 |
| 916 // Check whether the heap is currently iterable. |
| 917 bool IsHeapIterable(); |
| 918 |
| 916 // Ensure that we have swept all spaces in such a way that we can iterate | 919 // Ensure that we have swept all spaces in such a way that we can iterate |
| 917 // over all objects. May cause a GC. | 920 // over all objects. May cause a GC. |
| 918 void EnsureHeapIsIterable(); | 921 void EnsureHeapIsIterable(); |
| 919 | 922 |
| 920 // Last hope GC, should try to squeeze as much as possible. | 923 // Last hope GC, should try to squeeze as much as possible. |
| 921 void CollectAllAvailableGarbage(); | 924 void CollectAllAvailableGarbage(); |
| 922 | 925 |
| 923 // Notify the heap that a context has been disposed. | 926 // Notify the heap that a context has been disposed. |
| 924 int NotifyContextDisposed() { return ++contexts_disposed_; } | 927 int NotifyContextDisposed() { return ++contexts_disposed_; } |
| 925 | 928 |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 ObjectIterator* CreateIterator(); | 1925 ObjectIterator* CreateIterator(); |
| 1923 | 1926 |
| 1924 int current_space_; // from enum AllocationSpace. | 1927 int current_space_; // from enum AllocationSpace. |
| 1925 ObjectIterator* iterator_; // object iterator for the current space. | 1928 ObjectIterator* iterator_; // object iterator for the current space. |
| 1926 HeapObjectCallback size_func_; | 1929 HeapObjectCallback size_func_; |
| 1927 }; | 1930 }; |
| 1928 | 1931 |
| 1929 | 1932 |
| 1930 // A HeapIterator provides iteration over the whole heap. It | 1933 // A HeapIterator provides iteration over the whole heap. It |
| 1931 // aggregates the specific iterators for the different spaces as | 1934 // aggregates the specific iterators for the different spaces as |
| 1932 // these can only iterate over one space only. It can only be guaranteed | 1935 // these can only iterate over one space only. |
| 1933 // to iterate over live objects. | |
| 1934 // | 1936 // |
| 1935 // HeapIterator can skip free list nodes (that is, de-allocated heap | 1937 // HeapIterator can skip free list nodes (that is, de-allocated heap |
| 1936 // objects that still remain in the heap). As implementation of free | 1938 // objects that still remain in the heap). As implementation of free |
| 1937 // nodes filtering uses GC marks, it can't be used during MS/MC GC | 1939 // nodes filtering uses GC marks, it can't be used during MS/MC GC |
| 1938 // phases. Also, it is forbidden to interrupt iteration in this mode, | 1940 // phases. Also, it is forbidden to interrupt iteration in this mode, |
| 1939 // as this will leave heap objects marked (and thus, unusable). | 1941 // as this will leave heap objects marked (and thus, unusable). |
| 1940 class HeapObjectsFilter; | 1942 class HeapObjectsFilter; |
| 1941 | 1943 |
| 1942 class HeapIterator BASE_EMBEDDED { | 1944 class HeapIterator BASE_EMBEDDED { |
| 1943 public: | 1945 public: |
| 1946 enum HeapObjectsFiltering { |
| 1947 kNoFiltering, |
| 1948 kFilterFreeListNodes, |
| 1949 kFilterUnreachable |
| 1950 }; |
| 1951 |
| 1944 HeapIterator(); | 1952 HeapIterator(); |
| 1953 explicit HeapIterator(HeapObjectsFiltering filtering); |
| 1945 ~HeapIterator(); | 1954 ~HeapIterator(); |
| 1946 | 1955 |
| 1947 HeapObject* Next(); | 1956 HeapObject* next(); |
| 1948 void Reset(); | 1957 void reset(); |
| 1949 | 1958 |
| 1950 private: | 1959 private: |
| 1951 // Perform the initialization. | 1960 // Perform the initialization. |
| 1952 void Init(); | 1961 void Init(); |
| 1953 // Perform all necessary shutdown (destruction) work. | 1962 // Perform all necessary shutdown (destruction) work. |
| 1954 void Shutdown(); | 1963 void Shutdown(); |
| 1964 HeapObject* NextObject(); |
| 1955 | 1965 |
| 1966 HeapObjectsFiltering filtering_; |
| 1967 HeapObjectsFilter* filter_; |
| 1956 // Space iterator for iterating all the spaces. | 1968 // Space iterator for iterating all the spaces. |
| 1957 SpaceIterator* space_iterator_; | 1969 SpaceIterator* space_iterator_; |
| 1958 // Object iterator for the space currently being iterated. | 1970 // Object iterator for the space currently being iterated. |
| 1959 ObjectIterator* object_iterator_; | 1971 ObjectIterator* object_iterator_; |
| 1960 }; | 1972 }; |
| 1961 | 1973 |
| 1962 | 1974 |
| 1963 // Cache for mapping (map, property name) into field offset. | 1975 // Cache for mapping (map, property name) into field offset. |
| 1964 // Cleared at startup and prior to mark sweep collection. | 1976 // Cleared at startup and prior to mark sweep collection. |
| 1965 class KeyedLookupCache { | 1977 class KeyedLookupCache { |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2348 object->set_map_word(MapWord::FromRawValue(map_word | kNotMarkedBit)); | 2360 object->set_map_word(MapWord::FromRawValue(map_word | kNotMarkedBit)); |
| 2349 ASSERT(!IsMarked(object)); | 2361 ASSERT(!IsMarked(object)); |
| 2350 } | 2362 } |
| 2351 | 2363 |
| 2352 static void SetMark(HeapObject* object) { | 2364 static void SetMark(HeapObject* object) { |
| 2353 uintptr_t map_word = object->map_word().ToRawValue(); | 2365 uintptr_t map_word = object->map_word().ToRawValue(); |
| 2354 object->set_map_word(MapWord::FromRawValue(map_word & ~kNotMarkedBit)); | 2366 object->set_map_word(MapWord::FromRawValue(map_word & ~kNotMarkedBit)); |
| 2355 ASSERT(IsMarked(object)); | 2367 ASSERT(IsMarked(object)); |
| 2356 } | 2368 } |
| 2357 | 2369 |
| 2370 static Map* MapOfMarkedObject(HeapObject* object) { |
| 2371 uintptr_t map_word = object->map_word().ToRawValue(); |
| 2372 return MapWord::FromRawValue(map_word | kNotMarkedBit).ToMap(); |
| 2373 } |
| 2374 |
| 2358 static int SizeOfMarkedObject(HeapObject* object) { | 2375 static int SizeOfMarkedObject(HeapObject* object) { |
| 2359 uintptr_t map_word = object->map_word().ToRawValue(); | 2376 return object->SizeFromMap(MapOfMarkedObject(object)); |
| 2360 Map* map = MapWord::FromRawValue(map_word | kNotMarkedBit).ToMap(); | |
| 2361 return object->SizeFromMap(map); | |
| 2362 } | 2377 } |
| 2363 | 2378 |
| 2364 private: | 2379 private: |
| 2365 static const uintptr_t kNotMarkedBit = 0x1; | 2380 static const uintptr_t kNotMarkedBit = 0x1; |
| 2366 STATIC_ASSERT((kHeapObjectTag & kNotMarkedBit) != 0); | 2381 STATIC_ASSERT((kHeapObjectTag & kNotMarkedBit) != 0); |
| 2367 }; | 2382 }; |
| 2368 | 2383 |
| 2369 | 2384 |
| 2370 #if defined(DEBUG) || defined(LIVE_OBJECT_LIST) | 2385 #if defined(DEBUG) || defined(LIVE_OBJECT_LIST) |
| 2371 // Helper class for tracing paths to a search target Object from all roots. | 2386 // Helper class for tracing paths to a search target Object from all roots. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2423 | 2438 |
| 2424 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2439 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2425 }; | 2440 }; |
| 2426 #endif // DEBUG || LIVE_OBJECT_LIST | 2441 #endif // DEBUG || LIVE_OBJECT_LIST |
| 2427 | 2442 |
| 2428 } } // namespace v8::internal | 2443 } } // namespace v8::internal |
| 2429 | 2444 |
| 2430 #undef HEAP | 2445 #undef HEAP |
| 2431 | 2446 |
| 2432 #endif // V8_HEAP_H_ | 2447 #endif // V8_HEAP_H_ |
| OLD | NEW |