2017-01-30 19:27:00 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/compiler-dispatcher/optimizing-compile-dispatcher.h"
|
|
|
|
|
|
|
|
#include "src/base/atomic-utils.h"
|
|
|
|
#include "src/base/platform/semaphore.h"
|
|
|
|
#include "src/compilation-info.h"
|
|
|
|
#include "src/compiler.h"
|
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/objects-inl.h"
|
|
|
|
#include "src/parsing/parse-info.h"
|
|
|
|
#include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h"
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
typedef TestWithContext OptimizingCompileDispatcherTest;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class BlockingCompilationJob : public CompilationJob {
|
|
|
|
public:
|
|
|
|
BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function)
|
|
|
|
: CompilationJob(isolate, &info_, "BlockingCompilationJob",
|
|
|
|
State::kReadyToExecute),
|
Reland of land: [Parse] ParseInfo owns the parsing Zone. (patchset #1 id:1 of https://codereview.chromium.org/2683733002/ )
Reason for revert:
False alarm, bot hiccup
Original issue's description:
> Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (patchset #7 id:140001 of https://codereview.chromium.org/2632123006/ )
>
> Reason for revert:
> Speculative revert because of revert needed for https://codereview.chromium.org/2632123006
>
> Original issue's description:
> > Reland: [Parse] ParseInfo owns the parsing Zone.
> >
> > Moves ownership of the parsing Zone to ParseInfo with a shared_ptr. This is
> > in preperation for enabling background compilation jobs for inner functions
> > share the AST in the outer-function's parse zone memory (read-only), with the
> > and zone being released when all compilation jobs have completed.
> >
> > BUG=v8:5203,v8:5215
> >
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Original-Commit-Position: refs/heads/master@{#42993}
> > Committed: https://chromium.googlesource.com/v8/v8/+/14fb337200d5da09c77438ddd40bea935b1dc823
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Commit-Position: refs/heads/master@{#42996}
> > Committed: https://chromium.googlesource.com/v8/v8/+/9e7d5a6065470ca03411d4c8dbc61d1be5c3f84a
>
> TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:5203,v8:5215
>
> Review-Url: https://codereview.chromium.org/2683733002
> Cr-Commit-Position: refs/heads/master@{#43008}
> Committed: https://chromium.googlesource.com/v8/v8/+/9fe08ec067051c5b46e694568bd01c6dba44cc4d
TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203,v8:5215
Review-Url: https://codereview.chromium.org/2679303003
Cr-Commit-Position: refs/heads/master@{#43015}
2017-02-07 20:46:47 +00:00
|
|
|
parse_info_(handle(function->shared())),
|
2017-02-10 09:55:22 +00:00
|
|
|
info_(parse_info_.zone(), &parse_info_, function),
|
2017-01-30 19:27:00 +00:00
|
|
|
blocking_(false),
|
|
|
|
semaphore_(0) {}
|
|
|
|
~BlockingCompilationJob() override = default;
|
|
|
|
|
|
|
|
bool IsBlocking() const { return blocking_.Value(); }
|
|
|
|
void Signal() { semaphore_.Signal(); }
|
|
|
|
|
|
|
|
// CompilationJob implementation.
|
|
|
|
Status PrepareJobImpl() override {
|
|
|
|
UNREACHABLE();
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status ExecuteJobImpl() override {
|
|
|
|
blocking_.SetValue(true);
|
|
|
|
semaphore_.Wait();
|
|
|
|
blocking_.SetValue(false);
|
|
|
|
return SUCCEEDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status FinalizeJobImpl() override { return SUCCEEDED; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ParseInfo parse_info_;
|
|
|
|
CompilationInfo info_;
|
|
|
|
base::AtomicValue<bool> blocking_;
|
|
|
|
base::Semaphore semaphore_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BlockingCompilationJob);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_F(OptimizingCompileDispatcherTest, Construct) {
|
|
|
|
OptimizingCompileDispatcher dispatcher(i_isolate());
|
|
|
|
ASSERT_TRUE(OptimizingCompileDispatcher::Enabled());
|
|
|
|
ASSERT_TRUE(dispatcher.IsQueueAvailable());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OptimizingCompileDispatcherTest, NonBlockingFlush) {
|
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>::cast(
|
|
|
|
RunJS(isolate(), "function f() { function g() {}; return g;}; f();"));
|
|
|
|
BlockingCompilationJob* job = new BlockingCompilationJob(i_isolate(), fun);
|
|
|
|
|
|
|
|
OptimizingCompileDispatcher dispatcher(i_isolate());
|
|
|
|
ASSERT_TRUE(OptimizingCompileDispatcher::Enabled());
|
|
|
|
ASSERT_TRUE(dispatcher.IsQueueAvailable());
|
|
|
|
dispatcher.QueueForOptimization(job);
|
|
|
|
|
|
|
|
// Busy-wait for the job to run on a background thread.
|
|
|
|
while (!job->IsBlocking()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not block.
|
|
|
|
dispatcher.Flush(OptimizingCompileDispatcher::BlockingBehavior::kDontBlock);
|
|
|
|
|
|
|
|
// Unblock the job & finish.
|
|
|
|
job->Signal();
|
|
|
|
dispatcher.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|