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 12067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12078 v8::Local<Context> env = Context::New(isolate); | 12078 v8::Local<Context> env = Context::New(isolate); |
12079 env->Enter(); | 12079 env->Enter(); |
12080 v8::Handle<Value> value = NestedScope(env); | 12080 v8::Handle<Value> value = NestedScope(env); |
12081 v8::Handle<String> str(value->ToString()); | 12081 v8::Handle<String> str(value->ToString()); |
12082 CHECK(!str.IsEmpty()); | 12082 CHECK(!str.IsEmpty()); |
12083 env->Exit(); | 12083 env->Exit(); |
12084 } | 12084 } |
12085 | 12085 |
12086 | 12086 |
12087 static i::Handle<i::JSFunction>* foo_ptr = NULL; | 12087 static i::Handle<i::JSFunction>* foo_ptr = NULL; |
12088 static int foo_count = 0; | 12088 static int foo_entry_count = 0; |
12089 static i::Handle<i::JSFunction>* bar_ptr = NULL; | 12089 static i::Handle<i::JSFunction>* bar_ptr = NULL; |
12090 static int bar_count = 0; | 12090 static int bar_entry_count = 0; |
| 12091 static int bar_caller_count = 0; |
12091 | 12092 |
12092 | 12093 |
12093 static void entry_hook(uintptr_t function, | 12094 static void entry_hook(uintptr_t function, |
12094 uintptr_t return_addr_location) { | 12095 uintptr_t return_addr_location) { |
12095 i::Code* code = i::Code::GetCodeFromTargetAddress( | 12096 i::Code* code = i::Code::GetCodeFromTargetAddress( |
12096 reinterpret_cast<i::Address>(function)); | 12097 reinterpret_cast<i::Address>(function)); |
12097 CHECK(code != NULL); | 12098 CHECK(code != NULL); |
12098 | 12099 |
12099 if (bar_ptr != NULL && code == (*bar_ptr)->code()) | 12100 if (bar_ptr != NULL && code == (*bar_ptr)->code()) |
12100 ++bar_count; | 12101 ++bar_entry_count; |
12101 | 12102 |
12102 if (foo_ptr != NULL && code == (*foo_ptr)->code()) | 12103 if (foo_ptr != NULL && code == (*foo_ptr)->code()) |
12103 ++foo_count; | 12104 ++foo_entry_count; |
12104 | 12105 |
12105 // TODO(siggi): Verify return_addr_location. | 12106 // Let's check whether bar is the caller. |
12106 // This can be done by capturing JitCodeEvents, but requires an ordered | 12107 if (bar_ptr != NULL) { |
12107 // collection. | 12108 const v8::internal::byte* caller = |
| 12109 *reinterpret_cast<v8::internal::byte**>(return_addr_location); |
| 12110 |
| 12111 if ((*bar_ptr)->code()->instruction_start() <= caller && |
| 12112 (*bar_ptr)->code()->instruction_end() > caller) { |
| 12113 ++bar_caller_count; |
| 12114 } |
| 12115 } |
12108 } | 12116 } |
12109 | 12117 |
12110 | 12118 |
12111 static void RunLoopInNewEnv() { | 12119 static void RunLoopInNewEnv() { |
12112 bar_ptr = NULL; | 12120 bar_ptr = NULL; |
12113 foo_ptr = NULL; | 12121 foo_ptr = NULL; |
12114 | 12122 |
12115 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 12123 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
12116 v8::HandleScope outer(isolate); | 12124 v8::HandleScope outer(isolate); |
12117 v8::Local<Context> env = Context::New(isolate); | 12125 v8::Local<Context> env = Context::New(isolate); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12168 // Nulling it should always succeed. | 12176 // Nulling it should always succeed. |
12169 CHECK(v8::V8::SetFunctionEntryHook(NULL)); | 12177 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
12170 | 12178 |
12171 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); | 12179 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
12172 // Setting a hook while one's active should fail. | 12180 // Setting a hook while one's active should fail. |
12173 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook)); | 12181 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook)); |
12174 | 12182 |
12175 CHECK(v8::V8::SetFunctionEntryHook(NULL)); | 12183 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
12176 | 12184 |
12177 // Reset the entry count to zero and set the entry hook. | 12185 // Reset the entry count to zero and set the entry hook. |
12178 bar_count = 0; | 12186 bar_entry_count = 0; |
12179 foo_count = 0; | 12187 bar_caller_count = 0; |
| 12188 foo_entry_count = 0; |
12180 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); | 12189 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
12181 RunLoopInNewEnv(); | 12190 RunLoopInNewEnv(); |
12182 | 12191 |
12183 CHECK_EQ(2, bar_count); | 12192 CHECK_EQ(2, bar_entry_count); |
12184 CHECK_EQ(200, foo_count); | 12193 CHECK_EQ(200, bar_caller_count); |
| 12194 CHECK_EQ(200, foo_entry_count); |
12185 | 12195 |
12186 // Clear the entry hook and count. | 12196 // Clear the entry hook and count. |
12187 bar_count = 0; | 12197 bar_entry_count = 0; |
12188 foo_count = 0; | 12198 bar_caller_count = 0; |
| 12199 foo_entry_count = 0; |
12189 v8::V8::SetFunctionEntryHook(NULL); | 12200 v8::V8::SetFunctionEntryHook(NULL); |
12190 | 12201 |
12191 // Clear the compilation cache to make sure we don't reuse the | 12202 // Clear the compilation cache to make sure we don't reuse the |
12192 // functions from the previous invocation. | 12203 // functions from the previous invocation. |
12193 v8::internal::Isolate::Current()->compilation_cache()->Clear(); | 12204 v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
12194 | 12205 |
12195 // Verify that entry hooking is now disabled. | 12206 // Verify that entry hooking is now disabled. |
12196 RunLoopInNewEnv(); | 12207 RunLoopInNewEnv(); |
12197 CHECK_EQ(0u, bar_count); | 12208 CHECK_EQ(0u, bar_entry_count); |
12198 CHECK_EQ(0u, foo_count); | 12209 CHECK_EQ(0u, bar_caller_count); |
| 12210 CHECK_EQ(0u, foo_entry_count); |
12199 } | 12211 } |
12200 | 12212 |
12201 | 12213 |
12202 static i::HashMap* code_map = NULL; | 12214 static i::HashMap* code_map = NULL; |
12203 static i::HashMap* jitcode_line_info = NULL; | 12215 static i::HashMap* jitcode_line_info = NULL; |
12204 static int saw_bar = 0; | 12216 static int saw_bar = 0; |
12205 static int move_events = 0; | 12217 static int move_events = 0; |
12206 | 12218 |
12207 | 12219 |
12208 static bool FunctionNameIs(const char* expected, | 12220 static bool FunctionNameIs(const char* expected, |
(...skipping 6885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19094 i::Semaphore* sem_; | 19106 i::Semaphore* sem_; |
19095 volatile int sem_value_; | 19107 volatile int sem_value_; |
19096 }; | 19108 }; |
19097 | 19109 |
19098 | 19110 |
19099 THREADED_TEST(SemaphoreInterruption) { | 19111 THREADED_TEST(SemaphoreInterruption) { |
19100 ThreadInterruptTest().RunTest(); | 19112 ThreadInterruptTest().RunTest(); |
19101 } | 19113 } |
19102 | 19114 |
19103 #endif // WIN32 | 19115 #endif // WIN32 |
OLD | NEW |