Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: src/d8.h

Issue 1195613003: Add d8 API for spawning function on a new thread (Second try) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove UnboundQueue Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index 3b06059323c81f1a4f7810d348d07a095790a22b..11a1c6287faa4fa803cfaf4c083eb6a3b006a752 100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -8,6 +8,7 @@
#ifndef V8_SHARED
#include "src/allocation.h"
#include "src/hashmap.h"
+#include "src/list.h"
#include "src/smart-pointers.h"
#include "src/v8.h"
#else
@@ -167,6 +168,108 @@ class SourceGroup {
int end_offset_;
};
+#ifndef V8_SHARED
+enum SerializationTag {
+ kSerializationTagUndefined,
+ kSerializationTagNull,
+ kSerializationTagTrue,
+ kSerializationTagFalse,
+ kSerializationTagNumber,
+ kSerializationTagString,
+ kSerializationTagArray,
+ kSerializationTagObject,
+ kSerializationTagArrayBuffer,
+ kSerializationTagTransferredArrayBuffer,
+ kSerializationTagTransferredSharedArrayBuffer,
+};
+
+
+class SerializationData {
+ public:
+ SerializationData() {}
+ ~SerializationData();
+
+ void WriteTag(SerializationTag tag);
+ void WriteMemory(const void* p, int length);
+ void WriteArrayBufferContents(const ArrayBuffer::Contents& contents);
+ void WriteSharedArrayBufferContents(
+ const SharedArrayBuffer::Contents& contents);
+
+ template <typename T>
+ void Write(const T& data) {
+ WriteMemory(&data, sizeof(data));
+ }
+
+ SerializationTag ReadTag(int* offset) const;
+ void ReadMemory(void* p, int length, int* offset) const;
+ void ReadArrayBufferContents(ArrayBuffer::Contents* contents,
+ int* offset) const;
+ void ReadSharedArrayBufferContents(SharedArrayBuffer::Contents* contents,
+ int* offset) const;
+
+ template <typename T>
+ T Read(int* offset) const {
+ T value;
+ ReadMemory(&value, sizeof(value), offset);
+ return value;
+ }
+
+ private:
+ i::List<uint8_t> data;
+ i::List<ArrayBuffer::Contents> array_buffer_contents;
+ i::List<SharedArrayBuffer::Contents> shared_array_buffer_contents;
+};
+
+
+class SerializationDataQueue {
+ public:
+ void Enqueue(SerializationData* data);
+ bool Dequeue(SerializationData** data);
+ bool IsEmpty();
+ void Clear();
+
+ private:
+ base::Mutex mutex_;
+ i::List<SerializationData*> data_;
+};
+
+
+class Worker {
+ public:
+ Worker();
+ ~Worker();
+
+ void StartExecuteInThread(Isolate* isolate, const char* function_string);
+ void PostMessage(SerializationData* data);
+ SerializationData* GetMessage();
+ void Terminate();
+
+ private:
+ class WorkerThread : public base::Thread {
+ public:
+ explicit WorkerThread(Worker* worker)
+ : base::Thread(base::Thread::Options("WorkerThread")),
+ worker_(worker) {}
+
+ virtual void Run() { worker_->ExecuteInThread(); }
+
+ private:
+ Worker* worker_;
+ };
+
+ void ExecuteInThread();
+ void Cleanup();
+ static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+ base::Semaphore in_semaphore_;
+ base::Semaphore out_semaphore_;
+ SerializationDataQueue in_queue_;
+ SerializationDataQueue out_queue_;
+ base::Thread* thread_;
+ char* script_;
+};
+#endif // !V8_SHARED
+
class ShellOptions {
public:
@@ -246,6 +349,17 @@ class Shell : public i::AllStatic {
static void CollectGarbage(Isolate* isolate);
#ifndef V8_SHARED
+ // TODO(binji): stupid implementation for now. Is there an easy way to hash an
+ // object for use in i::HashMap? By pointer?
+ typedef i::List<Handle<Object>> ObjectList;
+ static bool SerializeValue(Isolate* isolate, Handle<Value> value,
+ const ObjectList& to_transfer,
+ ObjectList* seen_objects,
+ SerializationData* out_data);
+ static MaybeLocal<Value> DeserializeValue(Isolate* isolate,
+ const SerializationData& data,
+ int* offset);
+ static void CleanupWorkers();
static Handle<Array> GetCompletions(Isolate* isolate,
Handle<String> text,
Handle<String> full);
@@ -289,6 +403,11 @@ class Shell : public i::AllStatic {
args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
}
static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void WorkerPostMessage(
+ const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args);
// The OS object on the global object contains methods for performing
// operating system calls:
//
@@ -328,6 +447,7 @@ class Shell : public i::AllStatic {
static const char* kPrompt;
static ShellOptions options;
+ static ArrayBuffer::Allocator* array_buffer_allocator;
private:
static Persistent<Context> evaluation_context_;
@@ -341,6 +461,8 @@ class Shell : public i::AllStatic {
static base::OS::MemoryMappedFile* counters_file_;
static base::Mutex context_mutex_;
static const base::TimeTicks kInitialTicks;
+ static Worker worker_;
+ static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_;
static Counter* GetCounter(const char* name, bool is_histogram);
static void InstallUtilityScript(Isolate* isolate);
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698