| 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 12270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12281 | 12281 |
| 12282 static void entry_hook(uintptr_t function, | 12282 static void entry_hook(uintptr_t function, |
| 12283 uintptr_t return_addr_location) { | 12283 uintptr_t return_addr_location) { |
| 12284 i::Code* code = i::Code::GetCodeFromTargetAddress( | 12284 i::Code* code = i::Code::GetCodeFromTargetAddress( |
| 12285 reinterpret_cast<i::Address>(function)); | 12285 reinterpret_cast<i::Address>(function)); |
| 12286 CHECK(code != NULL); | 12286 CHECK(code != NULL); |
| 12287 | 12287 |
| 12288 if (bar_ptr != NULL && code == (*bar_ptr)->code()) | 12288 if (bar_ptr != NULL && code == (*bar_ptr)->code()) |
| 12289 ++bar_entry_count; | 12289 ++bar_entry_count; |
| 12290 | 12290 |
| 12291 if (foo_ptr != NULL && code == (*foo_ptr)->code()) | 12291 if (foo_ptr != NULL && code == (*foo_ptr)->code()) { |
| 12292 ++foo_entry_count; | 12292 ++foo_entry_count; |
| 12293 | 12293 |
| 12294 // Let's check whether bar is the caller. | 12294 // Count the bar->foo calls. |
| 12295 if (bar_ptr != NULL) { | 12295 if (bar_ptr != NULL) { |
| 12296 const v8::internal::byte* caller = | 12296 const v8::internal::byte* caller = |
| 12297 *reinterpret_cast<v8::internal::byte**>(return_addr_location); | 12297 *reinterpret_cast<v8::internal::byte**>(return_addr_location); |
| 12298 | 12298 |
| 12299 if ((*bar_ptr)->code()->instruction_start() <= caller && | 12299 if ((*bar_ptr)->code()->instruction_start() <= caller && |
| 12300 (*bar_ptr)->code()->instruction_end() > caller) { | 12300 (*bar_ptr)->code()->instruction_end() > caller) { |
| 12301 ++bar_caller_count; | 12301 ++bar_caller_count; |
| 12302 } |
| 12302 } | 12303 } |
| 12303 } | 12304 } |
| 12304 } | 12305 } |
| 12305 | 12306 |
| 12306 | 12307 |
| 12307 static void RunLoopInNewEnv() { | 12308 static void RunLoopInNewEnv(v8::Isolate* isolate) { |
| 12308 bar_ptr = NULL; | 12309 bar_ptr = NULL; |
| 12309 foo_ptr = NULL; | 12310 foo_ptr = NULL; |
| 12310 | 12311 |
| 12311 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 12312 v8::HandleScope outer(isolate); | 12312 v8::HandleScope outer(isolate); |
| 12313 v8::Local<Context> env = Context::New(isolate); | 12313 v8::Local<Context> env = Context::New(isolate); |
| 12314 env->Enter(); | 12314 env->Enter(); |
| 12315 | 12315 |
| 12316 const char* script = | 12316 const char* script = |
| 12317 "function bar() {" | 12317 "function bar() {" |
| 12318 " var sum = 0;" | 12318 " var sum = 0;" |
| 12319 " for (i = 0; i < 100; ++i)" | 12319 " for (i = 0; i < 100; ++i)" |
| 12320 " sum = foo(i);" | 12320 " sum = foo(i);" |
| 12321 " return sum;" | 12321 " return sum;" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12353 // FunctionEntryHook does not work well with experimental natives. | 12353 // FunctionEntryHook does not work well with experimental natives. |
| 12354 // Experimental natives are compiled during snapshot deserialization. | 12354 // Experimental natives are compiled during snapshot deserialization. |
| 12355 // This test breaks because InstallGetter (function from snapshot that | 12355 // This test breaks because InstallGetter (function from snapshot that |
| 12356 // only gets called from experimental natives) is compiled with entry hooks. | 12356 // only gets called from experimental natives) is compiled with entry hooks. |
| 12357 i::FLAG_harmony_typed_arrays = false; | 12357 i::FLAG_harmony_typed_arrays = false; |
| 12358 i::FLAG_harmony_array_buffer = false; | 12358 i::FLAG_harmony_array_buffer = false; |
| 12359 | 12359 |
| 12360 i::FLAG_allow_natives_syntax = true; | 12360 i::FLAG_allow_natives_syntax = true; |
| 12361 i::FLAG_use_inlining = false; | 12361 i::FLAG_use_inlining = false; |
| 12362 | 12362 |
| 12363 // Test setting and resetting the entry hook. | 12363 // Test setting and resetting the entry hook on the current isolate. |
| 12364 // Nulling it should always succeed. | 12364 // Nulling it should always succeed. |
| 12365 CHECK(v8::V8::SetFunctionEntryHook(NULL)); | 12365 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
| 12366 | 12366 |
| 12367 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); | 12367 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
| 12368 // Setting a hook while one's active should fail. | 12368 // Setting a hook while one's active should fail. |
| 12369 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook)); | 12369 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook)); |
| 12370 | 12370 |
| 12371 CHECK(v8::V8::SetFunctionEntryHook(NULL)); | 12371 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
| 12372 | 12372 |
| 12373 // Reset the entry count to zero and set the entry hook. | 12373 v8::Isolate* isolate = v8::Isolate::New(); |
| 12374 bar_entry_count = 0; | 12374 { |
| 12375 bar_caller_count = 0; | 12375 v8::Isolate::Scope scope(isolate); |
| 12376 foo_entry_count = 0; | |
| 12377 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); | |
| 12378 RunLoopInNewEnv(); | |
| 12379 | 12376 |
| 12380 CHECK_EQ(2, bar_entry_count); | 12377 // Reset the entry count to zero and set the entry hook. |
| 12381 CHECK_EQ(200, bar_caller_count); | 12378 bar_entry_count = 0; |
| 12382 CHECK_EQ(200, foo_entry_count); | 12379 bar_caller_count = 0; |
| 12380 foo_entry_count = 0; |
| 12381 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
| 12382 RunLoopInNewEnv(isolate); |
| 12383 | 12383 |
| 12384 // Clear the entry hook and count. | 12384 CHECK_EQ(2, bar_entry_count); |
| 12385 bar_entry_count = 0; | 12385 CHECK_EQ(200, bar_caller_count); |
| 12386 bar_caller_count = 0; | 12386 CHECK_EQ(200, foo_entry_count); |
| 12387 foo_entry_count = 0; | |
| 12388 v8::V8::SetFunctionEntryHook(NULL); | |
| 12389 | 12387 |
| 12390 // Clear the compilation cache to make sure we don't reuse the | 12388 // Clear the entry hook and count. |
| 12391 // functions from the previous invocation. | 12389 bar_entry_count = 0; |
| 12392 v8::internal::Isolate::Current()->compilation_cache()->Clear(); | 12390 bar_caller_count = 0; |
| 12391 foo_entry_count = 0; |
| 12392 v8::V8::SetFunctionEntryHook(NULL); |
| 12393 | 12393 |
| 12394 // Verify that entry hooking is now disabled. | 12394 // Clear the compilation cache to make sure we don't reuse the |
| 12395 RunLoopInNewEnv(); | 12395 // functions from the previous invocation. |
| 12396 CHECK_EQ(0u, bar_entry_count); | 12396 v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
| 12397 CHECK_EQ(0u, bar_caller_count); | 12397 |
| 12398 CHECK_EQ(0u, foo_entry_count); | 12398 // Verify that entry hooking is now disabled. |
| 12399 RunLoopInNewEnv(isolate); |
| 12400 CHECK_EQ(0u, bar_entry_count); |
| 12401 CHECK_EQ(0u, bar_caller_count); |
| 12402 CHECK_EQ(0u, foo_entry_count); |
| 12403 } |
| 12404 isolate->Dispose(); |
| 12399 } | 12405 } |
| 12400 | 12406 |
| 12401 | 12407 |
| 12402 static i::HashMap* code_map = NULL; | 12408 static i::HashMap* code_map = NULL; |
| 12403 static i::HashMap* jitcode_line_info = NULL; | 12409 static i::HashMap* jitcode_line_info = NULL; |
| 12404 static int saw_bar = 0; | 12410 static int saw_bar = 0; |
| 12405 static int move_events = 0; | 12411 static int move_events = 0; |
| 12406 | 12412 |
| 12407 | 12413 |
| 12408 static bool FunctionNameIs(const char* expected, | 12414 static bool FunctionNameIs(const char* expected, |
| (...skipping 6952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19361 i::Semaphore* sem_; | 19367 i::Semaphore* sem_; |
| 19362 volatile int sem_value_; | 19368 volatile int sem_value_; |
| 19363 }; | 19369 }; |
| 19364 | 19370 |
| 19365 | 19371 |
| 19366 THREADED_TEST(SemaphoreInterruption) { | 19372 THREADED_TEST(SemaphoreInterruption) { |
| 19367 ThreadInterruptTest().RunTest(); | 19373 ThreadInterruptTest().RunTest(); |
| 19368 } | 19374 } |
| 19369 | 19375 |
| 19370 #endif // WIN32 | 19376 #endif // WIN32 |
| OLD | NEW |