Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1172)

Side by Side Diff: src/sweeper-thread.cc

Issue 11782028: Parallel and concurrent sweeping. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "sweeper-thread.h"
29
30 #include "v8.h"
31
32 #include "isolate.h"
33 #include "v8threads.h"
34
35 namespace v8 {
36 namespace internal {
37
38 SweeperThread::SweeperThread(Isolate* isolate)
39 : Thread("SweeperThread"),
40 isolate_(isolate),
41 heap_(isolate->heap()),
42 collector_(heap_->mark_compact_collector()),
43 start_sweeping_semaphore_(OS::CreateSemaphore(0)),
44 end_sweeping_semaphore_(OS::CreateSemaphore(0)),
45 stop_semaphore_(OS::CreateSemaphore(0)),
46 free_list_old_data_space_(heap_->paged_space(OLD_DATA_SPACE)),
47 free_list_old_pointer_space_(heap_->paged_space(OLD_POINTER_SPACE)),
48 private_free_list_old_data_space_(heap_->paged_space(OLD_DATA_SPACE)),
49 private_free_list_old_pointer_space_(
50 heap_->paged_space(OLD_POINTER_SPACE)),
51 sweeper_type_(CONSERVATIVE) {
52 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false));
53 }
54
55
56 bool SweeperThread::sweeping_pending_ = false;
57
58
59 void SweeperThread::Run() {
60 Isolate::SetIsolateThreadLocals(isolate_, NULL);
61 while (true) {
62 start_sweeping_semaphore_->Wait();
63
64 if (Acquire_Load(&stop_thread_)) {
65 stop_semaphore_->Signal();
66 return;
67 }
68
69 collector_->SweepInParallel(heap_->old_data_space(),
70 sweeper_type_,
71 &private_free_list_old_data_space_,
72 &free_list_old_data_space_);
73 collector_->SweepInParallel(heap_->old_pointer_space(),
74 sweeper_type_,
75 &private_free_list_old_pointer_space_,
76 &free_list_old_pointer_space_);
77 end_sweeping_semaphore_->Signal();
78 }
79 }
80
81 intptr_t SweeperThread::StealMemory(PagedSpace* space) {
82 intptr_t free_bytes = 0;
83 if (space->identity() == OLD_POINTER_SPACE) {
84 free_bytes = space->free_list()->Concatenate(&free_list_old_pointer_space_);
85 space->AddToAccountingStats(free_bytes);
86 } else if (space->identity() == OLD_DATA_SPACE) {
87 free_bytes = space->free_list()->Concatenate(&free_list_old_data_space_);
88 space->AddToAccountingStats(free_bytes);
89 }
90 return free_bytes;
91 }
92
93 void SweeperThread::Stop() {
94 Release_Store(&stop_thread_, static_cast<AtomicWord>(true));
95 start_sweeping_semaphore_->Signal();
96 stop_semaphore_->Wait();
97 }
98
99
100 void SweeperThread::StartSweeping(SweeperType sweeper_type) {
101 sweeper_type_ = sweeper_type;
102 start_sweeping_semaphore_->Signal();
103 }
104
105
106 void SweeperThread::WaitForSweeperThread() {
107 end_sweeping_semaphore_->Wait();
108 }
109 } } // namespace v8::internal
OLDNEW
« src/spaces.h ('K') | « src/sweeper-thread.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698