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 10924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10935 reinterpret_cast<i::Address>(function)); | 10935 reinterpret_cast<i::Address>(function)); |
10936 CHECK(code != NULL); | 10936 CHECK(code != NULL); |
10937 | 10937 |
10938 if (bar_ptr != NULL && code == (*bar_ptr)->code()) | 10938 if (bar_ptr != NULL && code == (*bar_ptr)->code()) |
10939 ++bar_count; | 10939 ++bar_count; |
10940 | 10940 |
10941 if (foo_ptr != NULL && code == (*foo_ptr)->code()) | 10941 if (foo_ptr != NULL && code == (*foo_ptr)->code()) |
10942 ++foo_count; | 10942 ++foo_count; |
10943 | 10943 |
10944 // TODO(siggi): Verify return_addr_location. | 10944 // TODO(siggi): Verify return_addr_location. |
| 10945 // This can be done by capturing JitCodeEvents, but requires an ordered |
| 10946 // collection. |
10945 } | 10947 } |
10946 | 10948 |
10947 | 10949 |
10948 static void RunLoopInNewEnv() { | 10950 static void RunLoopInNewEnv() { |
10949 bar_ptr = NULL; | 10951 bar_ptr = NULL; |
10950 foo_ptr = NULL; | 10952 foo_ptr = NULL; |
10951 | 10953 |
10952 v8::HandleScope outer; | 10954 v8::HandleScope outer; |
10953 v8::Persistent<Context> env = Context::New(); | 10955 v8::Persistent<Context> env = Context::New(); |
10954 env->Enter(); | 10956 env->Enter(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11020 // functions from the previous invocation. | 11022 // functions from the previous invocation. |
11021 v8::internal::Isolate::Current()->compilation_cache()->Clear(); | 11023 v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
11022 | 11024 |
11023 // Verify that entry hooking is now disabled. | 11025 // Verify that entry hooking is now disabled. |
11024 RunLoopInNewEnv(); | 11026 RunLoopInNewEnv(); |
11025 CHECK_EQ(0u, bar_count); | 11027 CHECK_EQ(0u, bar_count); |
11026 CHECK_EQ(0u, foo_count); | 11028 CHECK_EQ(0u, foo_count); |
11027 } | 11029 } |
11028 | 11030 |
11029 | 11031 |
| 11032 static i::HashMap* code_map = NULL; |
| 11033 static int saw_foo = 0; |
| 11034 static int saw_bar = 0; |
| 11035 static int move_events = 0; |
| 11036 |
| 11037 |
| 11038 static void event_handler(const v8::JitCodeEvent* event) { |
| 11039 CHECK(event != NULL); |
| 11040 CHECK(code_map != NULL); |
| 11041 |
| 11042 uint32_t hash = reinterpret_cast<uint32_t>(event->code_start); |
| 11043 switch(event->type) { |
| 11044 case v8::JitCodeEvent::CODE_ADDED: { |
| 11045 CHECK(event->code_start != NULL); |
| 11046 CHECK_NE(0, event->code_len); |
| 11047 CHECK(event->name != NULL); |
| 11048 i::HashMap::Entry* entry = |
| 11049 code_map->Lookup(event->code_start, hash, true); |
| 11050 entry->value = reinterpret_cast<void*>(event->code_len); |
| 11051 |
| 11052 if (strcmp(event->name, "foo") == 0) { |
| 11053 ++saw_foo; |
| 11054 } else if (strcmp(event->name, "bar") == 0) { |
| 11055 ++saw_bar; |
| 11056 } |
| 11057 break; |
| 11058 } |
| 11059 |
| 11060 case v8::JitCodeEvent::CODE_MOVED: { |
| 11061 ++move_events; |
| 11062 |
| 11063 // We should never see code move that we haven't seen before. |
| 11064 i::HashMap::Entry* entry = |
| 11065 code_map->Lookup(event->code_start, hash, false); |
| 11066 CHECK(entry != NULL); |
| 11067 CHECK_EQ(reinterpret_cast<void*>(event->code_len), |
| 11068 code_map->Remove(event->code_start, hash)); |
| 11069 entry = code_map->Lookup(event->code_start, hash, true); |
| 11070 entry->value = reinterpret_cast<void*>(event->code_len); |
| 11071 break; |
| 11072 } |
| 11073 |
| 11074 break; |
| 11075 case v8::JitCodeEvent::CODE_REMOVED: |
| 11076 // Object/code removal events are currently not dispatched from the GC. |
| 11077 CHECK(false); |
| 11078 break; |
| 11079 default: |
| 11080 // Impossible event. |
| 11081 CHECK(false); |
| 11082 break; |
| 11083 } |
| 11084 } |
| 11085 |
| 11086 |
| 11087 // Implemented in the test-alloc.cc test suite. |
| 11088 void SimulateFullSpace(i::PagedSpace* space); |
| 11089 |
| 11090 |
| 11091 static bool MatchPointers(void* key1, void* key2) { |
| 11092 return key1 == key2; |
| 11093 } |
| 11094 |
| 11095 |
| 11096 TEST(SetJitCodeEventHandler) { |
| 11097 // Run this test in a new isolate to make sure we don't |
| 11098 // have remnants of state from other code. |
| 11099 v8::Isolate* isolate = v8::Isolate::New(); |
| 11100 isolate->Enter(); |
| 11101 |
| 11102 i::HashMap code(MatchPointers); |
| 11103 code_map = &code; |
| 11104 saw_foo = 0; |
| 11105 saw_bar = 0; |
| 11106 move_events = 0; |
| 11107 |
| 11108 |
| 11109 i::FLAG_stress_compaction = true; |
| 11110 v8::HandleScope scope; |
| 11111 |
| 11112 const char* script = |
| 11113 "function bar() {" |
| 11114 " var sum = 0;" |
| 11115 " for (i = 0; i < 100; ++i)" |
| 11116 " sum = foo(i);" |
| 11117 " return sum;" |
| 11118 "}" |
| 11119 "function foo(i) { return i * i; };" |
| 11120 "foo(100);"; |
| 11121 |
| 11122 V8::SetJitCodeEventHandler(event_handler); |
| 11123 |
| 11124 // Generate new code objects sparsely distributed across several |
| 11125 // different fragmented code-space pages. |
| 11126 const int kIterations = 10; |
| 11127 for (int i = 0; i < kIterations; ++i) { |
| 11128 LocalContext env; |
| 11129 |
| 11130 i::AlwaysAllocateScope always_allocate; |
| 11131 v8_compile(script); |
| 11132 SimulateFullSpace(HEAP->code_space()); |
| 11133 |
| 11134 ISOLATE->compilation_cache()->Clear(); |
| 11135 } |
| 11136 |
| 11137 CHECK_EQ(kIterations, saw_bar); |
| 11138 CHECK_EQ(kIterations, saw_foo); |
| 11139 CHECK_NE(0, move_events); |
| 11140 |
| 11141 code_map = NULL; |
| 11142 V8::SetJitCodeEventHandler(NULL); |
| 11143 |
| 11144 isolate->Exit(); |
| 11145 isolate->Dispose(); |
| 11146 } |
| 11147 |
| 11148 |
11030 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } | 11149 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } |
11031 | 11150 |
11032 | 11151 |
11033 THREADED_TEST(ExternalAllocatedMemory) { | 11152 THREADED_TEST(ExternalAllocatedMemory) { |
11034 v8::HandleScope outer; | 11153 v8::HandleScope outer; |
11035 v8::Persistent<Context> env(Context::New()); | 11154 v8::Persistent<Context> env(Context::New()); |
11036 CHECK(!env.IsEmpty()); | 11155 CHECK(!env.IsEmpty()); |
11037 const intptr_t kSize = 1024*1024; | 11156 const intptr_t kSize = 1024*1024; |
11038 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), | 11157 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), |
11039 cast(kSize)); | 11158 cast(kSize)); |
(...skipping 5977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17017 v8::HandleScope scope; | 17136 v8::HandleScope scope; |
17018 LocalContext context; | 17137 LocalContext context; |
17019 | 17138 |
17020 // Compile a try-finally clause where the finally block causes a GC | 17139 // Compile a try-finally clause where the finally block causes a GC |
17021 // while there still is a message pending for external reporting. | 17140 // while there still is a message pending for external reporting. |
17022 TryCatch try_catch; | 17141 TryCatch try_catch; |
17023 try_catch.SetVerbose(true); | 17142 try_catch.SetVerbose(true); |
17024 CompileRun("try { throw new Error(); } finally { gc(); }"); | 17143 CompileRun("try { throw new Error(); } finally { gc(); }"); |
17025 CHECK(try_catch.HasCaught()); | 17144 CHECK(try_catch.HasCaught()); |
17026 } | 17145 } |
OLD | NEW |