diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-08 23:58:15 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-08 23:58:15 +0000 |
commit | 6b395fee22239c0fedd1974ea4fad5a5031fc469 (patch) | |
tree | 91e4cb28ea1500dcf6abc88dbc2d8d0e4f758b4f /net | |
parent | 193149cfeb82bf67a677cade990249e5dd7ebf23 (diff) | |
download | chromium_src-6b395fee22239c0fedd1974ea4fad5a5031fc469.zip chromium_src-6b395fee22239c0fedd1974ea4fad5a5031fc469.tar.gz chromium_src-6b395fee22239c0fedd1974ea4fad5a5031fc469.tar.bz2 |
Make net use v8 through gin
- no longer try to use the default isolate (we want to remove it from v8)
- add the option to gin to manage an isolate in non-strict mode
BUG=359977
R=eroman@chromium.org,abarth@chromium.org
Review URL: https://codereview.chromium.org/227233006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262559 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/DEPS | 1 | ||||
-rw-r--r-- | net/net.gyp | 1 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_perftest.cc | 3 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_v8.cc | 53 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_v8.h | 22 | ||||
-rw-r--r-- | net/test/run_all_unittests.cc | 3 |
6 files changed, 33 insertions, 50 deletions
@@ -1,5 +1,6 @@ include_rules = [ "+crypto", + "+gin/public", "+jni", "+third_party/apple_apsl", "+third_party/libevent", diff --git a/net/net.gyp b/net/net.gyp index 074c867..ca9fbd0 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -2694,6 +2694,7 @@ 'variables': { 'enable_wexit_time_destructors': 1, }, 'dependencies': [ '../base/base.gyp:base', + '../gin/gin.gyp:gin', '../url/url.gyp:url_lib', '../v8/tools/gyp/v8.gyp:v8', 'net' diff --git a/net/proxy/proxy_resolver_perftest.cc b/net/proxy/proxy_resolver_perftest.cc index 12ffd1b..6b0b68f 100644 --- a/net/proxy/proxy_resolver_perftest.cc +++ b/net/proxy/proxy_resolver_perftest.cc @@ -218,8 +218,7 @@ class MockJSBindings : public net::ProxyResolverV8::JSBindings { }; TEST(ProxyResolverPerfTest, ProxyResolverV8) { - // This has to be done on the main thread. - net::ProxyResolverV8::RememberDefaultIsolate(); + net::ProxyResolverV8::EnsureIsolateCreated(); MockJSBindings js_bindings; net::ProxyResolverV8 resolver; diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc index 7e44f15..9c9f421 100644 --- a/net/proxy/proxy_resolver_v8.cc +++ b/net/proxy/proxy_resolver_v8.cc @@ -9,11 +9,13 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/debug/leak_annotations.h" #include "base/logging.h" #include "base/strings/string_tokenizer.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/synchronization/lock.h" +#include "gin/public/isolate_holder.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" #include "net/base/net_util.h" @@ -764,59 +766,44 @@ int ProxyResolverV8::SetPacScript( } // static -void ProxyResolverV8::RememberDefaultIsolate() { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - DCHECK(isolate) - << "ProxyResolverV8::RememberDefaultIsolate called on wrong thread"; - DCHECK(g_default_isolate_ == NULL || g_default_isolate_ == isolate) - << "Default Isolate can not be changed"; - g_default_isolate_ = isolate; +void ProxyResolverV8::EnsureIsolateCreated() { + if (g_proxy_resolver_isolate_) + return; + g_proxy_resolver_isolate_ = + new gin::IsolateHolder(gin::IsolateHolder::kNonStrictMode); + ANNOTATE_LEAKING_OBJECT_PTR(g_proxy_resolver_isolate_); } -#if defined(OS_WIN) -// static -void ProxyResolverV8::CreateIsolate() { - v8::Isolate* isolate = v8::Isolate::New(); - DCHECK(isolate); - DCHECK(g_default_isolate_ == NULL) << "Default Isolate can not be set twice"; - - isolate->Enter(); - v8::V8::Initialize(); - - g_default_isolate_ = isolate; -} -#endif // defined(OS_WIN) - // static v8::Isolate* ProxyResolverV8::GetDefaultIsolate() { - DCHECK(g_default_isolate_) - << "Must call ProxyResolverV8::RememberDefaultIsolate() first"; - return g_default_isolate_; + DCHECK(g_proxy_resolver_isolate_) + << "Must call ProxyResolverV8::EnsureIsolateCreated() first"; + return g_proxy_resolver_isolate_->isolate(); } -v8::Isolate* ProxyResolverV8::g_default_isolate_ = NULL; +gin::IsolateHolder* ProxyResolverV8::g_proxy_resolver_isolate_ = NULL; // static size_t ProxyResolverV8::GetTotalHeapSize() { - if (!g_default_isolate_) + if (!g_proxy_resolver_isolate_) return 0; - v8::Locker locked(g_default_isolate_); - v8::Isolate::Scope isolate_scope(g_default_isolate_); + v8::Locker locked(g_proxy_resolver_isolate_->isolate()); + v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); v8::HeapStatistics heap_statistics; - g_default_isolate_->GetHeapStatistics(&heap_statistics); + g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); return heap_statistics.total_heap_size(); } // static size_t ProxyResolverV8::GetUsedHeapSize() { - if (!g_default_isolate_) + if (!g_proxy_resolver_isolate_) return 0; - v8::Locker locked(g_default_isolate_); - v8::Isolate::Scope isolate_scope(g_default_isolate_); + v8::Locker locked(g_proxy_resolver_isolate_->isolate()); + v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); v8::HeapStatistics heap_statistics; - g_default_isolate_->GetHeapStatistics(&heap_statistics); + g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); return heap_statistics.used_heap_size(); } diff --git a/net/proxy/proxy_resolver_v8.h b/net/proxy/proxy_resolver_v8.h index 9c34e25..c754e31 100644 --- a/net/proxy/proxy_resolver_v8.h +++ b/net/proxy/proxy_resolver_v8.h @@ -10,6 +10,10 @@ #include "net/base/net_export.h" #include "net/proxy/proxy_resolver.h" +namespace gin { +class IsolateHolder; +} // namespace gin + namespace v8 { class HeapStatistics; class Isolate; @@ -90,18 +94,10 @@ class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver { const scoped_refptr<ProxyResolverScriptData>& script_data, const net::CompletionCallback& /*callback*/) OVERRIDE; - // Remember the default Isolate, must be called from the main thread. This - // hack can be removed when the "default Isolate" concept is gone. - static void RememberDefaultIsolate(); - -#if defined(OS_WIN) - // Create an isolate to use for the proxy resolver. Until the "default - // Isolate" concept is gone, it is preferable to invoke - // RememberDefaultIsolate() as creating a new Isolate in additional to the - // default Isolate will waste a few MB of memory and the runtime it took to - // create the default Isolate. - static void CreateIsolate(); -#endif + // Create an isolate to use for the proxy resolver. If the embedder invokes + // this method multiple times, it must be invoked in a thread safe manner, + // e.g. always from the same thread. + static void EnsureIsolateCreated(); static v8::Isolate* GetDefaultIsolate(); @@ -111,7 +107,7 @@ class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver { static size_t GetUsedHeapSize(); private: - static v8::Isolate* g_default_isolate_; + static gin::IsolateHolder* g_proxy_resolver_isolate_; // Context holds the Javascript state for the most recently loaded PAC // script. It corresponds with the data from the last call to diff --git a/net/test/run_all_unittests.cc b/net/test/run_all_unittests.cc index 9b5dad2..1067c21 100644 --- a/net/test/run_all_unittests.cc +++ b/net/test/run_all_unittests.cc @@ -48,8 +48,7 @@ int main(int argc, char** argv) { net::EnableSSLServerSockets(); #if !defined(OS_IOS) - // This has to be done on the main thread. - net::ProxyResolverV8::RememberDefaultIsolate(); + net::ProxyResolverV8::EnsureIsolateCreated(); #endif return base::LaunchUnitTests( |