OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 "};" | 1580 "};" |
1581 "foo()"; | 1581 "foo()"; |
1582 Handle<String> source = factory->InternalizeUtf8String(raw_source); | 1582 Handle<String> source = factory->InternalizeUtf8String(raw_source); |
1583 Handle<Context> native_context = isolate->native_context(); | 1583 Handle<Context> native_context = isolate->native_context(); |
1584 | 1584 |
1585 { | 1585 { |
1586 v8::HandleScope scope(CcTest::isolate()); | 1586 v8::HandleScope scope(CcTest::isolate()); |
1587 CompileRun(raw_source); | 1587 CompileRun(raw_source); |
1588 } | 1588 } |
1589 | 1589 |
1590 // On first compilation, only a hash is inserted in the code cache. We can't | 1590 // The script should be in the cache now. |
1591 // find that value. | |
1592 MaybeHandle<SharedFunctionInfo> info = compilation_cache->LookupScript( | 1591 MaybeHandle<SharedFunctionInfo> info = compilation_cache->LookupScript( |
1593 source, Handle<Object>(), 0, 0, | 1592 source, Handle<Object>(), 0, 0, |
1594 v8::ScriptOriginOptions(false, true, false), native_context, | 1593 v8::ScriptOriginOptions(false, true, false), native_context, |
1595 language_mode); | 1594 language_mode); |
1596 CHECK(info.is_null()); | |
1597 | |
1598 { | |
1599 v8::HandleScope scope(CcTest::isolate()); | |
1600 CompileRun(raw_source); | |
1601 } | |
1602 | |
1603 // On second compilation, the hash is replaced by a real cache entry mapping | |
1604 // the source to the shared function info containing the code. | |
1605 info = compilation_cache->LookupScript( | |
1606 source, Handle<Object>(), 0, 0, | |
1607 v8::ScriptOriginOptions(false, true, false), native_context, | |
1608 language_mode); | |
1609 CHECK(!info.is_null()); | 1595 CHECK(!info.is_null()); |
1610 | 1596 |
1611 // Check that the code cache entry survives at least on GC. | 1597 // Check that the code cache entry survives at least on GC. |
1612 // (Unless --optimize-for-size, in which case it might get collected | 1598 // (Unless --optimize-for-size, in which case it might get collected |
1613 // immediately.) | 1599 // immediately.) |
1614 if (!FLAG_optimize_for_size) { | 1600 if (!FLAG_optimize_for_size) { |
1615 heap->CollectAllGarbage(); | 1601 heap->CollectAllGarbage(); |
1616 info = compilation_cache->LookupScript( | 1602 info = compilation_cache->LookupScript( |
1617 source, Handle<Object>(), 0, 0, | 1603 source, Handle<Object>(), 0, 0, |
1618 v8::ScriptOriginOptions(false, true, false), native_context, | 1604 v8::ScriptOriginOptions(false, true, false), native_context, |
1619 language_mode); | 1605 language_mode); |
1620 CHECK(!info.is_null()); | 1606 CHECK(!info.is_null()); |
1621 } | 1607 } |
1622 | 1608 |
1623 // Progress code age until it's old and ready for GC. | 1609 // Progress code age until it's old and ready for GC. |
1624 while (!info.ToHandleChecked()->code()->IsOld()) { | 1610 while (!info.ToHandleChecked()->code()->IsOld()) { |
1625 // To guarantee progress, we have to MakeOlder with different parities. | 1611 // To guarantee progress, we have to MakeOlder with different parities. |
1626 // We can't just use NO_MARKING_PARITY, since e.g. kExecutedOnceCodeAge is | 1612 // We can't just use NO_MARKING_PARITY, since e.g. kExecutedOnceCodeAge is |
1627 // always NO_MARKING_PARITY and the code age only progresses if the parity | 1613 // always NO_MARKING_PARITY and the code age only progresses if the parity |
1628 // is different. | 1614 // is different. |
1629 info.ToHandleChecked()->code()->MakeOlder(ODD_MARKING_PARITY); | 1615 info.ToHandleChecked()->code()->MakeOlder(ODD_MARKING_PARITY); |
1630 info.ToHandleChecked()->code()->MakeOlder(EVEN_MARKING_PARITY); | 1616 info.ToHandleChecked()->code()->MakeOlder(EVEN_MARKING_PARITY); |
1631 } | 1617 } |
1632 | 1618 |
1633 heap->CollectAllGarbage(); | 1619 heap->CollectAllGarbage(); |
1634 // Ensure code aging cleared the entry from the cache. | 1620 // Ensure code aging cleared the entry from the cache. |
1635 info = compilation_cache->LookupScript( | 1621 info = compilation_cache->LookupScript( |
1636 source, Handle<Object>(), 0, 0, | 1622 source, Handle<Object>(), 0, 0, |
1637 v8::ScriptOriginOptions(false, true, false), native_context, | 1623 v8::ScriptOriginOptions(false, true, false), native_context, |
1638 language_mode); | |
1639 CHECK(info.is_null()); | |
1640 | |
1641 { | |
1642 v8::HandleScope scope(CcTest::isolate()); | |
1643 CompileRun(raw_source); | |
1644 } | |
1645 | |
1646 // On first compilation, only a hash is inserted in the code cache. We can't | |
1647 // find that value. | |
1648 info = compilation_cache->LookupScript( | |
1649 source, Handle<Object>(), 0, 0, | |
1650 v8::ScriptOriginOptions(false, true, false), native_context, | |
1651 language_mode); | |
1652 CHECK(info.is_null()); | |
1653 | |
1654 for (int i = 0; i < CompilationCacheTable::kHashGenerations; i++) { | |
1655 compilation_cache->MarkCompactPrologue(); | |
1656 } | |
1657 | |
1658 { | |
1659 v8::HandleScope scope(CcTest::isolate()); | |
1660 CompileRun(raw_source); | |
1661 } | |
1662 | |
1663 // If we aged the cache before caching the script, ensure that we didn't cache | |
1664 // on next compilation. | |
1665 info = compilation_cache->LookupScript( | |
1666 source, Handle<Object>(), 0, 0, | |
1667 v8::ScriptOriginOptions(false, true, false), native_context, | |
1668 language_mode); | 1624 language_mode); |
1669 CHECK(info.is_null()); | 1625 CHECK(info.is_null()); |
1670 } | 1626 } |
1671 | 1627 |
1672 | 1628 |
1673 static void OptimizeEmptyFunction(const char* name) { | 1629 static void OptimizeEmptyFunction(const char* name) { |
1674 HandleScope scope(CcTest::i_isolate()); | 1630 HandleScope scope(CcTest::i_isolate()); |
1675 EmbeddedVector<char, 256> source; | 1631 EmbeddedVector<char, 256> source; |
1676 SNPrintF(source, | 1632 SNPrintF(source, |
1677 "function %s() { return 0; }" | 1633 "function %s() { return 0; }" |
(...skipping 4924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6602 heap->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(arrays[j], N - 1); | 6558 heap->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(arrays[j], N - 1); |
6603 } | 6559 } |
6604 } | 6560 } |
6605 // Force allocation from the free list. | 6561 // Force allocation from the free list. |
6606 heap->set_force_oom(true); | 6562 heap->set_force_oom(true); |
6607 heap->CollectGarbage(OLD_SPACE); | 6563 heap->CollectGarbage(OLD_SPACE); |
6608 } | 6564 } |
6609 | 6565 |
6610 } // namespace internal | 6566 } // namespace internal |
6611 } // namespace v8 | 6567 } // namespace v8 |
OLD | NEW |