| 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 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 | 1740 |
| 1741 v8::V8::Initialize(); | 1741 v8::V8::Initialize(); |
| 1742 | 1742 |
| 1743 Isolate* isolate = CcTest::i_isolate(); | 1743 Isolate* isolate = CcTest::i_isolate(); |
| 1744 HandleScope scope(isolate); | 1744 HandleScope scope(isolate); |
| 1745 | 1745 |
| 1746 LocalContext context; | 1746 LocalContext context; |
| 1747 | 1747 |
| 1748 // Adjust source below and this check to match | 1748 // Adjust source below and this check to match |
| 1749 // RegExpImple::kRegExpTooLargeToOptimize. | 1749 // RegExpImple::kRegExpTooLargeToOptimize. |
| 1750 DCHECK_EQ(i::RegExpImpl::kRegExpTooLargeToOptimize, 10 * KB); | 1750 DCHECK_EQ(i::RegExpImpl::kRegExpTooLargeToOptimize, 20 * KB); |
| 1751 | 1751 |
| 1752 // Compile a regexp that is much larger if we are using regexp optimizations. | 1752 // Compile a regexp that is much larger if we are using regexp optimizations. |
| 1753 CompileRun( | 1753 CompileRun( |
| 1754 "var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';" | 1754 "var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';" |
| 1755 "var half_size_reg_exp;" | 1755 "var half_size_reg_exp;" |
| 1756 "while (reg_exp_source.length < 10 * 1024) {" | 1756 "while (reg_exp_source.length < 20 * 1024) {" |
| 1757 " half_size_reg_exp = reg_exp_source;" | 1757 " half_size_reg_exp = reg_exp_source;" |
| 1758 " reg_exp_source = reg_exp_source + reg_exp_source;" | 1758 " reg_exp_source = reg_exp_source + reg_exp_source;" |
| 1759 "}" | 1759 "}" |
| 1760 // Flatten string. | 1760 // Flatten string. |
| 1761 "reg_exp_source.match(/f/);"); | 1761 "reg_exp_source.match(/f/);"); |
| 1762 | 1762 |
| 1763 // Get initial heap size after several full GCs, which will stabilize | 1763 // Get initial heap size after several full GCs, which will stabilize |
| 1764 // the heap size and return with sweeping finished completely. | 1764 // the heap size and return with sweeping finished completely. |
| 1765 CcTest::heap()->CollectAllGarbage(); | 1765 CcTest::heap()->CollectAllGarbage(); |
| 1766 CcTest::heap()->CollectAllGarbage(); | 1766 CcTest::heap()->CollectAllGarbage(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1777 CcTest::heap()->CollectAllGarbage(); | 1777 CcTest::heap()->CollectAllGarbage(); |
| 1778 int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects()); | 1778 int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1779 | 1779 |
| 1780 CompileRun("'foo'.match(half_size_reg_exp);"); | 1780 CompileRun("'foo'.match(half_size_reg_exp);"); |
| 1781 CcTest::heap()->CollectAllGarbage(); | 1781 CcTest::heap()->CollectAllGarbage(); |
| 1782 int size_with_optimized_regexp = | 1782 int size_with_optimized_regexp = |
| 1783 static_cast<int>(CcTest::heap()->SizeOfObjects()); | 1783 static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1784 | 1784 |
| 1785 int size_of_regexp_code = size_with_regexp - initial_size; | 1785 int size_of_regexp_code = size_with_regexp - initial_size; |
| 1786 | 1786 |
| 1787 CHECK_LE(size_of_regexp_code, 1 * MB); | 1787 // On some platforms the debug-code flag causes huge amounts of regexp code |
| 1788 // to be emitted, breaking this test. |
| 1789 if (!FLAG_debug_code) { |
| 1790 CHECK_LE(size_of_regexp_code, 1 * MB); |
| 1791 } |
| 1788 | 1792 |
| 1789 // Small regexp is half the size, but compiles to more than twice the code | 1793 // Small regexp is half the size, but compiles to more than twice the code |
| 1790 // due to the optimization steps. | 1794 // due to the optimization steps. |
| 1791 CHECK_GE(size_with_optimized_regexp, | 1795 CHECK_GE(size_with_optimized_regexp, |
| 1792 size_with_regexp + size_of_regexp_code * 2); | 1796 size_with_regexp + size_of_regexp_code * 2); |
| 1793 } | 1797 } |
| 1794 | 1798 |
| 1795 | 1799 |
| 1796 TEST(TestSizeOfObjects) { | 1800 TEST(TestSizeOfObjects) { |
| 1797 v8::V8::Initialize(); | 1801 v8::V8::Initialize(); |
| (...skipping 4161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5959 size_t counter2 = 2000; | 5963 size_t counter2 = 2000; |
| 5960 tracer->SampleAllocation(time2, counter2, counter2); | 5964 tracer->SampleAllocation(time2, counter2, counter2); |
| 5961 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); | 5965 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); |
| 5962 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); | 5966 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); |
| 5963 int time3 = 1000; | 5967 int time3 = 1000; |
| 5964 size_t counter3 = 30000; | 5968 size_t counter3 = 30000; |
| 5965 tracer->SampleAllocation(time3, counter3, counter3); | 5969 tracer->SampleAllocation(time3, counter3, counter3); |
| 5966 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); | 5970 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); |
| 5967 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); | 5971 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); |
| 5968 } | 5972 } |
| OLD | NEW |