OLD | NEW |
1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 ->Run(isolate2->GetCurrentContext()) | 1680 ->Run(isolate2->GetCurrentContext()) |
1681 .ToLocalChecked(); | 1681 .ToLocalChecked(); |
1682 v8::Local<v8::String> result_str = | 1682 v8::Local<v8::String> result_str = |
1683 result->ToString(isolate2->GetCurrentContext()).ToLocalChecked(); | 1683 result->ToString(isolate2->GetCurrentContext()).ToLocalChecked(); |
1684 CHECK(result_str->Equals(isolate2->GetCurrentContext(), v8_str("XY")) | 1684 CHECK(result_str->Equals(isolate2->GetCurrentContext(), v8_str("XY")) |
1685 .FromJust()); | 1685 .FromJust()); |
1686 } | 1686 } |
1687 isolate2->Dispose(); | 1687 isolate2->Dispose(); |
1688 } | 1688 } |
1689 | 1689 |
1690 TEST(CodeSerializerInternalReference) { | |
1691 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_ARM64 | |
1692 return; | |
1693 #endif | |
1694 // In ignition there are only relative jumps, so the following code | |
1695 // would not have any internal references. This test is not relevant | |
1696 // for ignition. | |
1697 if (FLAG_ignition || FLAG_turbo) { | |
1698 return; | |
1699 } | |
1700 // Disable experimental natives that are loaded after deserialization. | |
1701 FLAG_function_context_specialization = false; | |
1702 FLAG_always_opt = true; | |
1703 const char* flag = "--turbo-filter=foo"; | |
1704 FlagList::SetFlagsFromString(flag, StrLength(flag)); | |
1705 | |
1706 const char* source = | |
1707 "var foo = (function(stdlib, foreign, heap) {" | |
1708 " function foo(i) {" | |
1709 " i = i|0;" | |
1710 " var j = 0;" | |
1711 " switch (i) {" | |
1712 " case 0:" | |
1713 " case 1: j = 1; break;" | |
1714 " case 2:" | |
1715 " case 3: j = 2; break;" | |
1716 " case 4:" | |
1717 " case 5: j = foo(3) + 1; break;" | |
1718 " default: j = 0; break;" | |
1719 " }" | |
1720 " return j + 10;" | |
1721 " }" | |
1722 " return { foo: foo };" | |
1723 "})(this, {}, undefined).foo;" | |
1724 "foo(1);"; | |
1725 | |
1726 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source); | |
1727 CHECK(data.data); | |
1728 | |
1729 v8::Isolate::CreateParams params; | |
1730 params.snapshot_blob = &data; | |
1731 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | |
1732 v8::Isolate* isolate = v8::Isolate::New(params); | |
1733 { | |
1734 v8::Isolate::Scope i_scope(isolate); | |
1735 v8::HandleScope h_scope(isolate); | |
1736 v8::Local<v8::Context> context = v8::Context::New(isolate); | |
1737 delete[] data.data; // We can dispose of the snapshot blob now. | |
1738 v8::Context::Scope c_scope(context); | |
1739 v8::Local<v8::Function> foo = | |
1740 v8::Local<v8::Function>::Cast(CompileRun("foo")); | |
1741 | |
1742 // There are at least 6 internal references. | |
1743 int mask = RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) | | |
1744 RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED); | |
1745 RelocIterator it( | |
1746 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*foo))->code(), mask); | |
1747 for (int i = 0; i < 6; ++i) { | |
1748 CHECK(!it.done()); | |
1749 it.next(); | |
1750 } | |
1751 | |
1752 CHECK(Handle<JSFunction>::cast(v8::Utils::OpenHandle(*foo)) | |
1753 ->code() | |
1754 ->is_turbofanned()); | |
1755 CHECK_EQ(11, CompileRun("foo(0)") | |
1756 ->Int32Value(isolate->GetCurrentContext()) | |
1757 .FromJust()); | |
1758 CHECK_EQ(11, CompileRun("foo(1)") | |
1759 ->Int32Value(isolate->GetCurrentContext()) | |
1760 .FromJust()); | |
1761 CHECK_EQ(12, CompileRun("foo(2)") | |
1762 ->Int32Value(isolate->GetCurrentContext()) | |
1763 .FromJust()); | |
1764 CHECK_EQ(12, CompileRun("foo(3)") | |
1765 ->Int32Value(isolate->GetCurrentContext()) | |
1766 .FromJust()); | |
1767 CHECK_EQ(23, CompileRun("foo(4)") | |
1768 ->Int32Value(isolate->GetCurrentContext()) | |
1769 .FromJust()); | |
1770 CHECK_EQ(23, CompileRun("foo(5)") | |
1771 ->Int32Value(isolate->GetCurrentContext()) | |
1772 .FromJust()); | |
1773 CHECK_EQ(10, CompileRun("foo(6)") | |
1774 ->Int32Value(isolate->GetCurrentContext()) | |
1775 .FromJust()); | |
1776 } | |
1777 isolate->Dispose(); | |
1778 } | |
1779 | |
1780 TEST(CodeSerializerEagerCompilationAndPreAge) { | 1690 TEST(CodeSerializerEagerCompilationAndPreAge) { |
1781 if (FLAG_ignition || FLAG_turbo) return; | 1691 if (FLAG_ignition || FLAG_turbo) return; |
1782 | 1692 |
1783 FLAG_lazy = true; | 1693 FLAG_lazy = true; |
1784 FLAG_serialize_toplevel = true; | 1694 FLAG_serialize_toplevel = true; |
1785 FLAG_serialize_age_code = true; | 1695 FLAG_serialize_age_code = true; |
1786 FLAG_serialize_eager = true; | 1696 FLAG_serialize_eager = true; |
1787 | 1697 |
1788 static const char* source = | 1698 static const char* source = |
1789 "function f() {" | 1699 "function f() {" |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2546 } | 2456 } |
2547 delete[] blob.data; | 2457 delete[] blob.data; |
2548 } | 2458 } |
2549 | 2459 |
2550 TEST(SerializationMemoryStats) { | 2460 TEST(SerializationMemoryStats) { |
2551 FLAG_profile_deserialization = true; | 2461 FLAG_profile_deserialization = true; |
2552 FLAG_always_opt = false; | 2462 FLAG_always_opt = false; |
2553 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2463 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2554 delete[] blob.data; | 2464 delete[] blob.data; |
2555 } | 2465 } |
OLD | NEW |