OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1237 |
1238 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { | 1238 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
1239 InitializeVM(); | 1239 InitializeVM(); |
1240 HEAP->EnsureHeapIsIterable(); | 1240 HEAP->EnsureHeapIsIterable(); |
1241 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); | 1241 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); |
1242 HeapIterator iterator; | 1242 HeapIterator iterator; |
1243 intptr_t size_of_objects_2 = 0; | 1243 intptr_t size_of_objects_2 = 0; |
1244 for (HeapObject* obj = iterator.next(); | 1244 for (HeapObject* obj = iterator.next(); |
1245 obj != NULL; | 1245 obj != NULL; |
1246 obj = iterator.next()) { | 1246 obj = iterator.next()) { |
1247 size_of_objects_2 += obj->Size(); | 1247 if (!obj->IsFreeSpace()) { |
| 1248 size_of_objects_2 += obj->Size(); |
| 1249 } |
1248 } | 1250 } |
1249 // Delta must be within 5% of the larger result. | 1251 // Delta must be within 5% of the larger result. |
1250 // TODO(gc): Tighten this up by distinguishing between byte | 1252 // TODO(gc): Tighten this up by distinguishing between byte |
1251 // arrays that are real and those that merely mark free space | 1253 // arrays that are real and those that merely mark free space |
1252 // on the heap. | 1254 // on the heap. |
1253 if (size_of_objects_1 > size_of_objects_2) { | 1255 if (size_of_objects_1 > size_of_objects_2) { |
1254 intptr_t delta = size_of_objects_1 - size_of_objects_2; | 1256 intptr_t delta = size_of_objects_1 - size_of_objects_2; |
1255 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " | 1257 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " |
1256 "Iterator: %" V8_PTR_PREFIX "d, " | 1258 "Iterator: %" V8_PTR_PREFIX "d, " |
1257 "delta: %" V8_PTR_PREFIX "d\n", | 1259 "delta: %" V8_PTR_PREFIX "d\n", |
1258 size_of_objects_1, size_of_objects_2, delta); | 1260 size_of_objects_1, size_of_objects_2, delta); |
1259 CHECK_GT(size_of_objects_1 / 20, delta); | 1261 CHECK_GT(size_of_objects_1 / 20, delta); |
1260 } else { | 1262 } else { |
1261 intptr_t delta = size_of_objects_2 - size_of_objects_1; | 1263 intptr_t delta = size_of_objects_2 - size_of_objects_1; |
1262 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " | 1264 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " |
1263 "Iterator: %" V8_PTR_PREFIX "d, " | 1265 "Iterator: %" V8_PTR_PREFIX "d, " |
1264 "delta: %" V8_PTR_PREFIX "d\n", | 1266 "delta: %" V8_PTR_PREFIX "d\n", |
1265 size_of_objects_1, size_of_objects_2, delta); | 1267 size_of_objects_1, size_of_objects_2, delta); |
1266 CHECK_GT(size_of_objects_2 / 20, delta); | 1268 CHECK_GT(size_of_objects_2 / 20, delta); |
1267 } | 1269 } |
1268 } | 1270 } |
1269 | 1271 |
1270 | 1272 |
1271 static void FillUpNewSpace(NewSpace* new_space) { | 1273 static void FillUpNewSpace(NewSpace* new_space) { |
1272 // Fill up new space to the point that it is completely full. Make sure | 1274 // Fill up new space to the point that it is completely full. Make sure |
1273 // that the scavenger does not undo the filling. | 1275 // that the scavenger does not undo the filling. |
1274 v8::HandleScope scope; | 1276 v8::HandleScope scope; |
1275 AlwaysAllocateScope always_allocate; | 1277 AlwaysAllocateScope always_allocate; |
1276 LinearAllocationScope allocate_linearly; | |
1277 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); | 1278 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); |
1278 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; | 1279 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; |
1279 for (intptr_t i = 0; i < number_of_fillers; i++) { | 1280 for (intptr_t i = 0; i < number_of_fillers; i++) { |
1280 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(32, NOT_TENURED))); | 1281 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(32, NOT_TENURED))); |
1281 } | 1282 } |
1282 } | 1283 } |
1283 | 1284 |
1284 | 1285 |
1285 TEST(GrowAndShrinkNewSpace) { | 1286 TEST(GrowAndShrinkNewSpace) { |
1286 InitializeVM(); | 1287 InitializeVM(); |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1921 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); | 1922 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); |
1922 CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); | 1923 CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); |
1923 | 1924 |
1924 // Triggering subsequent GCs should cause at least half of the pages | 1925 // Triggering subsequent GCs should cause at least half of the pages |
1925 // to be released to the OS after at most two cycles. | 1926 // to be released to the OS after at most two cycles. |
1926 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 1"); | 1927 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 1"); |
1927 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); | 1928 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); |
1928 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 2"); | 1929 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 2"); |
1929 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages() * 2); | 1930 CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages() * 2); |
1930 | 1931 |
1931 // Triggering a last-resort GC should cause all pages to be released | 1932 // Triggering a last-resort GC should cause all pages to be released to the |
1932 // to the OS so that other processes can seize the memory. | 1933 // OS so that other processes can seize the memory. If we get a failure here |
| 1934 // where there are 2 pages left instead of 1, then we should increase the |
| 1935 // size of the first page a little in SizeOfFirstPage in spaces.cc. The |
| 1936 // first page should be small in order to reduce memory used when the VM |
| 1937 // boots, but if the 20 small arrays don't fit on the first page then that's |
| 1938 // an indication that it is too small. |
1933 HEAP->CollectAllAvailableGarbage("triggered really hard"); | 1939 HEAP->CollectAllAvailableGarbage("triggered really hard"); |
1934 CHECK_EQ(1, old_pointer_space->CountTotalPages()); | 1940 CHECK_EQ(1, old_pointer_space->CountTotalPages()); |
1935 } | 1941 } |
1936 | 1942 |
1937 | 1943 |
1938 TEST(Regress2237) { | 1944 TEST(Regress2237) { |
1939 InitializeVM(); | 1945 InitializeVM(); |
1940 v8::HandleScope scope; | 1946 v8::HandleScope scope; |
1941 Handle<String> slice(HEAP->empty_string()); | 1947 Handle<String> slice(HEAP->empty_string()); |
1942 | 1948 |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2231 // External source is being retained by the stack trace. | 2237 // External source is being retained by the stack trace. |
2232 CHECK(!resource->IsDisposed()); | 2238 CHECK(!resource->IsDisposed()); |
2233 | 2239 |
2234 CompileRun("error.stack; error.stack;"); | 2240 CompileRun("error.stack; error.stack;"); |
2235 HEAP->CollectAllAvailableGarbage(); | 2241 HEAP->CollectAllAvailableGarbage(); |
2236 // External source has been released. | 2242 // External source has been released. |
2237 CHECK(resource->IsDisposed()); | 2243 CHECK(resource->IsDisposed()); |
2238 | 2244 |
2239 delete resource; | 2245 delete resource; |
2240 } | 2246 } |
OLD | NEW |