From ca16bb7ae2259672f5ae6b38e51d3a8790f6f05a Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Thu, 3 Jul 2014 07:37:27 +0000 Subject: [PATCH] Split out libplatform into a separate libary Also remove the "use default platform" compile flag. Instead, the embedder has to provide the platform. Change all binaries to use the default platfrom from libplatform. Unless --job-based-sweeping is passed, nothing uses the platform yet, so nothing will break for embedders (yet). BUG=none R=jkummerow@chromium.org LOG=y Review URL: https://codereview.chromium.org/345903004 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22180 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- BUILD.gn | 34 +++++++++++++++++----------- build/features.gypi | 6 ----- include/libplatform/libplatform.h | 27 +++++++++++++++++++++++ include/v8-platform.h | 5 ++--- samples/lineprocessor.cc | 9 ++++++-- samples/process.cc | 6 ++++- samples/samples.gyp | 3 ++- samples/shell.cc | 8 ++++++- src/DEPS | 11 +++++++--- src/api.cc | 8 ------- src/d8.cc | 6 +++++ src/d8.gyp | 1 + src/libplatform/default-platform.cc | 8 +++++++ src/mksnapshot.cc | 6 +++++ src/v8.cc | 21 ------------------ test/cctest/cctest.cc | 6 +++++ test/cctest/cctest.gyp | 1 + tools/gyp/v8.gyp | 44 ++++++++++++++++++++++++++++++------- tools/lexer-shell.cc | 6 +++++ tools/lexer-shell.gyp | 2 ++ tools/parser-shell.cc | 6 +++++ 21 files changed, 157 insertions(+), 67 deletions(-) create mode 100644 include/libplatform/libplatform.h diff --git a/BUILD.gn b/BUILD.gn index 18e5ef2..02919ed 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -14,7 +14,6 @@ v8_enable_verify_heap = false v8_interpreted_regexp = false v8_object_print = false v8_postmortem_support = false -v8_use_default_platform = true v8_use_snapshot = true v8_use_external_startup_data = false v8_enable_extra_checks = is_debug @@ -90,11 +89,6 @@ config("features") { "V8_I18N_SUPPORT", ] } - if (v8_use_default_platform == true) { - defines += [ - "V8_USE_DEFAULT_PLATFORM", - ] - } if (v8_compress_startup_data == "bz2") { defines += [ "COMPRESS_STARTUP_DATA_BZ2", @@ -633,13 +627,6 @@ source_set("v8_base") { "src/jsregexp-inl.h", "src/jsregexp.cc", "src/jsregexp.h", - # TODO(jochen): move libplatform/ files to their own target. - "src/libplatform/default-platform.cc", - "src/libplatform/default-platform.h", - "src/libplatform/task-queue.cc", - "src/libplatform/task-queue.h", - "src/libplatform/worker-thread.cc", - "src/libplatform/worker-thread.h", "src/list-inl.h", "src/list.h", "src/lithium-allocator-inl.h", @@ -1077,6 +1064,26 @@ source_set("v8_libbase") { # TODO(jochen): Add support for qnx, freebsd, openbsd, netbsd, and solaris. } +source_set("v8_libplatform") { + sources = [ + "include/libplatform/libplatform.h", + "src/libplatform/default-platform.cc", + "src/libplatform/default-platform.h", + "src/libplatform/task-queue.cc", + "src/libplatform/task-queue.h", + "src/libplatform/worker-thread.cc", + "src/libplatform/worker-thread.h", + ] + + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ "//build/config/compiler:no_chromium_code" ] + configs += [ ":internal_config", ":features", ":toolchain" ] + + deps = [ + ":v8_libbase", + ] +} + ############################################################################### # Executables # @@ -1095,6 +1102,7 @@ if (current_toolchain == host_toolchain) { deps = [ ":v8_base", + ":v8_libplatform", ":v8_nosnapshot", ] diff --git a/build/features.gypi b/build/features.gypi index e808788..7ce66e4 100644 --- a/build/features.gypi +++ b/build/features.gypi @@ -59,9 +59,6 @@ # Enable compiler warnings when using V8_DEPRECATED apis. 'v8_deprecation_warnings%': 0, - # Use the v8 provided v8::Platform implementation. - 'v8_use_default_platform%': 1, - # Use external files for startup data blobs: # the JS builtins sources and the start snapshot. 'v8_use_external_startup_data%': 0, @@ -92,9 +89,6 @@ ['v8_enable_i18n_support==1', { 'defines': ['V8_I18N_SUPPORT',], }], - ['v8_use_default_platform==1', { - 'defines': ['V8_USE_DEFAULT_PLATFORM',], - }], ['v8_compress_startup_data=="bz2"', { 'defines': ['COMPRESS_STARTUP_DATA_BZ2',], }], diff --git a/include/libplatform/libplatform.h b/include/libplatform/libplatform.h new file mode 100644 index 0000000..a6d468e --- /dev/null +++ b/include/libplatform/libplatform.h @@ -0,0 +1,27 @@ +// Copyright 2014 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. + +#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_ +#define V8_LIBPLATFORM_LIBPLATFORM_H_ + +#include "include/v8-platform.h" + +namespace v8 { +namespace platform { + +/** + * Returns a new instance of the default v8::Platform implementation. + * + * The caller will take ownership of the returned pointer. |thread_pool_size| + * is the number of worker threads to allocate for background jobs. If a value + * of zero is passed, a suitable default based on the current number of + * processors online will be chosen. + */ +v8::Platform* CreateDefaultPlatform(int thread_pool_size); + + +} // namespace platform +} // namespace v8 + +#endif // V8_LIBPLATFORM_LIBPLATFORM_H_ diff --git a/include/v8-platform.h b/include/v8-platform.h index 5667211..d8ef044 100644 --- a/include/v8-platform.h +++ b/include/v8-platform.h @@ -37,6 +37,8 @@ class Platform { kLongRunningTask }; + virtual ~Platform() {} + /** * Schedules a task to be invoked on a background thread. |expected_runtime| * indicates that the task will run a long time. The Platform implementation @@ -53,9 +55,6 @@ class Platform { * scheduling. The definition of "foreground" is opaque to V8. */ virtual void CallOnForegroundThread(Isolate* isolate, Task* task) = 0; - - protected: - virtual ~Platform() {} }; } // namespace v8 diff --git a/samples/lineprocessor.cc b/samples/lineprocessor.cc index 40064ba..c3ce037 100644 --- a/samples/lineprocessor.cc +++ b/samples/lineprocessor.cc @@ -25,9 +25,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include -#include +#include +#include #include #include @@ -254,8 +255,12 @@ bool RunCppCycle(v8::Handle script, int main(int argc, char* argv[]) { v8::V8::InitializeICU(); + v8::Platform* platform = v8::platform::CreateDefaultPlatform(0); + v8::V8::InitializePlatform(platform); int result = RunMain(argc, argv); v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete platform; return result; } diff --git a/samples/process.cc b/samples/process.cc index 76b178b..ce6d8e6 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -25,7 +25,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include + +#include #include #include @@ -644,6 +646,8 @@ void PrintMap(map* m) { int main(int argc, char* argv[]) { v8::V8::InitializeICU(); + v8::Platform* platform = v8::platform::CreateDefaultPlatform(0); + v8::V8::InitializePlatform(platform); map options; string file; ParseOptions(argc, argv, &options, &file); diff --git a/samples/samples.gyp b/samples/samples.gyp index dfc7410..0c4c705 100644 --- a/samples/samples.gyp +++ b/samples/samples.gyp @@ -35,9 +35,10 @@ 'type': 'executable', 'dependencies': [ '../tools/gyp/v8.gyp:v8', + '../tools/gyp/v8.gyp:v8_libplatform', ], 'include_dirs': [ - '../include', + '..', ], 'conditions': [ ['v8_enable_i18n_support==1', { diff --git a/samples/shell.cc b/samples/shell.cc index 31063d3..0f8dc6a 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -25,7 +25,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include + +#include #include #include @@ -79,6 +81,8 @@ class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { int main(int argc, char* argv[]) { v8::V8::InitializeICU(); + v8::Platform* platform = v8::platform::CreateDefaultPlatform(0); + v8::V8::InitializePlatform(platform); v8::V8::SetFlagsFromCommandLine(&argc, argv, true); ShellArrayBufferAllocator array_buffer_allocator; v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); @@ -98,6 +102,8 @@ int main(int argc, char* argv[]) { if (run_shell) RunShell(context); } v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete platform; return result; } diff --git a/src/DEPS b/src/DEPS index 4196627..2061869 100644 --- a/src/DEPS +++ b/src/DEPS @@ -1,6 +1,11 @@ include_rules = [ "+src", - - # TODO(jochen): Enable this. - #"-src/libplatform", + "-src/libplatform", + "-include/libplatform", ] + +specific_include_rules = { + "(mksnapshot|d8)\.cc": [ + "+include/libplatform/libplatform.h", + ], +} diff --git a/src/api.cc b/src/api.cc index 7c484de..4af6915 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4963,20 +4963,12 @@ static void* ExternalValue(i::Object* obj) { void v8::V8::InitializePlatform(Platform* platform) { -#ifdef V8_USE_DEFAULT_PLATFORM - FATAL("Can't override v8::Platform when using default implementation"); -#else i::V8::InitializePlatform(platform); -#endif } void v8::V8::ShutdownPlatform() { -#ifdef V8_USE_DEFAULT_PLATFORM - FATAL("Can't override v8::Platform when using default implementation"); -#else i::V8::ShutdownPlatform(); -#endif } diff --git a/src/d8.cc b/src/d8.cc index 8bdf26f..33d3a2a 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -35,6 +35,7 @@ #include "src/d8.h" +#include "include/libplatform/libplatform.h" #ifndef V8_SHARED #include "src/api.h" #include "src/base/cpu.h" @@ -1549,6 +1550,9 @@ class StartupDataHandler { int Shell::Main(int argc, char* argv[]) { if (!SetOptions(argc, argv)) return 1; v8::V8::InitializeICU(options.icu_data_file); + v8::Platform* platform = + v8::platform::CreateDefaultPlatform(base::OS::NumberOfProcessorsOnline()); + v8::V8::InitializePlatform(platform); #ifdef V8_USE_EXTERNAL_STARTUP_DATA StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob); #endif @@ -1626,6 +1630,8 @@ int Shell::Main(int argc, char* argv[]) { } isolate->Dispose(); V8::Dispose(); + V8::ShutdownPlatform(); + delete platform; OnExit(); diff --git a/src/d8.gyp b/src/d8.gyp index 908a29f..a084979 100644 --- a/src/d8.gyp +++ b/src/d8.gyp @@ -41,6 +41,7 @@ 'type': 'executable', 'dependencies': [ '../tools/gyp/v8.gyp:v8', + '../tools/gyp/v8.gyp:v8_libplatform', ], # Generated source files need this explicitly: 'include_dirs+': [ diff --git a/src/libplatform/default-platform.cc b/src/libplatform/default-platform.cc index 2d34682..9a2c30d 100644 --- a/src/libplatform/default-platform.cc +++ b/src/libplatform/default-platform.cc @@ -15,6 +15,14 @@ namespace v8 { namespace platform { +v8::Platform* CreateDefaultPlatform(int thread_pool_size) { + DefaultPlatform* platform = new DefaultPlatform(); + platform->SetThreadPoolSize(thread_pool_size); + platform->EnsureInitialized(); + return platform; +} + + const int DefaultPlatform::kMaxThreadPoolSize = 4; diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc index 9099398..76bba75 100644 --- a/src/mksnapshot.cc +++ b/src/mksnapshot.cc @@ -11,6 +11,7 @@ #include "src/v8.h" +#include "include/libplatform/libplatform.h" #include "src/assembler.h" #include "src/base/platform/platform.h" #include "src/bootstrapper.h" @@ -317,6 +318,9 @@ void DumpException(Handle message) { int main(int argc, char** argv) { V8::InitializeICU(); + v8::Platform* platform = + v8::platform::CreateDefaultPlatform(base::OS::NumberOfProcessorsOnline()); + v8::V8::InitializePlatform(platform); i::CpuFeatures::Probe(true); // By default, log code create information in the snapshot. @@ -440,5 +444,7 @@ int main(int argc, char** argv) { isolate->Dispose(); V8::Dispose(); + V8::ShutdownPlatform(); + delete platform; return 0; } diff --git a/src/v8.cc b/src/v8.cc index 9a85e06..cc08d2f 100644 --- a/src/v8.cc +++ b/src/v8.cc @@ -15,9 +15,6 @@ #include "src/heap-profiler.h" #include "src/hydrogen.h" #include "src/isolate.h" -#ifdef V8_USE_DEFAULT_PLATFORM -#include "src/libplatform/default-platform.h" -#endif #include "src/lithium-allocator.h" #include "src/objects.h" #include "src/runtime-profiler.h" @@ -41,14 +38,6 @@ bool V8::Initialize(Deserializer* des) { if (isolate->IsDead()) return false; if (isolate->IsInitialized()) return true; -#ifdef V8_USE_DEFAULT_PLATFORM - platform::DefaultPlatform* platform = - static_cast(platform_); - platform->SetThreadPoolSize(isolate->max_available_threads()); - // We currently only start the threads early, if we know that we'll use them. - if (FLAG_job_based_sweeping) platform->EnsureInitialized(); -#endif - return isolate->Init(des); } @@ -62,13 +51,6 @@ void V8::TearDown() { Isolate::GlobalTearDown(); Sampler::TearDown(); - -#ifdef V8_USE_DEFAULT_PLATFORM - platform::DefaultPlatform* platform = - static_cast(platform_); - platform_ = NULL; - delete platform; -#endif } @@ -94,9 +76,6 @@ void V8::InitializeOncePerProcessImpl() { base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap); -#ifdef V8_USE_DEFAULT_PLATFORM - platform_ = new platform::DefaultPlatform; -#endif Sampler::SetUp(); CpuFeatures::Probe(false); init_memcopy_functions(); diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc index f51f7e4..eac85d4 100644 --- a/test/cctest/cctest.cc +++ b/test/cctest/cctest.cc @@ -28,6 +28,7 @@ #include "include/v8.h" #include "test/cctest/cctest.h" +#include "include/libplatform/libplatform.h" #include "src/debug.h" #include "test/cctest/print-extension.h" #include "test/cctest/profiler-extension.h" @@ -138,6 +139,9 @@ static void SuggestTestHarness(int tests) { int main(int argc, char* argv[]) { v8::V8::InitializeICU(); + v8::Platform* platform = v8::platform::CreateDefaultPlatform( + v8::base::OS::NumberOfProcessorsOnline()); + v8::V8::InitializePlatform(platform); v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true); @@ -205,6 +209,8 @@ int main(int argc, char* argv[]) { CcTest::TearDown(); // TODO(svenpanne) See comment above. // if (!disable_automatic_dispose_) v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete platform; return 0; } diff --git a/test/cctest/cctest.gyp b/test/cctest/cctest.gyp index 1f3e81f..4ba1fa6 100644 --- a/test/cctest/cctest.gyp +++ b/test/cctest/cctest.gyp @@ -37,6 +37,7 @@ 'type': 'executable', 'dependencies': [ 'resources', + '../../tools/gyp/v8.gyp:v8_libplatform', ], 'include_dirs': [ '../..', diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index c455c1f..3fabc25 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -532,13 +532,6 @@ '../../src/jsregexp-inl.h', '../../src/jsregexp.cc', '../../src/jsregexp.h', - # TODO(jochen): move libplatform/ files to their own target. - '../../src/libplatform/default-platform.cc', - '../../src/libplatform/default-platform.h', - '../../src/libplatform/task-queue.cc', - '../../src/libplatform/task-queue.h', - '../../src/libplatform/worker-thread.cc', - '../../src/libplatform/worker-thread.h', '../../src/list-inl.h', '../../src/list.h', '../../src/lithium-allocator-inl.h', @@ -1209,6 +1202,41 @@ ], }, { + 'target_name': 'v8_libplatform', + 'type': 'static_library', + 'variables': { + 'optimize': 'max', + }, + 'dependencies': [ + 'v8_libbase', + ], + 'include_dirs+': [ + '../..', + ], + 'sources': [ + '../../include/libplatform/libplatform.h', + '../../src/libplatform/default-platform.cc', + '../../src/libplatform/default-platform.h', + '../../src/libplatform/task-queue.cc', + '../../src/libplatform/task-queue.h', + '../../src/libplatform/worker-thread.cc', + '../../src/libplatform/worker-thread.h', + ], + 'conditions': [ + ['want_separate_host_toolset==1', { + 'toolsets': ['host', 'target'], + }, { + 'toolsets': ['target'], + }], + ['component=="shared_library"', { + 'defines': [ + 'BUILDING_V8_SHARED', + 'V8_SHARED', + ], + }], + ], + }, + { 'target_name': 'natives_blob', 'type': 'none', 'conditions': [ @@ -1382,7 +1410,7 @@ { 'target_name': 'mksnapshot', 'type': 'executable', - 'dependencies': ['v8_base', 'v8_nosnapshot'], + 'dependencies': ['v8_base', 'v8_nosnapshot', 'v8_libplatform'], 'include_dirs+': [ '../..', ], diff --git a/tools/lexer-shell.cc b/tools/lexer-shell.cc index 276a473..ae3dbd2 100644 --- a/tools/lexer-shell.cc +++ b/tools/lexer-shell.cc @@ -33,6 +33,7 @@ #include #include "src/v8.h" +#include "include/libplatform/libplatform.h" #include "src/api.h" #include "src/base/platform/platform.h" #include "src/messages.h" @@ -180,6 +181,9 @@ v8::base::TimeDelta ProcessFile( int main(int argc, char* argv[]) { v8::V8::InitializeICU(); + v8::Platform* platform = v8::platform::CreateDefaultPlatform( + v8::base::OS::NumberOfProcessorsOnline()); + v8::V8::InitializePlatform(platform); v8::V8::SetFlagsFromCommandLine(&argc, argv, true); Encoding encoding = LATIN1; bool print_tokens = false; @@ -226,5 +230,7 @@ int main(int argc, char* argv[]) { } } v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete platform; return 0; } diff --git a/tools/lexer-shell.gyp b/tools/lexer-shell.gyp index 6fd129a..836ea97 100644 --- a/tools/lexer-shell.gyp +++ b/tools/lexer-shell.gyp @@ -37,6 +37,7 @@ 'type': 'executable', 'dependencies': [ '../tools/gyp/v8.gyp:v8', + '../tools/gyp/v8.gyp:v8_libplatform', ], 'conditions': [ ['v8_enable_i18n_support==1', { @@ -59,6 +60,7 @@ 'type': 'executable', 'dependencies': [ '../tools/gyp/v8.gyp:v8', + '../tools/gyp/v8.gyp:v8_libplatform', ], 'conditions': [ ['v8_enable_i18n_support==1', { diff --git a/tools/parser-shell.cc b/tools/parser-shell.cc index dbac64a..2dae055 100644 --- a/tools/parser-shell.cc +++ b/tools/parser-shell.cc @@ -33,6 +33,7 @@ #include #include "src/v8.h" +#include "include/libplatform/libplatform.h" #include "src/api.h" #include "src/compiler.h" #include "src/scanner-character-streams.h" @@ -121,6 +122,9 @@ std::pair RunBaselineParser( int main(int argc, char* argv[]) { v8::V8::InitializeICU(); + v8::Platform* platform = v8::platform::CreateDefaultPlatform( + v8::base::OS::NumberOfProcessorsOnline()); + v8::V8::InitializePlatform(platform); v8::V8::SetFlagsFromCommandLine(&argc, argv, true); Encoding encoding = LATIN1; std::vector fnames; @@ -168,5 +172,7 @@ int main(int argc, char* argv[]) { } } v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete platform; return 0; } -- 2.7.4