Chromium Code Reviews| 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 " a = a[1];" | 764 " a = a[1];" |
| 765 "}" | 765 "}" |
| 766 "sum"; | 766 "sum"; |
| 767 v8::Maybe<int32_t> result = | 767 v8::Maybe<int32_t> result = |
| 768 CompileRun(test)->Int32Value(isolate->GetCurrentContext()); | 768 CompileRun(test)->Int32Value(isolate->GetCurrentContext()); |
| 769 CHECK_EQ(9999 * 5000, result.FromJust()); | 769 CHECK_EQ(9999 * 5000, result.FromJust()); |
| 770 } | 770 } |
| 771 isolate->Dispose(); | 771 isolate->Dispose(); |
| 772 } | 772 } |
| 773 | 773 |
| 774 bool IsCompiled(const char* name) { | |
| 775 return i::Handle<i::JSFunction>::cast( | |
| 776 v8::Utils::OpenHandle(*CompileRun(name))) | |
| 777 ->shared() | |
| 778 ->is_compiled(); | |
| 779 } | |
| 780 | |
| 781 TEST(SnapshotDataBlobWithWarmup) { | |
| 782 DisableTurbofan(); | |
| 783 const char* warmup = "Math.tan(1); Math.sin = 1;"; | |
| 784 | |
| 785 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob(); | |
| 786 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup); | |
| 787 delete[] cold.data; | |
| 788 | |
| 789 v8::Isolate::CreateParams params; | |
| 790 params.snapshot_blob = &warm; | |
| 791 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | |
| 792 | |
| 793 v8::Isolate* isolate = v8::Isolate::New(params); | |
| 794 { | |
| 795 v8::Isolate::Scope i_scope(isolate); | |
| 796 v8::HandleScope h_scope(isolate); | |
| 797 v8::Local<v8::Context> context = v8::Context::New(isolate); | |
| 798 delete[] warm.data; | |
| 799 v8::Context::Scope c_scope(context); | |
| 800 // Running the warmup script has effect on whether functions are | |
| 801 // pre-compiled, but does not pollute the context. | |
| 802 CHECK(IsCompiled("Math.tan")); | |
| 803 CHECK(!IsCompiled("Math.cos")); | |
| 804 CHECK(CompileRun("Math.sin")->IsFunction()); | |
|
vogelheim
2016/03/16 14:52:36
Just for my understanding: You garble Math.sin in
Yang
2016/03/16 15:05:38
exactly.
| |
| 805 } | |
| 806 isolate->Dispose(); | |
| 807 } | |
| 808 | |
| 809 TEST(CustomSnapshotDataBlobWithWarmup) { | |
| 810 DisableTurbofan(); | |
| 811 const char* source = | |
| 812 "function f() { return Math.sin(1); }\n" | |
| 813 "function g() { return Math.cos(1); }\n" | |
| 814 "Math.tan(1);" | |
| 815 "var a = 5"; | |
| 816 const char* warmup = "a = f()"; | |
| 817 | |
| 818 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob(source); | |
| 819 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup); | |
| 820 delete[] cold.data; | |
| 821 | |
| 822 v8::Isolate::CreateParams params; | |
| 823 params.snapshot_blob = &warm; | |
| 824 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | |
| 825 | |
| 826 v8::Isolate* isolate = v8::Isolate::New(params); | |
| 827 { | |
| 828 v8::Isolate::Scope i_scope(isolate); | |
| 829 v8::HandleScope h_scope(isolate); | |
| 830 v8::Local<v8::Context> context = v8::Context::New(isolate); | |
| 831 delete[] warm.data; | |
| 832 v8::Context::Scope c_scope(context); | |
| 833 // Running the warmup script has effect on whether functions are | |
| 834 // pre-compiled, but does not pollute the context. | |
| 835 CHECK(IsCompiled("f")); | |
| 836 CHECK(IsCompiled("Math.sin")); | |
| 837 CHECK(!IsCompiled("g")); | |
| 838 CHECK(!IsCompiled("Math.cos")); | |
| 839 CHECK(!IsCompiled("Math.tan")); | |
| 840 CHECK_EQ(5, CompileRun("a")->Int32Value(context).FromJust()); | |
| 841 } | |
| 842 isolate->Dispose(); | |
| 843 } | |
| 774 | 844 |
| 775 TEST(TestThatAlwaysSucceeds) { | 845 TEST(TestThatAlwaysSucceeds) { |
| 776 } | 846 } |
| 777 | 847 |
| 778 | 848 |
| 779 TEST(TestThatAlwaysFails) { | 849 TEST(TestThatAlwaysFails) { |
| 780 bool ArtificialFailure = false; | 850 bool ArtificialFailure = false; |
| 781 CHECK(ArtificialFailure); | 851 CHECK(ArtificialFailure); |
| 782 } | 852 } |
| 783 | 853 |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 delete script_data; | 1791 delete script_data; |
| 1722 } | 1792 } |
| 1723 | 1793 |
| 1724 | 1794 |
| 1725 TEST(SerializationMemoryStats) { | 1795 TEST(SerializationMemoryStats) { |
| 1726 FLAG_profile_deserialization = true; | 1796 FLAG_profile_deserialization = true; |
| 1727 FLAG_always_opt = false; | 1797 FLAG_always_opt = false; |
| 1728 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 1798 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 1729 delete[] blob.data; | 1799 delete[] blob.data; |
| 1730 } | 1800 } |
| OLD | NEW |