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

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

Issue 10795074: Add a new API V8::SetJitCodeEventHandler to push code name and location to users such as profilers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix instruction address calculation on move events. Fix test use of map, fix compilation on Win64. Created 8 years, 3 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/serialize.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 10963 matching lines...) Expand 10 before | Expand all | Expand 10 after
10974 reinterpret_cast<i::Address>(function)); 10974 reinterpret_cast<i::Address>(function));
10975 CHECK(code != NULL); 10975 CHECK(code != NULL);
10976 10976
10977 if (bar_ptr != NULL && code == (*bar_ptr)->code()) 10977 if (bar_ptr != NULL && code == (*bar_ptr)->code())
10978 ++bar_count; 10978 ++bar_count;
10979 10979
10980 if (foo_ptr != NULL && code == (*foo_ptr)->code()) 10980 if (foo_ptr != NULL && code == (*foo_ptr)->code())
10981 ++foo_count; 10981 ++foo_count;
10982 10982
10983 // TODO(siggi): Verify return_addr_location. 10983 // TODO(siggi): Verify return_addr_location.
10984 // This can be done by capturing JitCodeEvents, but requires an ordered
10985 // collection.
10984 } 10986 }
10985 10987
10986 10988
10987 static void RunLoopInNewEnv() { 10989 static void RunLoopInNewEnv() {
10988 bar_ptr = NULL; 10990 bar_ptr = NULL;
10989 foo_ptr = NULL; 10991 foo_ptr = NULL;
10990 10992
10991 v8::HandleScope outer; 10993 v8::HandleScope outer;
10992 v8::Persistent<Context> env = Context::New(); 10994 v8::Persistent<Context> env = Context::New();
10993 env->Enter(); 10995 env->Enter();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
11059 // functions from the previous invocation. 11061 // functions from the previous invocation.
11060 v8::internal::Isolate::Current()->compilation_cache()->Clear(); 11062 v8::internal::Isolate::Current()->compilation_cache()->Clear();
11061 11063
11062 // Verify that entry hooking is now disabled. 11064 // Verify that entry hooking is now disabled.
11063 RunLoopInNewEnv(); 11065 RunLoopInNewEnv();
11064 CHECK_EQ(0u, bar_count); 11066 CHECK_EQ(0u, bar_count);
11065 CHECK_EQ(0u, foo_count); 11067 CHECK_EQ(0u, foo_count);
11066 } 11068 }
11067 11069
11068 11070
11071 static i::HashMap* code_map = NULL;
11072 static int saw_bar = 0;
11073 static int move_events = 0;
11074
11075
11076 static bool FunctionNameIs(const char* expected,
11077 const v8::JitCodeEvent* event) {
11078 // Log lines for functions are of the general form:
11079 // "LazyCompile:<type><function_name>", where the type is one of
11080 // "*", "~" or "".
11081 static const char kPreamble[] = "LazyCompile:";
11082 static size_t kPreambleLen = sizeof(kPreamble) - 1;
11083
11084 if (event->name.len < sizeof(kPreamble) - 1 ||
11085 strncmp(kPreamble, event->name.str, kPreambleLen) != 0) {
11086 return false;
11087 }
11088
11089 const char* tail = event->name.str + kPreambleLen;
11090 size_t tail_len = event->name.len - kPreambleLen;
11091 size_t expected_len = strlen(expected);
11092 if (tail_len == expected_len + 1) {
11093 if (*tail == '*' || *tail == '~') {
11094 --tail_len;
11095 ++tail;
11096 } else {
11097 return false;
11098 }
11099 }
11100
11101 if (tail_len != expected_len)
11102 return false;
11103
11104 return strncmp(tail, expected, expected_len) == 0;
11105 }
11106
11107
11108 static void event_handler(const v8::JitCodeEvent* event) {
11109 CHECK(event != NULL);
11110 CHECK(code_map != NULL);
11111
11112 switch(event->type) {
11113 case v8::JitCodeEvent::CODE_ADDED: {
11114 CHECK(event->code_start != NULL);
11115 CHECK(event->code_len != 0);
11116 CHECK(event->name.str != NULL);
11117 i::HashMap::Entry* entry =
11118 code_map->Lookup(event->code_start,
11119 i::ComputePointerHash(event->code_start),
11120 true);
11121 entry->value = reinterpret_cast<void*>(event->code_len);
11122
11123 if (FunctionNameIs("bar", event)) {
11124 ++saw_bar;
11125 }
11126 }
11127 break;
11128
11129 case v8::JitCodeEvent::CODE_MOVED: {
11130 ++move_events;
11131
11132 uint32_t hash = i::ComputePointerHash(event->code_start);
11133 // We should never see code move that we haven't seen before.
11134 i::HashMap::Entry* entry =
11135 code_map->Lookup(event->code_start, hash, false);
11136 CHECK(entry != NULL);
11137 CHECK_EQ(reinterpret_cast<void*>(event->code_len), entry->value);
11138 code_map->Remove(event->code_start, hash);
11139
11140 entry = code_map->Lookup(event->new_code_start,
11141 i::ComputePointerHash(event->new_code_start),
11142 true);
11143 CHECK(entry != NULL);
11144 entry->value = reinterpret_cast<void*>(event->code_len);
11145 }
11146 break;
11147
11148 case v8::JitCodeEvent::CODE_REMOVED:
11149 // Object/code removal events are currently not dispatched from the GC.
11150 CHECK(false);
11151 break;
11152 default:
11153 // Impossible event.
11154 CHECK(false);
11155 break;
11156 }
11157 }
11158
11159
11160 // Implemented in the test-alloc.cc test suite.
11161 void SimulateFullSpace(i::PagedSpace* space);
11162
11163
11164 static bool MatchPointers(void* key1, void* key2) {
11165 return key1 == key2;
11166 }
11167
11168
11169 TEST(SetJitCodeEventHandler) {
11170 const char* script =
11171 "function bar() {"
11172 " var sum = 0;"
11173 " for (i = 0; i < 100; ++i)"
11174 " sum = foo(i);"
11175 " return sum;"
11176 "}"
11177 "function foo(i) { return i * i; };"
11178 "bar();";
11179
11180 // Run this test in a new isolate to make sure we don't
11181 // have remnants of state from other code.
11182 v8::Isolate* isolate = v8::Isolate::New();
11183 isolate->Enter();
11184
11185 {
11186 i::HashMap code(MatchPointers);
11187 code_map = &code;
11188
11189 saw_bar = 0;
11190 move_events = 0;
11191
11192 i::FLAG_stress_compaction = true;
11193 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
11194
11195 v8::HandleScope scope;
11196 // Generate new code objects sparsely distributed across several
11197 // different fragmented code-space pages.
11198 const int kIterations = 10;
11199 for (int i = 0; i < kIterations; ++i) {
11200 LocalContext env;
11201
11202 v8::Handle<v8::Script> compiled_script;
11203 {
11204 i::AlwaysAllocateScope always_allocate;
11205 SimulateFullSpace(HEAP->code_space());
11206 compiled_script = v8_compile(script);
11207 }
11208 compiled_script->Run();
11209
11210 // Clear the compilation cache to get more wastage.
11211 ISOLATE->compilation_cache()->Clear();
11212 }
11213
11214 // Force code movement.
11215 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler");
11216
11217 CHECK_LE(kIterations, saw_bar);
11218 CHECK_NE(0, move_events);
11219
11220 code_map = NULL;
11221 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
11222 }
11223
11224 isolate->Exit();
11225 isolate->Dispose();
11226
11227 // Do this in a new isolate.
11228 isolate = v8::Isolate::New();
11229 isolate->Enter();
11230
11231 // Verify that we get callbacks for existing code objects when we
11232 // request enumeration of existing code.
11233 {
11234 v8::HandleScope scope;
11235 LocalContext env;
11236 CompileRun(script);
11237
11238 // Now get code through initial iteration.
11239 i::HashMap code(MatchPointers);
11240 code_map = &code;
11241
11242 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler);
11243 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
11244
11245 code_map = NULL;
11246
11247 // We expect that we got some events. Note that if we could get code removal
11248 // notifications, we could compare two collections, one created by listening
11249 // from the time of creation of an isolate, and the other by subscribing
11250 // with EnumExisting.
11251 CHECK_NE(0, code.occupancy());
11252 }
11253
11254 isolate->Exit();
11255 isolate->Dispose();
11256 }
11257
11258
11069 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 11259 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
11070 11260
11071 11261
11072 THREADED_TEST(ExternalAllocatedMemory) { 11262 THREADED_TEST(ExternalAllocatedMemory) {
11073 v8::HandleScope outer; 11263 v8::HandleScope outer;
11074 v8::Persistent<Context> env(Context::New()); 11264 v8::Persistent<Context> env(Context::New());
11075 CHECK(!env.IsEmpty()); 11265 CHECK(!env.IsEmpty());
11076 const intptr_t kSize = 1024*1024; 11266 const intptr_t kSize = 1024*1024;
11077 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), 11267 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)),
11078 cast(kSize)); 11268 cast(kSize));
(...skipping 6168 matching lines...) Expand 10 before | Expand all | Expand 10 after
17247 17437
17248 i::Semaphore* sem_; 17438 i::Semaphore* sem_;
17249 volatile int sem_value_; 17439 volatile int sem_value_;
17250 }; 17440 };
17251 17441
17252 17442
17253 THREADED_TEST(SemaphoreInterruption) { 17443 THREADED_TEST(SemaphoreInterruption) {
17254 ThreadInterruptTest().RunTest(); 17444 ThreadInterruptTest().RunTest();
17255 } 17445 }
17256 #endif // WIN32 17446 #endif // WIN32
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698