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

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

Issue 10706002: 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
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 10855 matching lines...) Expand 10 before | Expand all | Expand 10 after
10866 v8::Persistent<Context> env = Context::New(); 10866 v8::Persistent<Context> env = Context::New();
10867 env->Enter(); 10867 env->Enter();
10868 v8::Handle<Value> value = NestedScope(env); 10868 v8::Handle<Value> value = NestedScope(env);
10869 v8::Handle<String> str(value->ToString()); 10869 v8::Handle<String> str(value->ToString());
10870 CHECK(!str.IsEmpty()); 10870 CHECK(!str.IsEmpty());
10871 env->Exit(); 10871 env->Exit();
10872 env.Dispose(); 10872 env.Dispose();
10873 } 10873 }
10874 10874
10875 10875
10876 #if defined(V8_HOST_ARCH_IA32)
10877 static size_t entry_count = 0;
10878
10879
10880 __declspec(naked) static void entry_hook() {
10881 __asm {
10882 inc entry_count
10883 ret
10884 }
10885 }
10886
10887
10888 static void RunLoopInNewEnv() {
10889 v8::HandleScope outer;
10890 v8::Persistent<Context> env = Context::New();
10891 env->Enter();
10892
10893 const char* script =
10894 "function bar() {"
10895 " var sum = 0;"
10896 " for (i = 0; i < 100; ++i)"
10897 " sum = foo(i);"
10898 " return sum;"
10899 "}"
10900 "function foo(i) { return i * i; }"
danno 2012/06/27 23:01:54 To test optimized code, you can for V8 to optimize
Sigurður Ásgeirsson 2012/06/28 10:35:34 Done.
10901 "bar();";
10902 v8::Handle<v8::Value> value = CompileRun(script);
10903 CHECK(value->IsNumber());
10904 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value());
10905 env->Exit();
10906 }
10907
10908
10909 THREADED_TEST(SetFunctionEntryHook) {
10910 // Reset the entry count to zero and set the entry hook.
10911 entry_count = 0;
10912 v8::V8::SetFunctionEntryHook(reinterpret_cast<uintptr_t>(entry_hook));
10913 RunLoopInNewEnv();
10914 // TODO(siggi): This will fail if ever V8 inlines the function foo().
10915 CHECK_LE(102, entry_count);
10916
10917 // Clear the entry hook and count.
10918 entry_count = 0;
10919 v8::V8::SetFunctionEntryHook(0);
10920
10921 // Clear the compilation cache to make sure we don't reuse the
10922 // functions from the previous invocation.
10923 v8::internal::Isolate::Current()->compilation_cache()->Clear();
10924
10925 // Verify that entry hooking is now disabled.
10926 RunLoopInNewEnv();
10927 CHECK_EQ(0, entry_count);
10928 }
10929 #endif
10930
10931
10876 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 10932 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
10877 10933
10878 10934
10879 THREADED_TEST(ExternalAllocatedMemory) { 10935 THREADED_TEST(ExternalAllocatedMemory) {
10880 v8::HandleScope outer; 10936 v8::HandleScope outer;
10881 v8::Persistent<Context> env(Context::New()); 10937 v8::Persistent<Context> env(Context::New());
10882 CHECK(!env.IsEmpty()); 10938 CHECK(!env.IsEmpty());
10883 const intptr_t kSize = 1024*1024; 10939 const intptr_t kSize = 1024*1024;
10884 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), 10940 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)),
10885 cast(kSize)); 10941 cast(kSize));
(...skipping 5920 matching lines...) Expand 10 before | Expand all | Expand 10 after
16806 " x++; \n" 16862 " x++; \n"
16807 " throw new Error('again'); \n" // This is the new uncaught error. 16863 " throw new Error('again'); \n" // This is the new uncaught error.
16808 "} \n"; 16864 "} \n";
16809 CompileRun(throw_again); 16865 CompileRun(throw_again);
16810 CHECK(try_catch.HasCaught()); 16866 CHECK(try_catch.HasCaught());
16811 Local<Message> message = try_catch.Message(); 16867 Local<Message> message = try_catch.Message();
16812 CHECK(!message.IsEmpty()); 16868 CHECK(!message.IsEmpty());
16813 CHECK_EQ(6, message->GetLineNumber()); 16869 CHECK_EQ(6, message->GetLineNumber());
16814 } 16870 }
16815 } 16871 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698