de914c7507
This is a reland of 44708a5b6f
Original change's description:
> [compiler, heap] Create LocalHeap outside of ExecuteJob
>
> Create LocalHeap directly in the Task or in GetOptimizedCodeNow and
> pass its reference as argument to ExecuteJob. This allows us to create
> LocalHeap differently for the main and background thread, e.g. by
> passing an additional argument to the constructor in the future.
> It will be required in the future anyways when the main thread will
> have its own LocalHeap/LocalIsolate.
>
> Extending the scope of LocalHeap, also made
> HandleBase::IsDereferenceAllowed more precise and uncovered two
> potential issues: heap accesses in
> OptimizingCompileDispatcher::CompileNext and PipelineImpl::AssembleCode
> with --code-comments.
>
> LocalHeap can now be created in the parked state. Also fixed a data
> race with LocalHeap's destructor publishing write barrier entries
> without holding the lock.
>
> Bug: v8:10315
> Change-Id: I9226972601a07b87108cd66efbbb6a0d118af58d
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2460818
> Commit-Queue: Georg Neis <neis@chromium.org>
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Reviewed-by: Santiago Aboy Solanes <solanes@chromium.org>
> Reviewed-by: Georg Neis <neis@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#70521}
Bug: v8:10315
Change-Id: I4c459fd6dfb98d47fc9941c0dc6864bf5a1d2d3e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2474788
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70560}
102 lines
3.2 KiB
C++
102 lines
3.2 KiB
C++
// 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/api/api-inl.h"
|
|
#include "src/base/atomic-utils.h"
|
|
#include "src/base/platform/semaphore.h"
|
|
#include "src/codegen/compiler.h"
|
|
#include "src/codegen/optimized-compilation-info.h"
|
|
#include "src/execution/isolate.h"
|
|
#include "src/execution/local-isolate.h"
|
|
#include "src/handles/handles.h"
|
|
#include "src/heap/local-heap.h"
|
|
#include "src/objects/objects-inl.h"
|
|
#include "src/parsing/parse-info.h"
|
|
#include "test/unittests/test-helpers.h"
|
|
#include "test/unittests/test-utils.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
using OptimizingCompileDispatcherTest = TestWithNativeContext;
|
|
|
|
namespace {
|
|
|
|
class BlockingCompilationJob : public OptimizedCompilationJob {
|
|
public:
|
|
BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function)
|
|
: OptimizedCompilationJob(&info_, "BlockingCompilationJob",
|
|
State::kReadyToExecute),
|
|
shared_(function->shared(), isolate),
|
|
zone_(isolate->allocator(), ZONE_NAME),
|
|
info_(&zone_, isolate, shared_, function, CodeKind::TURBOFAN),
|
|
blocking_(false),
|
|
semaphore_(0) {}
|
|
~BlockingCompilationJob() override = default;
|
|
|
|
bool IsBlocking() const { return blocking_.Value(); }
|
|
void Signal() { semaphore_.Signal(); }
|
|
|
|
// OptimiziedCompilationJob implementation.
|
|
Status PrepareJobImpl(Isolate* isolate) override { UNREACHABLE(); }
|
|
|
|
Status ExecuteJobImpl(RuntimeCallStats* stats,
|
|
LocalIsolate* local_isolate) override {
|
|
blocking_.SetValue(true);
|
|
semaphore_.Wait();
|
|
blocking_.SetValue(false);
|
|
return SUCCEEDED;
|
|
}
|
|
|
|
Status FinalizeJobImpl(Isolate* isolate) override { return SUCCEEDED; }
|
|
|
|
private:
|
|
Handle<SharedFunctionInfo> shared_;
|
|
Zone zone_;
|
|
OptimizedCompilationInfo 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 =
|
|
RunJS<JSFunction>("function f() { function g() {}; return g;}; f();");
|
|
IsCompiledScope is_compiled_scope;
|
|
ASSERT_TRUE(
|
|
Compiler::Compile(fun, Compiler::CLEAR_EXCEPTION, &is_compiled_scope));
|
|
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(BlockingBehavior::kDontBlock);
|
|
|
|
// Unblock the job & finish.
|
|
job->Signal();
|
|
dispatcher.Stop();
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|