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 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Adjust source below and this check to match |
| 1616 // RegExpImple::kRegExpTooLargeToOptimize. |
| 1617 DCHECK_EQ(i::RegExpImpl::kRegExpTooLargeToOptimize, 10 * KB); |
| 1618 |
| 1619 // Compile a regexp that is much larger if we are using regexp optimizations. |
| 1620 CompileRun( |
| 1621 "var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';" |
| 1622 "var half_size_reg_exp;" |
| 1623 "while (reg_exp_source.length < 10 * 1024) {" |
| 1624 " half_size_reg_exp = reg_exp_source;" |
| 1625 " reg_exp_source = reg_exp_source + reg_exp_source;" |
| 1626 "}" |
| 1627 // Flatten string. |
| 1628 "reg_exp_source.match(/f/);"); |
| 1629 |
| 1630 // Get initial heap size after several full GCs, which will stabilize |
| 1631 // the heap size and return with sweeping finished completely. |
| 1632 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1633 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1634 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1635 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1636 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1637 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); |
| 1638 if (collector->sweeping_in_progress()) { |
| 1639 collector->EnsureSweepingCompleted(); |
| 1640 } |
| 1641 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1642 |
| 1643 CompileRun("'foo'.match(reg_exp_source);"); |
| 1644 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1645 int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1646 |
| 1647 CompileRun("'foo'.match(half_size_reg_exp);"); |
| 1648 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1649 int size_with_optimized_regexp = |
| 1650 static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1651 |
| 1652 int size_of_regexp_code = size_with_regexp - initial_size; |
| 1653 |
| 1654 CHECK_LE(size_of_regexp_code, 500 * KB); |
| 1655 |
| 1656 // Small regexp is half the size, but compiles to more than twice the code |
| 1657 // due to the optimization steps. |
| 1658 CHECK_GE(size_with_optimized_regexp, |
| 1659 size_with_regexp + size_of_regexp_code * 2); |
| 1660 } |
| 1661 |
| 1662 |
1605 TEST(TestSizeOfObjects) { | 1663 TEST(TestSizeOfObjects) { |
1606 v8::V8::Initialize(); | 1664 v8::V8::Initialize(); |
1607 | 1665 |
1608 // Get initial heap size after several full GCs, which will stabilize | 1666 // Get initial heap size after several full GCs, which will stabilize |
1609 // the heap size and return with sweeping finished completely. | 1667 // the heap size and return with sweeping finished completely. |
1610 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1668 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1611 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1669 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1612 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1670 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1613 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1671 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
1614 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1672 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
(...skipping 2890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4505 #ifdef DEBUG | 4563 #ifdef DEBUG |
4506 TEST(PathTracer) { | 4564 TEST(PathTracer) { |
4507 CcTest::InitializeVM(); | 4565 CcTest::InitializeVM(); |
4508 v8::HandleScope scope(CcTest::isolate()); | 4566 v8::HandleScope scope(CcTest::isolate()); |
4509 | 4567 |
4510 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4568 v8::Local<v8::Value> result = CompileRun("'abc'"); |
4511 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4569 Handle<Object> o = v8::Utils::OpenHandle(*result); |
4512 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4570 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
4513 } | 4571 } |
4514 #endif // DEBUG | 4572 #endif // DEBUG |
OLD | NEW |