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

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

Issue 8892002: Filter out maps from different global context when collecting type feedback. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: addressed latest comments Created 9 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
« no previous file with comments | « src/type-info.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 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 { 1311 {
1312 AlwaysAllocateScope aa_scope; 1312 AlwaysAllocateScope aa_scope;
1313 CompileRun(source); 1313 CompileRun(source);
1314 } 1314 }
1315 intptr_t old_size = HEAP->SizeOfObjects(); 1315 intptr_t old_size = HEAP->SizeOfObjects();
1316 bool no_idle_work = v8::V8::IdleNotification(900); 1316 bool no_idle_work = v8::V8::IdleNotification(900);
1317 while (!v8::V8::IdleNotification(900)) ; 1317 while (!v8::V8::IdleNotification(900)) ;
1318 intptr_t new_size = HEAP->SizeOfObjects(); 1318 intptr_t new_size = HEAP->SizeOfObjects();
1319 CHECK(no_idle_work || new_size < old_size); 1319 CHECK(no_idle_work || new_size < old_size);
1320 } 1320 }
1321
1322
1323 static int NumberOfGlobalObjects() {
1324 int count = 0;
1325 HeapIterator iterator;
1326 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
1327 if (obj->IsGlobalObject()) count++;
1328 }
1329 return count;
1330 }
1331
1332
1333 // Test that we don't embed maps from foreign contexts into
1334 // optimized code.
1335 TEST(LeakGlobalContextViaMap) {
1336 v8::HandleScope outer_scope;
1337 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
1338 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
1339 ctx1->Enter();
1340
1341 HEAP->CollectAllAvailableGarbage();
1342 CHECK_EQ(4, NumberOfGlobalObjects());
1343
1344 {
1345 v8::HandleScope inner_scope;
1346 CompileRun("var v = {x: 42}");
1347 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
1348 ctx2->Enter();
1349 ctx2->Global()->Set(v8_str("o"), v);
1350 v8::Local<v8::Value> res = CompileRun(
1351 "function f() { return o.x; }"
1352 "for (var i = 0; i < 1000000; ++i) f();"
1353 "f();");
1354 CHECK_EQ(42, res->Int32Value());
1355 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
1356 ctx2->Exit();
1357 ctx1->Exit();
1358 ctx1.Dispose();
1359 }
1360 HEAP->CollectAllAvailableGarbage();
1361 CHECK_EQ(2, NumberOfGlobalObjects());
1362 ctx2.Dispose();
1363 HEAP->CollectAllAvailableGarbage();
1364 CHECK_EQ(0, NumberOfGlobalObjects());
1365 }
1366
1367
1368 // Test that we don't embed functions from foreign contexts into
1369 // optimized code.
1370 TEST(LeakGlobalContextViaFunction) {
1371 v8::HandleScope outer_scope;
1372 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
1373 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
1374 ctx1->Enter();
1375
1376 HEAP->CollectAllAvailableGarbage();
1377 CHECK_EQ(4, NumberOfGlobalObjects());
1378
1379 {
1380 v8::HandleScope inner_scope;
1381 CompileRun("var v = function() { return 42; }");
1382 v8::Local<v8::Value> v = ctx1->Global()->Get(v8_str("v"));
1383 ctx2->Enter();
1384 ctx2->Global()->Set(v8_str("o"), v);
1385 v8::Local<v8::Value> res = CompileRun(
1386 "function f(x) { return x(); }"
1387 "for (var i = 0; i < 1000000; ++i) f(o);"
1388 "f(o);");
1389 CHECK_EQ(42, res->Int32Value());
1390 ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0));
1391 ctx2->Exit();
1392 ctx1->Exit();
1393 ctx1.Dispose();
1394 }
1395 HEAP->CollectAllAvailableGarbage();
1396 CHECK_EQ(2, NumberOfGlobalObjects());
1397 ctx2.Dispose();
1398 HEAP->CollectAllAvailableGarbage();
1399 CHECK_EQ(0, NumberOfGlobalObjects());
1400 }
OLDNEW
« no previous file with comments | « src/type-info.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698