aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/d8.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-03-08 21:41:09 +0100
committerMichaƫl Zasso <targos@protonmail.com>2017-03-25 09:44:10 +0100
commit83bf2975ec7a105c1e08caba21e5c4cccd9beabb (patch)
treedd619038cdc120de77ef4f1bcea5f1b305946024 /deps/v8/src/d8.h
parent3f9c8fb87fe7ac79f433104ab564130d000772b8 (diff)
downloadandroid-node-v8-83bf2975ec7a105c1e08caba21e5c4cccd9beabb.tar.gz
android-node-v8-83bf2975ec7a105c1e08caba21e5c4cccd9beabb.tar.bz2
android-node-v8-83bf2975ec7a105c1e08caba21e5c4cccd9beabb.zip
deps: cherry-pick V8 ValueSerializer changes
Refs: https://github.com/nodejs/node/pull/11048 Below is the list of commits: deps: cherry-pick 78c0be52d from V8 upstream Original commit message: ValueSerializer: Promote scheduled exceptions from wasm::ErrorThrower. wasm::ErrorThrower doesn't actually throw exceptions, it just schedules them. As a result, this exception isn't handled properly by code which expects ValueDeserializer to actually throw. For instance, the unit tests use a TryCatch to catch and handle expected exceptions in unit tests. Before this patch, I see local unit test failures because a wasm decode test schedules one, but it isn't caught (and instead causes Context::New to fail at the beginning of the next test). BUG=685713 Review-Url: https://codereview.chromium.org/2659483004 Cr-Commit-Position: refs/heads/master@{#42718} deps: cherry-pick 966355585 from V8 upstream Original commit message: [d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer) Review-Url: https://codereview.chromium.org/2643723010 Cr-Commit-Position: refs/heads/master@{#42749} deps: cherry-pick bf511b426 from V8 upstream Original commit message: ValueSerializer: Support efficiently reading and writing one-byte strings. memcpy is faster than UTF-8 encoding/decoding. This yields 10-20% wins on serializing and deserializing long ASCII strings, according to blink_perf.bindings -- and these are already in a fast path where the entire string is known to be ASCII (but this has to be checked). The win may be larger for strings in Latin-1 but not ASCII (though I suspect this is an uncommon case). A change is also made to make ValueSerializerTest.EncodeTwoByteStringUsesPadding survive wire format version number changes. This is the first of a series of wire format changes from the previous Blink format. The deserializer continues to be able to read the old format, but Chromium M56 will no longer be able to read the messages written by this, in M58. BUG=chromium:686159 Review-Url: https://codereview.chromium.org/2658793004 Cr-Commit-Position: refs/heads/master@{#42753} deps: cherry-pick 6f1639ed1 from V8 upstream Original commit message: ValueSerializer: Distinguish between 'undefined' and an absent property. Dealing with this case requires a wire format change. It is possible that an element can be absent even in an array where the dense format was chosen (because the array initially had no holes), if the elements are modified while they are being serialized. In this case, a new tag for the "hole" is emitted. The logic to treat undefined in dense arrays as an absent property is restricted to versions of the wire format that this tag did not exist. BUG=chromium:686159,chromium:665820 Review-Url: https://codereview.chromium.org/2660093002 Cr-Original-Commit-Position: refs/heads/master@{#42784} Committed: https://chromium.googlesource.com/v8/v8/+/dc85f4c8338c1c824af4f7ee3274dc9f95d14e49 Review-Url: https://codereview.chromium.org/2660093002 Cr-Commit-Position: refs/heads/master@{#42800} deps: cherry-pick c3856de37 from V8 upstream Original commit message: ValueSerializer: Check for zero length before casting to FixedDoubleArray. Even though the elements kind is FAST_DOUBLE_ELEMENTS, if length is zero the isolate's empty_fixed_array is used. It's illegal to cast this to FixedDoubleArray, so we avoid the cast. BUG=chromium:686479 Review-Url: https://codereview.chromium.org/2665313003 Cr-Commit-Position: refs/heads/master@{#42867} deps: cherry-pick 591cc0b4c from V8 upstream Original commit message: ValueSerializer: Share string encoding code with String and RegExp objects. This avoids the need to pull in the UTF-8 encoding code from the public API, and allows it to take advantage of any supported way that i::String can be encoded (one- or two-byte). Backward compatibility is maintained, but this is the behavior beginning with this version. BUG=chromium:686159 Review-Url: https://codereview.chromium.org/2665653004 Cr-Commit-Position: refs/heads/master@{#42872} deps: cherry-pick 79837f5f6 from V8 upstream Original commit message: Improve ValueSerializer perf regression after 96635558 BUG=687196 R=jbroman@chromium.org Review-Url: https://codereview.chromium.org/2674613002 Cr-Commit-Position: refs/heads/master@{#42938} deps: cherry-pick 8990399dc from V8 upstream Original commit message: ValueDeserializer: Only allow valid keys when deserializing object properties. The serializer won't ever write a more complex object. Not validating this allows other things to be used as keys, and converted to string when the property set actually occurs. It turns out this gives an opportunity to trigger OOM by giving an object a key which is a very large sparse array (whose string representation is very large). This case is now rejected by the deserializer. BUG=chromium:686511 Review-Url: https://codereview.chromium.org/2697023002 Cr-Commit-Position: refs/heads/master@{#43249} deps: cherry-pick 68960eeb7 from V8 upstream Original commit message: ValueDeserializer: Make sure that an exception is the legacy path. The entry points to the deserializer are responsible for ensuring that an exception is pending by the time they return. Some failures throw exceptions themselves, while others (like errors in the format) are exceptions caused by the deserializer, not coming from the runtime. Like the non-legacy path, a default deserialization exception should be thrown in such cases. BUG=chromium:693411 Review-Url: https://codereview.chromium.org/2712713002 Cr-Commit-Position: refs/heads/master@{#43390} deps: cherry-pick 3b15d950e from V8 upstream Original commit message: ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag Add `ValueSerializer::SetTreatArrayBufferViewsAsHostObjects()` which instructs the `ValueSerializer` to treat ArrayBufferView objects as host objects. BUG=v8:5926 Review-Url: https://codereview.chromium.org/2696133007 Cr-Commit-Position: refs/heads/master@{#43281} deps: cherry-pick 654351997 from V8 upstream Original commit message: ValueSerializer: Add an explicit tag for host objects. This makes it no longer necessary to ensure that V8 and Blink have non-colliding tags, which makes it easier for them to evolve independently, and also makes the wire format more suitable for other V8 embedders, who would not necessarily be surveyed before V8 introduced a new tag that might collide with theirs. BUG=chromium:686159 Review-Url: https://codereview.chromium.org/2709023003 Cr-Commit-Position: refs/heads/master@{#43466} PR-URL: https://github.com/nodejs/node/pull/11752 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'deps/v8/src/d8.h')
-rw-r--r--deps/v8/src/d8.h109
1 files changed, 53 insertions, 56 deletions
diff --git a/deps/v8/src/d8.h b/deps/v8/src/d8.h
index c3729f92ba..558b8bb58d 100644
--- a/deps/v8/src/d8.h
+++ b/deps/v8/src/d8.h
@@ -5,9 +5,13 @@
#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"
@@ -143,68 +147,51 @@ class SourceGroup {
int end_offset_;
};
-enum SerializationTag {
- kSerializationTagUndefined,
- kSerializationTagNull,
- kSerializationTagTrue,
- kSerializationTagFalse,
- kSerializationTagNumber,
- kSerializationTagString,
- kSerializationTagArray,
- kSerializationTagObject,
- kSerializationTagArrayBuffer,
- kSerializationTagTransferredArrayBuffer,
- kSerializationTagTransferredSharedArrayBuffer,
-};
-
class SerializationData {
public:
- SerializationData() {}
+ SerializationData() : data_(nullptr), size_(0) {}
~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));
+ uint8_t* data() { return data_.get(); }
+ size_t size() { return size_; }
+ const std::vector<ArrayBuffer::Contents>& array_buffer_contents() {
+ return array_buffer_contents_;
}
-
- 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;
+ 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:
- i::List<uint8_t> data_;
- i::List<ArrayBuffer::Contents> array_buffer_contents_;
- i::List<SharedArrayBuffer::Contents> shared_array_buffer_contents_;
+ friend class Serializer;
+
+ DISALLOW_COPY_AND_ASSIGN(SerializationData);
};
class SerializationDataQueue {
public:
- void Enqueue(SerializationData* data);
- bool Dequeue(SerializationData** data);
+ void Enqueue(std::unique_ptr<SerializationData> data);
+ bool Dequeue(std::unique_ptr<SerializationData>* data);
bool IsEmpty();
void Clear();
private:
base::Mutex mutex_;
- i::List<SerializationData*> data_;
+ std::vector<std::unique_ptr<SerializationData>> data_;
};
@@ -219,13 +206,13 @@ class Worker {
// 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(SerializationData* data);
+ void PostMessage(std::unique_ptr<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.
- SerializationData* GetMessage();
+ std::unique_ptr<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.
@@ -335,16 +322,10 @@ class Shell : public i::AllStatic {
static void CollectGarbage(Isolate* isolate);
static void EmptyMessageQueues(Isolate* isolate);
- // 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 std::unique_ptr<SerializationData> SerializeValue(
+ Isolate* isolate, Local<Value> value, Local<Value> transfer);
+ static MaybeLocal<Value> DeserializeValue(
+ Isolate* isolate, std::unique_ptr<SerializationData> data);
static void CleanupWorkers();
static int* LookupCounter(const char* name);
static void* CreateHistogram(const char* name,
@@ -444,10 +425,26 @@ class Shell : public i::AllStatic {
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 i::List<SharedArrayBuffer::Contents> externalized_shared_contents_;
+ static std::unordered_set<SharedArrayBuffer::Contents,
+ SharedArrayBufferContentsHash,
+ SharedArrayBufferContentsIsEqual>
+ externalized_shared_contents_;
static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
static Counter* GetCounter(const char* name, bool is_histogram);