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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2147433002: [ic] [stubs] Don't use Code::flags in megamorphic stub cache hash computations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@split-stub-cache
Patch Set: Improved stub cache tests and the fixes. Created 4 years, 5 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/test-api.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 "src/base/utils/random-number-generator.h" 5 #include "src/base/utils/random-number-generator.h"
6 #include "src/ic/stub-cache.h" 6 #include "src/ic/stub-cache.h"
7 #include "src/isolate.h" 7 #include "src/isolate.h"
8 #include "test/cctest/compiler/code-assembler-tester.h" 8 #include "test/cctest/compiler/code-assembler-tester.h"
9 #include "test/cctest/compiler/function-tester.h" 9 #include "test/cctest/compiler/function-tester.h"
10 10
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 } 1102 }
1103 1103
1104 namespace { 1104 namespace {
1105 1105
1106 void TestStubCacheOffsetCalculation(StubCache::Table table, 1106 void TestStubCacheOffsetCalculation(StubCache::Table table,
1107 Code::Kind handler_kind) { 1107 Code::Kind handler_kind) {
1108 Isolate* isolate(CcTest::InitIsolateOnce()); 1108 Isolate* isolate(CcTest::InitIsolateOnce());
1109 const int kNumParams = 2; 1109 const int kNumParams = 2;
1110 CodeStubAssemblerTester m(isolate, kNumParams); 1110 CodeStubAssemblerTester m(isolate, kNumParams);
1111 1111
1112 Code::Flags code_flags =
1113 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(handler_kind));
1114 { 1112 {
1115 Node* name = m.Parameter(0); 1113 Node* name = m.Parameter(0);
1116 Node* map = m.Parameter(1); 1114 Node* map = m.Parameter(1);
1117 Node* primary_offset = m.StubCachePrimaryOffset(name, code_flags, map); 1115 Node* primary_offset = m.StubCachePrimaryOffset(name, map);
1118 Node* result; 1116 Node* result;
1119 if (table == StubCache::kPrimary) { 1117 if (table == StubCache::kPrimary) {
1120 result = primary_offset; 1118 result = primary_offset;
1121 } else { 1119 } else {
1122 CHECK_EQ(StubCache::kSecondary, table); 1120 CHECK_EQ(StubCache::kSecondary, table);
1123 result = m.StubCacheSecondaryOffset(name, code_flags, primary_offset); 1121 result = m.StubCacheSecondaryOffset(name, primary_offset);
1124 } 1122 }
1125 m.Return(m.SmiFromWord32(result)); 1123 m.Return(m.SmiFromWord32(result));
1126 } 1124 }
1127 1125
1128 Handle<Code> code = m.GenerateCode(); 1126 Handle<Code> code = m.GenerateCode();
1129 FunctionTester ft(code, kNumParams); 1127 FunctionTester ft(code, kNumParams);
1130 1128
1131 Factory* factory = isolate->factory(); 1129 Factory* factory = isolate->factory();
1132 Handle<Name> names[] = { 1130 Handle<Name> names[] = {
1133 factory->NewSymbol(), 1131 factory->NewSymbol(),
(...skipping 22 matching lines...) Expand all
1156 factory->sloppy_arguments_elements_map(), 1154 factory->sloppy_arguments_elements_map(),
1157 }; 1155 };
1158 1156
1159 for (int name_index = 0; name_index < arraysize(names); name_index++) { 1157 for (int name_index = 0; name_index < arraysize(names); name_index++) {
1160 Handle<Name> name = names[name_index]; 1158 Handle<Name> name = names[name_index];
1161 for (int map_index = 0; map_index < arraysize(maps); map_index++) { 1159 for (int map_index = 0; map_index < arraysize(maps); map_index++) {
1162 Handle<Map> map = maps[map_index]; 1160 Handle<Map> map = maps[map_index];
1163 1161
1164 int expected_result; 1162 int expected_result;
1165 { 1163 {
1166 int primary_offset = 1164 int primary_offset = StubCache::PrimaryOffsetForTesting(*name, *map);
1167 StubCache::PrimaryOffsetForTesting(*name, code_flags, *map);
1168 if (table == StubCache::kPrimary) { 1165 if (table == StubCache::kPrimary) {
1169 expected_result = primary_offset; 1166 expected_result = primary_offset;
1170 } else { 1167 } else {
1171 expected_result = StubCache::SecondaryOffsetForTesting( 1168 expected_result =
1172 *name, code_flags, primary_offset); 1169 StubCache::SecondaryOffsetForTesting(*name, primary_offset);
1173 } 1170 }
1174 } 1171 }
1175 Handle<Object> result = ft.Call(name, map).ToHandleChecked(); 1172 Handle<Object> result = ft.Call(name, map).ToHandleChecked();
1176 1173
1177 Smi* expected = Smi::FromInt(expected_result & Smi::kMaxValue); 1174 Smi* expected = Smi::FromInt(expected_result & Smi::kMaxValue);
1178 CHECK_EQ(expected, Smi::cast(*result)); 1175 CHECK_EQ(expected, Smi::cast(*result));
1179 } 1176 }
1180 } 1177 }
1181 } 1178 }
1182 1179
(...skipping 27 matching lines...) Expand all
1210 } // namespace 1207 } // namespace
1211 1208
1212 TEST(TryProbeStubCache) { 1209 TEST(TryProbeStubCache) {
1213 typedef CodeStubAssembler::Label Label; 1210 typedef CodeStubAssembler::Label Label;
1214 typedef CodeStubAssembler::Variable Variable; 1211 typedef CodeStubAssembler::Variable Variable;
1215 Isolate* isolate(CcTest::InitIsolateOnce()); 1212 Isolate* isolate(CcTest::InitIsolateOnce());
1216 const int kNumParams = 3; 1213 const int kNumParams = 3;
1217 CodeStubAssemblerTester m(isolate, kNumParams); 1214 CodeStubAssemblerTester m(isolate, kNumParams);
1218 1215
1219 Code::Kind ic_kind = Code::LOAD_IC; 1216 Code::Kind ic_kind = Code::LOAD_IC;
1220 Code::Flags flags_to_query =
1221 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(ic_kind));
1222
1223 StubCache stub_cache(isolate, ic_kind); 1217 StubCache stub_cache(isolate, ic_kind);
1224 stub_cache.Clear(); 1218 stub_cache.Clear();
1225 1219
1226 { 1220 {
1227 Node* receiver = m.Parameter(0); 1221 Node* receiver = m.Parameter(0);
1228 Node* name = m.Parameter(1); 1222 Node* name = m.Parameter(1);
1229 Node* expected_handler = m.Parameter(2); 1223 Node* expected_handler = m.Parameter(2);
1230 1224
1231 Label passed(&m), failed(&m); 1225 Label passed(&m), failed(&m);
1232 1226
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 } 1286 }
1293 1287
1294 // Generate some number of receiver maps and receivers. 1288 // Generate some number of receiver maps and receivers.
1295 for (int i = 0; i < StubCache::kSecondaryTableSize / 2; i++) { 1289 for (int i = 0; i < StubCache::kSecondaryTableSize / 2; i++) {
1296 Handle<Map> map = Map::Create(isolate, 0); 1290 Handle<Map> map = Map::Create(isolate, 0);
1297 receivers.push_back(factory->NewJSObjectFromMap(map)); 1291 receivers.push_back(factory->NewJSObjectFromMap(map));
1298 } 1292 }
1299 1293
1300 // Generate some number of handlers. 1294 // Generate some number of handlers.
1301 for (int i = 0; i < 30; i++) { 1295 for (int i = 0; i < 30; i++) {
1302 Code::Kind code_kind;
1303 switch (rand_gen.NextInt(4)) {
1304 case 0:
1305 code_kind = Code::LOAD_IC;
1306 break;
1307 case 1:
1308 code_kind = Code::KEYED_LOAD_IC;
1309 break;
1310 case 2:
1311 code_kind = Code::STORE_IC;
1312 break;
1313 case 3:
1314 code_kind = Code::KEYED_STORE_IC;
1315 break;
1316 default:
1317 UNREACHABLE();
1318 }
1319 Code::Flags flags = 1296 Code::Flags flags =
1320 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(code_kind)); 1297 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(ic_kind));
1321 handlers.push_back(CreateCodeWithFlags(flags)); 1298 handlers.push_back(CreateCodeWithFlags(flags));
1322 } 1299 }
1323 1300
1324 // Ensure that GC does happen because from now on we are going to fill our 1301 // Ensure that GC does happen because from now on we are going to fill our
1325 // own stub cache instance with raw values. 1302 // own stub cache instance with raw values.
1326 DisallowHeapAllocation no_gc; 1303 DisallowHeapAllocation no_gc;
1327 1304
1328 // Populate {stub_cache}. 1305 // Populate {stub_cache}.
1329 const int N = StubCache::kPrimaryTableSize + StubCache::kSecondaryTableSize; 1306 const int N = StubCache::kPrimaryTableSize + StubCache::kSecondaryTableSize;
1330 for (int i = 0; i < N; i++) { 1307 for (int i = 0; i < N; i++) {
1331 int index = rand_gen.NextInt(); 1308 int index = rand_gen.NextInt();
1332 Handle<Name> name = names[index % names.size()]; 1309 Handle<Name> name = names[index % names.size()];
1333 Handle<JSObject> receiver = receivers[index % receivers.size()]; 1310 Handle<JSObject> receiver = receivers[index % receivers.size()];
1334 Handle<Code> handler = handlers[index % handlers.size()]; 1311 Handle<Code> handler = handlers[index % handlers.size()];
1335 stub_cache.Set(*name, receiver->map(), *handler); 1312 stub_cache.Set(*name, receiver->map(), *handler);
1336 } 1313 }
1337 1314
1338 // Perform some queries. 1315 // Perform some queries.
1339 bool queried_existing = false; 1316 bool queried_existing = false;
1340 bool queried_non_existing = false; 1317 bool queried_non_existing = false;
1341 for (int i = 0; i < N; i++) { 1318 for (int i = 0; i < N; i++) {
1342 int index = rand_gen.NextInt(); 1319 int index = rand_gen.NextInt();
1343 Handle<Name> name = names[index % names.size()]; 1320 Handle<Name> name = names[index % names.size()];
1344 Handle<JSObject> receiver = receivers[index % receivers.size()]; 1321 Handle<JSObject> receiver = receivers[index % receivers.size()];
1345 Code* handler = stub_cache.Get(*name, receiver->map(), flags_to_query); 1322 Code* handler = stub_cache.Get(*name, receiver->map());
1346 if (handler == nullptr) { 1323 if (handler == nullptr) {
1347 queried_non_existing = true; 1324 queried_non_existing = true;
1348 } else { 1325 } else {
1349 queried_existing = true; 1326 queried_existing = true;
1350 } 1327 }
1351 1328
1352 Handle<Code> expected_handler(handler, isolate); 1329 Handle<Code> expected_handler(handler, isolate);
1353 ft.CheckTrue(receiver, name, expected_handler); 1330 ft.CheckTrue(receiver, name, expected_handler);
1354 } 1331 }
1355 1332
1356 for (int i = 0; i < N; i++) { 1333 for (int i = 0; i < N; i++) {
1357 int index1 = rand_gen.NextInt(); 1334 int index1 = rand_gen.NextInt();
1358 int index2 = rand_gen.NextInt(); 1335 int index2 = rand_gen.NextInt();
1359 Handle<Name> name = names[index1 % names.size()]; 1336 Handle<Name> name = names[index1 % names.size()];
1360 Handle<JSObject> receiver = receivers[index2 % receivers.size()]; 1337 Handle<JSObject> receiver = receivers[index2 % receivers.size()];
1361 Code* handler = stub_cache.Get(*name, receiver->map(), flags_to_query); 1338 Code* handler = stub_cache.Get(*name, receiver->map());
1362 if (handler == nullptr) { 1339 if (handler == nullptr) {
1363 queried_non_existing = true; 1340 queried_non_existing = true;
1364 } else { 1341 } else {
1365 queried_existing = true; 1342 queried_existing = true;
1366 } 1343 }
1367 1344
1368 Handle<Code> expected_handler(handler, isolate); 1345 Handle<Code> expected_handler(handler, isolate);
1369 ft.CheckTrue(receiver, name, expected_handler); 1346 ft.CheckTrue(receiver, name, expected_handler);
1370 } 1347 }
1371 // Ensure we performed both kind of queries. 1348 // Ensure we performed both kind of queries.
1372 CHECK(queried_existing && queried_non_existing); 1349 CHECK(queried_existing && queried_non_existing);
1373 } 1350 }
1374 1351
1375 } // namespace internal 1352 } // namespace internal
1376 } // namespace v8 1353 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698