Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[turbofan] Enable concurrent (re)compilation.
Browse files Browse the repository at this point in the history
Refactor the TurboFan pipeline to allow for concurrent recompilation in
the same way that Crankshaft does it. For now we limit the concurrent
phases to scheduling, instruction selection, register allocation and
jump threading.

R=mstarzinger@chromium.org, ahaas@chromium.org, jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#35818}
  • Loading branch information
bmeurer authored and Commit bot committed Apr 27, 2016
1 parent 7f3954c commit ff19726
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 181 deletions.
19 changes: 11 additions & 8 deletions src/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ bool GetOptimizedCodeNow(CompilationInfo* info) {
TRACE_EVENT0("v8", "V8.OptimizeCode");

bool use_turbofan = UseTurboFan(info);
OptimizedCompileJob* job = use_turbofan
? compiler::Pipeline::NewCompilationJob(info)
: new (info->zone()) HCompilationJob(info);
base::SmartPointer<OptimizedCompileJob> job(
use_turbofan ? compiler::Pipeline::NewCompilationJob(info)
: new HCompilationJob(info));

// Parsing is not required when optimizing from existing bytecode.
if (!use_turbofan || !info->shared_info()->HasBytecodeArray()) {
Expand Down Expand Up @@ -755,9 +755,9 @@ bool GetOptimizedCodeLater(CompilationInfo* info) {
}

bool use_turbofan = UseTurboFan(info);
OptimizedCompileJob* job = use_turbofan
? compiler::Pipeline::NewCompilationJob(info)
: new (info->zone()) HCompilationJob(info);
base::SmartPointer<OptimizedCompileJob> job(
use_turbofan ? compiler::Pipeline::NewCompilationJob(info)
: new HCompilationJob(info));

// All handles below this point will be allocated in a deferred handle scope
// that is detached and handed off to the background thread when we return.
Expand All @@ -778,7 +778,8 @@ bool GetOptimizedCodeLater(CompilationInfo* info) {
TRACE_EVENT0("v8", "V8.RecompileSynchronous");

if (job->CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false;
isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
isolate->optimizing_compile_dispatcher()->QueueForOptimization(job.get());
job.Detach(); // The background recompile job owns this now.

if (FLAG_trace_concurrent_recompilation) {
PrintF(" ** Queued ");
Expand Down Expand Up @@ -1725,7 +1726,7 @@ MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function,

void Compiler::FinalizeOptimizedCompileJob(OptimizedCompileJob* job) {
// Take ownership of compilation info. Deleting compilation info
// also tears down the zone and the recompile job.
// also tears down the zone.
base::SmartPointer<CompilationInfo> info(job->info());
Isolate* isolate = info->isolate();

Expand Down Expand Up @@ -1761,6 +1762,7 @@ void Compiler::FinalizeOptimizedCompileJob(OptimizedCompileJob* job) {
PrintF("]\n");
}
info->closure()->ReplaceCode(*info->code());
delete job;
return;
}
}
Expand All @@ -1772,6 +1774,7 @@ void Compiler::FinalizeOptimizedCompileJob(OptimizedCompileJob* job) {
PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
}
info->closure()->ReplaceCode(shared->code());
delete job;
}

void Compiler::PostInstantiation(Handle<JSFunction> function,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ class CompilationInfo {
// Each of the three phases can either fail, bail-out to full code generator or
// succeed. Apart from their return value, the status of the phase last run can
// be checked using {last_status()} as well.
class OptimizedCompileJob: public ZoneObject {
// TODO(mstarzinger): Make CompilationInfo base embedded.
class OptimizedCompileJob {
public:
explicit OptimizedCompileJob(CompilationInfo* info, const char* compiler_name)
: info_(info), compiler_name_(compiler_name), last_status_(SUCCEEDED) {}
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/ia32/instruction-selector-ia32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ class IA32OperandGenerator final : public OperandGenerator {
case IrOpcode::kRelocatableInt64Constant:
return true;
case IrOpcode::kHeapConstant: {
// TODO(bmeurer): We must not dereference handles concurrently. If we
// really have to this here, then we need to find a way to put this
// information on the HeapConstant node already.
#if 0
// Constants in new space cannot be used as immediates in V8 because
// the GC does not scan code objects when collecting the new generation.
Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node);
Isolate* isolate = value->GetIsolate();
return !isolate->heap()->InNewSpace(*value);
#endif
}
default:
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/pipeline-statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <string>

#include "src/base/platform/elapsed-timer.h"
#include "src/base/smart-pointers.h"
#include "src/compilation-statistics.h"
#include "src/compiler/zone-pool.h"

Expand All @@ -22,6 +24,7 @@ class PipelineStatistics : public Malloced {
~PipelineStatistics();

void BeginPhaseKind(const char* phase_kind_name);
void EndPhaseKind();

private:
size_t OuterZoneSize() {
Expand All @@ -43,7 +46,6 @@ class PipelineStatistics : public Malloced {
};

bool InPhaseKind() { return !phase_kind_stats_.scope_.is_empty(); }
void EndPhaseKind();

friend class PhaseScope;
bool InPhase() { return !phase_stats_.scope_.is_empty(); }
Expand Down
Loading

0 comments on commit ff19726

Please sign in to comment.