Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: test/cctest/test-api.cc

Issue 10695206: Revert 12083: Implements a new API to set a function entry hook for profiling. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/lithium-codegen-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
37 #include "snapshot.h" 36 #include "snapshot.h"
38 #include "platform.h" 37 #include "platform.h"
39 #include "utils.h" 38 #include "utils.h"
40 #include "cctest.h" 39 #include "cctest.h"
41 #include "parser.h" 40 #include "parser.h"
42 #include "unicode-inl.h" 41 #include "unicode-inl.h"
43 42
44 static const bool kLogThreading = false; 43 static const bool kLogThreading = false;
45 44
46 static bool IsNaN(double x) { 45 static bool IsNaN(double x) {
(...skipping 10820 matching lines...) Expand 10 before | Expand all | Expand 10 after
10867 v8::Persistent<Context> env = Context::New(); 10866 v8::Persistent<Context> env = Context::New();
10868 env->Enter(); 10867 env->Enter();
10869 v8::Handle<Value> value = NestedScope(env); 10868 v8::Handle<Value> value = NestedScope(env);
10870 v8::Handle<String> str(value->ToString()); 10869 v8::Handle<String> str(value->ToString());
10871 CHECK(!str.IsEmpty()); 10870 CHECK(!str.IsEmpty());
10872 env->Exit(); 10871 env->Exit();
10873 env.Dispose(); 10872 env.Dispose();
10874 } 10873 }
10875 10874
10876 10875
10877 static i::Handle<i::JSFunction>* foo_ptr = NULL;
10878 static int foo_count = 0;
10879 static i::Handle<i::JSFunction>* bar_ptr = NULL;
10880 static int bar_count = 0;
10881
10882
10883 static void entry_hook(uintptr_t function,
10884 uintptr_t return_addr_location) {
10885 i::Code* code = i::Code::GetCodeFromTargetAddress(
10886 reinterpret_cast<i::Address>(function));
10887 CHECK(code != NULL);
10888
10889 if (bar_ptr != NULL && code == (*bar_ptr)->code())
10890 ++bar_count;
10891
10892 if (foo_ptr != NULL && code == (*foo_ptr)->code())
10893 ++foo_count;
10894
10895 // TODO(siggi): Verify return_addr_location.
10896 }
10897
10898
10899 static void RunLoopInNewEnv() {
10900 bar_ptr = NULL;
10901 foo_ptr = NULL;
10902
10903 v8::HandleScope outer;
10904 v8::Persistent<Context> env = Context::New();
10905 env->Enter();
10906
10907 const char* script =
10908 "function bar() {"
10909 " var sum = 0;"
10910 " for (i = 0; i < 100; ++i)"
10911 " sum = foo(i);"
10912 " return sum;"
10913 "}"
10914 "function foo(i) { return i * i; }";
10915 CompileRun(script);
10916 i::Handle<i::JSFunction> bar =
10917 i::Handle<i::JSFunction>::cast(
10918 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))));
10919 ASSERT(*bar);
10920
10921 i::Handle<i::JSFunction> foo =
10922 i::Handle<i::JSFunction>::cast(
10923 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))));
10924 ASSERT(*foo);
10925
10926 bar_ptr = &bar;
10927 foo_ptr = &foo;
10928
10929 v8::Handle<v8::Value> value = CompileRun("bar();");
10930 CHECK(value->IsNumber());
10931 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value());
10932
10933 // Test the optimized codegen path.
10934 value = CompileRun("%OptimizeFunctionOnNextCall(foo);"
10935 "bar();");
10936 CHECK(value->IsNumber());
10937 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value());
10938
10939 env->Exit();
10940 }
10941
10942
10943 THREADED_TEST(SetFunctionEntryHook) {
10944 i::FLAG_allow_natives_syntax = true;
10945
10946 // Test setting and resetting the entry hook.
10947 // Nulling it should always succeed.
10948 CHECK(v8::V8::SetFunctionEntryHook(NULL));
10949
10950 CHECK(v8::V8::SetFunctionEntryHook(entry_hook));
10951 // Setting a hook while one's active should fail.
10952 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook));
10953
10954 CHECK(v8::V8::SetFunctionEntryHook(NULL));
10955
10956 // Reset the entry count to zero and set the entry hook.
10957 bar_count = 0;
10958 foo_count = 0;
10959 CHECK(v8::V8::SetFunctionEntryHook(entry_hook));
10960 RunLoopInNewEnv();
10961
10962 CHECK_EQ(2, bar_count);
10963 CHECK_EQ(200, foo_count);
10964
10965 // Clear the entry hook and count.
10966 bar_count = 0;
10967 foo_count = 0;
10968 v8::V8::SetFunctionEntryHook(NULL);
10969
10970 // Clear the compilation cache to make sure we don't reuse the
10971 // functions from the previous invocation.
10972 v8::internal::Isolate::Current()->compilation_cache()->Clear();
10973
10974 // Verify that entry hooking is now disabled.
10975 RunLoopInNewEnv();
10976 CHECK(0u == bar_count);
10977 CHECK(0u == foo_count);
10978 }
10979
10980
10981 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 10876 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
10982 10877
10983 10878
10984 THREADED_TEST(ExternalAllocatedMemory) { 10879 THREADED_TEST(ExternalAllocatedMemory) {
10985 v8::HandleScope outer; 10880 v8::HandleScope outer;
10986 v8::Persistent<Context> env(Context::New()); 10881 v8::Persistent<Context> env(Context::New());
10987 CHECK(!env.IsEmpty()); 10882 CHECK(!env.IsEmpty());
10988 const intptr_t kSize = 1024*1024; 10883 const intptr_t kSize = 1024*1024;
10989 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), 10884 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)),
10990 cast(kSize)); 10885 cast(kSize));
(...skipping 5920 matching lines...) Expand 10 before | Expand all | Expand 10 after
16911 " x++; \n" 16806 " x++; \n"
16912 " throw new Error('again'); \n" // This is the new uncaught error. 16807 " throw new Error('again'); \n" // This is the new uncaught error.
16913 "} \n"; 16808 "} \n";
16914 CompileRun(throw_again); 16809 CompileRun(throw_again);
16915 CHECK(try_catch.HasCaught()); 16810 CHECK(try_catch.HasCaught());
16916 Local<Message> message = try_catch.Message(); 16811 Local<Message> message = try_catch.Message();
16917 CHECK(!message.IsEmpty()); 16812 CHECK(!message.IsEmpty());
16918 CHECK_EQ(6, message->GetLineNumber()); 16813 CHECK_EQ(6, message->GetLineNumber());
16919 } 16814 }
16920 } 16815 }
OLDNEW
« no previous file with comments | « src/x64/lithium-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698