Skip to content

Commit 826cde8

Browse files
committed
src: fix gc heuristic for external twobyte strings
Large external two-byte strings reported their character length instead of their byte length, throwing off the garbage collector heuristic by a factor of two. PR-URL: #1042 Reviewed-By: Trevor Norris <[email protected]>
1 parent f5b7e18 commit 826cde8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/string_bytes.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class ExternString: public ResourceType {
2828
public:
2929
~ExternString() override {
3030
delete[] data_;
31-
int64_t change_in_bytes = -static_cast<int64_t>(length_);
32-
isolate()->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
31+
isolate()->AdjustAmountOfExternalAllocatedMemory(-byte_length());
3332
}
3433

3534
const TypeName* data() const override {
@@ -40,6 +39,10 @@ class ExternString: public ResourceType {
4039
return length_;
4140
}
4241

42+
int64_t byte_length() const {
43+
return length() * sizeof(*data());
44+
}
45+
4346
static Local<String> NewFromCopy(Isolate* isolate,
4447
const TypeName* data,
4548
size_t length) {
@@ -69,7 +72,7 @@ class ExternString: public ResourceType {
6972
data,
7073
length);
7174
Local<String> str = String::NewExternal(isolate, h_str);
72-
isolate->AdjustAmountOfExternalAllocatedMemory(length);
75+
isolate->AdjustAmountOfExternalAllocatedMemory(h_str->byte_length());
7376

7477
return scope.Escape(str);
7578
}

0 commit comments

Comments
 (0)