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 11671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11682 } | 11682 } |
11683 } | 11683 } |
11684 | 11684 |
11685 | 11685 |
11686 static bool MatchPointers(void* key1, void* key2) { | 11686 static bool MatchPointers(void* key1, void* key2) { |
11687 return key1 == key2; | 11687 return key1 == key2; |
11688 } | 11688 } |
11689 | 11689 |
11690 | 11690 |
11691 TEST(SetJitCodeEventHandler) { | 11691 TEST(SetJitCodeEventHandler) { |
| 11692 i::FLAG_stress_compaction = true; |
11692 const char* script = | 11693 const char* script = |
11693 "function bar() {" | 11694 "function bar() {" |
11694 " var sum = 0;" | 11695 " var sum = 0;" |
11695 " for (i = 0; i < 100; ++i)" | 11696 " for (i = 0; i < 100; ++i)" |
11696 " sum = foo(i);" | 11697 " sum = foo(i);" |
11697 " return sum;" | 11698 " return sum;" |
11698 "}" | 11699 "}" |
11699 "function foo(i) { return i * i; };" | 11700 "function foo(i) { return i * i; };" |
11700 "bar();"; | 11701 "bar();"; |
11701 | 11702 |
11702 // Run this test in a new isolate to make sure we don't | 11703 // Run this test in a new isolate to make sure we don't |
11703 // have remnants of state from other code. | 11704 // have remnants of state from other code. |
11704 v8::Isolate* isolate = v8::Isolate::New(); | 11705 v8::Isolate* isolate = v8::Isolate::New(); |
11705 isolate->Enter(); | 11706 isolate->Enter(); |
11706 | 11707 |
11707 { | 11708 { |
| 11709 v8::HandleScope scope; |
11708 i::HashMap code(MatchPointers); | 11710 i::HashMap code(MatchPointers); |
11709 code_map = &code; | 11711 code_map = &code; |
11710 | 11712 |
11711 saw_bar = 0; | 11713 saw_bar = 0; |
11712 move_events = 0; | 11714 move_events = 0; |
11713 | 11715 |
11714 i::FLAG_stress_compaction = true; | |
11715 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); | 11716 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); |
11716 | 11717 |
11717 v8::HandleScope scope; | |
11718 // Generate new code objects sparsely distributed across several | 11718 // Generate new code objects sparsely distributed across several |
11719 // different fragmented code-space pages. | 11719 // different fragmented code-space pages. |
11720 const int kIterations = 10; | 11720 const int kIterations = 10; |
11721 for (int i = 0; i < kIterations; ++i) { | 11721 for (int i = 0; i < kIterations; ++i) { |
11722 LocalContext env; | 11722 LocalContext env; |
| 11723 i::AlwaysAllocateScope always_allocate; |
| 11724 SimulateFullSpace(HEAP->code_space()); |
| 11725 CompileRun(script); |
11723 | 11726 |
11724 v8::Handle<v8::Script> compiled_script; | 11727 // Keep a strong reference to the code object in the handle scope. |
11725 { | 11728 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( |
11726 i::AlwaysAllocateScope always_allocate; | 11729 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); |
11727 SimulateFullSpace(HEAP->code_space()); | 11730 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( |
11728 compiled_script = v8_compile(script); | 11731 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); |
11729 } | |
11730 compiled_script->Run(); | |
11731 | 11732 |
11732 // Clear the compilation cache to get more wastage. | 11733 // Clear the compilation cache to get more wastage. |
11733 ISOLATE->compilation_cache()->Clear(); | 11734 ISOLATE->compilation_cache()->Clear(); |
11734 } | 11735 } |
11735 | 11736 |
11736 // Force code movement. | 11737 // Force code movement. |
11737 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); | 11738 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); |
11738 | 11739 |
| 11740 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
| 11741 |
11739 CHECK_LE(kIterations, saw_bar); | 11742 CHECK_LE(kIterations, saw_bar); |
11740 CHECK_NE(0, move_events); | 11743 CHECK_LT(0, move_events); |
11741 | 11744 |
11742 code_map = NULL; | 11745 code_map = NULL; |
11743 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | |
11744 } | 11746 } |
11745 | 11747 |
11746 isolate->Exit(); | 11748 isolate->Exit(); |
11747 isolate->Dispose(); | 11749 isolate->Dispose(); |
11748 | 11750 |
11749 // Do this in a new isolate. | 11751 // Do this in a new isolate. |
11750 isolate = v8::Isolate::New(); | 11752 isolate = v8::Isolate::New(); |
11751 isolate->Enter(); | 11753 isolate->Enter(); |
11752 | 11754 |
11753 // Verify that we get callbacks for existing code objects when we | 11755 // Verify that we get callbacks for existing code objects when we |
11754 // request enumeration of existing code. | 11756 // request enumeration of existing code. |
11755 { | 11757 { |
11756 v8::HandleScope scope; | 11758 v8::HandleScope scope; |
11757 LocalContext env; | 11759 LocalContext env; |
11758 CompileRun(script); | 11760 CompileRun(script); |
11759 | 11761 |
11760 // Now get code through initial iteration. | 11762 // Now get code through initial iteration. |
11761 i::HashMap code(MatchPointers); | 11763 i::HashMap code(MatchPointers); |
11762 code_map = &code; | 11764 code_map = &code; |
11763 | 11765 |
11764 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); | 11766 V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler); |
11765 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 11767 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
11766 | 11768 |
11767 code_map = NULL; | |
11768 | |
11769 // We expect that we got some events. Note that if we could get code removal | 11769 // We expect that we got some events. Note that if we could get code removal |
11770 // notifications, we could compare two collections, one created by listening | 11770 // notifications, we could compare two collections, one created by listening |
11771 // from the time of creation of an isolate, and the other by subscribing | 11771 // from the time of creation of an isolate, and the other by subscribing |
11772 // with EnumExisting. | 11772 // with EnumExisting. |
11773 CHECK_NE(0, code.occupancy()); | 11773 CHECK_LT(0, code.occupancy()); |
| 11774 |
| 11775 code_map = NULL; |
11774 } | 11776 } |
11775 | 11777 |
11776 isolate->Exit(); | 11778 isolate->Exit(); |
11777 isolate->Dispose(); | 11779 isolate->Dispose(); |
11778 } | 11780 } |
11779 | 11781 |
11780 | 11782 |
11781 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } | 11783 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } |
11782 | 11784 |
11783 | 11785 |
(...skipping 6432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18216 i::Semaphore* sem_; | 18218 i::Semaphore* sem_; |
18217 volatile int sem_value_; | 18219 volatile int sem_value_; |
18218 }; | 18220 }; |
18219 | 18221 |
18220 | 18222 |
18221 THREADED_TEST(SemaphoreInterruption) { | 18223 THREADED_TEST(SemaphoreInterruption) { |
18222 ThreadInterruptTest().RunTest(); | 18224 ThreadInterruptTest().RunTest(); |
18223 } | 18225 } |
18224 | 18226 |
18225 #endif // WIN32 | 18227 #endif // WIN32 |
OLD | NEW |