diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 21:09:16 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 21:09:16 +0000 |
commit | b64e521a4734417c33bd6758296c8eb7c3a8fe3f (patch) | |
tree | e500819946c5313dd86f5315c5eed537619dd440 /gin | |
parent | 4df54e8c095bd239b8f7c3786440a4878d2eb509 (diff) | |
download | chromium_src-b64e521a4734417c33bd6758296c8eb7c3a8fe3f.zip chromium_src-b64e521a4734417c33bd6758296c8eb7c3a8fe3f.tar.gz chromium_src-b64e521a4734417c33bd6758296c8eb7c3a8fe3f.tar.bz2 |
[gin] Add a v8::Platform implementation to allow for v8 posting tasks
This currently has no effect unless concurrent sweeping and job based
sweeping is turned on in v8.
BUG=v8:3015
R=abarth@chromium.org,dcarney@chromium.org
Review URL: https://codereview.chromium.org/225413004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin')
-rw-r--r-- | gin/gin.gyp | 4 | ||||
-rw-r--r-- | gin/isolate_holder.cc | 2 | ||||
-rw-r--r-- | gin/per_isolate_data.cc | 5 | ||||
-rw-r--r-- | gin/per_isolate_data.h | 9 | ||||
-rw-r--r-- | gin/public/v8_platform.h | 38 | ||||
-rw-r--r-- | gin/v8_platform.cc | 42 |
6 files changed, 99 insertions, 1 deletions
diff --git a/gin/gin.gyp b/gin/gin.gyp index a7b359f1..f7f25a91 100644 --- a/gin/gin.gyp +++ b/gin/gin.gyp @@ -12,7 +12,9 @@ 'type': '<(component)', 'dependencies': [ '../base/base.gyp:base', + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../v8/tools/gyp/v8.gyp:v8', + ], 'export_dependent_settings': [ '../base/base.gyp:base', @@ -58,6 +60,7 @@ 'public/context_holder.h', 'public/gin_embedders.h', 'public/isolate_holder.h', + 'public/v8_platform.h', 'public/wrapper_info.h', 'runner.cc', 'runner.h', @@ -65,6 +68,7 @@ 'shell_runner.h', 'try_catch.cc', 'try_catch.h', + 'v8_platform.cc', 'wrappable.cc', 'wrappable.h', 'wrapper_info.cc', diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc index bb24349..3bda7f5 100644 --- a/gin/isolate_holder.cc +++ b/gin/isolate_holder.cc @@ -13,6 +13,7 @@ #include "gin/array_buffer.h" #include "gin/function_template.h" #include "gin/per_isolate_data.h" +#include "gin/public/v8_platform.h" namespace gin { @@ -36,6 +37,7 @@ void EnsureV8Initialized(bool gin_managed) { if (!gin_managed) return; + v8::V8::InitializePlatform(V8Platform::Get()); v8::V8::SetArrayBufferAllocator(ArrayBufferAllocator::SharedInstance()); static const char v8_flags[] = "--use_strict --harmony"; v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); diff --git a/gin/per_isolate_data.cc b/gin/per_isolate_data.cc index b3f24ab..99c928c 100644 --- a/gin/per_isolate_data.cc +++ b/gin/per_isolate_data.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/logging.h" +#include "base/message_loop/message_loop_proxy.h" #include "gin/per_isolate_data.h" #include "gin/public/gin_embedders.h" @@ -18,7 +19,9 @@ namespace gin { PerIsolateData::PerIsolateData(Isolate* isolate, ArrayBuffer::Allocator* allocator) - : isolate_(isolate), allocator_(allocator) { + : isolate_(isolate), + allocator_(allocator), + message_loop_proxy_(base::MessageLoopProxy::current()) { isolate_->SetData(kEmbedderNativeGin, this); } diff --git a/gin/per_isolate_data.h b/gin/per_isolate_data.h index fbdbca7..bffe5fb 100644 --- a/gin/per_isolate_data.h +++ b/gin/per_isolate_data.h @@ -8,10 +8,15 @@ #include <map> #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "gin/gin_export.h" #include "gin/public/wrapper_info.h" #include "v8/include/v8.h" +namespace base { +class MessageLoopProxy; +} + namespace gin { class IndexedPropertyInterceptor; @@ -60,6 +65,9 @@ class GIN_EXPORT PerIsolateData { v8::Isolate* isolate() { return isolate_; } v8::ArrayBuffer::Allocator* allocator() { return allocator_; } + base::MessageLoopProxy* message_loop_proxy() { + return message_loop_proxy_.get(); + } private: typedef std::map< @@ -79,6 +87,7 @@ class GIN_EXPORT PerIsolateData { FunctionTemplateMap function_templates_; IndexedPropertyInterceptorMap indexed_interceptors_; NamedPropertyInterceptorMap named_interceptors_; + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; DISALLOW_COPY_AND_ASSIGN(PerIsolateData); }; diff --git a/gin/public/v8_platform.h b/gin/public/v8_platform.h new file mode 100644 index 0000000..2df0f84 --- /dev/null +++ b/gin/public/v8_platform.h @@ -0,0 +1,38 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GIN_PUBLIC_V8_PLATFORM_H_ +#define GIN_PUBLIC_V8_PLATFORM_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/lazy_instance.h" +#include "gin/gin_export.h" +#include "v8/include/v8-platform.h" + +namespace gin { + +// A v8::Platform implementation to use with gin. +class GIN_EXPORT V8Platform : public NON_EXPORTED_BASE(v8::Platform) { + public: + static V8Platform* Get(); + + // v8::Platform implementation. + virtual void CallOnBackgroundThread( + v8::Task* task, + v8::Platform::ExpectedRuntime expected_runtime) OVERRIDE; + virtual void CallOnForegroundThread(v8::Isolate* isolate, + v8::Task* task) OVERRIDE; + private: + friend struct base::DefaultLazyInstanceTraits<V8Platform>; + + V8Platform(); + virtual ~V8Platform(); + + DISALLOW_COPY_AND_ASSIGN(V8Platform); +}; + +} // namespace gin + +#endif // GIN_PUBLIC_V8_PLATFORM_H_ diff --git a/gin/v8_platform.cc b/gin/v8_platform.cc new file mode 100644 index 0000000..d50ff24 --- /dev/null +++ b/gin/v8_platform.cc @@ -0,0 +1,42 @@ +// Copyright 2014 The Chromium 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 "gin/public/v8_platform.h" + +#include "base/bind.h" +#include "base/location.h" +#include "base/message_loop/message_loop_proxy.h" +#include "base/threading/worker_pool.h" +#include "gin/per_isolate_data.h" + +namespace gin { + +namespace { + +base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; + +} // namespace + +// static +V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); } + +V8Platform::V8Platform() {} + +V8Platform::~V8Platform() {} + +void V8Platform::CallOnBackgroundThread( + v8::Task* task, + v8::Platform::ExpectedRuntime expected_runtime) { + base::WorkerPool::PostTask( + FROM_HERE, + base::Bind(&v8::Task::Run, base::Owned(task)), + expected_runtime == v8::Platform::kLongRunningTask); +} + +void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { + PerIsolateData::From(isolate)->message_loop_proxy()->PostTask( + FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task))); +} + +} // namespace gin |