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
This commit is contained in:
jochen@chromium.org 2014-07-03 07:37:27 +00:00
parent d7934d1fbe
commit ca16bb7ae2
21 changed files with 157 additions and 67 deletions

View File

@ -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",
]

View File

@ -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',],
}],

View File

@ -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_

View File

@ -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

View File

@ -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 <v8.h>
#include <include/v8.h>
#include <v8-debug.h>
#include <include/libplatform/libplatform.h>
#include <include/v8-debug.h>
#include <fcntl.h>
#include <stdio.h>
@ -254,8 +255,12 @@ bool RunCppCycle(v8::Handle<v8::Script> 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;
}

View File

@ -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 <v8.h>
#include <include/v8.h>
#include <include/libplatform/libplatform.h>
#include <map>
#include <string>
@ -644,6 +646,8 @@ void PrintMap(map<string, string>* m) {
int main(int argc, char* argv[]) {
v8::V8::InitializeICU();
v8::Platform* platform = v8::platform::CreateDefaultPlatform(0);
v8::V8::InitializePlatform(platform);
map<string, string> options;
string file;
ParseOptions(argc, argv, &options, &file);

View File

@ -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', {

View File

@ -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 <v8.h>
#include <include/v8.h>
#include <include/libplatform/libplatform.h>
#include <assert.h>
#include <fcntl.h>
@ -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;
}

View File

@ -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",
],
}

View File

@ -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
}

View File

@ -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();

View File

@ -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+': [

View File

@ -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;

View File

@ -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> 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;
}

View File

@ -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::DefaultPlatform*>(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::DefaultPlatform*>(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();

View File

@ -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;
}

View File

@ -37,6 +37,7 @@
'type': 'executable',
'dependencies': [
'resources',
'../../tools/gyp/v8.gyp:v8_libplatform',
],
'include_dirs': [
'../..',

View File

@ -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+': [
'../..',
],

View File

@ -33,6 +33,7 @@
#include <vector>
#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;
}

View File

@ -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', {

View File

@ -33,6 +33,7 @@
#include <vector>
#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<v8::base::TimeDelta, v8::base::TimeDelta> 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<std::string> fnames;
@ -168,5 +172,7 @@ int main(int argc, char* argv[]) {
}
}
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete platform;
return 0;
}