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

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

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

Powered by Google App Engine
This is Rietveld 408576698