Added parallel marking threads.

BUG=

Review URL: https://codereview.chromium.org/12047044

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13569 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
hpayer@chromium.org 2013-01-31 14:23:36 +00:00
parent 07bab08378
commit 7fe9f3b05c
8 changed files with 209 additions and 0 deletions

View File

@ -421,6 +421,8 @@ DEFINE_bool(parallel_sweeping, false, "enable parallel sweeping")
DEFINE_bool(concurrent_sweeping, false, "enable concurrent sweeping")
DEFINE_int(sweeper_threads, 1,
"number of parallel and concurrent sweeping threads")
DEFINE_bool(parallel_marking, false, "enable parallel marking")
DEFINE_int(marking_threads, 1, "number of parallel marking threads")
#ifdef VERIFY_HEAP
DEFINE_bool(verify_heap, false, "verify heap pointers before and after GC")
#endif

View File

@ -40,6 +40,7 @@
#include "isolate.h"
#include "lithium-allocator.h"
#include "log.h"
#include "marking-thread.h"
#include "messages.h"
#include "platform.h"
#include "regexp-stack.h"
@ -1653,6 +1654,7 @@ Isolate::Isolate()
context_exit_happened_(false),
deferred_handles_head_(NULL),
optimizing_compiler_thread_(this),
marking_thread_(NULL),
sweeper_thread_(NULL) {
TRACE_ISOLATE(constructor);
@ -1745,6 +1747,14 @@ void Isolate::Deinit() {
delete[] sweeper_thread_;
}
if (FLAG_parallel_marking) {
for (int i = 0; i < FLAG_marking_threads; i++) {
marking_thread_[i]->Stop();
delete marking_thread_[i];
}
delete[] marking_thread_;
}
if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Stop();
if (FLAG_hydrogen_stats) HStatistics::Instance()->Print();
@ -2115,6 +2125,17 @@ bool Isolate::Init(Deserializer* des) {
if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Start();
if (FLAG_parallel_marking) {
if (FLAG_marking_threads < 1) {
FLAG_marking_threads = 1;
}
marking_thread_ = new MarkingThread*[FLAG_marking_threads];
for (int i = 0; i < FLAG_marking_threads; i++) {
marking_thread_[i] = new MarkingThread(this);
marking_thread_[i]->Start();
}
}
if (FLAG_parallel_sweeping || FLAG_concurrent_sweeping) {
if (FLAG_sweeper_threads < 1) {
FLAG_sweeper_threads = 1;

View File

@ -71,6 +71,7 @@ class HeapProfiler;
class InlineRuntimeFunctionsTable;
class NoAllocationStringAllocator;
class InnerPointerToCodeCache;
class MarkingThread;
class PreallocatedMemoryThread;
class RegExpStack;
class SaveContext;
@ -1074,6 +1075,10 @@ class Isolate {
// TODO(svenpanne) This method is on death row...
static v8::Isolate* GetDefaultIsolateForLocking();
MarkingThread** marking_threads() {
return marking_thread_;
}
SweeperThread** sweeper_threads() {
return sweeper_thread_;
}
@ -1301,11 +1306,13 @@ class Isolate {
DeferredHandles* deferred_handles_head_;
OptimizingCompilerThread optimizing_compiler_thread_;
MarkingThread** marking_thread_;
SweeperThread** sweeper_thread_;
friend class ExecutionAccess;
friend class HandleScopeImplementer;
friend class IsolateInitializer;
friend class MarkingThread;
friend class OptimizingCompilerThread;
friend class SweeperThread;
friend class ThreadManager;

View File

@ -37,6 +37,7 @@
#include "ic-inl.h"
#include "incremental-marking.h"
#include "mark-compact.h"
#include "marking-thread.h"
#include "objects-visiting.h"
#include "objects-visiting-inl.h"
#include "stub-cache.h"
@ -540,6 +541,20 @@ bool MarkCompactCollector::AreSweeperThreadsActivated() {
}
void MarkCompactCollector::MarkInParallel() {
for (int i = 0; i < FLAG_marking_threads; i++) {
heap()->isolate()->marking_threads()[i]->StartMarking();
}
}
void MarkCompactCollector::WaitUntilMarkingCompleted() {
for (int i = 0; i < FLAG_marking_threads; i++) {
heap()->isolate()->marking_threads()[i]->WaitForMarkingThread();
}
}
bool Marking::TransferMark(Address old_start, Address new_start) {
// This is only used when resizing an object.
ASSERT(MemoryChunk::FromAddress(old_start) ==

View File

@ -680,6 +680,7 @@ class MarkCompactCollector {
MarkingParity marking_parity() { return marking_parity_; }
// Concurrent and parallel sweeping support.
void SweepInParallel(PagedSpace* space,
FreeList* private_free_list,
FreeList* free_list);
@ -690,6 +691,11 @@ class MarkCompactCollector {
bool AreSweeperThreadsActivated();
// Parallel marking support.
void MarkInParallel();
void WaitUntilMarkingCompleted();
private:
MarkCompactCollector();
~MarkCompactCollector();

85
src/marking-thread.cc Normal file
View File

@ -0,0 +1,85 @@
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "marking-thread.h"
#include "v8.h"
#include "isolate.h"
#include "v8threads.h"
namespace v8 {
namespace internal {
MarkingThread::MarkingThread(Isolate* isolate)
: Thread("MarkingThread"),
isolate_(isolate),
heap_(isolate->heap()),
start_marking_semaphore_(OS::CreateSemaphore(0)),
end_marking_semaphore_(OS::CreateSemaphore(0)),
stop_semaphore_(OS::CreateSemaphore(0)) {
NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false));
id_ = NoBarrier_AtomicIncrement(&id_counter_, 1);
}
Atomic32 MarkingThread::id_counter_ = -1;
void MarkingThread::Run() {
Isolate::SetIsolateThreadLocals(isolate_, NULL);
while (true) {
start_marking_semaphore_->Wait();
if (Acquire_Load(&stop_thread_)) {
stop_semaphore_->Signal();
return;
}
end_marking_semaphore_->Signal();
}
}
void MarkingThread::Stop() {
Release_Store(&stop_thread_, static_cast<AtomicWord>(true));
start_marking_semaphore_->Signal();
stop_semaphore_->Wait();
}
void MarkingThread::StartMarking() {
start_marking_semaphore_->Signal();
}
void MarkingThread::WaitForMarkingThread() {
end_marking_semaphore_->Wait();
}
} } // namespace v8::internal

71
src/marking-thread.h Normal file
View File

@ -0,0 +1,71 @@
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_MARKING_THREAD_H_
#define V8_MARKING_THREAD_H_
#include "atomicops.h"
#include "flags.h"
#include "platform.h"
#include "v8utils.h"
#include "spaces.h"
#include "heap.h"
namespace v8 {
namespace internal {
class MarkingThread : public Thread {
public:
explicit MarkingThread(Isolate* isolate);
void Run();
void Stop();
void StartMarking();
void WaitForMarkingThread();
~MarkingThread() {
delete start_marking_semaphore_;
delete end_marking_semaphore_;
delete stop_semaphore_;
}
private:
Isolate* isolate_;
Heap* heap_;
Semaphore* start_marking_semaphore_;
Semaphore* end_marking_semaphore_;
Semaphore* stop_semaphore_;
volatile AtomicWord stop_thread_;
int id_;
static Atomic32 id_counter_;
};
} } // namespace v8::internal
#endif // V8_MARKING_THREAD_H_

View File

@ -382,6 +382,8 @@
'../../src/macro-assembler.h',
'../../src/mark-compact.cc',
'../../src/mark-compact.h',
'../../src/marking-thread.h',
'../../src/marking-thread.cc',
'../../src/messages.cc',
'../../src/messages.h',
'../../src/natives.h',