Introduce a v8::Platform class that bundles embedder callbacks
Also provide a default implementation to use in cctests. For now, there are just two thread releated callbacks. In future CLs, I will move callbacks registered e.g. via V8::SetFooCallback over. BUG=v8:3015 R=svenpanne@chromium.org, danno@chromium.org LOG=no Review URL: https://codereview.chromium.org/75283002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17877 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
40d255ec82
commit
c24ce076e9
@ -58,6 +58,9 @@
|
||||
|
||||
# Enable compiler warnings when using V8_DEPRECATED apis.
|
||||
'v8_deprecation_warnings%': 0,
|
||||
|
||||
# Use the v8 provided v8::Platform implementation.
|
||||
'v8_use_default_platform%': 1,
|
||||
},
|
||||
'target_defaults': {
|
||||
'conditions': [
|
||||
@ -85,6 +88,9 @@
|
||||
['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',
|
||||
|
75
include/v8-platform.h
Normal file
75
include/v8-platform.h
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef V8_V8_PLATFROM_H_
|
||||
#define V8_V8_PLATFORM_H_
|
||||
|
||||
#include "v8.h"
|
||||
|
||||
namespace v8 {
|
||||
|
||||
/**
|
||||
* A Task represents a unit of work.
|
||||
*/
|
||||
class Task {
|
||||
public:
|
||||
virtual ~Task() {}
|
||||
|
||||
virtual void Run() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* V8 Platform abstraction layer.
|
||||
*
|
||||
* The embedder has to provide an implementation of this interface before
|
||||
* initializing the rest of V8.
|
||||
*/
|
||||
class Platform {
|
||||
public:
|
||||
/**
|
||||
* Schedules a task to be invoked on a background thread. |task_is_slow|
|
||||
* indicates that the task will run a long time. The Platform implementation
|
||||
* takes ownership of |task|. There is no guarantee about order of execution
|
||||
* of tasks wrt order of scheduling, nor is there a guarantee about the
|
||||
* thread the task will be run on.
|
||||
*/
|
||||
virtual void CallOnBackgroundThread(Task* task, bool task_is_slow) = 0;
|
||||
|
||||
/**
|
||||
* Schedules a task to be invoked on a foreground thread wrt a specific
|
||||
* |isolate|. Tasks posted for the same isolate should be execute in order of
|
||||
* scheduling. The definition of "foreground" is opaque to V8.
|
||||
*/
|
||||
virtual void CallOnForegroundThread(Isolate* isolate, Task* task) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~Platform() {}
|
||||
};
|
||||
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_V8_PLATFORM_H_
|
13
include/v8.h
13
include/v8.h
@ -105,6 +105,7 @@ class NumberObject;
|
||||
class Object;
|
||||
class ObjectOperationDescriptor;
|
||||
class ObjectTemplate;
|
||||
class Platform;
|
||||
class Primitive;
|
||||
class RawOperationDescriptor;
|
||||
class Signature;
|
||||
@ -4783,6 +4784,18 @@ class V8_EXPORT V8 {
|
||||
*/
|
||||
static bool InitializeICU();
|
||||
|
||||
/**
|
||||
* Sets the v8::Platform to use. This should be invoked before V8 is
|
||||
* initialized.
|
||||
*/
|
||||
static void InitializePlatform(Platform* platform);
|
||||
|
||||
/**
|
||||
* Clears all references to the v8::Platform. This should be invoked after
|
||||
* V8 was disposed.
|
||||
*/
|
||||
static void ShutdownPlatform();
|
||||
|
||||
private:
|
||||
V8();
|
||||
|
||||
|
30
src/api.cc
30
src/api.cc
@ -40,6 +40,9 @@
|
||||
#include "counters.h"
|
||||
#include "cpu-profiler.h"
|
||||
#include "debug.h"
|
||||
#ifdef V8_USE_DEFAULT_PLATFORM
|
||||
#include "default-platform.h"
|
||||
#endif
|
||||
#include "deoptimizer.h"
|
||||
#include "execution.h"
|
||||
#include "global-handles.h"
|
||||
@ -5052,11 +5055,32 @@ static void* ExternalValue(i::Object* obj) {
|
||||
// --- E n v i r o n m e n t ---
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
bool v8::V8::Initialize() {
|
||||
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
|
||||
if (isolate != NULL && isolate->IsInitialized()) {
|
||||
return true;
|
||||
}
|
||||
#ifdef V8_USE_DEFAULT_PLATFORM
|
||||
i::V8::InitializePlatform(new i::DefaultPlatform);
|
||||
#endif
|
||||
return InitializeHelper(isolate);
|
||||
}
|
||||
|
||||
@ -5121,6 +5145,12 @@ bool v8::V8::Dispose() {
|
||||
return false;
|
||||
}
|
||||
i::V8::TearDown();
|
||||
#ifdef V8_USE_DEFAULT_PLATFORM
|
||||
i::DefaultPlatform* platform =
|
||||
static_cast<i::DefaultPlatform*>(i::V8::GetCurrentPlatform());
|
||||
i::V8::ShutdownPlatform();
|
||||
delete platform;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
55
src/default-platform.cc
Normal file
55
src/default-platform.cc
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (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 "default-platform.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
|
||||
DefaultPlatform::DefaultPlatform() {}
|
||||
|
||||
|
||||
DefaultPlatform::~DefaultPlatform() {}
|
||||
|
||||
void DefaultPlatform::CallOnBackgroundThread(Task *task, bool task_is_slow) {
|
||||
// TODO(jochen): implement.
|
||||
task->Run();
|
||||
delete task;
|
||||
}
|
||||
|
||||
|
||||
void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
|
||||
// TODO(jochen): implement.
|
||||
task->Run();
|
||||
delete task;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace v8::internal
|
55
src/default-platform.h
Normal file
55
src/default-platform.h
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef V8_DEFAULT_PLATFORM_H_
|
||||
#define V8_DEFAULT_PLATFORM_H_
|
||||
|
||||
#include "v8.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class DefaultPlatform : public Platform {
|
||||
public:
|
||||
DefaultPlatform();
|
||||
virtual ~DefaultPlatform();
|
||||
|
||||
// v8::Platform implementation.
|
||||
virtual void CallOnBackgroundThread(Task *task,
|
||||
bool task_is_slow) V8_OVERRIDE;
|
||||
virtual void CallOnForegroundThread(v8::Isolate *isolate,
|
||||
Task *task) V8_OVERRIDE;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace v8::internal
|
||||
|
||||
|
||||
#endif // V8_DEFAULT_PLATFORM_H_
|
20
src/v8.cc
20
src/v8.cc
@ -52,6 +52,7 @@ V8_DECLARE_ONCE(init_once);
|
||||
|
||||
List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
|
||||
v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
|
||||
v8::Platform* V8::platform_ = NULL;
|
||||
|
||||
|
||||
bool V8::Initialize(Deserializer* des) {
|
||||
@ -194,4 +195,23 @@ void V8::InitializeOncePerProcess() {
|
||||
CallOnce(&init_once, &InitializeOncePerProcessImpl);
|
||||
}
|
||||
|
||||
|
||||
void V8::InitializePlatform(v8::Platform* platform) {
|
||||
ASSERT(!platform_);
|
||||
ASSERT(platform);
|
||||
platform_ = platform;
|
||||
}
|
||||
|
||||
|
||||
void V8::ShutdownPlatform() {
|
||||
ASSERT(platform_);
|
||||
platform_ = NULL;
|
||||
}
|
||||
|
||||
|
||||
v8::Platform* V8::GetCurrentPlatform() {
|
||||
ASSERT(platform_);
|
||||
return platform_;
|
||||
}
|
||||
|
||||
} } // namespace v8::internal
|
||||
|
7
src/v8.h
7
src/v8.h
@ -50,6 +50,7 @@
|
||||
|
||||
// Basic includes
|
||||
#include "../include/v8.h"
|
||||
#include "../include/v8-platform.h"
|
||||
#include "v8globals.h"
|
||||
#include "v8checks.h"
|
||||
#include "allocation.h"
|
||||
@ -111,6 +112,10 @@ class V8 : public AllStatic {
|
||||
array_buffer_allocator_ = allocator;
|
||||
}
|
||||
|
||||
static void InitializePlatform(v8::Platform* platform);
|
||||
static void ShutdownPlatform();
|
||||
static v8::Platform* GetCurrentPlatform();
|
||||
|
||||
private:
|
||||
static void InitializeOncePerProcessImpl();
|
||||
static void InitializeOncePerProcess();
|
||||
@ -119,6 +124,8 @@ class V8 : public AllStatic {
|
||||
static List<CallCompletedCallback>* call_completed_callbacks_;
|
||||
// Allocator for external array buffers.
|
||||
static v8::ArrayBuffer::Allocator* array_buffer_allocator_;
|
||||
// v8::Platform to use.
|
||||
static v8::Platform* platform_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -281,6 +281,8 @@
|
||||
'../../src/debug-agent.h',
|
||||
'../../src/debug.cc',
|
||||
'../../src/debug.h',
|
||||
'../../src/default-platform.cc',
|
||||
'../../src/default-platform.h',
|
||||
'../../src/deoptimizer.cc',
|
||||
'../../src/deoptimizer.h',
|
||||
'../../src/disasm.h',
|
||||
@ -891,6 +893,12 @@
|
||||
'<(icu_gyp_path):icudata',
|
||||
],
|
||||
}],
|
||||
['v8_use_default_platform==0', {
|
||||
'sources!': [
|
||||
'../../src/default-platform.cc',
|
||||
'../../src/default-platform.h',
|
||||
],
|
||||
}],
|
||||
],
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user