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 14153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14164 "bar();"); | 14164 "bar();"); |
14165 CHECK(value->IsNumber()); | 14165 CHECK(value->IsNumber()); |
14166 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); | 14166 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
14167 | 14167 |
14168 env->Exit(); | 14168 env->Exit(); |
14169 } | 14169 } |
14170 | 14170 |
14171 | 14171 |
14172 void SetFunctionEntryHookTest::RunTest() { | 14172 void SetFunctionEntryHookTest::RunTest() { |
14173 // Work in a new isolate throughout. | 14173 // Work in a new isolate throughout. |
14174 v8::Isolate* isolate = v8::Isolate::New(); | 14174 v8::Isolate::CreateParams create_params; |
14175 | 14175 create_params.entry_hook = EntryHook; |
14176 // Test setting the entry hook on the new isolate. | 14176 create_params.code_event_handler = JitEvent; |
14177 CHECK(v8::V8::SetFunctionEntryHook(isolate, EntryHook)); | 14177 v8::Isolate* isolate = v8::Isolate::New(create_params); |
14178 | |
14179 // Replacing the hook, once set should fail. | |
14180 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(isolate, EntryHook)); | |
14181 | 14178 |
14182 { | 14179 { |
14183 v8::Isolate::Scope scope(isolate); | 14180 v8::Isolate::Scope scope(isolate); |
14184 | 14181 |
14185 v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, JitEvent); | |
14186 | |
14187 RunLoopInNewEnv(isolate); | 14182 RunLoopInNewEnv(isolate); |
14188 | 14183 |
14189 // Check the exepected invocation counts. | 14184 // Check the exepected invocation counts. |
14190 CHECK_EQ(2, CountInvocations(NULL, "bar")); | 14185 CHECK_EQ(2, CountInvocations(NULL, "bar")); |
14191 CHECK_EQ(200, CountInvocations("bar", "foo")); | 14186 CHECK_EQ(200, CountInvocations("bar", "foo")); |
14192 CHECK_EQ(200, CountInvocations(NULL, "foo")); | 14187 CHECK_EQ(200, CountInvocations(NULL, "foo")); |
14193 | 14188 |
14194 // Verify that we have an entry hook on some specific stubs. | 14189 // Verify that we have an entry hook on some specific stubs. |
14195 CHECK_NE(0, CountInvocations(NULL, "CEntryStub")); | 14190 CHECK_NE(0, CountInvocations(NULL, "CEntryStub")); |
14196 CHECK_NE(0, CountInvocations(NULL, "JSEntryStub")); | 14191 CHECK_NE(0, CountInvocations(NULL, "JSEntryStub")); |
14197 CHECK_NE(0, CountInvocations(NULL, "JSEntryTrampoline")); | 14192 CHECK_NE(0, CountInvocations(NULL, "JSEntryTrampoline")); |
14198 } | 14193 } |
14199 isolate->Dispose(); | 14194 isolate->Dispose(); |
14200 | 14195 |
14201 Reset(); | 14196 Reset(); |
14202 | 14197 |
14203 // Make sure a second isolate is unaffected by the previous entry hook. | 14198 // Make sure a second isolate is unaffected by the previous entry hook. |
14204 isolate = v8::Isolate::New(); | 14199 isolate = v8::Isolate::New(); |
14205 { | 14200 { |
14206 v8::Isolate::Scope scope(isolate); | 14201 v8::Isolate::Scope scope(isolate); |
14207 | 14202 |
14208 // Reset the entry count to zero and set the entry hook. | 14203 // Reset the entry count to zero and set the entry hook. |
14209 RunLoopInNewEnv(isolate); | 14204 RunLoopInNewEnv(isolate); |
14210 | 14205 |
14211 // We should record no invocations in this isolate. | 14206 // We should record no invocations in this isolate. |
14212 CHECK_EQ(0, static_cast<int>(invocations_.size())); | 14207 CHECK_EQ(0, static_cast<int>(invocations_.size())); |
14213 } | 14208 } |
14214 // Since the isolate has been used, we shouldn't be able to set an entry | |
14215 // hook anymore. | |
14216 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(isolate, EntryHook)); | |
14217 | 14209 |
14218 isolate->Dispose(); | 14210 isolate->Dispose(); |
14219 } | 14211 } |
14220 | 14212 |
14221 | 14213 |
14222 TEST(SetFunctionEntryHook) { | 14214 TEST(SetFunctionEntryHook) { |
14223 // FunctionEntryHook does not work well with experimental natives. | 14215 // FunctionEntryHook does not work well with experimental natives. |
14224 // Experimental natives are compiled during snapshot deserialization. | 14216 // Experimental natives are compiled during snapshot deserialization. |
14225 // This test breaks because InstallGetter (function from snapshot that | 14217 // This test breaks because InstallGetter (function from snapshot that |
14226 // only gets called from experimental natives) is compiled with entry hooks. | 14218 // only gets called from experimental natives) is compiled with entry hooks. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14400 v8::HandleScope scope(isolate); | 14392 v8::HandleScope scope(isolate); |
14401 i::HashMap code(MatchPointers); | 14393 i::HashMap code(MatchPointers); |
14402 code_map = &code; | 14394 code_map = &code; |
14403 | 14395 |
14404 i::HashMap lineinfo(MatchPointers); | 14396 i::HashMap lineinfo(MatchPointers); |
14405 jitcode_line_info = &lineinfo; | 14397 jitcode_line_info = &lineinfo; |
14406 | 14398 |
14407 saw_bar = 0; | 14399 saw_bar = 0; |
14408 move_events = 0; | 14400 move_events = 0; |
14409 | 14401 |
14410 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); | 14402 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); |
14411 | 14403 |
14412 // Generate new code objects sparsely distributed across several | 14404 // Generate new code objects sparsely distributed across several |
14413 // different fragmented code-space pages. | 14405 // different fragmented code-space pages. |
14414 const int kIterations = 10; | 14406 const int kIterations = 10; |
14415 for (int i = 0; i < kIterations; ++i) { | 14407 for (int i = 0; i < kIterations; ++i) { |
14416 LocalContext env(isolate); | 14408 LocalContext env(isolate); |
14417 i::AlwaysAllocateScope always_allocate(i_isolate); | 14409 i::AlwaysAllocateScope always_allocate(i_isolate); |
14418 SimulateFullSpace(heap->code_space()); | 14410 SimulateFullSpace(heap->code_space()); |
14419 CompileRun(script); | 14411 CompileRun(script); |
14420 | 14412 |
14421 // Keep a strong reference to the code object in the handle scope. | 14413 // Keep a strong reference to the code object in the handle scope. |
14422 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( | 14414 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( |
14423 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); | 14415 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); |
14424 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( | 14416 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( |
14425 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); | 14417 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); |
14426 | 14418 |
14427 // Clear the compilation cache to get more wastage. | 14419 // Clear the compilation cache to get more wastage. |
14428 reinterpret_cast<i::Isolate*>(isolate)->compilation_cache()->Clear(); | 14420 reinterpret_cast<i::Isolate*>(isolate)->compilation_cache()->Clear(); |
14429 } | 14421 } |
14430 | 14422 |
14431 // Force code movement. | 14423 // Force code movement. |
14432 heap->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); | 14424 heap->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); |
14433 | 14425 |
14434 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 14426 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
14435 | 14427 |
14436 CHECK_LE(kIterations, saw_bar); | 14428 CHECK_LE(kIterations, saw_bar); |
14437 CHECK_LT(0, move_events); | 14429 CHECK_LT(0, move_events); |
14438 | 14430 |
14439 code_map = NULL; | 14431 code_map = NULL; |
14440 jitcode_line_info = NULL; | 14432 jitcode_line_info = NULL; |
14441 } | 14433 } |
14442 | 14434 |
14443 isolate->Exit(); | 14435 isolate->Exit(); |
14444 isolate->Dispose(); | 14436 isolate->Dispose(); |
14445 | 14437 |
14446 // Do this in a new isolate. | 14438 // Do this in a new isolate. |
14447 isolate = v8::Isolate::New(); | 14439 isolate = v8::Isolate::New(); |
14448 isolate->Enter(); | 14440 isolate->Enter(); |
14449 | 14441 |
14450 // Verify that we get callbacks for existing code objects when we | 14442 // Verify that we get callbacks for existing code objects when we |
14451 // request enumeration of existing code. | 14443 // request enumeration of existing code. |
14452 { | 14444 { |
14453 v8::HandleScope scope(isolate); | 14445 v8::HandleScope scope(isolate); |
14454 LocalContext env(isolate); | 14446 LocalContext env(isolate); |
14455 CompileRun(script); | 14447 CompileRun(script); |
14456 | 14448 |
14457 // Now get code through initial iteration. | 14449 // Now get code through initial iteration. |
14458 i::HashMap code(MatchPointers); | 14450 i::HashMap code(MatchPointers); |
14459 code_map = &code; | 14451 code_map = &code; |
14460 | 14452 |
14461 i::HashMap lineinfo(MatchPointers); | 14453 i::HashMap lineinfo(MatchPointers); |
14462 jitcode_line_info = &lineinfo; | 14454 jitcode_line_info = &lineinfo; |
14463 | 14455 |
14464 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); | 14456 isolate->SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, |
14465 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 14457 event_handler); |
| 14458 isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
14466 | 14459 |
14467 jitcode_line_info = NULL; | 14460 jitcode_line_info = NULL; |
14468 // We expect that we got some events. Note that if we could get code removal | 14461 // We expect that we got some events. Note that if we could get code removal |
14469 // notifications, we could compare two collections, one created by listening | 14462 // notifications, we could compare two collections, one created by listening |
14470 // from the time of creation of an isolate, and the other by subscribing | 14463 // from the time of creation of an isolate, and the other by subscribing |
14471 // with EnumExisting. | 14464 // with EnumExisting. |
14472 CHECK_LT(0, code.occupancy()); | 14465 CHECK_LT(0, code.occupancy()); |
14473 | 14466 |
14474 code_map = NULL; | 14467 code_map = NULL; |
14475 } | 14468 } |
(...skipping 8875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23351 // TestSourceStream::GetMoreData won't block, so it's OK to just run the | 23344 // TestSourceStream::GetMoreData won't block, so it's OK to just run the |
23352 // task here in the main thread. | 23345 // task here in the main thread. |
23353 task->Run(); | 23346 task->Run(); |
23354 delete task; | 23347 delete task; |
23355 | 23348 |
23356 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); | 23349 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); |
23357 CHECK(cached_data != NULL); | 23350 CHECK(cached_data != NULL); |
23358 CHECK(cached_data->data != NULL); | 23351 CHECK(cached_data->data != NULL); |
23359 CHECK_GT(cached_data->length, 0); | 23352 CHECK_GT(cached_data->length, 0); |
23360 } | 23353 } |
OLD | NEW |