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

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

Issue 6014004: Implement HeapIterator that skips over unreachable objects. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 10 years 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
« src/heap.cc ('K') | « src/profile-generator.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); 1209 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0]));
1210 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); 1210 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4));
1211 1211
1212 ctx[0]->Exit(); 1212 ctx[0]->Exit();
1213 } 1213 }
1214 1214
1215 1215
1216 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { 1216 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
1217 InitializeVM(); 1217 InitializeVM();
1218 intptr_t size_of_objects_1 = Heap::SizeOfObjects(); 1218 intptr_t size_of_objects_1 = Heap::SizeOfObjects();
1219 HeapIterator iterator(HeapIterator::kPreciseFiltering); 1219 HeapIterator iterator(HeapIterator::kFilterFreeListNodes);
1220 intptr_t size_of_objects_2 = 0; 1220 intptr_t size_of_objects_2 = 0;
1221 for (HeapObject* obj = iterator.next(); 1221 for (HeapObject* obj = iterator.next();
1222 obj != NULL; 1222 obj != NULL;
1223 obj = iterator.next()) { 1223 obj = iterator.next()) {
1224 size_of_objects_2 += obj->Size(); 1224 size_of_objects_2 += obj->Size();
1225 } 1225 }
1226 // Delta must be within 1% of the larger result. 1226 // Delta must be within 1% of the larger result.
1227 if (size_of_objects_1 > size_of_objects_2) { 1227 if (size_of_objects_1 > size_of_objects_2) {
1228 intptr_t delta = size_of_objects_1 - size_of_objects_2; 1228 intptr_t delta = size_of_objects_1 - size_of_objects_2;
1229 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " 1229 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
1230 "Iterator: %" V8_PTR_PREFIX "d, " 1230 "Iterator: %" V8_PTR_PREFIX "d, "
1231 "delta: %" V8_PTR_PREFIX "d\n", 1231 "delta: %" V8_PTR_PREFIX "d\n",
1232 size_of_objects_1, size_of_objects_2, delta); 1232 size_of_objects_1, size_of_objects_2, delta);
1233 CHECK_GT(size_of_objects_1 / 100, delta); 1233 CHECK_GT(size_of_objects_1 / 100, delta);
1234 } else { 1234 } else {
1235 intptr_t delta = size_of_objects_2 - size_of_objects_1; 1235 intptr_t delta = size_of_objects_2 - size_of_objects_1;
1236 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " 1236 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
1237 "Iterator: %" V8_PTR_PREFIX "d, " 1237 "Iterator: %" V8_PTR_PREFIX "d, "
1238 "delta: %" V8_PTR_PREFIX "d\n", 1238 "delta: %" V8_PTR_PREFIX "d\n",
1239 size_of_objects_1, size_of_objects_2, delta); 1239 size_of_objects_1, size_of_objects_2, delta);
1240 CHECK_GT(size_of_objects_2 / 100, delta); 1240 CHECK_GT(size_of_objects_2 / 100, delta);
1241 } 1241 }
1242 } 1242 }
1243
1244
1245 class HeapIteratorTestHelper {
1246 public:
1247 HeapIteratorTestHelper(Object* a, Object* b)
1248 : a_(a), b_(b), a_found_(false), b_found_(false) {}
1249 bool a_found() { return a_found_; }
1250 bool b_found() { return b_found_; }
1251 void IterateHeap(HeapIterator::HeapObjectsFiltering mode) {
1252 HeapIterator iterator(mode);
1253 for (HeapObject* obj = iterator.next();
1254 obj != NULL;
1255 obj = iterator.next()) {
1256 if (obj == a_)
1257 a_found_ = true;
1258 else if (obj == b_)
1259 b_found_ = true;
1260 }
1261 }
1262 private:
1263 Object* a_;
1264 Object* b_;
1265 bool a_found_;
1266 bool b_found_;
1267 };
1268
1269 TEST(HeapIteratorFilterUnreachable) {
1270 InitializeVM();
1271 v8::HandleScope scope;
1272 CompileRun("a = {}; b = {};");
1273 v8::Handle<Object> a(Top::context()->global()->GetProperty(
1274 *Factory::LookupAsciiSymbol("a"))->ToObjectChecked());
1275 v8::Handle<Object> b(Top::context()->global()->GetProperty(
1276 *Factory::LookupAsciiSymbol("b"))->ToObjectChecked());
1277 CHECK_NE(*a, *b);
1278 {
1279 HeapIteratorTestHelper helper(*a, *b);
1280 helper.IterateHeap(HeapIterator::kFilterUnreachable);
1281 CHECK(helper.a_found());
1282 CHECK(helper.b_found());
1283 }
1284 CHECK(Top::context()->global()->DeleteProperty(
1285 *Factory::LookupAsciiSymbol("a"), JSObject::FORCE_DELETION));
1286 // We ensure that GC will not happen, so our raw pointer stays valid.
1287 AssertNoAllocation no_alloc;
1288 Object* a_saved = *a;
1289 a.Clear();
1290 // Verify that "a" object still resides in the heap...
1291 {
1292 HeapIteratorTestHelper helper(a_saved, *b);
1293 helper.IterateHeap(HeapIterator::kNoFiltering);
1294 CHECK(helper.a_found());
1295 CHECK(helper.b_found());
1296 }
1297 // ...but is now unreachable.
1298 {
1299 HeapIteratorTestHelper helper(a_saved, *b);
1300 helper.IterateHeap(HeapIterator::kFilterUnreachable);
1301 CHECK(!helper.a_found());
1302 CHECK(helper.b_found());
1303 }
1304 }
OLDNEW
« src/heap.cc ('K') | « src/profile-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698