OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include <stdlib.h> | 28 #include <stdlib.h> |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "api.h" | 32 #include "api.h" |
33 #include "compilation-cache.h" | 33 #include "compilation-cache.h" |
| 34 #include "execution.h" |
34 #include "snapshot.h" | 35 #include "snapshot.h" |
35 #include "platform.h" | 36 #include "platform.h" |
36 #include "top.h" | 37 #include "top.h" |
37 #include "cctest.h" | 38 #include "cctest.h" |
38 | 39 |
| 40 #if V8_TARGET_ARCH_IA32 |
| 41 #include "ia32/simulator-ia32.h" |
| 42 #elif V8_TARGET_ARCH_X64 |
| 43 #include "x64/simulator-x64.h" |
| 44 #elif V8_TARGET_ARCH_ARM |
| 45 #include "arm/simulator-arm.h" |
| 46 #else |
| 47 #error Unsupported target architecture. |
| 48 #endif |
| 49 |
| 50 |
39 static bool IsNaN(double x) { | 51 static bool IsNaN(double x) { |
40 #ifdef WIN32 | 52 #ifdef WIN32 |
41 return _isnan(x); | 53 return _isnan(x); |
42 #else | 54 #else |
43 return isnan(x); | 55 return isnan(x); |
44 #endif | 56 #endif |
45 } | 57 } |
46 | 58 |
47 using ::v8::ObjectTemplate; | 59 using ::v8::ObjectTemplate; |
48 using ::v8::Value; | 60 using ::v8::Value; |
(...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 "var a = new Array(); while(true) a.push(a);"; | 1731 "var a = new Array(); while(true) a.push(a);"; |
1720 | 1732 |
1721 | 1733 |
1722 // These tests run for a long time and prevent us from running tests | 1734 // These tests run for a long time and prevent us from running tests |
1723 // that come after them so they cannot run in parallel. | 1735 // that come after them so they cannot run in parallel. |
1724 TEST(OutOfMemory) { | 1736 TEST(OutOfMemory) { |
1725 // It's not possible to read a snapshot into a heap with different dimensions. | 1737 // It's not possible to read a snapshot into a heap with different dimensions. |
1726 if (v8::internal::Snapshot::IsEnabled()) return; | 1738 if (v8::internal::Snapshot::IsEnabled()) return; |
1727 // Set heap limits. | 1739 // Set heap limits. |
1728 static const int K = 1024; | 1740 static const int K = 1024; |
1729 v8::ResourceConstraints constraints; | 1741 v8::HeapResourceConstraints constraints; |
1730 constraints.set_max_young_space_size(256 * K); | 1742 constraints.set_max_young_space_size(256 * K); |
1731 constraints.set_max_old_space_size(4 * K * K); | 1743 constraints.set_max_old_space_size(4 * K * K); |
1732 v8::SetResourceConstraints(&constraints); | 1744 v8::SetHeapResourceConstraints(&constraints); |
1733 | 1745 |
1734 // Execute a script that causes out of memory. | 1746 // Execute a script that causes out of memory. |
1735 v8::HandleScope scope; | 1747 v8::HandleScope scope; |
1736 LocalContext context; | 1748 LocalContext context; |
1737 v8::V8::IgnoreOutOfMemoryException(); | 1749 v8::V8::IgnoreOutOfMemoryException(); |
1738 Local<Script> script = | 1750 Local<Script> script = |
1739 Script::Compile(String::New(js_code_causing_out_of_memory)); | 1751 Script::Compile(String::New(js_code_causing_out_of_memory)); |
1740 Local<Value> result = script->Run(); | 1752 Local<Value> result = script->Run(); |
1741 | 1753 |
1742 // Check for out of memory state. | 1754 // Check for out of memory state. |
(...skipping 17 matching lines...) Expand all Loading... |
1760 | 1772 |
1761 return result; | 1773 return result; |
1762 } | 1774 } |
1763 | 1775 |
1764 | 1776 |
1765 TEST(OutOfMemoryNested) { | 1777 TEST(OutOfMemoryNested) { |
1766 // It's not possible to read a snapshot into a heap with different dimensions. | 1778 // It's not possible to read a snapshot into a heap with different dimensions. |
1767 if (v8::internal::Snapshot::IsEnabled()) return; | 1779 if (v8::internal::Snapshot::IsEnabled()) return; |
1768 // Set heap limits. | 1780 // Set heap limits. |
1769 static const int K = 1024; | 1781 static const int K = 1024; |
1770 v8::ResourceConstraints constraints; | 1782 v8::HeapResourceConstraints constraints; |
1771 constraints.set_max_young_space_size(256 * K); | 1783 constraints.set_max_young_space_size(256 * K); |
1772 constraints.set_max_old_space_size(4 * K * K); | 1784 constraints.set_max_old_space_size(4 * K * K); |
1773 v8::SetResourceConstraints(&constraints); | 1785 v8::SetHeapResourceConstraints(&constraints); |
1774 | 1786 |
1775 v8::HandleScope scope; | 1787 v8::HandleScope scope; |
1776 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1788 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1777 templ->Set(v8_str("ProvokeOutOfMemory"), | 1789 templ->Set(v8_str("ProvokeOutOfMemory"), |
1778 v8::FunctionTemplate::New(ProvokeOutOfMemory)); | 1790 v8::FunctionTemplate::New(ProvokeOutOfMemory)); |
1779 LocalContext context(0, templ); | 1791 LocalContext context(0, templ); |
1780 v8::V8::IgnoreOutOfMemoryException(); | 1792 v8::V8::IgnoreOutOfMemoryException(); |
1781 Local<Value> result = CompileRun( | 1793 Local<Value> result = CompileRun( |
1782 "var thrown = false;" | 1794 "var thrown = false;" |
1783 "try {" | 1795 "try {" |
1784 " ProvokeOutOfMemory();" | 1796 " ProvokeOutOfMemory();" |
1785 "} catch (e) {" | 1797 "} catch (e) {" |
1786 " thrown = true;" | 1798 " thrown = true;" |
1787 "}"); | 1799 "}"); |
1788 // Check for out of memory state. | 1800 // Check for out of memory state. |
1789 CHECK(result.IsEmpty()); | 1801 CHECK(result.IsEmpty()); |
1790 CHECK(context->HasOutOfMemoryException()); | 1802 CHECK(context->HasOutOfMemoryException()); |
1791 } | 1803 } |
1792 | 1804 |
1793 | 1805 |
1794 TEST(HugeConsStringOutOfMemory) { | 1806 TEST(HugeConsStringOutOfMemory) { |
1795 // It's not possible to read a snapshot into a heap with different dimensions. | 1807 // It's not possible to read a snapshot into a heap with different dimensions. |
1796 if (v8::internal::Snapshot::IsEnabled()) return; | 1808 if (v8::internal::Snapshot::IsEnabled()) return; |
1797 v8::HandleScope scope; | 1809 v8::HandleScope scope; |
1798 LocalContext context; | 1810 LocalContext context; |
1799 // Set heap limits. | 1811 // Set heap limits. |
1800 static const int K = 1024; | 1812 static const int K = 1024; |
1801 v8::ResourceConstraints constraints; | 1813 v8::HeapResourceConstraints constraints; |
1802 constraints.set_max_young_space_size(256 * K); | 1814 constraints.set_max_young_space_size(256 * K); |
1803 constraints.set_max_old_space_size(2 * K * K); | 1815 constraints.set_max_old_space_size(2 * K * K); |
1804 v8::SetResourceConstraints(&constraints); | 1816 v8::SetHeapResourceConstraints(&constraints); |
1805 | 1817 |
1806 // Execute a script that causes out of memory. | 1818 // Execute a script that causes out of memory. |
1807 v8::V8::IgnoreOutOfMemoryException(); | 1819 v8::V8::IgnoreOutOfMemoryException(); |
1808 | 1820 |
1809 // Build huge string. This should fail with out of memory exception. | 1821 // Build huge string. This should fail with out of memory exception. |
1810 Local<Value> result = CompileRun( | 1822 Local<Value> result = CompileRun( |
1811 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" | 1823 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" |
1812 "for (var i = 0; i < 21; i++) { str = str + str; }"); | 1824 "for (var i = 0; i < 21; i++) { str = str + str; }"); |
1813 | 1825 |
1814 // Check for out of memory state. | 1826 // Check for out of memory state. |
(...skipping 4557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6372 v8::HandleScope inner; | 6384 v8::HandleScope inner; |
6373 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); | 6385 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); |
6374 local->SetInternalFieldCount(1); | 6386 local->SetInternalFieldCount(1); |
6375 templ = v8::Persistent<v8::ObjectTemplate>::New(inner.Close(local)); | 6387 templ = v8::Persistent<v8::ObjectTemplate>::New(inner.Close(local)); |
6376 } | 6388 } |
6377 v8::Handle<v8::Object> result = templ->NewInstance(); | 6389 v8::Handle<v8::Object> result = templ->NewInstance(); |
6378 CHECK_EQ(1, result->InternalFieldCount()); | 6390 CHECK_EQ(1, result->InternalFieldCount()); |
6379 } | 6391 } |
6380 | 6392 |
6381 | 6393 |
6382 // If part of the threaded tests, this test makes ThreadingTest fail | 6394 THREADED_TEST(CatchStackOverflow) { |
6383 // on mac. | |
6384 TEST(CatchStackOverflow) { | |
6385 v8::HandleScope scope; | 6395 v8::HandleScope scope; |
6386 LocalContext context; | 6396 LocalContext context; |
6387 v8::TryCatch try_catch; | 6397 v8::TryCatch try_catch; |
6388 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New( | 6398 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New( |
6389 "function f() {" | 6399 "function f() {" |
6390 " return f();" | 6400 " return f();" |
6391 "}" | 6401 "}" |
6392 "" | 6402 "" |
6393 "f();")); | 6403 "f();")); |
| 6404 |
| 6405 // the default thread stack size on OS X ia32/x64 is 512K/1M, which |
| 6406 // is too small for the 512K default V8 stack limit |
| 6407 static const int K = 1024; |
| 6408 uint32_t here; |
| 6409 v8::SetStackLimit(&here - 256 * K / sizeof(uint32_t*)); |
| 6410 |
6394 v8::Handle<v8::Value> result = script->Run(); | 6411 v8::Handle<v8::Value> result = script->Run(); |
6395 CHECK(result.IsEmpty()); | 6412 CHECK(result.IsEmpty()); |
6396 } | 6413 } |
6397 | 6414 |
6398 | 6415 |
6399 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, | 6416 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, |
6400 const char* resource_name, | 6417 const char* resource_name, |
6401 int line_offset) { | 6418 int line_offset) { |
6402 v8::HandleScope scope; | 6419 v8::HandleScope scope; |
6403 v8::TryCatch try_catch; | 6420 v8::TryCatch try_catch; |
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7872 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 7889 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
7873 } | 7890 } |
7874 | 7891 |
7875 | 7892 |
7876 // Test that idle notification can be handled when V8 has not yet been | 7893 // Test that idle notification can be handled when V8 has not yet been |
7877 // set up. | 7894 // set up. |
7878 THREADED_TEST(IdleNotification) { | 7895 THREADED_TEST(IdleNotification) { |
7879 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(true); | 7896 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(true); |
7880 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(false); | 7897 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(false); |
7881 } | 7898 } |
| 7899 |
| 7900 |
| 7901 static uintptr_t js_limit; |
| 7902 |
| 7903 |
| 7904 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) { |
| 7905 js_limit = i::StackGuard::jslimit(); |
| 7906 return v8::Undefined(); |
| 7907 } |
| 7908 |
| 7909 |
| 7910 THREADED_TEST(SetStackLimit) { |
| 7911 v8::HandleScope scope; |
| 7912 LocalContext env; |
| 7913 Local<v8::FunctionTemplate> fun_templ = |
| 7914 v8::FunctionTemplate::New(GetStackLimitCallback); |
| 7915 Local<Function> fun = fun_templ->GetFunction(); |
| 7916 env->Global()->Set(v8_str("get_stack_limit"), fun); |
| 7917 |
| 7918 // Set the stack limit. |
| 7919 static const int K = 1024; |
| 7920 uint32_t here; |
| 7921 uint32_t* limit = &here - 128 * K / sizeof(uint32_t*); |
| 7922 v8::SetStackLimit(limit); |
| 7923 CompileRun("get_stack_limit();"); |
| 7924 |
| 7925 // Must use GENERATED_CODE_STACK_LIMIT to run on the ARM simulator. |
| 7926 uintptr_t expected_limit = |
| 7927 GENERATED_CODE_STACK_LIMIT(reinterpret_cast<uintptr_t>(limit)); |
| 7928 CHECK(expected_limit == js_limit); |
| 7929 } |
OLD | NEW |