-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original commit message: [objects] Compact and shrink script_list So far creating scripts always grew the script_list without ever reusing cleared slots or shrinking. While this is probably not a problem with script_list in practice, this is still a memory leak. Fix this leak by using WeakArrayList::Append instead of AddToEnd. Append adds to the end of the array, but potentially compacts and shrinks the list as well. Other WeakArrayLists can use this method as well, as long as they are not using indices into this array. Bug: v8:10031 Change-Id: If743c4cc3f8d67ab735522f0ded038b2fb43e437 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1967385 Commit-Queue: Dominik Inführ <[email protected]> Reviewed-by: Ulan Degenbaev <[email protected]> Cr-Commit-Position: refs/heads/master@{#65640} Refs: v8/v8@fb26d0b
- Loading branch information
Showing
7 changed files
with
215 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2019 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "src/heap/factory.h" | ||
#include "test/unittests/test-utils.h" | ||
|
||
namespace v8 { | ||
namespace internal { | ||
|
||
using WeakArrayListTest = TestWithIsolate; | ||
|
||
TEST_F(WeakArrayListTest, Compact) { | ||
Handle<WeakArrayList> list = isolate()->factory()->NewWeakArrayList(10); | ||
EXPECT_EQ(list->length(), 0); | ||
EXPECT_EQ(list->capacity(), 10); | ||
|
||
MaybeObject some_object = | ||
MaybeObject::FromObject(*isolate()->factory()->empty_fixed_array()); | ||
MaybeObject weak_ref = MaybeObject::MakeWeak(some_object); | ||
MaybeObject smi = MaybeObject::FromSmi(Smi::FromInt(0)); | ||
MaybeObject cleared_ref = HeapObjectReference::ClearedValue(isolate()); | ||
list->Set(0, weak_ref); | ||
list->Set(1, smi); | ||
list->Set(2, cleared_ref); | ||
list->Set(3, cleared_ref); | ||
list->set_length(5); | ||
|
||
list->Compact(isolate()); | ||
EXPECT_EQ(list->length(), 3); | ||
EXPECT_EQ(list->capacity(), 10); | ||
} | ||
|
||
TEST_F(WeakArrayListTest, OutOfPlaceCompact) { | ||
Handle<WeakArrayList> list = isolate()->factory()->NewWeakArrayList(20); | ||
EXPECT_EQ(list->length(), 0); | ||
EXPECT_EQ(list->capacity(), 20); | ||
|
||
MaybeObject some_object = | ||
MaybeObject::FromObject(*isolate()->factory()->empty_fixed_array()); | ||
MaybeObject weak_ref = MaybeObject::MakeWeak(some_object); | ||
MaybeObject smi = MaybeObject::FromSmi(Smi::FromInt(0)); | ||
MaybeObject cleared_ref = HeapObjectReference::ClearedValue(isolate()); | ||
list->Set(0, weak_ref); | ||
list->Set(1, smi); | ||
list->Set(2, cleared_ref); | ||
list->Set(3, smi); | ||
list->Set(4, cleared_ref); | ||
list->set_length(6); | ||
|
||
Handle<WeakArrayList> compacted = | ||
isolate()->factory()->CompactWeakArrayList(list, 4); | ||
EXPECT_EQ(list->length(), 6); | ||
EXPECT_EQ(compacted->length(), 4); | ||
EXPECT_EQ(compacted->capacity(), 4); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace v8 |