Commit 3d8e87aa authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Switch tracing to use v8::TracingController

BUG=v8:6511
R=fmeawad@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I4961e4b61a9ddc98385ed97c3ffcbcaef2d9cba7
Reviewed-on: https://chromium-review.googlesource.com/543144
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: 's avatarFadi Meawad <fmeawad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46307}
parent 9845f01a
......@@ -70,6 +70,8 @@ V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
* Attempts to set the tracing controller for the given platform.
*
* The |platform| has to be created using |CreateDefaultPlatform|.
*
* DEPRECATED: Will be removed soon.
*/
V8_PLATFORM_EXPORT void SetTracingController(
v8::Platform* platform,
......
......@@ -206,7 +206,7 @@ class Platform {
/**
* Returns an instance of a v8::TracingController. This must be non-nullptr.
*/
virtual TracingController* GetTracingController() { return nullptr; }
virtual TracingController* GetTracingController() = 0;
// DEPRECATED methods, use TracingController interface instead.
......
......@@ -229,6 +229,10 @@ class PredictablePlatform : public Platform {
return synthetic_time_in_sec_ += 0.00001;
}
v8::TracingController* GetTracingController() override {
return platform_->GetTracingController();
}
Platform* platform() const { return platform_.get(); }
private:
......@@ -3104,13 +3108,7 @@ int Shell::Main(int argc, char* argv[]) {
? v8::platform::InProcessStackDumping::kDisabled
: v8::platform::InProcessStackDumping::kEnabled;
g_platform = v8::platform::CreateDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled, in_process_stack_dumping);
if (i::FLAG_verify_predictable) {
g_platform = new PredictablePlatform(std::unique_ptr<Platform>(g_platform));
}
platform::tracing::TracingController* tracing_controller;
platform::tracing::TracingController* tracing_controller = nullptr;
if (options.trace_enabled && !i::FLAG_verify_predictable) {
trace_file.open("v8_trace.json");
tracing_controller = new platform::tracing::TracingController();
......@@ -3119,7 +3117,13 @@ int Shell::Main(int argc, char* argv[]) {
platform::tracing::TraceBuffer::kRingBufferChunks,
platform::tracing::TraceWriter::CreateJSONTraceWriter(trace_file));
tracing_controller->Initialize(trace_buffer);
platform::SetTracingController(g_platform, tracing_controller);
}
g_platform = v8::platform::CreateDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled, in_process_stack_dumping,
tracing_controller);
if (i::FLAG_verify_predictable) {
g_platform = new PredictablePlatform(std::unique_ptr<Platform>(g_platform));
}
v8::V8::InitializePlatform(g_platform);
......
......@@ -13,6 +13,8 @@
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/base/sys-info.h"
#include "src/libplatform/tracing/trace-buffer.h"
#include "src/libplatform/tracing/trace-writer.h"
#include "src/libplatform/worker-thread.h"
namespace v8 {
......@@ -36,11 +38,10 @@ v8::Platform* CreateDefaultPlatform(
if (in_process_stack_dumping == InProcessStackDumping::kEnabled) {
v8::base::debug::EnableInProcessStackDumping();
}
DefaultPlatform* platform = new DefaultPlatform(idle_task_support);
DefaultPlatform* platform =
new DefaultPlatform(idle_task_support, tracing_controller);
platform->SetThreadPoolSize(thread_pool_size);
platform->EnsureInitialized();
if (tracing_controller != nullptr)
platform->SetTracingController(tracing_controller);
return platform;
}
......@@ -64,16 +65,28 @@ void RunIdleTasks(v8::Platform* platform, v8::Isolate* isolate,
void SetTracingController(
v8::Platform* platform,
v8::platform::tracing::TracingController* tracing_controller) {
return static_cast<DefaultPlatform*>(platform)->SetTracingController(
static_cast<DefaultPlatform*>(platform)->SetTracingController(
tracing_controller);
}
const int DefaultPlatform::kMaxThreadPoolSize = 8;
DefaultPlatform::DefaultPlatform(IdleTaskSupport idle_task_support)
DefaultPlatform::DefaultPlatform(IdleTaskSupport idle_task_support,
v8::TracingController* tracing_controller)
: initialized_(false),
thread_pool_size_(0),
idle_task_support_(idle_task_support) {}
idle_task_support_(idle_task_support) {
if (tracing_controller) {
tracing_controller_.reset(tracing_controller);
} else {
tracing::TraceWriter* writer = new tracing::NullTraceWriter();
tracing::TraceBuffer* ring_buffer =
new tracing::TraceBufferRingBuffer(1, writer);
tracing::TracingController* controller = new tracing::TracingController();
controller->Initialize(ring_buffer);
tracing_controller_.reset(controller);
}
}
DefaultPlatform::~DefaultPlatform() {
base::LockGuard<base::Mutex> guard(&lock_);
......@@ -274,47 +287,9 @@ TracingController* DefaultPlatform::GetTracingController() {
return tracing_controller_.get();
}
uint64_t DefaultPlatform::AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) {
if (tracing_controller_) {
return tracing_controller_->AddTraceEvent(
phase, category_enabled_flag, name, scope, id, bind_id, num_args,
arg_names, arg_types, arg_values, arg_convertables, flags);
}
return 0;
}
void DefaultPlatform::UpdateTraceEventDuration(
const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {
if (tracing_controller_) {
tracing_controller_->UpdateTraceEventDuration(category_enabled_flag, name,
handle);
}
}
const uint8_t* DefaultPlatform::GetCategoryGroupEnabled(const char* name) {
if (tracing_controller_) {
return tracing_controller_->GetCategoryGroupEnabled(name);
}
static uint8_t no = 0;
return &no;
}
const char* DefaultPlatform::GetCategoryGroupName(
const uint8_t* category_enabled_flag) {
static const char dummy[] = "dummy";
return dummy;
}
void DefaultPlatform::SetTracingController(
TracingController* tracing_controller) {
v8::TracingController* tracing_controller) {
DCHECK_NOT_NULL(tracing_controller);
tracing_controller_.reset(tracing_controller);
}
......@@ -322,16 +297,6 @@ size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() {
return static_cast<size_t>(thread_pool_size_);
}
void DefaultPlatform::AddTraceStateObserver(TraceStateObserver* observer) {
if (!tracing_controller_) return;
tracing_controller_->AddTraceStateObserver(observer);
}
void DefaultPlatform::RemoveTraceStateObserver(TraceStateObserver* observer) {
if (!tracing_controller_) return;
tracing_controller_->RemoveTraceStateObserver(observer);
}
Platform::StackTracePrinter DefaultPlatform::GetStackTracePrinter() {
return PrintStackTrace;
}
......
......@@ -30,7 +30,8 @@ class WorkerThread;
class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
public:
explicit DefaultPlatform(
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled);
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
v8::TracingController* tracing_controller = nullptr);
virtual ~DefaultPlatform();
void SetThreadPoolSize(int thread_pool_size);
......@@ -44,6 +45,8 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
void RunIdleTasks(v8::Isolate* isolate, double idle_time_in_seconds);
void SetTracingController(v8::TracingController* tracing_controller);
// v8::Platform implementation.
size_t NumberOfAvailableBackgroundThreads() override;
void CallOnBackgroundThread(Task* task,
......@@ -54,24 +57,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override;
bool IdleTasksEnabled(Isolate* isolate) override;
double MonotonicallyIncreasingTime() override;
TracingController* GetTracingController() override;
const uint8_t* GetCategoryGroupEnabled(const char* name) override;
const char* GetCategoryGroupName(
const uint8_t* category_enabled_flag) override;
using Platform::AddTraceEvent;
uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) override;
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) override;
void SetTracingController(TracingController* tracing_controller);
void AddTraceStateObserver(TraceStateObserver* observer) override;
void RemoveTraceStateObserver(TraceStateObserver* observer) override;
v8::TracingController* GetTracingController() override;
StackTracePrinter GetStackTracePrinter() override;
private:
......
......@@ -26,6 +26,14 @@ class JSONTraceWriter : public TraceWriter {
bool append_comma_ = false;
};
class NullTraceWriter : public TraceWriter {
public:
NullTraceWriter() = default;
~NullTraceWriter() = default;
void AppendTraceEvent(TraceObject*) override {}
void Flush() override {}
};
} // namespace tracing
} // namespace platform
} // namespace v8
......
......@@ -40,7 +40,7 @@ v8::base::AtomicWord g_category_index = g_num_builtin_categories;
TracingController::TracingController() {}
TracingController::~TracingController() {}
TracingController::~TracingController() { StopTracing(); }
void TracingController::Initialize(TraceBuffer* trace_buffer) {
trace_buffer_.reset(trace_buffer);
......@@ -111,6 +111,10 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
}
void TracingController::StopTracing() {
if (mode_ == DISABLED) {
return;
}
DCHECK(trace_buffer_);
mode_ = DISABLED;
UpdateCategoryGroupEnabledFlags();
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
......
......@@ -25,12 +25,13 @@ TracingCpuProfilerImpl::TracingCpuProfilerImpl(Isolate* isolate)
TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"));
TRACE_EVENT_WARMUP_CATEGORY(
TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler.hires"));
V8::GetCurrentPlatform()->AddTraceStateObserver(this);
V8::GetCurrentPlatform()->GetTracingController()->AddTraceStateObserver(this);
}
TracingCpuProfilerImpl::~TracingCpuProfilerImpl() {
StopProfiling();
V8::GetCurrentPlatform()->RemoveTraceStateObserver(this);
V8::GetCurrentPlatform()->GetTracingController()->RemoveTraceStateObserver(
this);
}
void TracingCpuProfilerImpl::OnTraceEnabled() {
......
......@@ -17,13 +17,14 @@ namespace internal {
class CpuProfiler;
class Isolate;
class TracingCpuProfilerImpl final : public TracingCpuProfiler,
private v8::Platform::TraceStateObserver {
class TracingCpuProfilerImpl final
: public TracingCpuProfiler,
private v8::TracingController::TraceStateObserver {
public:
explicit TracingCpuProfilerImpl(Isolate*);
~TracingCpuProfilerImpl();
// v8::Platform::TraceStateObserver
// v8::TracingController::TraceStateObserver
void OnTraceEnabled() final;
void OnTraceDisabled() final;
......
......@@ -15,8 +15,8 @@ namespace v8 {
namespace internal {
namespace tracing {
v8::Platform* TraceEventHelper::GetCurrentPlatform() {
return v8::internal::V8::GetCurrentPlatform();
v8::TracingController* TraceEventHelper::GetTracingController() {
return v8::internal::V8::GetCurrentPlatform()->GetTracingController();
}
void CallStatsScopedTracer::AddEndTraceEvent() {
......
......@@ -73,7 +73,7 @@ enum CategoryGroupEnabledFlags {
// const uint8_t*
// TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
v8::internal::tracing::TraceEventHelper::GetTracingController() \
->GetCategoryGroupEnabled
// Get the number of times traces have been recorded. This is used to implement
......@@ -102,7 +102,7 @@ enum CategoryGroupEnabledFlags {
// const char* name,
// uint64_t id)
#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
v8::internal::tracing::TraceEventHelper::GetTracingController() \
->UpdateTraceEventDuration
// Defines atomic operations used internally by the tracing system.
......@@ -277,7 +277,7 @@ const uint64_t kNoId = 0;
class TraceEventHelper {
public:
static v8::Platform* GetCurrentPlatform();
static v8::TracingController* GetTracingController();
};
// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
......@@ -424,10 +424,10 @@ static V8_INLINE uint64_t AddTraceEventImpl(
static_cast<intptr_t>(arg_values[1])));
}
DCHECK(num_args <= 2);
v8::Platform* platform =
v8::internal::tracing::TraceEventHelper::GetCurrentPlatform();
return platform->AddTraceEvent(phase, category_group_enabled, name, scope, id,
bind_id, num_args, arg_names, arg_types,
v8::TracingController* controller =
v8::internal::tracing::TraceEventHelper::GetTracingController();
return controller->AddTraceEvent(phase, category_group_enabled, name, scope,
id, bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertables, flags);
}
......
......@@ -15,8 +15,9 @@ TracingCategoryObserver* TracingCategoryObserver::instance_ = nullptr;
void TracingCategoryObserver::SetUp() {
TracingCategoryObserver::instance_ = new TracingCategoryObserver();
v8::internal::V8::GetCurrentPlatform()->AddTraceStateObserver(
TracingCategoryObserver::instance_);
v8::internal::V8::GetCurrentPlatform()
->GetTracingController()
->AddTraceStateObserver(TracingCategoryObserver::instance_);
TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"));
TRACE_EVENT_WARMUP_CATEGORY(
TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling"));
......@@ -25,8 +26,9 @@ void TracingCategoryObserver::SetUp() {
}
void TracingCategoryObserver::TearDown() {
v8::internal::V8::GetCurrentPlatform()->RemoveTraceStateObserver(
TracingCategoryObserver::instance_);
v8::internal::V8::GetCurrentPlatform()
->GetTracingController()
->RemoveTraceStateObserver(TracingCategoryObserver::instance_);
delete TracingCategoryObserver::instance_;
}
......
......@@ -10,7 +10,7 @@
namespace v8 {
namespace tracing {
class TracingCategoryObserver : public Platform::TraceStateObserver {
class TracingCategoryObserver : public TracingController::TraceStateObserver {
public:
enum Mode {
ENABLED_BY_NATIVE = 1 << 0,
......@@ -21,7 +21,7 @@ class TracingCategoryObserver : public Platform::TraceStateObserver {
static void SetUp();
static void TearDown();
// v8::Platform::TraceStateObserver
// v8::TracingController::TraceStateObserver
void OnTraceEnabled() final;
void OnTraceDisabled() final;
......
......@@ -62,6 +62,10 @@ class MockPlatform : public v8::Platform {
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
v8::TracingController* GetTracingController() override {
return platform_->GetTracingController();
}
bool PendingTask() { return task_ != nullptr; }
void PerformTask() {
......
......@@ -4,6 +4,7 @@
#include <limits>
#include "include/libplatform/v8-tracing.h"
#include "src/libplatform/default-platform.h"
#include "src/tracing/trace-event.h"
#include "test/cctest/cctest.h"
......@@ -135,7 +136,8 @@ TEST(TestJSONTraceWriter) {
// Create a scope for the tracing controller to terminate the trace writer.
{
TracingController tracing_controller;
platform::SetTracingController(default_platform, &tracing_controller);
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
TraceBuffer* ring_buffer =
......@@ -178,7 +180,8 @@ TEST(TestTracingController) {
i::V8::SetPlatformForTesting(default_platform);
TracingController tracing_controller;
platform::SetTracingController(default_platform, &tracing_controller);
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
MockTraceWriter* writer = new MockTraceWriter();
TraceBuffer* ring_buffer =
......@@ -244,7 +247,8 @@ TEST(TestTracingControllerMultipleArgsAndCopy) {
// Create a scope for the tracing controller to terminate the trace writer.
{
TracingController tracing_controller;
platform::SetTracingController(default_platform, &tracing_controller);
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
TraceBuffer* ring_buffer =
......@@ -339,7 +343,7 @@ TEST(TestTracingControllerMultipleArgsAndCopy) {
namespace {
class TraceStateObserverImpl : public Platform::TraceStateObserver {
class TraceStateObserverImpl : public TracingController::TraceStateObserver {
public:
void OnTraceEnabled() override { ++enabled_count; }
void OnTraceDisabled() override { ++disabled_count; }
......@@ -356,7 +360,8 @@ TEST(TracingObservers) {
i::V8::SetPlatformForTesting(default_platform);
v8::platform::tracing::TracingController tracing_controller;
v8::platform::SetTracingController(default_platform, &tracing_controller);
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
MockTraceWriter* writer = new MockTraceWriter();
v8::platform::tracing::TraceBuffer* ring_buffer =
v8::platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(1,
......@@ -367,7 +372,7 @@ TEST(TracingObservers) {
trace_config->AddIncludedCategory("v8");
TraceStateObserverImpl observer;
default_platform->AddTraceStateObserver(&observer);
tracing_controller.AddTraceStateObserver(&observer);
CHECK_EQ(0, observer.enabled_count);
CHECK_EQ(0, observer.disabled_count);
......@@ -378,12 +383,12 @@ TEST(TracingObservers) {
CHECK_EQ(0, observer.disabled_count);
TraceStateObserverImpl observer2;
default_platform->AddTraceStateObserver(&observer2);
tracing_controller.AddTraceStateObserver(&observer2);
CHECK_EQ(1, observer2.enabled_count);
CHECK_EQ(0, observer2.disabled_count);
default_platform->RemoveTraceStateObserver(&observer2);
tracing_controller.RemoveTraceStateObserver(&observer2);
CHECK_EQ(1, observer2.enabled_count);
CHECK_EQ(0, observer2.disabled_count);
......@@ -395,7 +400,7 @@ TEST(TracingObservers) {
CHECK_EQ(1, observer2.enabled_count);
CHECK_EQ(0, observer2.disabled_count);
default_platform->RemoveTraceStateObserver(&observer);
tracing_controller.RemoveTraceStateObserver(&observer);
CHECK_EQ(1, observer.enabled_count);
CHECK_EQ(1, observer.disabled_count);
......
......@@ -33,6 +33,7 @@
#include "src/api.h"
#include "src/base/platform/platform.h"
#include "src/deoptimizer.h"
#include "src/libplatform/default-platform.h"
#include "src/objects-inl.h"
#include "src/profiler/cpu-profiler-inl.h"
#include "src/profiler/profiler-listener.h"
......@@ -2152,7 +2153,8 @@ TEST(TracingCpuProfiler) {
i::V8::SetPlatformForTesting(default_platform);
v8::platform::tracing::TracingController tracing_controller;
v8::platform::SetTracingController(default_platform, &tracing_controller);
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
CpuProfileEventChecker* event_checker = new CpuProfileEventChecker();
TraceBuffer* ring_buffer =
......
......@@ -40,38 +40,16 @@ struct MockTraceObject {
typedef v8::internal::List<MockTraceObject*> MockTraceObjectList;
class MockTracingPlatform : public v8::Platform {
class MockTracingController : public v8::TracingController {
public:
explicit MockTracingPlatform(v8::Platform* platform) {}
virtual ~MockTracingPlatform() {
MockTracingController() = default;
~MockTracingController() {
for (int i = 0; i < trace_object_list_.length(); ++i) {
delete trace_object_list_[i];
}
trace_object_list_.Clear();
}
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {}
void CallOnForegroundThread(Isolate* isolate, Task* task) override {}
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override {}
double MonotonicallyIncreasingTime() override { return 0.0; }
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {}
bool IdleTasksEnabled(Isolate* isolate) override { return false; }
bool PendingIdleTask() { return false; }
void PerformIdleTask(double idle_time_in_seconds) {}
bool PendingDelayedTask() { return false; }
void PerformDelayedTask() {}
using Platform::AddTraceEvent;
uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
......@@ -98,16 +76,52 @@ class MockTracingPlatform : public v8::Platform {
}
}
const char* GetCategoryGroupName(
const uint8_t* category_enabled_flag) override {
static const char dummy[] = "dummy";
return dummy;
}
MockTraceObjectList* GetMockTraceObjects() { return &trace_object_list_; }
private:
MockTraceObjectList trace_object_list_;
DISALLOW_COPY_AND_ASSIGN(MockTracingController);
};
class MockTracingPlatform : public v8::Platform {
public:
explicit MockTracingPlatform(v8::Platform* platform) {}
virtual ~MockTracingPlatform() {}
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {}
void CallOnForegroundThread(Isolate* isolate, Task* task) override {}
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override {}
double MonotonicallyIncreasingTime() override { return 0.0; }
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {}
bool IdleTasksEnabled(Isolate* isolate) override { return false; }
v8::TracingController* GetTracingController() override {
return &tracing_controller_;
}
bool PendingIdleTask() { return false; }
void PerformIdleTask(double idle_time_in_seconds) {}
bool PendingDelayedTask() { return false; }
void PerformDelayedTask() {}
MockTraceObjectList* GetMockTraceObjects() {
return tracing_controller_.GetMockTraceObjects();
}
private:
MockTracingController tracing_controller_;
DISALLOW_COPY_AND_ASSIGN(MockTracingPlatform);
};
......
......@@ -103,7 +103,12 @@ namespace {
class MockPlatform : public v8::Platform {
public:
MockPlatform() : time_(0.0), time_step_(0.0), idle_task_(nullptr), sem_(0) {}
explicit MockPlatform(v8::TracingController* tracing_controller)
: time_(0.0),
time_step_(0.0),
idle_task_(nullptr),
sem_(0),
tracing_controller_(tracing_controller) {}
~MockPlatform() override {
base::LockGuard<base::Mutex> lock(&mutex_);
EXPECT_TRUE(foreground_tasks_.empty());
......@@ -143,6 +148,10 @@ class MockPlatform : public v8::Platform {
return time_;
}
v8::TracingController* GetTracingController() override {
return tracing_controller_;
}
void RunIdleTask(double deadline_in_seconds, double time_step) {
time_step_ = time_step;
IdleTask* task;
......@@ -269,6 +278,8 @@ class MockPlatform : public v8::Platform {
base::Semaphore sem_;
v8::TracingController* tracing_controller_;
DISALLOW_COPY_AND_ASSIGN(MockPlatform);
};
......@@ -277,12 +288,12 @@ const char test_script[] = "(x) { x*x; }";
} // namespace
TEST_F(CompilerDispatcherTest, Construct) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
}
TEST_F(CompilerDispatcherTest, IsEnqueued) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -300,7 +311,7 @@ TEST_F(CompilerDispatcherTest, IsEnqueued) {
}
TEST_F(CompilerDispatcherTest, FinishNow) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -319,7 +330,7 @@ TEST_F(CompilerDispatcherTest, FinishNow) {
}
TEST_F(CompilerDispatcherTest, FinishAllNow) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
constexpr int num_funcs = 2;
......@@ -349,7 +360,7 @@ TEST_F(CompilerDispatcherTest, FinishAllNow) {
}
TEST_F(CompilerDispatcherTest, IdleTask) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -370,7 +381,7 @@ TEST_F(CompilerDispatcherTest, IdleTask) {
}
TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -409,7 +420,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) {
}
TEST_F(CompilerDispatcherTest, IdleTaskException) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
std::string func_name("f" STR(__LINE__));
......@@ -436,7 +447,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskException) {
}
TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -480,7 +491,7 @@ TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
}
TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -520,7 +531,7 @@ TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
}
TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script1[] = TEST_SCRIPT();
......@@ -549,7 +560,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) {
}
TEST_F(CompilerDispatcherTest, FinishNowException) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
std::string func_name("f" STR(__LINE__));
......@@ -577,7 +588,7 @@ TEST_F(CompilerDispatcherTest, FinishNowException) {
}
TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -620,7 +631,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
}
TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script1[] = TEST_SCRIPT();
......@@ -702,7 +713,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
}
TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -781,7 +792,7 @@ TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
}
TEST_F(CompilerDispatcherTest, MemoryPressure) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -829,7 +840,7 @@ class PressureNotificationTask : public CancelableTask {
} // namespace
TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -862,7 +873,7 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
}
TEST_F(CompilerDispatcherTest, EnqueueJob) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
Handle<JSFunction> f =
......@@ -881,7 +892,7 @@ TEST_F(CompilerDispatcherTest, EnqueueJob) {
}
TEST_F(CompilerDispatcherTest, EnqueueWithoutSFI) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
ASSERT_TRUE(dispatcher.jobs_.empty());
ASSERT_TRUE(dispatcher.shared_to_job_id_.empty());
......@@ -906,7 +917,7 @@ TEST_F(CompilerDispatcherTest, EnqueueWithoutSFI) {
}
TEST_F(CompilerDispatcherTest, EnqueueAndStep) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT();
......@@ -928,7 +939,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStep) {
}
TEST_F(CompilerDispatcherTest, EnqueueParsed) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char source[] = TEST_SCRIPT();
......@@ -955,7 +966,7 @@ TEST_F(CompilerDispatcherTest, EnqueueParsed) {
}
TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char source[] = TEST_SCRIPT();
......@@ -984,7 +995,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) {
}
TEST_F(CompilerDispatcherTest, CompileParsedOutOfScope) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char source[] = TEST_SCRIPT();
......@@ -1046,7 +1057,7 @@ class MockNativeFunctionExtension : public Extension {
} // namespace
TEST_F(CompilerDispatcherTestWithoutContext, CompileExtensionWithoutContext) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
Local<v8::Context> context = v8::Context::New(isolate());
......@@ -1145,7 +1156,7 @@ TEST_F(CompilerDispatcherTest, CompileLazy2FinishesDispatcherJob) {
}
TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char source[] = TEST_SCRIPT();
......@@ -1186,7 +1197,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
}
TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) {
MockPlatform platform;
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController());
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script1[] = TEST_SCRIPT();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment