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

Side by Side Diff: test/cctest/test-heap.cc

Issue 9173001: Make heap size estimation more accurate. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed more comments by Vyacheslav Egorov. Created 8 years, 11 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
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0])); 1180 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0]));
1181 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2)); 1181 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2));
1182 CompileRun("f5()"); 1182 CompileRun("f5()");
1183 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); 1183 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0]));
1184 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); 1184 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4));
1185 1185
1186 ctx[0]->Exit(); 1186 ctx[0]->Exit();
1187 } 1187 }
1188 1188
1189 1189
1190 TEST(TestSizeOfObjects) {
1191 v8::V8::Initialize();
1192
1193 // Get initial heap size after several full GCs, which will stabilize
1194 // the heap size and return with sweeping finished completely.
1195 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1196 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1197 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1198 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1199 CHECK(HEAP->old_pointer_space()->IsSweepingComplete());
1200 intptr_t initial_size = HEAP->SizeOfObjects();
1201
1202 {
1203 // Allocate objects on several different old-space pages so that
1204 // lazy sweeping kicks in for subsequent GC runs.
1205 AlwaysAllocateScope always_allocate;
1206 intptr_t filler_size = FixedArray::SizeFor(8192);
1207 for (int i = 1; i <= 100; i++) {
1208 HEAP->AllocateFixedArray(8192, TENURED)->ToObjectChecked();
1209 CHECK_EQ(initial_size + i * filler_size, HEAP->SizeOfObjects());
1210 }
1211 }
1212
1213 // The heap size should go back to initial size after a full GC, even
1214 // though sweeping didn't finish yet.
1215 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1216 CHECK(!HEAP->old_pointer_space()->IsSweepingComplete());
1217 CHECK_EQ(initial_size, HEAP->SizeOfObjects());
1218
1219 // Advancing the sweeper step-wise should not change the heap size.
1220 while (!HEAP->old_pointer_space()->IsSweepingComplete()) {
1221 HEAP->old_pointer_space()->AdvanceSweeper(KB);
1222 CHECK_EQ(initial_size, HEAP->SizeOfObjects());
1223 }
1224 }
1225
1226
1190 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { 1227 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
1191 InitializeVM(); 1228 InitializeVM();
1192 HEAP->EnsureHeapIsIterable(); 1229 HEAP->EnsureHeapIsIterable();
1193 intptr_t size_of_objects_1 = HEAP->SizeOfObjects(); 1230 intptr_t size_of_objects_1 = HEAP->SizeOfObjects();
1194 HeapIterator iterator; 1231 HeapIterator iterator;
1195 intptr_t size_of_objects_2 = 0; 1232 intptr_t size_of_objects_2 = 0;
1196 for (HeapObject* obj = iterator.next(); 1233 for (HeapObject* obj = iterator.next();
1197 obj != NULL; 1234 obj != NULL;
1198 obj = iterator.next()) { 1235 obj = iterator.next()) {
1199 size_of_objects_2 += obj->Size(); 1236 size_of_objects_2 += obj->Size();
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 ctx2->Exit(); 1506 ctx2->Exit();
1470 ctx1->Exit(); 1507 ctx1->Exit();
1471 ctx1.Dispose(); 1508 ctx1.Dispose();
1472 } 1509 }
1473 HEAP->CollectAllAvailableGarbage(); 1510 HEAP->CollectAllAvailableGarbage();
1474 CHECK_EQ(2, NumberOfGlobalObjects()); 1511 CHECK_EQ(2, NumberOfGlobalObjects());
1475 ctx2.Dispose(); 1512 ctx2.Dispose();
1476 HEAP->CollectAllAvailableGarbage(); 1513 HEAP->CollectAllAvailableGarbage();
1477 CHECK_EQ(0, NumberOfGlobalObjects()); 1514 CHECK_EQ(0, NumberOfGlobalObjects());
1478 } 1515 }
OLDNEW
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698