Skip to content

Commit 5cf5767

Browse files
sethbrenithCommit Bot
authored andcommitted
Reland "[runtime] Improve handling of enumeration index on global dictionary"
This is a reland of 25d1657 Changes from original: replaced slow test with fast test Original change's description: > [runtime] Improve handling of enumeration index on global dictionary > > Bug: chromium:1056054 > Change-Id: Ie1f2da98bc54a2ad5189cbe2ee1686fe1ef7019a > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2079035 > Reviewed-by: Toon Verwaest <[email protected]> > Reviewed-by: Jakob Kummerow <[email protected]> > Commit-Queue: Seth Brenith <[email protected]> > Cr-Commit-Position: refs/heads/master@{#66504} Bug: chromium:1056054 Change-Id: I45b9a096b1e37bf1dc5e792f106cdfadd47fabf9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2080855 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Seth Brenith <[email protected]> Cr-Commit-Position: refs/heads/master@{#66535}
1 parent ab033d0 commit 5cf5767

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

src/objects/objects.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7280,10 +7280,9 @@ int BaseNameDictionary<Derived, Shape>::NextEnumerationIndex(
72807280
// Check whether the next enumeration index is valid.
72817281
if (!PropertyDetails::IsValidIndex(index)) {
72827282
// If not, we generate new indices for the properties.
7283-
int length = dictionary->NumberOfElements();
7284-
72857283
Handle<FixedArray> iteration_order = IterationIndices(isolate, dictionary);
7286-
DCHECK_EQ(length, iteration_order->length());
7284+
int length = iteration_order->length();
7285+
DCHECK_LE(length, dictionary->NumberOfElements());
72877286

72887287
// Iterate over the dictionary using the enumeration order and update
72897288
// the dictionary with new enumeration indices.
@@ -7527,8 +7526,8 @@ void BaseNameDictionary<Derived, Shape>::CopyEnumKeysTo(
75277526
template <typename Derived, typename Shape>
75287527
Handle<FixedArray> BaseNameDictionary<Derived, Shape>::IterationIndices(
75297528
Isolate* isolate, Handle<Derived> dictionary) {
7530-
int length = dictionary->NumberOfElements();
7531-
Handle<FixedArray> array = isolate->factory()->NewFixedArray(length);
7529+
Handle<FixedArray> array =
7530+
isolate->factory()->NewFixedArray(dictionary->NumberOfElements());
75327531
ReadOnlyRoots roots(isolate);
75337532
int array_size = 0;
75347533
{
@@ -7540,7 +7539,13 @@ Handle<FixedArray> BaseNameDictionary<Derived, Shape>::IterationIndices(
75407539
array->set(array_size++, Smi::FromInt(i.as_int()));
75417540
}
75427541

7543-
DCHECK_EQ(array_size, length);
7542+
// The global dictionary doesn't track its deletion count, so we may iterate
7543+
// fewer entries than the count of elements claimed by the dictionary.
7544+
if (std::is_same<Derived, GlobalDictionary>::value) {
7545+
DCHECK_LE(array_size, dictionary->NumberOfElements());
7546+
} else {
7547+
DCHECK_EQ(array_size, dictionary->NumberOfElements());
7548+
}
75447549

75457550
EnumIndexComparator<Derived> cmp(raw_dictionary);
75467551
// Use AtomicSlot wrapper to ensure that std::sort uses atomic load and

test/unittests/BUILD.gn

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ v8_executable("unittests") {
3838
"//testing/gtest",
3939
]
4040

41-
data_deps = [
42-
"../../tools:v8_testrunner",
43-
]
41+
data_deps = [ "../../tools:v8_testrunner" ]
4442

4543
data = [
4644
"testcfg.py",
@@ -212,6 +210,7 @@ v8_source_set("unittests_sources") {
212210
"parser/preparser-unittest.cc",
213211
"profiler/strings-storage-unittest.cc",
214212
"regress/regress-crbug-1041240-unittest.cc",
213+
"regress/regress-crbug-1056054-unittest.cc",
215214
"regress/regress-crbug-938251-unittest.cc",
216215
"run-all-unittests.cc",
217216
"strings/char-predicates-unittest.cc",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "src/execution/isolate.h"
6+
#include "src/heap/factory.h"
7+
#include "test/unittests/test-utils.h"
8+
9+
namespace v8 {
10+
namespace internal {
11+
12+
using EnumIndexOverflowTest = TestWithNativeContextAndZone;
13+
14+
TEST_F(EnumIndexOverflowTest, GlobalObject) {
15+
Handle<GlobalDictionary> dictionary(
16+
isolate()->global_object()->global_dictionary(), isolate());
17+
dictionary->set_next_enumeration_index(
18+
PropertyDetails::DictionaryStorageField::kMax);
19+
Handle<Object> value(Smi::FromInt(static_cast<int>(42)), isolate());
20+
Handle<Name> name = factory()->InternalizeUtf8String("eeeee");
21+
JSObject::AddProperty(isolate(), isolate()->global_object(), name, value,
22+
NONE);
23+
}
24+
25+
} // namespace internal
26+
} // namespace v8

0 commit comments

Comments
 (0)