Chromium Code Reviews| Index: test/cctest/test-heap.cc |
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc |
| index ee476db6cdc4729b1a65a560fe03734a65f2bfdb..42213552eb90723ad0d7e4c8d53e39e70a0d9b99 100644 |
| --- a/test/cctest/test-heap.cc |
| +++ b/test/cctest/test-heap.cc |
| @@ -1602,6 +1602,60 @@ TEST(TestInternalWeakListsTraverseWithGC) { |
| } |
| +TEST(TestSizeOfRegExpCode) { |
| + if (!FLAG_regexp_optimization) return; |
| + |
| + v8::V8::Initialize(); |
| + |
| + Isolate* isolate = CcTest::i_isolate(); |
| + HandleScope scope(isolate); |
| + |
| + LocalContext context; |
| + |
| + // Compile a regexp that is much larger if we are using regexp optimizations. |
| + CompileRun( |
| + "var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';" |
| + "var half_size_reg_exp;" |
| + "while (reg_exp_source.length < 10000) {" |
|
Jakob Kummerow
2014/12/15 20:00:29
The limit here mirrors kRegExpTooLargeToOptimize,
Erik Corry
2014/12/16 12:05:33
Done.
|
| + " half_size_reg_exp = reg_exp_source;" |
| + " reg_exp_source = reg_exp_source + reg_exp_source;" |
| + "}" |
| + // Flatten string. |
| + "reg_exp_source.match(/f/);"); |
| + |
| + // Get initial heap size after several full GCs, which will stabilize |
| + // the heap size and return with sweeping finished completely. |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); |
| + if (collector->sweeping_in_progress()) { |
| + collector->EnsureSweepingCompleted(); |
| + } |
| + int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| + |
| + CompileRun("'foo'.match(reg_exp_source);"); |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| + |
| + CompileRun("'foo'.match(half_size_reg_exp);"); |
| + CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| + int size_with_optimized_regexp = |
| + static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| + |
| + int size_of_regexp_code = size_with_regexp - initial_size; |
| + |
| + CHECK_LE(size_of_regexp_code, 500 * KB); |
| + |
| + // Small regexp is half the size, but compiles to more than twice the code |
| + // due to the optimization steps. |
| + CHECK_GE(size_with_optimized_regexp, |
| + size_with_regexp + size_of_regexp_code * 2); |
| +} |
| + |
| + |
| TEST(TestSizeOfObjects) { |
| v8::V8::Initialize(); |