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 15 matching lines...) Expand all Loading... |
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 <limits.h> | 28 #include <limits.h> |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "api.h" | 32 #include "api.h" |
33 #include "isolate.h" | 33 #include "isolate.h" |
34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
35 #include "execution.h" | 35 #include "execution.h" |
| 36 #include "objects.h" |
36 #include "snapshot.h" | 37 #include "snapshot.h" |
37 #include "platform.h" | 38 #include "platform.h" |
38 #include "utils.h" | 39 #include "utils.h" |
39 #include "cctest.h" | 40 #include "cctest.h" |
40 #include "parser.h" | 41 #include "parser.h" |
41 #include "unicode-inl.h" | 42 #include "unicode-inl.h" |
42 | 43 |
43 static const bool kLogThreading = false; | 44 static const bool kLogThreading = false; |
44 | 45 |
45 static bool IsNaN(double x) { | 46 static bool IsNaN(double x) { |
(...skipping 10820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10866 v8::Persistent<Context> env = Context::New(); | 10867 v8::Persistent<Context> env = Context::New(); |
10867 env->Enter(); | 10868 env->Enter(); |
10868 v8::Handle<Value> value = NestedScope(env); | 10869 v8::Handle<Value> value = NestedScope(env); |
10869 v8::Handle<String> str(value->ToString()); | 10870 v8::Handle<String> str(value->ToString()); |
10870 CHECK(!str.IsEmpty()); | 10871 CHECK(!str.IsEmpty()); |
10871 env->Exit(); | 10872 env->Exit(); |
10872 env.Dispose(); | 10873 env.Dispose(); |
10873 } | 10874 } |
10874 | 10875 |
10875 | 10876 |
| 10877 static size_t entry_count = 0; |
| 10878 static uint64_t last_cycles = 0; |
| 10879 |
| 10880 |
| 10881 static void entry_hook(intptr_t function, |
| 10882 intptr_t stack_pointer, |
| 10883 uint64_t entry_time) { |
| 10884 CHECK(entry_time >= last_cycles); |
| 10885 |
| 10886 i::Code* code = i::Code::GetCodeFromTargetAddress( |
| 10887 reinterpret_cast<i::Address>(function)); |
| 10888 CHECK(code != NULL); |
| 10889 |
| 10890 // TODO(siggi): How can I reach back to the JS function objects and test |
| 10891 // some of their properties (like name)? |
| 10892 |
| 10893 last_cycles = entry_time; |
| 10894 ++entry_count; |
| 10895 } |
| 10896 |
| 10897 |
| 10898 static void RunLoopInNewEnv() { |
| 10899 v8::HandleScope outer; |
| 10900 v8::Persistent<Context> env = Context::New(); |
| 10901 env->Enter(); |
| 10902 |
| 10903 const char* script = |
| 10904 "function bar() {" |
| 10905 " var sum = 0;" |
| 10906 " for (i = 0; i < 100; ++i)" |
| 10907 " sum = foo(i);" |
| 10908 " return sum;" |
| 10909 "}" |
| 10910 "function foo(i) { return i * i; }" |
| 10911 "bar();"; |
| 10912 v8::Handle<v8::Value> value = CompileRun(script); |
| 10913 CHECK(value->IsNumber()); |
| 10914 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
| 10915 |
| 10916 // Test the optimized codegen path. |
| 10917 value = CompileRun("%OptimizeFunctionOnNextCall(foo);" |
| 10918 "bar();"); |
| 10919 CHECK(value->IsNumber()); |
| 10920 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
| 10921 |
| 10922 env->Exit(); |
| 10923 } |
| 10924 |
| 10925 |
| 10926 THREADED_TEST(SetFunctionEntryHook) { |
| 10927 i::FLAG_allow_natives_syntax = true; |
| 10928 |
| 10929 // Test setting and resetting the entry hook. |
| 10930 // Nulling it should alwasy succeed. |
| 10931 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
| 10932 |
| 10933 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
| 10934 // Setting a hook while one's active should fail. |
| 10935 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook)); |
| 10936 |
| 10937 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
| 10938 |
| 10939 // Reset the entry count to zero and set the entry hook. |
| 10940 entry_count = 0; |
| 10941 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
| 10942 RunLoopInNewEnv(); |
| 10943 // TODO(siggi): This will fail if ever V8 inlines the function foo() above. |
| 10944 CHECK_LE(204, entry_count); |
| 10945 |
| 10946 // Clear the entry hook and count. |
| 10947 entry_count = 0; |
| 10948 v8::V8::SetFunctionEntryHook(NULL); |
| 10949 |
| 10950 // Clear the compilation cache to make sure we don't reuse the |
| 10951 // functions from the previous invocation. |
| 10952 v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
| 10953 |
| 10954 // Verify that entry hooking is now disabled. |
| 10955 RunLoopInNewEnv(); |
| 10956 CHECK(0u == entry_count); |
| 10957 } |
| 10958 |
| 10959 |
10876 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } | 10960 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } |
10877 | 10961 |
10878 | 10962 |
10879 THREADED_TEST(ExternalAllocatedMemory) { | 10963 THREADED_TEST(ExternalAllocatedMemory) { |
10880 v8::HandleScope outer; | 10964 v8::HandleScope outer; |
10881 v8::Persistent<Context> env(Context::New()); | 10965 v8::Persistent<Context> env(Context::New()); |
10882 CHECK(!env.IsEmpty()); | 10966 CHECK(!env.IsEmpty()); |
10883 const intptr_t kSize = 1024*1024; | 10967 const intptr_t kSize = 1024*1024; |
10884 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), | 10968 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), |
10885 cast(kSize)); | 10969 cast(kSize)); |
(...skipping 5920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16806 " x++; \n" | 16890 " x++; \n" |
16807 " throw new Error('again'); \n" // This is the new uncaught error. | 16891 " throw new Error('again'); \n" // This is the new uncaught error. |
16808 "} \n"; | 16892 "} \n"; |
16809 CompileRun(throw_again); | 16893 CompileRun(throw_again); |
16810 CHECK(try_catch.HasCaught()); | 16894 CHECK(try_catch.HasCaught()); |
16811 Local<Message> message = try_catch.Message(); | 16895 Local<Message> message = try_catch.Message(); |
16812 CHECK(!message.IsEmpty()); | 16896 CHECK(!message.IsEmpty()); |
16813 CHECK_EQ(6, message->GetLineNumber()); | 16897 CHECK_EQ(6, message->GetLineNumber()); |
16814 } | 16898 } |
16815 } | 16899 } |
OLD | NEW |