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 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0])); | 1687 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0])); |
1688 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2)); | 1688 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2)); |
1689 CompileRun("f5()"); | 1689 CompileRun("f5()"); |
1690 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); | 1690 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); |
1691 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); | 1691 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); |
1692 | 1692 |
1693 ctx[0]->Exit(); | 1693 ctx[0]->Exit(); |
1694 } | 1694 } |
1695 | 1695 |
1696 | 1696 |
| 1697 TEST(TestSizeOfRegExpCode) { |
| 1698 if (!FLAG_regexp_optimization) return; |
| 1699 |
| 1700 v8::V8::Initialize(); |
| 1701 |
| 1702 Isolate* isolate = CcTest::i_isolate(); |
| 1703 HandleScope scope(isolate); |
| 1704 |
| 1705 LocalContext context; |
| 1706 |
| 1707 // Adjust source below and this check to match |
| 1708 // RegExpImple::kRegExpTooLargeToOptimize. |
| 1709 DCHECK_EQ(i::RegExpImpl::kRegExpTooLargeToOptimize, 10 * KB); |
| 1710 |
| 1711 // Compile a regexp that is much larger if we are using regexp optimizations. |
| 1712 CompileRun( |
| 1713 "var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';" |
| 1714 "var half_size_reg_exp;" |
| 1715 "while (reg_exp_source.length < 10 * 1024) {" |
| 1716 " half_size_reg_exp = reg_exp_source;" |
| 1717 " reg_exp_source = reg_exp_source + reg_exp_source;" |
| 1718 "}" |
| 1719 // Flatten string. |
| 1720 "reg_exp_source.match(/f/);"); |
| 1721 |
| 1722 // Get initial heap size after several full GCs, which will stabilize |
| 1723 // the heap size and return with sweeping finished completely. |
| 1724 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1725 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1726 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1727 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1728 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1729 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); |
| 1730 if (collector->sweeping_in_progress()) { |
| 1731 collector->EnsureSweepingCompleted(); |
| 1732 } |
| 1733 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1734 |
| 1735 CompileRun("'foo'.match(reg_exp_source);"); |
| 1736 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1737 int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1738 |
| 1739 CompileRun("'foo'.match(half_size_reg_exp);"); |
| 1740 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1741 int size_with_optimized_regexp = |
| 1742 static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1743 |
| 1744 int size_of_regexp_code = size_with_regexp - initial_size; |
| 1745 |
| 1746 CHECK_LE(size_of_regexp_code, 500 * KB); |
| 1747 |
| 1748 // Small regexp is half the size, but compiles to more than twice the code |
| 1749 // due to the optimization steps. |
| 1750 CHECK_GE(size_with_optimized_regexp, |
| 1751 size_with_regexp + size_of_regexp_code * 2); |
| 1752 } |
| 1753 |
| 1754 |
1697 TEST(TestSizeOfObjects) { | 1755 TEST(TestSizeOfObjects) { |
1698 v8::V8::Initialize(); | 1756 v8::V8::Initialize(); |
1699 | 1757 |
1700 // Get initial heap size after several full GCs, which will stabilize | 1758 // Get initial heap size after several full GCs, which will stabilize |
1701 // the heap size and return with sweeping finished completely. | 1759 // the heap size and return with sweeping finished completely. |
1702 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1760 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1703 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1761 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1704 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1762 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1705 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1763 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1706 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1764 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
(...skipping 3055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4762 #ifdef DEBUG | 4820 #ifdef DEBUG |
4763 TEST(PathTracer) { | 4821 TEST(PathTracer) { |
4764 CcTest::InitializeVM(); | 4822 CcTest::InitializeVM(); |
4765 v8::HandleScope scope(CcTest::isolate()); | 4823 v8::HandleScope scope(CcTest::isolate()); |
4766 | 4824 |
4767 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4825 v8::Local<v8::Value> result = CompileRun("'abc'"); |
4768 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4826 Handle<Object> o = v8::Utils::OpenHandle(*result); |
4769 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4827 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
4770 } | 4828 } |
4771 #endif // DEBUG | 4829 #endif // DEBUG |
OLD | NEW |