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

Side by Side Diff: test/unittests/heap/slot-set-unittest.cc

Issue 1701963003: Filter invalid slots after array trimming. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix compile Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « test/cctest/heap/test-heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "src/globals.h" 7 #include "src/globals.h"
8 #include "src/heap/slot-set.h" 8 #include "src/heap/slot-set.h"
9 #include "src/heap/spaces.h" 9 #include "src/heap/spaces.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 for (int i = 0; i < Page::kPageSize; i += kPointerSize) { 88 for (int i = 0; i < Page::kPageSize; i += kPointerSize) {
89 if (i % 21 == 0) { 89 if (i % 21 == 0) {
90 EXPECT_TRUE(set.Lookup(i)); 90 EXPECT_TRUE(set.Lookup(i));
91 } else { 91 } else {
92 EXPECT_FALSE(set.Lookup(i)); 92 EXPECT_FALSE(set.Lookup(i));
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 void CheckRemoveRangeOn(uint32_t start, uint32_t end) {
98 SlotSet set;
99 set.SetPageStart(0);
100 uint32_t first = start == 0 ? 0 : start - kPointerSize;
101 uint32_t last = end == Page::kPageSize ? end - kPointerSize : end;
102 for (uint32_t i = first; i <= last; i += kPointerSize) {
103 set.Insert(i);
104 }
105 set.RemoveRange(start, end);
106 if (first != start) {
107 EXPECT_TRUE(set.Lookup(first));
108 }
109 if (last == end) {
110 EXPECT_TRUE(set.Lookup(last));
111 }
112 for (uint32_t i = start; i < end; i += kPointerSize) {
113 EXPECT_FALSE(set.Lookup(i));
114 }
115 }
116
97 TEST(SlotSet, RemoveRange) { 117 TEST(SlotSet, RemoveRange) {
118 CheckRemoveRangeOn(0, Page::kPageSize);
119 CheckRemoveRangeOn(1 * kPointerSize, 1023 * kPointerSize);
120 for (uint32_t start = 0; start <= 32; start++) {
121 CheckRemoveRangeOn(start * kPointerSize, (start + 1) * kPointerSize);
122 CheckRemoveRangeOn(start * kPointerSize, (start + 2) * kPointerSize);
123 const uint32_t kEnds[] = {32, 64, 100, 128, 1024, 1500, 2048};
124 for (int i = 0; i < sizeof(kEnds) / sizeof(uint32_t); i++) {
125 for (int k = -3; k <= 3; k++) {
126 uint32_t end = (kEnds[i] + k);
127 if (start < end) {
128 CheckRemoveRangeOn(start * kPointerSize, end * kPointerSize);
129 }
130 }
131 }
132 }
98 SlotSet set; 133 SlotSet set;
99 set.SetPageStart(0); 134 set.SetPageStart(0);
100 for (int i = 0; i < Page::kPageSize; i += kPointerSize) { 135 set.Insert(Page::kPageSize / 2);
101 set.Insert(i);
102 }
103
104 set.RemoveRange(0, Page::kPageSize); 136 set.RemoveRange(0, Page::kPageSize);
105 137 for (uint32_t i = 0; i < Page::kPageSize; i += kPointerSize) {
106 for (int i = 0; i < Page::kPageSize; i += kPointerSize) {
107 EXPECT_FALSE(set.Lookup(i)); 138 EXPECT_FALSE(set.Lookup(i));
108 } 139 }
109
110 for (int i = 0; i < Page::kPageSize; i += kPointerSize) {
111 set.Insert(i);
112 }
113
114 set.RemoveRange(10 * kPointerSize, 10 * kPointerSize);
115 EXPECT_TRUE(set.Lookup(9 * kPointerSize));
116 EXPECT_TRUE(set.Lookup(10 * kPointerSize));
117 EXPECT_TRUE(set.Lookup(11 * kPointerSize));
118
119 set.RemoveRange(10 * kPointerSize, 1000 * kPointerSize);
120 for (int i = 0; i < Page::kPageSize; i += kPointerSize) {
121 if (10 * kPointerSize <= i && i < 1000 * kPointerSize) {
122 EXPECT_FALSE(set.Lookup(i));
123 } else {
124 EXPECT_TRUE(set.Lookup(i));
125 }
126 }
127 } 140 }
128 141
129 } // namespace internal 142 } // namespace internal
130 } // namespace v8 143 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/heap/test-heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698