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

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 start_sweeping_semaphore_(OS::CreateSemaphore(0)),
43 end_sweeping_semaphore_(OS::CreateSemaphore(0)),
44 stop_semaphore_(OS::CreateSemaphore(0)),
45 free_list_old_data_space_(heap_->paged_space(OLD_DATA_SPACE)),
46 free_list_old_pointer_space_(heap_->paged_space(OLD_POINTER_SPACE)),
47 private_free_list_old_data_space_(heap_->paged_space(OLD_DATA_SPACE)),
48 private_free_list_old_pointer_space_(
49 heap_->paged_space(OLD_POINTER_SPACE)),
50 sweeper_type_(CONSERVATIVE) {
51 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false));
52 }
53
54
55 bool SweeperThread::sweeping_pending_ = false;
56
57
58 void SweeperThread::Run() {
59 Isolate::SetIsolateThreadLocals(isolate_, NULL);
60 while (true) {
61 start_sweeping_semaphore_->Wait();
62
63 if (Acquire_Load(&stop_thread_)) {
64 stop_semaphore_->Signal();
65 return;
66 }
67
68 heap_->SweepInParallel(heap_->old_data_space(),
69 sweeper_type_,
70 &private_free_list_old_data_space_,
71 &free_list_old_data_space_);
72 heap_->SweepInParallel(heap_->old_pointer_space(),
73 sweeper_type_,
74 &private_free_list_old_pointer_space_,
75 &free_list_old_pointer_space_);
76 end_sweeping_semaphore_->Signal();
77 }
78 }
79
80 void SweeperThread::StealMemory(PagedSpace* space) {
81 intptr_t free_bytes;
82 if (space->identity() == OLD_POINTER_SPACE) {
83 free_bytes = space->free_list()->Concatenate(&free_list_old_pointer_space_);
84 space->AddToAccountingStats(free_bytes);
85 } else if (space->identity() == OLD_DATA_SPACE) {
86 free_bytes = space->free_list()->Concatenate(&free_list_old_data_space_);
87 space->AddToAccountingStats(free_bytes);
88 }
89 }
90
91 void SweeperThread::Stop() {
92 Release_Store(&stop_thread_, static_cast<AtomicWord>(true));
93 start_sweeping_semaphore_->Signal();
94 stop_semaphore_->Wait();
95 }
96
97
98 void SweeperThread::StartSweeping(SweeperType sweeper_type) {
99 sweeper_type_ = sweeper_type;
100 start_sweeping_semaphore_->Signal();
101 }
102
103
104 void SweeperThread::WaitForSweeperThread() {
105 end_sweeping_semaphore_->Wait();
106 }
107 } } // namespace v8::internal
OLDNEW
« src/spaces.cc ('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