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 11541 matching lines...) Loading... |
11552 v8::internal::Isolate::Current()->compilation_cache()->Clear(); | 11552 v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
11553 | 11553 |
11554 // Verify that entry hooking is now disabled. | 11554 // Verify that entry hooking is now disabled. |
11555 RunLoopInNewEnv(); | 11555 RunLoopInNewEnv(); |
11556 CHECK_EQ(0u, bar_count); | 11556 CHECK_EQ(0u, bar_count); |
11557 CHECK_EQ(0u, foo_count); | 11557 CHECK_EQ(0u, foo_count); |
11558 } | 11558 } |
11559 | 11559 |
11560 | 11560 |
11561 static i::HashMap* code_map = NULL; | 11561 static i::HashMap* code_map = NULL; |
| 11562 static i::HashMap* jitcode_line_info = NULL; |
11562 static int saw_bar = 0; | 11563 static int saw_bar = 0; |
11563 static int move_events = 0; | 11564 static int move_events = 0; |
11564 | 11565 |
11565 | 11566 |
11566 static bool FunctionNameIs(const char* expected, | 11567 static bool FunctionNameIs(const char* expected, |
11567 const v8::JitCodeEvent* event) { | 11568 const v8::JitCodeEvent* event) { |
11568 // Log lines for functions are of the general form: | 11569 // Log lines for functions are of the general form: |
11569 // "LazyCompile:<type><function_name>", where the type is one of | 11570 // "LazyCompile:<type><function_name>", where the type is one of |
11570 // "*", "~" or "". | 11571 // "*", "~" or "". |
11571 static const char kPreamble[] = "LazyCompile:"; | 11572 static const char kPreamble[] = "LazyCompile:"; |
(...skipping 19 matching lines...) Loading... |
11591 if (tail_len != expected_len) | 11592 if (tail_len != expected_len) |
11592 return false; | 11593 return false; |
11593 | 11594 |
11594 return strncmp(tail, expected, expected_len) == 0; | 11595 return strncmp(tail, expected, expected_len) == 0; |
11595 } | 11596 } |
11596 | 11597 |
11597 | 11598 |
11598 static void event_handler(const v8::JitCodeEvent* event) { | 11599 static void event_handler(const v8::JitCodeEvent* event) { |
11599 CHECK(event != NULL); | 11600 CHECK(event != NULL); |
11600 CHECK(code_map != NULL); | 11601 CHECK(code_map != NULL); |
| 11602 CHECK(jitcode_line_info != NULL); |
| 11603 |
| 11604 class DummyJitCodeLineInfo { |
| 11605 }; |
11601 | 11606 |
11602 switch (event->type) { | 11607 switch (event->type) { |
11603 case v8::JitCodeEvent::CODE_ADDED: { | 11608 case v8::JitCodeEvent::CODE_ADDED: { |
11604 CHECK(event->code_start != NULL); | 11609 CHECK(event->code_start != NULL); |
11605 CHECK_NE(0, static_cast<int>(event->code_len)); | 11610 CHECK_NE(0, static_cast<int>(event->code_len)); |
11606 CHECK(event->name.str != NULL); | 11611 CHECK(event->name.str != NULL); |
11607 i::HashMap::Entry* entry = | 11612 i::HashMap::Entry* entry = |
11608 code_map->Lookup(event->code_start, | 11613 code_map->Lookup(event->code_start, |
11609 i::ComputePointerHash(event->code_start), | 11614 i::ComputePointerHash(event->code_start), |
11610 true); | 11615 true); |
(...skipping 28 matching lines...) Loading... |
11639 CHECK(entry != NULL); | 11644 CHECK(entry != NULL); |
11640 entry->value = reinterpret_cast<void*>(event->code_len); | 11645 entry->value = reinterpret_cast<void*>(event->code_len); |
11641 } | 11646 } |
11642 } | 11647 } |
11643 break; | 11648 break; |
11644 | 11649 |
11645 case v8::JitCodeEvent::CODE_REMOVED: | 11650 case v8::JitCodeEvent::CODE_REMOVED: |
11646 // Object/code removal events are currently not dispatched from the GC. | 11651 // Object/code removal events are currently not dispatched from the GC. |
11647 CHECK(false); | 11652 CHECK(false); |
11648 break; | 11653 break; |
| 11654 |
| 11655 // For CODE_START_LINE_INFO_RECORDING event, we will create one |
| 11656 // DummyJitCodeLineInfo data structure pointed by event->user_dat. We |
| 11657 // record it in jitcode_line_info. |
| 11658 case v8::JitCodeEvent::CODE_START_LINE_INFO_RECORDING: { |
| 11659 DummyJitCodeLineInfo* line_info = new DummyJitCodeLineInfo(); |
| 11660 v8::JitCodeEvent* temp_event = const_cast<v8::JitCodeEvent*>(event); |
| 11661 temp_event->user_data = line_info; |
| 11662 i::HashMap::Entry* entry = |
| 11663 jitcode_line_info->Lookup(line_info, |
| 11664 i::ComputePointerHash(line_info), |
| 11665 true); |
| 11666 entry->value = reinterpret_cast<void*>(line_info); |
| 11667 } |
| 11668 break; |
| 11669 // For these two events, we will check whether the event->user_data |
| 11670 // data structure is created before during CODE_START_LINE_INFO_RECORDING |
| 11671 // event. And delete it in CODE_END_LINE_INFO_RECORDING event handling. |
| 11672 case v8::JitCodeEvent::CODE_END_LINE_INFO_RECORDING: { |
| 11673 CHECK(event->user_data != NULL); |
| 11674 uint32_t hash = i::ComputePointerHash(event->user_data); |
| 11675 i::HashMap::Entry* entry = |
| 11676 jitcode_line_info->Lookup(event->user_data, hash, false); |
| 11677 CHECK(entry != NULL); |
| 11678 delete reinterpret_cast<DummyJitCodeLineInfo*>(event->user_data); |
| 11679 } |
| 11680 break; |
| 11681 |
| 11682 case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: { |
| 11683 CHECK(event->user_data != NULL); |
| 11684 uint32_t hash = i::ComputePointerHash(event->user_data); |
| 11685 i::HashMap::Entry* entry = |
| 11686 jitcode_line_info->Lookup(event->user_data, hash, false); |
| 11687 CHECK(entry != NULL); |
| 11688 } |
| 11689 break; |
| 11690 |
11649 default: | 11691 default: |
11650 // Impossible event. | 11692 // Impossible event. |
11651 CHECK(false); | 11693 CHECK(false); |
11652 break; | 11694 break; |
11653 } | 11695 } |
11654 } | 11696 } |
11655 | 11697 |
11656 | 11698 |
11657 static bool MatchPointers(void* key1, void* key2) { | 11699 static bool MatchPointers(void* key1, void* key2) { |
11658 return key1 == key2; | 11700 return key1 == key2; |
(...skipping 13 matching lines...) Loading... |
11672 | 11714 |
11673 // Run this test in a new isolate to make sure we don't | 11715 // Run this test in a new isolate to make sure we don't |
11674 // have remnants of state from other code. | 11716 // have remnants of state from other code. |
11675 v8::Isolate* isolate = v8::Isolate::New(); | 11717 v8::Isolate* isolate = v8::Isolate::New(); |
11676 isolate->Enter(); | 11718 isolate->Enter(); |
11677 | 11719 |
11678 { | 11720 { |
11679 i::HashMap code(MatchPointers); | 11721 i::HashMap code(MatchPointers); |
11680 code_map = &code; | 11722 code_map = &code; |
11681 | 11723 |
| 11724 i::HashMap lineinfo(MatchPointers); |
| 11725 jitcode_line_info = &lineinfo; |
| 11726 |
11682 saw_bar = 0; | 11727 saw_bar = 0; |
11683 move_events = 0; | 11728 move_events = 0; |
11684 | 11729 |
11685 i::FLAG_stress_compaction = true; | 11730 i::FLAG_stress_compaction = true; |
11686 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); | 11731 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler, true); |
11687 | 11732 |
11688 v8::HandleScope scope; | 11733 v8::HandleScope scope; |
11689 // Generate new code objects sparsely distributed across several | 11734 // Generate new code objects sparsely distributed across several |
11690 // different fragmented code-space pages. | 11735 // different fragmented code-space pages. |
11691 const int kIterations = 10; | 11736 const int kIterations = 10; |
11692 for (int i = 0; i < kIterations; ++i) { | 11737 for (int i = 0; i < kIterations; ++i) { |
11693 LocalContext env; | 11738 LocalContext env; |
11694 | 11739 |
11695 v8::Handle<v8::Script> compiled_script; | 11740 v8::Handle<v8::Script> compiled_script; |
11696 { | 11741 { |
11697 i::AlwaysAllocateScope always_allocate; | 11742 i::AlwaysAllocateScope always_allocate; |
11698 SimulateFullSpace(HEAP->code_space()); | 11743 SimulateFullSpace(HEAP->code_space()); |
11699 compiled_script = v8_compile(script); | 11744 compiled_script = v8_compile(script); |
11700 } | 11745 } |
11701 compiled_script->Run(); | 11746 compiled_script->Run(); |
11702 | 11747 |
11703 // Clear the compilation cache to get more wastage. | 11748 // Clear the compilation cache to get more wastage. |
11704 ISOLATE->compilation_cache()->Clear(); | 11749 ISOLATE->compilation_cache()->Clear(); |
11705 } | 11750 } |
11706 | 11751 |
11707 // Force code movement. | 11752 // Force code movement. |
11708 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); | 11753 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); |
11709 | 11754 |
11710 CHECK_LE(kIterations, saw_bar); | 11755 CHECK_LE(kIterations, saw_bar); |
11711 CHECK_NE(0, move_events); | 11756 CHECK_NE(0, move_events); |
11712 | 11757 |
11713 code_map = NULL; | 11758 code_map = NULL; |
11714 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 11759 jitcode_line_info = NULL; |
| 11760 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL, true); |
11715 } | 11761 } |
11716 | 11762 |
11717 isolate->Exit(); | 11763 isolate->Exit(); |
11718 isolate->Dispose(); | 11764 isolate->Dispose(); |
11719 | 11765 |
11720 // Do this in a new isolate. | 11766 // Do this in a new isolate. |
11721 isolate = v8::Isolate::New(); | 11767 isolate = v8::Isolate::New(); |
11722 isolate->Enter(); | 11768 isolate->Enter(); |
11723 | 11769 |
11724 // Verify that we get callbacks for existing code objects when we | 11770 // Verify that we get callbacks for existing code objects when we |
11725 // request enumeration of existing code. | 11771 // request enumeration of existing code. |
11726 { | 11772 { |
11727 v8::HandleScope scope; | 11773 v8::HandleScope scope; |
11728 LocalContext env; | 11774 LocalContext env; |
11729 CompileRun(script); | 11775 CompileRun(script); |
11730 | 11776 |
11731 // Now get code through initial iteration. | 11777 // Now get code through initial iteration. |
11732 i::HashMap code(MatchPointers); | 11778 i::HashMap code(MatchPointers); |
11733 code_map = &code; | 11779 code_map = &code; |
11734 | 11780 |
11735 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); | 11781 i::HashMap lineinfo(MatchPointers); |
11736 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 11782 jitcode_line_info = &lineinfo; |
| 11783 |
| 11784 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, |
| 11785 event_handler, |
| 11786 true); |
| 11787 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL, true); |
11737 | 11788 |
11738 code_map = NULL; | 11789 code_map = NULL; |
| 11790 jitcode_line_info = NULL; |
11739 | 11791 |
11740 // We expect that we got some events. Note that if we could get code removal | 11792 // We expect that we got some events. Note that if we could get code removal |
11741 // notifications, we could compare two collections, one created by listening | 11793 // notifications, we could compare two collections, one created by listening |
11742 // from the time of creation of an isolate, and the other by subscribing | 11794 // from the time of creation of an isolate, and the other by subscribing |
11743 // with EnumExisting. | 11795 // with EnumExisting. |
11744 CHECK_NE(0, code.occupancy()); | 11796 CHECK_NE(0, code.occupancy()); |
11745 } | 11797 } |
11746 | 11798 |
11747 isolate->Exit(); | 11799 isolate->Exit(); |
11748 isolate->Dispose(); | 11800 isolate->Dispose(); |
(...skipping 6406 matching lines...) Loading... |
18155 i::Semaphore* sem_; | 18207 i::Semaphore* sem_; |
18156 volatile int sem_value_; | 18208 volatile int sem_value_; |
18157 }; | 18209 }; |
18158 | 18210 |
18159 | 18211 |
18160 THREADED_TEST(SemaphoreInterruption) { | 18212 THREADED_TEST(SemaphoreInterruption) { |
18161 ThreadInterruptTest().RunTest(); | 18213 ThreadInterruptTest().RunTest(); |
18162 } | 18214 } |
18163 | 18215 |
18164 #endif // WIN32 | 18216 #endif // WIN32 |
OLD | NEW |