| 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 "compilation-cache.h" | 
| 7 #include "execution.h" | 8 #include "execution.h" | 
| 8 #include "factory.h" | 9 #include "factory.h" | 
| 9 #include "macro-assembler.h" | 10 #include "macro-assembler.h" | 
| 10 #include "global-handles.h" | 11 #include "global-handles.h" | 
| 11 #include "cctest.h" | 12 #include "cctest.h" | 
| 12 | 13 | 
| 13 using namespace v8::internal; | 14 using namespace v8::internal; | 
| 14 | 15 | 
| 15 static v8::Persistent<v8::Context> env; | 16 static v8::Persistent<v8::Context> env; | 
| 16 | 17 | 
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1055     // Remove function f1, and | 1056     // Remove function f1, and | 
| 1056     CompileRun("f1=null"); | 1057     CompileRun("f1=null"); | 
| 1057 | 1058 | 
| 1058     // Scavenge treats these references as strong. | 1059     // Scavenge treats these references as strong. | 
| 1059     for (int j = 0; j < 10; j++) { | 1060     for (int j = 0; j < 10; j++) { | 
| 1060       HEAP->PerformScavenge(); | 1061       HEAP->PerformScavenge(); | 
| 1061       CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); | 1062       CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i])); | 
| 1062     } | 1063     } | 
| 1063 | 1064 | 
| 1064     // Mark compact handles the weak references. | 1065     // Mark compact handles the weak references. | 
|  | 1066     ISOLATE->compilation_cache()->Clear(); | 
| 1065     HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1067     HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 
| 1066     CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 1068     CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 
| 1067 | 1069 | 
| 1068     // Get rid of f3 and f5 in the same way. | 1070     // Get rid of f3 and f5 in the same way. | 
| 1069     CompileRun("f3=null"); | 1071     CompileRun("f3=null"); | 
| 1070     for (int j = 0; j < 10; j++) { | 1072     for (int j = 0; j < 10; j++) { | 
| 1071       HEAP->PerformScavenge(); | 1073       HEAP->PerformScavenge(); | 
| 1072       CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 1074       CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i])); | 
| 1073     } | 1075     } | 
| 1074     HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1076     HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1385     v8::Local<v8::Value> res = CompileRun( | 1387     v8::Local<v8::Value> res = CompileRun( | 
| 1386         "function f() { return o.x; }" | 1388         "function f() { return o.x; }" | 
| 1387         "for (var i = 0; i < 10; ++i) f();" | 1389         "for (var i = 0; i < 10; ++i) f();" | 
| 1388         "%OptimizeFunctionOnNextCall(f);" | 1390         "%OptimizeFunctionOnNextCall(f);" | 
| 1389         "f();"); | 1391         "f();"); | 
| 1390     CHECK_EQ(42, res->Int32Value()); | 1392     CHECK_EQ(42, res->Int32Value()); | 
| 1391     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1393     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 
| 1392     ctx2->Exit(); | 1394     ctx2->Exit(); | 
| 1393     ctx1->Exit(); | 1395     ctx1->Exit(); | 
| 1394     ctx1.Dispose(); | 1396     ctx1.Dispose(); | 
|  | 1397     v8::V8::ContextDisposedNotification(); | 
| 1395   } | 1398   } | 
| 1396   HEAP->CollectAllAvailableGarbage(); | 1399   HEAP->CollectAllAvailableGarbage(); | 
| 1397   CHECK_EQ(2, NumberOfGlobalObjects()); | 1400   CHECK_EQ(2, NumberOfGlobalObjects()); | 
| 1398   ctx2.Dispose(); | 1401   ctx2.Dispose(); | 
| 1399   HEAP->CollectAllAvailableGarbage(); | 1402   HEAP->CollectAllAvailableGarbage(); | 
| 1400   CHECK_EQ(0, NumberOfGlobalObjects()); | 1403   CHECK_EQ(0, NumberOfGlobalObjects()); | 
| 1401 } | 1404 } | 
| 1402 | 1405 | 
| 1403 | 1406 | 
| 1404 // Test that we don't embed functions from foreign contexts into | 1407 // Test that we don't embed functions from foreign contexts into | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 1422     v8::Local<v8::Value> res = CompileRun( | 1425     v8::Local<v8::Value> res = CompileRun( | 
| 1423         "function f(x) { return x(); }" | 1426         "function f(x) { return x(); }" | 
| 1424         "for (var i = 0; i < 10; ++i) f(o);" | 1427         "for (var i = 0; i < 10; ++i) f(o);" | 
| 1425         "%OptimizeFunctionOnNextCall(f);" | 1428         "%OptimizeFunctionOnNextCall(f);" | 
| 1426         "f(o);"); | 1429         "f(o);"); | 
| 1427     CHECK_EQ(42, res->Int32Value()); | 1430     CHECK_EQ(42, res->Int32Value()); | 
| 1428     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1431     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 
| 1429     ctx2->Exit(); | 1432     ctx2->Exit(); | 
| 1430     ctx1->Exit(); | 1433     ctx1->Exit(); | 
| 1431     ctx1.Dispose(); | 1434     ctx1.Dispose(); | 
|  | 1435     v8::V8::ContextDisposedNotification(); | 
| 1432   } | 1436   } | 
| 1433   HEAP->CollectAllAvailableGarbage(); | 1437   HEAP->CollectAllAvailableGarbage(); | 
| 1434   CHECK_EQ(2, NumberOfGlobalObjects()); | 1438   CHECK_EQ(2, NumberOfGlobalObjects()); | 
| 1435   ctx2.Dispose(); | 1439   ctx2.Dispose(); | 
| 1436   HEAP->CollectAllAvailableGarbage(); | 1440   HEAP->CollectAllAvailableGarbage(); | 
| 1437   CHECK_EQ(0, NumberOfGlobalObjects()); | 1441   CHECK_EQ(0, NumberOfGlobalObjects()); | 
| 1438 } | 1442 } | 
| 1439 | 1443 | 
| 1440 | 1444 | 
| 1441 TEST(LeakGlobalContextViaMapKeyed) { | 1445 TEST(LeakGlobalContextViaMapKeyed) { | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 1457     v8::Local<v8::Value> res = CompileRun( | 1461     v8::Local<v8::Value> res = CompileRun( | 
| 1458         "function f() { return o[0]; }" | 1462         "function f() { return o[0]; }" | 
| 1459         "for (var i = 0; i < 10; ++i) f();" | 1463         "for (var i = 0; i < 10; ++i) f();" | 
| 1460         "%OptimizeFunctionOnNextCall(f);" | 1464         "%OptimizeFunctionOnNextCall(f);" | 
| 1461         "f();"); | 1465         "f();"); | 
| 1462     CHECK_EQ(42, res->Int32Value()); | 1466     CHECK_EQ(42, res->Int32Value()); | 
| 1463     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1467     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 
| 1464     ctx2->Exit(); | 1468     ctx2->Exit(); | 
| 1465     ctx1->Exit(); | 1469     ctx1->Exit(); | 
| 1466     ctx1.Dispose(); | 1470     ctx1.Dispose(); | 
|  | 1471     v8::V8::ContextDisposedNotification(); | 
| 1467   } | 1472   } | 
| 1468   HEAP->CollectAllAvailableGarbage(); | 1473   HEAP->CollectAllAvailableGarbage(); | 
| 1469   CHECK_EQ(2, NumberOfGlobalObjects()); | 1474   CHECK_EQ(2, NumberOfGlobalObjects()); | 
| 1470   ctx2.Dispose(); | 1475   ctx2.Dispose(); | 
| 1471   HEAP->CollectAllAvailableGarbage(); | 1476   HEAP->CollectAllAvailableGarbage(); | 
| 1472   CHECK_EQ(0, NumberOfGlobalObjects()); | 1477   CHECK_EQ(0, NumberOfGlobalObjects()); | 
| 1473 } | 1478 } | 
| 1474 | 1479 | 
| 1475 | 1480 | 
| 1476 TEST(LeakGlobalContextViaMapProto) { | 1481 TEST(LeakGlobalContextViaMapProto) { | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 1496         "  return p.x;" | 1501         "  return p.x;" | 
| 1497         "}" | 1502         "}" | 
| 1498         "for (var i = 0; i < 10; ++i) f();" | 1503         "for (var i = 0; i < 10; ++i) f();" | 
| 1499         "%OptimizeFunctionOnNextCall(f);" | 1504         "%OptimizeFunctionOnNextCall(f);" | 
| 1500         "f();"); | 1505         "f();"); | 
| 1501     CHECK_EQ(42, res->Int32Value()); | 1506     CHECK_EQ(42, res->Int32Value()); | 
| 1502     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 1507     ctx2->Global()->Set(v8_str("o"), v8::Int32::New(0)); | 
| 1503     ctx2->Exit(); | 1508     ctx2->Exit(); | 
| 1504     ctx1->Exit(); | 1509     ctx1->Exit(); | 
| 1505     ctx1.Dispose(); | 1510     ctx1.Dispose(); | 
|  | 1511     v8::V8::ContextDisposedNotification(); | 
| 1506   } | 1512   } | 
| 1507   HEAP->CollectAllAvailableGarbage(); | 1513   HEAP->CollectAllAvailableGarbage(); | 
| 1508   CHECK_EQ(2, NumberOfGlobalObjects()); | 1514   CHECK_EQ(2, NumberOfGlobalObjects()); | 
| 1509   ctx2.Dispose(); | 1515   ctx2.Dispose(); | 
| 1510   HEAP->CollectAllAvailableGarbage(); | 1516   HEAP->CollectAllAvailableGarbage(); | 
| 1511   CHECK_EQ(0, NumberOfGlobalObjects()); | 1517   CHECK_EQ(0, NumberOfGlobalObjects()); | 
| 1512 } | 1518 } | 
| 1513 | 1519 | 
| 1514 | 1520 | 
| 1515 TEST(InstanceOfStubWriteBarrier) { | 1521 TEST(InstanceOfStubWriteBarrier) { | 
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2090   CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 2096   CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 
| 2091              "function f(o) { return o.x; } f(obj); f(obj);"); | 2097              "function f(o) { return o.x; } f(obj); f(obj);"); | 
| 2092   Handle<JSFunction> f = | 2098   Handle<JSFunction> f = | 
| 2093       v8::Utils::OpenHandle( | 2099       v8::Utils::OpenHandle( | 
| 2094           *v8::Handle<v8::Function>::Cast( | 2100           *v8::Handle<v8::Function>::Cast( | 
| 2095               v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2101               v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 
| 2096 | 2102 | 
| 2097   Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2103   Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 
| 2098   CHECK(ic_before->ic_state() == MONOMORPHIC); | 2104   CHECK(ic_before->ic_state() == MONOMORPHIC); | 
| 2099 | 2105 | 
| 2100   // Fire context dispose notification. |  | 
| 2101   v8::V8::ContextDisposedNotification(); |  | 
| 2102   SimulateIncrementalMarking(); | 2106   SimulateIncrementalMarking(); | 
| 2103   HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2107   HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 
| 2104 | 2108 | 
| 2105   Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2109   Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 
| 2106   CHECK(ic_after->ic_state() == MONOMORPHIC); | 2110   CHECK(ic_after->ic_state() == MONOMORPHIC); | 
| 2107 } | 2111 } | 
| 2108 | 2112 | 
| 2109 | 2113 | 
| 2110 TEST(IncrementalMarkingClearsMonomorhpicIC) { | 2114 TEST(IncrementalMarkingClearsMonomorhpicIC) { | 
| 2111   if (i::FLAG_always_opt) return; | 2115   if (i::FLAG_always_opt) return; | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2173   CHECK(ic_before->ic_state() == MEGAMORPHIC); | 2177   CHECK(ic_before->ic_state() == MEGAMORPHIC); | 
| 2174 | 2178 | 
| 2175   // Fire context dispose notification. | 2179   // Fire context dispose notification. | 
| 2176   v8::V8::ContextDisposedNotification(); | 2180   v8::V8::ContextDisposedNotification(); | 
| 2177   SimulateIncrementalMarking(); | 2181   SimulateIncrementalMarking(); | 
| 2178   HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2182   HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 
| 2179 | 2183 | 
| 2180   Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2184   Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 
| 2181   CHECK(ic_after->ic_state() == UNINITIALIZED); | 2185   CHECK(ic_after->ic_state() == UNINITIALIZED); | 
| 2182 } | 2186 } | 
| OLD | NEW | 
|---|