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 "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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 408 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
409 | 409 |
410 CHECK((*h1)->IsString()); | 410 CHECK((*h1)->IsString()); |
411 | 411 |
412 CHECK(WeakPointerCleared); | 412 CHECK(WeakPointerCleared); |
413 CHECK(!GlobalHandles::IsNearDeath(h1.location())); | 413 CHECK(!GlobalHandles::IsNearDeath(h1.location())); |
414 | 414 |
415 global_handles->Destroy(h1.location()); | 415 global_handles->Destroy(h1.location()); |
416 } | 416 } |
417 | 417 |
| 418 |
418 TEST(DeleteWeakGlobalHandle) { | 419 TEST(DeleteWeakGlobalHandle) { |
419 InitializeVM(); | 420 InitializeVM(); |
420 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 421 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
421 | 422 |
422 WeakPointerCleared = false; | 423 WeakPointerCleared = false; |
423 | 424 |
424 Handle<Object> h; | 425 Handle<Object> h; |
425 | 426 |
426 { | 427 { |
427 HandleScope scope; | 428 HandleScope scope; |
(...skipping 10 matching lines...) Expand all Loading... |
438 HEAP->PerformScavenge(); | 439 HEAP->PerformScavenge(); |
439 | 440 |
440 CHECK(!WeakPointerCleared); | 441 CHECK(!WeakPointerCleared); |
441 | 442 |
442 // Mark-compact treats weak reference properly. | 443 // Mark-compact treats weak reference properly. |
443 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 444 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
444 | 445 |
445 CHECK(WeakPointerCleared); | 446 CHECK(WeakPointerCleared); |
446 } | 447 } |
447 | 448 |
| 449 |
448 static const char* not_so_random_string_table[] = { | 450 static const char* not_so_random_string_table[] = { |
449 "abstract", | 451 "abstract", |
450 "boolean", | 452 "boolean", |
451 "break", | 453 "break", |
452 "byte", | 454 "byte", |
453 "case", | 455 "case", |
454 "catch", | 456 "catch", |
455 "char", | 457 "char", |
456 "class", | 458 "class", |
457 "const", | 459 "const", |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 for (intptr_t i = 0; i < number_of_fillers; i++) { | 1276 for (intptr_t i = 0; i < number_of_fillers; i++) { |
1275 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(32, NOT_TENURED))); | 1277 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(32, NOT_TENURED))); |
1276 } | 1278 } |
1277 } | 1279 } |
1278 | 1280 |
1279 | 1281 |
1280 TEST(GrowAndShrinkNewSpace) { | 1282 TEST(GrowAndShrinkNewSpace) { |
1281 InitializeVM(); | 1283 InitializeVM(); |
1282 NewSpace* new_space = HEAP->new_space(); | 1284 NewSpace* new_space = HEAP->new_space(); |
1283 | 1285 |
1284 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { | 1286 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || |
| 1287 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { |
1285 // The max size cannot exceed the reserved size, since semispaces must be | 1288 // The max size cannot exceed the reserved size, since semispaces must be |
1286 // always within the reserved space. We can't test new space growing and | 1289 // always within the reserved space. We can't test new space growing and |
1287 // shrinking if the reserved size is the same as the minimum (initial) size. | 1290 // shrinking if the reserved size is the same as the minimum (initial) size. |
1288 return; | 1291 return; |
1289 } | 1292 } |
1290 | 1293 |
1291 // Explicitly growing should double the space capacity. | 1294 // Explicitly growing should double the space capacity. |
1292 intptr_t old_capacity, new_capacity; | 1295 intptr_t old_capacity, new_capacity; |
1293 old_capacity = new_space->Capacity(); | 1296 old_capacity = new_space->Capacity(); |
1294 new_space->Grow(); | 1297 new_space->Grow(); |
(...skipping 27 matching lines...) Expand all Loading... |
1322 new_space->Shrink(); | 1325 new_space->Shrink(); |
1323 new_space->Shrink(); | 1326 new_space->Shrink(); |
1324 new_capacity = new_space->Capacity(); | 1327 new_capacity = new_space->Capacity(); |
1325 CHECK(old_capacity == new_capacity); | 1328 CHECK(old_capacity == new_capacity); |
1326 } | 1329 } |
1327 | 1330 |
1328 | 1331 |
1329 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { | 1332 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { |
1330 InitializeVM(); | 1333 InitializeVM(); |
1331 | 1334 |
1332 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { | 1335 if (HEAP->ReservedSemiSpaceSize() == HEAP->InitialSemiSpaceSize() || |
| 1336 HEAP->MaxSemiSpaceSize() == HEAP->InitialSemiSpaceSize()) { |
1333 // The max size cannot exceed the reserved size, since semispaces must be | 1337 // The max size cannot exceed the reserved size, since semispaces must be |
1334 // always within the reserved space. We can't test new space growing and | 1338 // always within the reserved space. We can't test new space growing and |
1335 // shrinking if the reserved size is the same as the minimum (initial) size. | 1339 // shrinking if the reserved size is the same as the minimum (initial) size. |
1336 return; | 1340 return; |
1337 } | 1341 } |
1338 | 1342 |
1339 v8::HandleScope scope; | 1343 v8::HandleScope scope; |
1340 NewSpace* new_space = HEAP->new_space(); | 1344 NewSpace* new_space = HEAP->new_space(); |
1341 intptr_t old_capacity, new_capacity; | 1345 intptr_t old_capacity, new_capacity; |
1342 old_capacity = new_space->Capacity(); | 1346 old_capacity = new_space->Capacity(); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 } | 1753 } |
1750 | 1754 |
1751 | 1755 |
1752 // Test that map transitions are cleared and maps are collected with | 1756 // Test that map transitions are cleared and maps are collected with |
1753 // incremental marking as well. | 1757 // incremental marking as well. |
1754 TEST(Regress1465) { | 1758 TEST(Regress1465) { |
1755 i::FLAG_allow_natives_syntax = true; | 1759 i::FLAG_allow_natives_syntax = true; |
1756 i::FLAG_trace_incremental_marking = true; | 1760 i::FLAG_trace_incremental_marking = true; |
1757 InitializeVM(); | 1761 InitializeVM(); |
1758 v8::HandleScope scope; | 1762 v8::HandleScope scope; |
| 1763 static const int transitions_count = 256; |
1759 | 1764 |
1760 #define TRANSITION_COUNT 256 | 1765 { |
1761 for (int i = 0; i < TRANSITION_COUNT; i++) { | 1766 AlwaysAllocateScope always_allocate; |
1762 EmbeddedVector<char, 64> buffer; | 1767 for (int i = 0; i < transitions_count; i++) { |
1763 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); | 1768 EmbeddedVector<char, 64> buffer; |
1764 CompileRun(buffer.start()); | 1769 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); |
| 1770 CompileRun(buffer.start()); |
| 1771 } |
| 1772 CompileRun("var root = new Object;"); |
1765 } | 1773 } |
1766 CompileRun("var root = new Object;"); | 1774 |
1767 Handle<JSObject> root = | 1775 Handle<JSObject> root = |
1768 v8::Utils::OpenHandle( | 1776 v8::Utils::OpenHandle( |
1769 *v8::Handle<v8::Object>::Cast( | 1777 *v8::Handle<v8::Object>::Cast( |
1770 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); | 1778 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); |
1771 | 1779 |
1772 // Count number of live transitions before marking. | 1780 // Count number of live transitions before marking. |
1773 int transitions_before = CountMapTransitions(root->map()); | 1781 int transitions_before = CountMapTransitions(root->map()); |
1774 CompileRun("%DebugPrint(root);"); | 1782 CompileRun("%DebugPrint(root);"); |
1775 CHECK_EQ(TRANSITION_COUNT, transitions_before); | 1783 CHECK_EQ(transitions_count, transitions_before); |
1776 | 1784 |
1777 // Go through all incremental marking steps in one swoop. | 1785 // Go through all incremental marking steps in one swoop. |
1778 IncrementalMarking* marking = HEAP->incremental_marking(); | 1786 IncrementalMarking* marking = HEAP->incremental_marking(); |
1779 CHECK(marking->IsStopped()); | 1787 CHECK(marking->IsStopped()); |
1780 marking->Start(); | 1788 marking->Start(); |
1781 CHECK(marking->IsMarking()); | 1789 CHECK(marking->IsMarking()); |
1782 while (!marking->IsComplete()) { | 1790 while (!marking->IsComplete()) { |
1783 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 1791 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
1784 } | 1792 } |
1785 CHECK(marking->IsComplete()); | 1793 CHECK(marking->IsComplete()); |
1786 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1794 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1787 CHECK(marking->IsStopped()); | |
1788 | 1795 |
1789 // Count number of live transitions after marking. Note that one transition | 1796 // Count number of live transitions after marking. Note that one transition |
1790 // is left, because 'o' still holds an instance of one transition target. | 1797 // is left, because 'o' still holds an instance of one transition target. |
1791 int transitions_after = CountMapTransitions(root->map()); | 1798 int transitions_after = CountMapTransitions(root->map()); |
1792 CompileRun("%DebugPrint(root);"); | 1799 CompileRun("%DebugPrint(root);"); |
1793 CHECK_EQ(1, transitions_after); | 1800 CHECK_EQ(1, transitions_after); |
1794 } | 1801 } |
1795 | 1802 |
1796 | 1803 |
1797 TEST(Regress2143a) { | 1804 TEST(Regress2143a) { |
(...skipping 25 matching lines...) Expand all Loading... |
1823 " o.foo = 0;" | 1830 " o.foo = 0;" |
1824 "}" | 1831 "}" |
1825 "f(new Object);" | 1832 "f(new Object);" |
1826 "f(root);"); | 1833 "f(root);"); |
1827 | 1834 |
1828 // This bug only triggers with aggressive IC clearing. | 1835 // This bug only triggers with aggressive IC clearing. |
1829 HEAP->AgeInlineCaches(); | 1836 HEAP->AgeInlineCaches(); |
1830 | 1837 |
1831 // Explicitly request GC to perform final marking step and sweeping. | 1838 // Explicitly request GC to perform final marking step and sweeping. |
1832 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1839 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1833 CHECK(marking->IsStopped()); | |
1834 | 1840 |
1835 Handle<JSObject> root = | 1841 Handle<JSObject> root = |
1836 v8::Utils::OpenHandle( | 1842 v8::Utils::OpenHandle( |
1837 *v8::Handle<v8::Object>::Cast( | 1843 *v8::Handle<v8::Object>::Cast( |
1838 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); | 1844 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); |
1839 | 1845 |
1840 // The root object should be in a sane state. | 1846 // The root object should be in a sane state. |
1841 CHECK(root->IsJSObject()); | 1847 CHECK(root->IsJSObject()); |
1842 CHECK(root->map()->IsMap()); | 1848 CHECK(root->map()->IsMap()); |
1843 } | 1849 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 "f(new Object);" | 1882 "f(new Object);" |
1877 "%OptimizeFunctionOnNextCall(f);" | 1883 "%OptimizeFunctionOnNextCall(f);" |
1878 "f(root);" | 1884 "f(root);" |
1879 "%DeoptimizeFunction(f);"); | 1885 "%DeoptimizeFunction(f);"); |
1880 | 1886 |
1881 // This bug only triggers with aggressive IC clearing. | 1887 // This bug only triggers with aggressive IC clearing. |
1882 HEAP->AgeInlineCaches(); | 1888 HEAP->AgeInlineCaches(); |
1883 | 1889 |
1884 // Explicitly request GC to perform final marking step and sweeping. | 1890 // Explicitly request GC to perform final marking step and sweeping. |
1885 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 1891 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
1886 CHECK(marking->IsStopped()); | |
1887 | 1892 |
1888 Handle<JSObject> root = | 1893 Handle<JSObject> root = |
1889 v8::Utils::OpenHandle( | 1894 v8::Utils::OpenHandle( |
1890 *v8::Handle<v8::Object>::Cast( | 1895 *v8::Handle<v8::Object>::Cast( |
1891 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); | 1896 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); |
1892 | 1897 |
1893 // The root object should be in a sane state. | 1898 // The root object should be in a sane state. |
1894 CHECK(root->IsJSObject()); | 1899 CHECK(root->IsJSObject()); |
1895 CHECK(root->map()->IsMap()); | 1900 CHECK(root->map()->IsMap()); |
1896 } | 1901 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2064 // Go through all incremental marking steps in one swoop. | 2069 // Go through all incremental marking steps in one swoop. |
2065 IncrementalMarking* marking = HEAP->incremental_marking(); | 2070 IncrementalMarking* marking = HEAP->incremental_marking(); |
2066 CHECK(marking->IsStopped()); | 2071 CHECK(marking->IsStopped()); |
2067 marking->Start(); | 2072 marking->Start(); |
2068 CHECK(marking->IsMarking()); | 2073 CHECK(marking->IsMarking()); |
2069 while (!marking->IsComplete()) { | 2074 while (!marking->IsComplete()) { |
2070 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 2075 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
2071 } | 2076 } |
2072 CHECK(marking->IsComplete()); | 2077 CHECK(marking->IsComplete()); |
2073 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2078 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2074 CHECK(marking->IsStopped()); | |
2075 | 2079 |
2076 CHECK_EQ(2, cells->CellCount()); | 2080 CHECK_EQ(2, cells->CellCount()); |
2077 CHECK(cells->Cell(0)->value()->IsTheHole()); | 2081 CHECK(cells->Cell(0)->value()->IsTheHole()); |
2078 CHECK(cells->Cell(1)->value()->IsTheHole()); | 2082 CHECK(cells->Cell(1)->value()->IsTheHole()); |
2079 } | 2083 } |
OLD | NEW |