| Index: src/d8.h
|
| diff --git a/src/d8.h b/src/d8.h
|
| index b86558357b1538b25b61c4523103a21abf0cafb2..1bb8a8965ba9a94fbfc738b8663d4eb05eaf20ff 100644
|
| --- a/src/d8.h
|
| +++ b/src/d8.h
|
| @@ -5,13 +5,9 @@
|
| #ifndef V8_D8_H_
|
| #define V8_D8_H_
|
|
|
| -#include <memory>
|
| #include <string>
|
| -#include <unordered_set>
|
| -#include <vector>
|
|
|
| #include "src/allocation.h"
|
| -#include "src/base/functional.h"
|
| #include "src/base/hashmap.h"
|
| #include "src/base/platform/time.h"
|
| #include "src/list.h"
|
| @@ -147,51 +143,68 @@
|
| int end_offset_;
|
| };
|
|
|
| +enum SerializationTag {
|
| + kSerializationTagUndefined,
|
| + kSerializationTagNull,
|
| + kSerializationTagTrue,
|
| + kSerializationTagFalse,
|
| + kSerializationTagNumber,
|
| + kSerializationTagString,
|
| + kSerializationTagArray,
|
| + kSerializationTagObject,
|
| + kSerializationTagArrayBuffer,
|
| + kSerializationTagTransferredArrayBuffer,
|
| + kSerializationTagTransferredSharedArrayBuffer,
|
| +};
|
| +
|
|
|
| class SerializationData {
|
| public:
|
| - SerializationData() : data_(nullptr), size_(0) {}
|
| + SerializationData() {}
|
| ~SerializationData();
|
|
|
| - uint8_t* data() { return data_.get(); }
|
| - size_t size() { return size_; }
|
| - const std::vector<ArrayBuffer::Contents>& array_buffer_contents() {
|
| - return array_buffer_contents_;
|
| - }
|
| - const std::vector<SharedArrayBuffer::Contents>&
|
| - shared_array_buffer_contents() {
|
| - return shared_array_buffer_contents_;
|
| - }
|
| -
|
| - void ClearTransferredArrayBuffers();
|
| -
|
| - private:
|
| - struct DataDeleter {
|
| - void operator()(uint8_t* p) const { free(p); }
|
| - };
|
| -
|
| - std::unique_ptr<uint8_t, DataDeleter> data_;
|
| - size_t size_;
|
| - std::vector<ArrayBuffer::Contents> array_buffer_contents_;
|
| - std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_;
|
| -
|
| - private:
|
| - friend class Serializer;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(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(std::unique_ptr<SerializationData> data);
|
| - bool Dequeue(std::unique_ptr<SerializationData>* data);
|
| + void Enqueue(SerializationData* data);
|
| + bool Dequeue(SerializationData** data);
|
| bool IsEmpty();
|
| void Clear();
|
|
|
| private:
|
| base::Mutex mutex_;
|
| - std::vector<std::unique_ptr<SerializationData>> data_;
|
| + i::List<SerializationData*> data_;
|
| };
|
|
|
|
|
| @@ -206,13 +219,13 @@
|
| // Post a message to the worker's incoming message queue. The worker will
|
| // take ownership of the SerializationData.
|
| // This function should only be called by the thread that created the Worker.
|
| - void PostMessage(std::unique_ptr<SerializationData> data);
|
| + void PostMessage(SerializationData* data);
|
| // Synchronously retrieve messages from the worker's outgoing message queue.
|
| // If there is no message in the queue, block until a message is available.
|
| // If there are no messages in the queue and the worker is no longer running,
|
| // return nullptr.
|
| // This function should only be called by the thread that created the Worker.
|
| - std::unique_ptr<SerializationData> GetMessage();
|
| + SerializationData* GetMessage();
|
| // Terminate the worker's event loop. Messages from the worker that have been
|
| // queued can still be read via GetMessage().
|
| // This function can be called by any thread.
|
| @@ -322,10 +335,16 @@
|
| static void CollectGarbage(Isolate* isolate);
|
| static void EmptyMessageQueues(Isolate* isolate);
|
|
|
| - static std::unique_ptr<SerializationData> SerializeValue(
|
| - Isolate* isolate, Local<Value> value, Local<Value> transfer);
|
| - static MaybeLocal<Value> DeserializeValue(
|
| - Isolate* isolate, std::unique_ptr<SerializationData> data);
|
| + // TODO(binji): stupid implementation for now. Is there an easy way to hash an
|
| + // object for use in base::HashMap? By pointer?
|
| + typedef i::List<Local<Object>> ObjectList;
|
| + static bool SerializeValue(Isolate* isolate, Local<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 int* LookupCounter(const char* name);
|
| static void* CreateHistogram(const char* name,
|
| @@ -424,26 +443,10 @@
|
| static base::LazyMutex context_mutex_;
|
| static const base::TimeTicks kInitialTicks;
|
|
|
| - struct SharedArrayBufferContentsHash {
|
| - size_t operator()(const v8::SharedArrayBuffer::Contents& contents) const {
|
| - return base::hash_combine(contents.Data(), contents.ByteLength());
|
| - }
|
| - };
|
| -
|
| - struct SharedArrayBufferContentsIsEqual {
|
| - bool operator()(const SharedArrayBuffer::Contents& a,
|
| - const SharedArrayBuffer::Contents& b) const {
|
| - return a.Data() == b.Data() && a.ByteLength() == b.ByteLength();
|
| - }
|
| - };
|
| -
|
| static base::LazyMutex workers_mutex_;
|
| static bool allow_new_workers_;
|
| static i::List<Worker*> workers_;
|
| - static std::unordered_set<SharedArrayBuffer::Contents,
|
| - SharedArrayBufferContentsHash,
|
| - SharedArrayBufferContentsIsEqual>
|
| - externalized_shared_contents_;
|
| + static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_;
|
|
|
| static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
|
| static Counter* GetCounter(const char* name, bool is_histogram);
|
|
|