[cleanup] use unique_ptr for the DefaultPlatform

With this CL, {CreateDefaultPlatform} returns a unique_ptr to indicate
that the caller owns the returned memory. We had several memory leaks
where the memory of the DefaultPlatform did not get deallocated.

In addition, the {TracingController} of the {DefaultPlatform} also gets
received as a unique_ptr. Thereby we document that the {DefaultPlatform}
takes ownership of the {TracingController}. Note that the memory of the
{TracingController} was already owned by the {DefaultPlatform}, but it
was not documented in the interface, and it was used incorrectly in
tests.

This CL fixes the asan issues in 
https://chromium-review.googlesource.com/c/v8/v8/+/753583	
([platform] Implement TaskRunners in the DefaultPlatform)

R=rmcilroy@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I0d1a6d3b22bb8289dc050b1977e4f58381cec675
Reviewed-on: https://chromium-review.googlesource.com/755033
Reviewed-by: Adam Klein <adamk@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49349}
This commit is contained in:
Andreas Haas 2017-11-13 14:16:49 +01:00 committed by Commit Bot
parent 6526c6dd10
commit ffee558e14
18 changed files with 161 additions and 139 deletions

View File

@ -8,6 +8,7 @@
#include "libplatform/libplatform-export.h"
#include "libplatform/v8-tracing.h"
#include "v8-platform.h" // NOLINT(build/include)
#include "v8config.h" // NOLINT(build/include)
namespace v8 {
namespace platform {
@ -33,12 +34,21 @@ enum class MessageLoopBehavior : bool {
* If |tracing_controller| is nullptr, the default platform will create a
* v8::platform::TracingController instance and use it.
*/
V8_PLATFORM_EXPORT v8::Platform* CreateDefaultPlatform(
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
int thread_pool_size = 0,
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
InProcessStackDumping in_process_stack_dumping =
InProcessStackDumping::kEnabled,
v8::TracingController* tracing_controller = nullptr);
std::unique_ptr<v8::TracingController> tracing_controller = {});
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
"Use NewDefaultPlatform instead",
v8::Platform* CreateDefaultPlatform(
int thread_pool_size = 0,
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
InProcessStackDumping in_process_stack_dumping =
InProcessStackDumping::kEnabled,
v8::TracingController* tracing_controller = nullptr));
/**
* Pumps the message loop for the given isolate.
@ -46,7 +56,7 @@ V8_PLATFORM_EXPORT v8::Platform* CreateDefaultPlatform(
* The caller has to make sure that this is called from the right thread.
* Returns true if a task was executed, and false otherwise. Unless requested
* through the |behavior| parameter, this call does not block if no task is
* pending. The |platform| has to be created using |CreateDefaultPlatform|.
* pending. The |platform| has to be created using |NewDefaultPlatform|.
*/
V8_PLATFORM_EXPORT bool PumpMessageLoop(
v8::Platform* platform, v8::Isolate* isolate,
@ -60,7 +70,7 @@ V8_PLATFORM_EXPORT void EnsureEventLoopInitialized(v8::Platform* platform,
*
* The caller has to make sure that this is called from the right thread.
* This call does not block if no task is pending. The |platform| has to be
* created using |CreateDefaultPlatform|.
* created using |NewDefaultPlatform|.
*/
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
v8::Isolate* isolate,
@ -69,13 +79,14 @@ 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|.
* The |platform| has to be created using |NewDefaultPlatform|.
*
* DEPRECATED: Will be removed soon.
*/
V8_PLATFORM_EXPORT void SetTracingController(
v8::Platform* platform,
v8::platform::tracing::TracingController* tracing_controller);
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
"Access the DefaultPlatform directly",
void SetTracingController(
v8::Platform* platform,
v8::platform::tracing::TracingController* tracing_controller));
} // namespace platform
} // namespace v8

View File

@ -13,8 +13,8 @@ int main(int argc, char* argv[]) {
// Initialize V8.
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
// Create a new Isolate and make it the current one.
@ -56,7 +56,6 @@ int main(int argc, char* argv[]) {
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
delete create_params.array_buffer_allocator;
return 0;
}

View File

@ -701,8 +701,8 @@ void PrintMap(map<string, string>* m) {
int main(int argc, char* argv[]) {
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
map<string, string> options;
string file;
@ -728,7 +728,7 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "Error initializing processor.\n");
return 1;
}
if (!ProcessEntries(platform, &processor, kSampleSize, kSampleRequests))
if (!ProcessEntries(platform.get(), &processor, kSampleSize, kSampleRequests))
return 1;
PrintMap(&output);
}

View File

@ -66,8 +66,8 @@ static bool run_shell;
int main(int argc, char* argv[]) {
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::Isolate::CreateParams create_params;
@ -85,13 +85,12 @@ int main(int argc, char* argv[]) {
return 1;
}
v8::Context::Scope context_scope(context);
result = RunMain(isolate, platform, argc, argv);
if (run_shell) RunShell(context, platform);
result = RunMain(isolate, platform.get(), argc, argv);
if (run_shell) RunShell(context, platform.get());
}
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
delete create_params.array_buffer_allocator;
return result;
}

View File

@ -252,12 +252,12 @@ class PredictablePlatform : public Platform {
DISALLOW_COPY_AND_ASSIGN(PredictablePlatform);
};
v8::Platform* g_platform = nullptr;
std::unique_ptr<v8::Platform> g_platform;
v8::Platform* GetDefaultPlatform() {
return i::FLAG_verify_predictable
? static_cast<PredictablePlatform*>(g_platform)->platform()
: g_platform;
? static_cast<PredictablePlatform*>(g_platform.get())->platform()
: g_platform.get();
}
static Local<Value> Throw(Isolate* isolate, const char* message) {
@ -3210,25 +3210,26 @@ int Shell::Main(int argc, char* argv[]) {
? v8::platform::InProcessStackDumping::kDisabled
: v8::platform::InProcessStackDumping::kEnabled;
platform::tracing::TracingController* tracing_controller = nullptr;
std::unique_ptr<platform::tracing::TracingController> tracing;
if (options.trace_enabled && !i::FLAG_verify_predictable) {
tracing = base::make_unique<platform::tracing::TracingController>();
trace_file.open("v8_trace.json");
tracing_controller = new platform::tracing::TracingController();
platform::tracing::TraceBuffer* trace_buffer =
platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(
platform::tracing::TraceBuffer::kRingBufferChunks,
platform::tracing::TraceWriter::CreateJSONTraceWriter(trace_file));
tracing_controller->Initialize(trace_buffer);
tracing->Initialize(trace_buffer);
}
g_platform = v8::platform::CreateDefaultPlatform(
platform::tracing::TracingController* tracing_controller = tracing.get();
g_platform = v8::platform::NewDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled, in_process_stack_dumping,
tracing_controller);
std::move(tracing));
if (i::FLAG_verify_predictable) {
g_platform = new PredictablePlatform(std::unique_ptr<Platform>(g_platform));
g_platform.reset(new PredictablePlatform(std::move(g_platform)));
}
v8::V8::InitializePlatform(g_platform);
v8::V8::InitializePlatform(g_platform.get());
v8::V8::Initialize();
if (options.natives_blob || options.snapshot_blob) {
v8::V8::InitializeExternalStartupData(options.natives_blob,
@ -3343,7 +3344,6 @@ int Shell::Main(int argc, char* argv[]) {
OnExit(isolate);
V8::Dispose();
V8::ShutdownPlatform();
delete g_platform;
return result;
}

View File

@ -29,18 +29,28 @@ void PrintStackTrace() {
} // namespace
std::unique_ptr<v8::Platform> NewDefaultPlatform(
int thread_pool_size, IdleTaskSupport idle_task_support,
InProcessStackDumping in_process_stack_dumping,
std::unique_ptr<v8::TracingController> tracing_controller) {
if (in_process_stack_dumping == InProcessStackDumping::kEnabled) {
v8::base::debug::EnableInProcessStackDumping();
}
std::unique_ptr<DefaultPlatform> platform(
new DefaultPlatform(idle_task_support, std::move(tracing_controller)));
platform->SetThreadPoolSize(thread_pool_size);
platform->EnsureInitialized();
return std::move(platform);
}
v8::Platform* CreateDefaultPlatform(
int thread_pool_size, IdleTaskSupport idle_task_support,
InProcessStackDumping in_process_stack_dumping,
v8::TracingController* tracing_controller) {
if (in_process_stack_dumping == InProcessStackDumping::kEnabled) {
v8::base::debug::EnableInProcessStackDumping();
}
DefaultPlatform* platform =
new DefaultPlatform(idle_task_support, tracing_controller);
platform->SetThreadPoolSize(thread_pool_size);
platform->EnsureInitialized();
return platform;
return NewDefaultPlatform(
thread_pool_size, idle_task_support, in_process_stack_dumping,
std::unique_ptr<v8::TracingController>(tracing_controller))
.release();
}
bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate,
@ -64,19 +74,19 @@ void SetTracingController(
v8::Platform* platform,
v8::platform::tracing::TracingController* tracing_controller) {
static_cast<DefaultPlatform*>(platform)->SetTracingController(
tracing_controller);
std::unique_ptr<v8::TracingController>(tracing_controller));
}
const int DefaultPlatform::kMaxThreadPoolSize = 8;
DefaultPlatform::DefaultPlatform(IdleTaskSupport idle_task_support,
v8::TracingController* tracing_controller)
DefaultPlatform::DefaultPlatform(
IdleTaskSupport idle_task_support,
std::unique_ptr<v8::TracingController> tracing_controller)
: initialized_(false),
thread_pool_size_(0),
idle_task_support_(idle_task_support) {
if (tracing_controller) {
tracing_controller_.reset(tracing_controller);
} else {
idle_task_support_(idle_task_support),
tracing_controller_(std::move(tracing_controller)) {
if (!tracing_controller_) {
tracing::TracingController* controller = new tracing::TracingController();
controller->Initialize(nullptr);
tracing_controller_.reset(controller);
@ -287,9 +297,9 @@ TracingController* DefaultPlatform::GetTracingController() {
}
void DefaultPlatform::SetTracingController(
v8::TracingController* tracing_controller) {
DCHECK_NOT_NULL(tracing_controller);
tracing_controller_.reset(tracing_controller);
std::unique_ptr<v8::TracingController> tracing_controller) {
DCHECK_NOT_NULL(tracing_controller.get());
tracing_controller_ = std::move(tracing_controller);
}
size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() {

View File

@ -31,7 +31,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
public:
explicit DefaultPlatform(
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
v8::TracingController* tracing_controller = nullptr);
std::unique_ptr<v8::TracingController> tracing_controller = {nullptr});
virtual ~DefaultPlatform();
void SetThreadPoolSize(int thread_pool_size);
@ -45,7 +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);
void SetTracingController(
std::unique_ptr<v8::TracingController> tracing_controller);
// v8::Platform implementation.
size_t NumberOfAvailableBackgroundThreads() override;

View File

@ -156,8 +156,8 @@ int main(int argc, char** argv) {
i::CpuFeatures::Probe(true);
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
{
@ -186,6 +186,5 @@ int main(int argc, char** argv) {
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
return 0;
}

View File

@ -263,8 +263,8 @@ int main(int argc, char* argv[]) {
}
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform(v8::platform::NewDefaultPlatform());
v8::V8::InitializePlatform(platform.get());
v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
v8::V8::Initialize();
v8::V8::InitializeExternalStartupData(argv[0]);
@ -334,7 +334,6 @@ int main(int argc, char* argv[]) {
// TODO(svenpanne) See comment above.
// if (!disable_automatic_dispose_) v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
return 0;
}

View File

@ -301,7 +301,7 @@ void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT
}
V8InitializationScope::V8InitializationScope(const char* exec_path)
: platform_(v8::platform::CreateDefaultPlatform()) {
: platform_(v8::platform::NewDefaultPlatform()) {
i::FLAG_always_opt = false;
i::FLAG_allow_natives_syntax = true;

View File

@ -130,35 +130,40 @@ TEST(TestTraceBufferRingBuffer) {
TEST(TestJSONTraceWriter) {
std::ostringstream stream;
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
i::V8::SetPlatformForTesting(default_platform);
// Create a scope for the tracing controller to terminate the trace writer.
{
TracingController tracing_controller;
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform());
i::V8::SetPlatformForTesting(default_platform.get());
auto tracing =
base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller =
tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
TraceBuffer* ring_buffer =
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
tracing_controller.Initialize(ring_buffer);
tracing_controller->Initialize(ring_buffer);
TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory("v8-cat");
tracing_controller.StartTracing(trace_config);
tracing_controller->StartTracing(trace_config);
TraceObject trace_object;
trace_object.InitializeForTesting(
'X', tracing_controller.GetCategoryGroupEnabled("v8-cat"), "Test0",
'X', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test0",
v8::internal::tracing::kGlobalScope, 42, 123, 0, nullptr, nullptr,
nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID, 11, 22, 100, 50, 33, 44);
writer->AppendTraceEvent(&trace_object);
trace_object.InitializeForTesting(
'Y', tracing_controller.GetCategoryGroupEnabled("v8-cat"), "Test1",
'Y', tracing_controller->GetCategoryGroupEnabled("v8-cat"), "Test1",
v8::internal::tracing::kGlobalScope, 43, 456, 0, nullptr, nullptr,
nullptr, nullptr, 0, 55, 66, 110, 55, 77, 88);
writer->AppendTraceEvent(&trace_object);
tracing_controller.StopTracing();
tracing_controller->StopTracing();
i::V8::SetPlatformForTesting(old_platform);
}
std::string trace_str = stream.str();
@ -170,32 +175,32 @@ TEST(TestJSONTraceWriter) {
"\"Test1\",\"dur\":77,\"tdur\":88,\"args\":{}}]}";
CHECK_EQ(expected_trace_str, trace_str);
i::V8::SetPlatformForTesting(old_platform);
}
TEST(TestTracingController) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
i::V8::SetPlatformForTesting(default_platform);
std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform());
i::V8::SetPlatformForTesting(default_platform.get());
TracingController tracing_controller;
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
auto tracing = base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller = tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));
MockTraceWriter* writer = new MockTraceWriter();
TraceBuffer* ring_buffer =
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
tracing_controller.Initialize(ring_buffer);
tracing_controller->Initialize(ring_buffer);
TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory("v8");
tracing_controller.StartTracing(trace_config);
tracing_controller->StartTracing(trace_config);
TRACE_EVENT0("v8", "v8.Test");
// cat category is not included in default config
TRACE_EVENT0("cat", "v8.Test2");
TRACE_EVENT0("v8", "v8.Test3");
tracing_controller.StopTracing();
tracing_controller->StopTracing();
CHECK_EQ(2u, writer->events().size());
CHECK_EQ(std::string("v8.Test"), writer->events()[0]);
@ -220,10 +225,6 @@ void GetJSONStrings(std::vector<std::string>& ret, std::string str,
TEST(TestTracingControllerMultipleArgsAndCopy) {
std::ostringstream stream;
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
i::V8::SetPlatformForTesting(default_platform);
uint64_t aa = 11;
unsigned int bb = 22;
uint16_t cc = 33;
@ -246,17 +247,25 @@ TEST(TestTracingControllerMultipleArgsAndCopy) {
// Create a scope for the tracing controller to terminate the trace writer.
{
TracingController tracing_controller;
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform());
i::V8::SetPlatformForTesting(default_platform.get());
auto tracing =
base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller =
tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));
TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
TraceBuffer* ring_buffer =
TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
tracing_controller.Initialize(ring_buffer);
tracing_controller->Initialize(ring_buffer);
TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory("v8");
tracing_controller.StartTracing(trace_config);
tracing_controller->StartTracing(trace_config);
TRACE_EVENT1("v8", "v8.Test.aa", "aa", aa);
TRACE_EVENT1("v8", "v8.Test.bb", "bb", bb);
@ -296,7 +305,9 @@ TEST(TestTracingControllerMultipleArgsAndCopy) {
std::move(trace_event_arg), "a2",
new ConvertableToTraceFormatMock(123));
tracing_controller.StopTracing();
tracing_controller->StopTracing();
i::V8::SetPlatformForTesting(old_platform);
}
std::string trace_str = stream.str();
@ -337,8 +348,6 @@ TEST(TestTracingControllerMultipleArgsAndCopy) {
CHECK_EQ(all_args[21], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\"");
CHECK_EQ(all_args[22], "\"a1\":[42,42]");
CHECK_EQ(all_args[23], "\"a1\":[42,42],\"a2\":[123,123]");
i::V8::SetPlatformForTesting(old_platform);
}
namespace {
@ -356,58 +365,60 @@ class TraceStateObserverImpl : public TracingController::TraceStateObserver {
TEST(TracingObservers) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
i::V8::SetPlatformForTesting(default_platform);
std::unique_ptr<v8::Platform> default_platform(
v8::platform::NewDefaultPlatform());
i::V8::SetPlatformForTesting(default_platform.get());
v8::platform::tracing::TracingController tracing_controller;
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
auto tracing = base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller = tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));
MockTraceWriter* writer = new MockTraceWriter();
v8::platform::tracing::TraceBuffer* ring_buffer =
v8::platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(1,
writer);
tracing_controller.Initialize(ring_buffer);
tracing_controller->Initialize(ring_buffer);
v8::platform::tracing::TraceConfig* trace_config =
new v8::platform::tracing::TraceConfig();
trace_config->AddIncludedCategory("v8");
TraceStateObserverImpl observer;
tracing_controller.AddTraceStateObserver(&observer);
tracing_controller->AddTraceStateObserver(&observer);
CHECK_EQ(0, observer.enabled_count);
CHECK_EQ(0, observer.disabled_count);
tracing_controller.StartTracing(trace_config);
tracing_controller->StartTracing(trace_config);
CHECK_EQ(1, observer.enabled_count);
CHECK_EQ(0, observer.disabled_count);
TraceStateObserverImpl observer2;
tracing_controller.AddTraceStateObserver(&observer2);
tracing_controller->AddTraceStateObserver(&observer2);
CHECK_EQ(1, observer2.enabled_count);
CHECK_EQ(0, observer2.disabled_count);
tracing_controller.RemoveTraceStateObserver(&observer2);
tracing_controller->RemoveTraceStateObserver(&observer2);
CHECK_EQ(1, observer2.enabled_count);
CHECK_EQ(0, observer2.disabled_count);
tracing_controller.StopTracing();
tracing_controller->StopTracing();
CHECK_EQ(1, observer.enabled_count);
CHECK_EQ(1, observer.disabled_count);
CHECK_EQ(1, observer2.enabled_count);
CHECK_EQ(0, observer2.disabled_count);
tracing_controller.RemoveTraceStateObserver(&observer);
tracing_controller->RemoveTraceStateObserver(&observer);
CHECK_EQ(1, observer.enabled_count);
CHECK_EQ(1, observer.disabled_count);
trace_config = new v8::platform::tracing::TraceConfig();
tracing_controller.StartTracing(trace_config);
tracing_controller.StopTracing();
tracing_controller->StartTracing(trace_config);
tracing_controller->StopTracing();
CHECK_EQ(1, observer.enabled_count);
CHECK_EQ(1, observer.disabled_count);

View File

@ -2131,17 +2131,19 @@ class CpuProfileEventChecker : public v8::platform::tracing::TraceWriter {
TEST(TracingCpuProfiler) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
i::V8::SetPlatformForTesting(default_platform);
std::unique_ptr<v8::Platform> default_platform =
v8::platform::NewDefaultPlatform();
i::V8::SetPlatformForTesting(default_platform.get());
v8::platform::tracing::TracingController tracing_controller;
static_cast<v8::platform::DefaultPlatform*>(default_platform)
->SetTracingController(&tracing_controller);
auto tracing = base::make_unique<v8::platform::tracing::TracingController>();
v8::platform::tracing::TracingController* tracing_controller = tracing.get();
static_cast<v8::platform::DefaultPlatform*>(default_platform.get())
->SetTracingController(std::move(tracing));
CpuProfileEventChecker* event_checker = new CpuProfileEventChecker();
TraceBuffer* ring_buffer =
TraceBuffer::CreateTraceBufferRingBuffer(1, event_checker);
tracing_controller.Initialize(ring_buffer);
tracing_controller->Initialize(ring_buffer);
TraceConfig* trace_config = new TraceConfig();
trace_config->AddIncludedCategory(
TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"));
@ -2149,10 +2151,10 @@ TEST(TracingCpuProfiler) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
{
tracing_controller.StartTracing(trace_config);
tracing_controller->StartTracing(trace_config);
auto profiler = v8::TracingCpuProfiler::Create(env->GetIsolate());
CompileRun("function foo() { } foo();");
tracing_controller.StopTracing();
tracing_controller->StopTracing();
CompileRun("function bar() { } bar();");
}

View File

@ -32,8 +32,8 @@ FuzzerSupport::FuzzerSupport(int* argc, char*** argv) {
v8::V8::SetFlagsFromCommandLine(argc, *argv, true);
v8::V8::InitializeICUDefaultLocation((*argv)[0]);
v8::V8::InitializeExternalStartupData((*argv)[0]);
platform_ = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform_);
platform_ = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform_.get());
v8::V8::Initialize();
allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
@ -47,7 +47,7 @@ FuzzerSupport::FuzzerSupport(int* argc, char*** argv) {
context_.Reset(isolate_, v8::Context::New(isolate_));
}
v8::platform::EnsureEventLoopInitialized(platform_, isolate_);
v8::platform::EnsureEventLoopInitialized(platform_.get(), isolate_);
}
FuzzerSupport::~FuzzerSupport() {
@ -70,9 +70,6 @@ FuzzerSupport::~FuzzerSupport() {
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform_;
platform_ = nullptr;
}
// static
@ -90,7 +87,7 @@ v8::Local<v8::Context> FuzzerSupport::GetContext() {
bool FuzzerSupport::PumpMessageLoop(
v8::platform::MessageLoopBehavior behavior) {
return v8::platform::PumpMessageLoop(platform_, isolate_, behavior);
return v8::platform::PumpMessageLoop(platform_.get(), isolate_, behavior);
}
} // namespace v8_fuzzer

View File

@ -27,8 +27,7 @@ class FuzzerSupport {
FuzzerSupport(const FuzzerSupport&);
FuzzerSupport& operator=(const FuzzerSupport&);
v8::Platform* platform_;
std::unique_ptr<v8::Platform> platform_;
v8::ArrayBuffer::Allocator* allocator_;
v8::Isolate* isolate_;
v8::Global<v8::Context> context_;

View File

@ -869,8 +869,8 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
int main(int argc, char* argv[]) {
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform(v8::platform::NewDefaultPlatform());
v8::V8::InitializePlatform(platform.get());
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::V8::InitializeExternalStartupData(argv[0]);
v8::V8::Initialize();

View File

@ -46,8 +46,8 @@ class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
static int DumpHeapConstants(const char* argv0) {
// Start up V8.
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
v8::V8::InitializeExternalStartupData(argv0);
Isolate::CreateParams create_params;
@ -128,7 +128,6 @@ static int DumpHeapConstants(const char* argv0) {
// Teardown.
isolate->Dispose();
v8::V8::ShutdownPlatform();
delete platform;
return 0;
}

View File

@ -11,27 +11,24 @@ namespace {
class DefaultPlatformEnvironment final : public ::testing::Environment {
public:
DefaultPlatformEnvironment() : platform_(NULL) {}
DefaultPlatformEnvironment() {}
void SetUp() override {
EXPECT_EQ(NULL, platform_);
platform_ = v8::platform::CreateDefaultPlatform(
platform_ = v8::platform::NewDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled);
ASSERT_TRUE(platform_ != NULL);
v8::V8::InitializePlatform(platform_);
ASSERT_TRUE(platform_.get() != NULL);
v8::V8::InitializePlatform(platform_.get());
ASSERT_TRUE(v8::V8::Initialize());
}
void TearDown() override {
ASSERT_TRUE(platform_ != NULL);
ASSERT_TRUE(platform_.get() != NULL);
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform_;
platform_ = NULL;
}
private:
v8::Platform* platform_;
std::unique_ptr<v8::Platform> platform_;
};
} // namespace

View File

@ -129,8 +129,8 @@ std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser(
int main(int argc, char* argv[]) {
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
v8::V8::InitializeExternalStartupData(argv[0]);
@ -184,7 +184,6 @@ int main(int argc, char* argv[]) {
}
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
delete create_params.array_buffer_allocator;
return 0;
}