27
27
#include " node_errors.h"
28
28
#include " simdutf.h"
29
29
#include " util.h"
30
+ #include " v8-external-memory-accounter.h"
30
31
31
32
#include < climits>
32
33
#include < cstring> // memcpy
40
41
41
42
namespace node {
42
43
44
+ using v8::ExternalMemoryAccounter;
43
45
using v8::HandleScope;
44
46
using v8::Isolate;
45
47
using v8::Just;
@@ -57,7 +59,8 @@ class ExternString: public ResourceType {
57
59
public:
58
60
~ExternString () override {
59
61
free (const_cast <TypeName*>(data_));
60
- isolate ()->AdjustAmountOfExternalAllocatedMemory (-byte_length ());
62
+ external_memory_accounter_->Decrease (isolate (), byte_length ());
63
+ delete external_memory_accounter_;
61
64
}
62
65
63
66
const TypeName* data () const override {
@@ -68,9 +71,7 @@ class ExternString: public ResourceType {
68
71
return length_;
69
72
}
70
73
71
- int64_t byte_length () const {
72
- return length () * sizeof (*data ());
73
- }
74
+ size_t byte_length () const { return length () * sizeof (*data ()); }
74
75
75
76
static MaybeLocal<Value> NewFromCopy (Isolate* isolate,
76
77
const TypeName* data,
@@ -117,16 +118,19 @@ class ExternString: public ResourceType {
117
118
return MaybeLocal<Value>();
118
119
}
119
120
120
- isolate->AdjustAmountOfExternalAllocatedMemory (h_str->byte_length ());
121
-
122
121
return str;
123
122
}
124
123
125
124
inline Isolate* isolate () const { return isolate_; }
126
125
127
126
private:
128
127
ExternString (Isolate* isolate, const TypeName* data, size_t length)
129
- : isolate_(isolate), data_(data), length_(length) { }
128
+ : isolate_(isolate),
129
+ external_memory_accounter_ (new ExternalMemoryAccounter()),
130
+ data_(data),
131
+ length_(length) {
132
+ external_memory_accounter_->Increase (isolate, byte_length ());
133
+ }
130
134
static MaybeLocal<Value> NewExternal (Isolate* isolate,
131
135
ExternString* h_str);
132
136
@@ -136,6 +140,7 @@ class ExternString: public ResourceType {
136
140
size_t length);
137
141
138
142
Isolate* isolate_;
143
+ ExternalMemoryAccounter* external_memory_accounter_;
139
144
const TypeName* data_;
140
145
size_t length_;
141
146
};
0 commit comments