diff --git a/BUILD.gn b/BUILD.gn index 18e5ef21ff..02919edf67 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 e808788657..7ce66e4c98 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 0000000000..a6d468e60b --- /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 5667211c32..d8ef044404 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 40064ba19b..c3ce03789c 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 76b178bc92..ce6d8e6bea 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 dfc7410070..0c4c705609 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 31063d39a7..0f8dc6a834 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 4196627416..2061869ab1 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 7c484de53e..4af691515f 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 8bdf26f4c2..33d3a2a008 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 908a29f6ba..a084979de2 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 2d34682572..9a2c30dcde 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 9099398cef..76bba752a9 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 9a85e06a2e..cc08d2f2bb 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 f51f7e4b5a..eac85d44d6 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 1f3e81fbea..4ba1fa6022 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 c455c1f33d..3fabc25788 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', @@ -1208,6 +1201,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', @@ -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 276a47315f..ae3dbd2745 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 6fd129ac69..836ea9762a 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 dbac64ab8f..2dae0558b8 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; }