Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/cctest/test-heap.cc

Issue 799403003: Limit code size generated for very large regexps (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/jsregexp.cc ('K') | « src/jsregexp.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0])); 1595 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[0]));
1596 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2)); 1596 CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 2));
1597 CompileRun("f5()"); 1597 CompileRun("f5()");
1598 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0])); 1598 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[0]));
1599 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4)); 1599 CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctionsWithGC(ctx[0], 4));
1600 1600
1601 ctx[0]->Exit(); 1601 ctx[0]->Exit();
1602 } 1602 }
1603 1603
1604 1604
1605 TEST(TestSizeOfRegExpCode) {
1606 if (!FLAG_regexp_optimization) return;
1607
1608 v8::V8::Initialize();
1609
1610 Isolate* isolate = CcTest::i_isolate();
1611 HandleScope scope(isolate);
1612
1613 LocalContext context;
1614
1615 // Compile a regexp that is much larger if we are using regexp optimizations.
1616 CompileRun(
1617 "var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';"
1618 "var half_size_reg_exp;"
1619 "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.
1620 " half_size_reg_exp = reg_exp_source;"
1621 " reg_exp_source = reg_exp_source + reg_exp_source;"
1622 "}"
1623 // Flatten string.
1624 "reg_exp_source.match(/f/);");
1625
1626 // Get initial heap size after several full GCs, which will stabilize
1627 // the heap size and return with sweeping finished completely.
1628 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1629 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1630 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1631 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1632 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1633 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
1634 if (collector->sweeping_in_progress()) {
1635 collector->EnsureSweepingCompleted();
1636 }
1637 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects());
1638
1639 CompileRun("'foo'.match(reg_exp_source);");
1640 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1641 int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects());
1642
1643 CompileRun("'foo'.match(half_size_reg_exp);");
1644 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1645 int size_with_optimized_regexp =
1646 static_cast<int>(CcTest::heap()->SizeOfObjects());
1647
1648 int size_of_regexp_code = size_with_regexp - initial_size;
1649
1650 CHECK_LE(size_of_regexp_code, 500 * KB);
1651
1652 // Small regexp is half the size, but compiles to more than twice the code
1653 // due to the optimization steps.
1654 CHECK_GE(size_with_optimized_regexp,
1655 size_with_regexp + size_of_regexp_code * 2);
1656 }
1657
1658
1605 TEST(TestSizeOfObjects) { 1659 TEST(TestSizeOfObjects) {
1606 v8::V8::Initialize(); 1660 v8::V8::Initialize();
1607 1661
1608 // Get initial heap size after several full GCs, which will stabilize 1662 // Get initial heap size after several full GCs, which will stabilize
1609 // the heap size and return with sweeping finished completely. 1663 // the heap size and return with sweeping finished completely.
1610 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1664 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1611 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1665 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1612 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1666 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1613 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1667 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
1614 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); 1668 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
(...skipping 2890 matching lines...) Expand 10 before | Expand all | Expand 10 after
4505 #ifdef DEBUG 4559 #ifdef DEBUG
4506 TEST(PathTracer) { 4560 TEST(PathTracer) {
4507 CcTest::InitializeVM(); 4561 CcTest::InitializeVM();
4508 v8::HandleScope scope(CcTest::isolate()); 4562 v8::HandleScope scope(CcTest::isolate());
4509 4563
4510 v8::Local<v8::Value> result = CompileRun("'abc'"); 4564 v8::Local<v8::Value> result = CompileRun("'abc'");
4511 Handle<Object> o = v8::Utils::OpenHandle(*result); 4565 Handle<Object> o = v8::Utils::OpenHandle(*result);
4512 CcTest::i_isolate()->heap()->TracePathToObject(*o); 4566 CcTest::i_isolate()->heap()->TracePathToObject(*o);
4513 } 4567 }
4514 #endif // DEBUG 4568 #endif // DEBUG
OLDNEW
« src/jsregexp.cc ('K') | « src/jsregexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698