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

Unified Diff: src/d8.h

Issue 2662193002: [d8] Fix ArrayBuffer memory leaks in d8 introduced by commit 96635558. (Closed)
Patch Set: comment Created 3 years, 11 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 b86558357b1538b25b61c4523103a21abf0cafb2..bedf43ef6671fadc02dec46fd5cce19f549528f6 100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -5,13 +5,12 @@
#ifndef V8_D8_H_
#define V8_D8_H_
+#include <iterator>
#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,11 +146,40 @@ class SourceGroup {
int end_offset_;
};
+// The backing store of an ArrayBuffer or SharedArrayBuffer, after
+// Externalize() has been called on it.
+class ExternalizedContents {
+ public:
+ explicit ExternalizedContents(const ArrayBuffer::Contents& contents)
+ : data_(contents.Data()), size_(contents.ByteLength()) {}
+ explicit ExternalizedContents(const SharedArrayBuffer::Contents& contents)
+ : data_(contents.Data()), size_(contents.ByteLength()) {}
+ ExternalizedContents(ExternalizedContents&& other)
+ : data_(other.data_), size_(other.size_) {
+ other.data_ = nullptr;
+ other.size_ = 0;
+ }
+ ExternalizedContents& operator=(ExternalizedContents&& other) {
+ if (this != &other) {
+ data_ = other.data_;
+ size_ = other.size_;
+ other.data_ = nullptr;
+ other.size_ = 0;
+ }
+ return *this;
+ }
+ ~ExternalizedContents();
+
+ private:
+ void* data_;
+ size_t size_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExternalizedContents);
+};
class SerializationData {
public:
- SerializationData() : data_(nullptr), size_(0) {}
- ~SerializationData();
+ SerializationData() : size_(0) {}
uint8_t* data() { return data_.get(); }
size_t size() { return size_; }
@@ -163,7 +191,12 @@ class SerializationData {
return shared_array_buffer_contents_;
}
- void ClearTransferredArrayBuffers();
+ void AppendExternalizedContentsTo(std::vector<ExternalizedContents>* to) {
+ to->insert(to->end(),
+ std::make_move_iterator(externalized_contents_.begin()),
+ std::make_move_iterator(externalized_contents_.end()));
+ externalized_contents_.clear();
+ }
private:
struct DataDeleter {
@@ -174,6 +207,7 @@ class SerializationData {
size_t size_;
std::vector<ArrayBuffer::Contents> array_buffer_contents_;
std::vector<SharedArrayBuffer::Contents> shared_array_buffer_contents_;
+ std::vector<ExternalizedContents> externalized_contents_;
private:
friend class Serializer;
@@ -424,26 +458,10 @@ 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 std::unordered_set<SharedArrayBuffer::Contents,
- SharedArrayBufferContentsHash,
- SharedArrayBufferContentsIsEqual>
- externalized_shared_contents_;
+ static std::vector<ExternalizedContents> externalized_contents_;
static void WriteIgnitionDispatchCountersFile(v8::Isolate* isolate);
static Counter* GetCounter(const char* name, bool is_histogram);
« 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