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

Side by Side Diff: src/x64/code-stubs-x64.cc

Issue 2333243004: CallConstruct also gets call count information if megamorphic. (Closed)
Patch Set: Compile/runtime fixes. Created 4 years, 3 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/code-stubs.h" 7 #include "src/code-stubs.h"
8 #include "src/api-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 __ Push(rbx); 1168 __ Push(rbx);
1169 __ Push(rsi); 1169 __ Push(rsi);
1170 1170
1171 __ CallStub(stub); 1171 __ CallStub(stub);
1172 1172
1173 __ Pop(rsi); 1173 __ Pop(rsi);
1174 __ Pop(rbx); 1174 __ Pop(rbx);
1175 __ Pop(rdx); 1175 __ Pop(rdx);
1176 __ Pop(rdi); 1176 __ Pop(rdi);
1177 __ Pop(rax); 1177 __ Pop(rax);
1178 __ SmiToInteger32(rdx, rdx);
1178 __ SmiToInteger32(rax, rax); 1179 __ SmiToInteger32(rax, rax);
1179 } 1180 }
1180 1181
1181 1182
1182 static void GenerateRecordCallTarget(MacroAssembler* masm) { 1183 static void GenerateRecordCallTarget(MacroAssembler* masm) {
1183 // Cache the called function in a feedback vector slot. Cache states 1184 // Cache the called function in a feedback vector slot. Cache states
1184 // are uninitialized, monomorphic (indicated by a JSFunction), and 1185 // are uninitialized, monomorphic (indicated by a JSFunction), and
1185 // megamorphic. 1186 // megamorphic.
1186 // rax : number of arguments to the construct function 1187 // rax : number of arguments to the construct function
1187 // rbx : feedback vector 1188 // rbx : feedback vector
1188 // rdx : slot in feedback vector (Smi) 1189 // rdx : slot in feedback vector (Smi)
1189 // rdi : the function to call 1190 // rdi : the function to call
1190 Isolate* isolate = masm->isolate(); 1191 Isolate* isolate = masm->isolate();
1191 Label initialize, done, miss, megamorphic, not_array_function; 1192 Label initialize, done, miss, megamorphic, not_array_function;
1192 Label done_initialize_count, done_increment_count;
1193 1193
1194 // Load the cache state into r11. 1194 // Load the cache state into r11.
1195 __ SmiToInteger32(rdx, rdx); 1195 __ SmiToInteger32(rdx, rdx);
1196 __ movp(r11, 1196 __ movp(r11,
1197 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); 1197 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
1198 1198
1199 // A monomorphic cache hit or an already megamorphic state: invoke the 1199 // A monomorphic cache hit or an already megamorphic state: invoke the
1200 // function without changing the state. 1200 // function without changing the state.
1201 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read 1201 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read
1202 // at this position in a symbol (see static asserts in 1202 // at this position in a symbol (see static asserts in
1203 // type-feedback-vector.h). 1203 // type-feedback-vector.h).
1204 Label check_allocation_site; 1204 Label check_allocation_site;
1205 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset)); 1205 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset));
1206 __ j(equal, &done_increment_count, Label::kFar); 1206 __ j(equal, &done, Label::kFar);
1207 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex); 1207 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex);
1208 __ j(equal, &done, Label::kFar); 1208 __ j(equal, &done, Label::kFar);
1209 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset), 1209 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset),
1210 Heap::kWeakCellMapRootIndex); 1210 Heap::kWeakCellMapRootIndex);
1211 __ j(not_equal, &check_allocation_site); 1211 __ j(not_equal, &check_allocation_site);
1212 1212
1213 // If the weak cell is cleared, we have a new chance to become monomorphic. 1213 // If the weak cell is cleared, we have a new chance to become monomorphic.
1214 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset)); 1214 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset));
1215 __ j(equal, &initialize); 1215 __ j(equal, &initialize);
1216 __ jmp(&megamorphic); 1216 __ jmp(&megamorphic);
1217 1217
1218 __ bind(&check_allocation_site); 1218 __ bind(&check_allocation_site);
1219 // If we came here, we need to see if we are the array function. 1219 // If we came here, we need to see if we are the array function.
1220 // If we didn't have a matching function, and we didn't find the megamorph 1220 // If we didn't have a matching function, and we didn't find the megamorph
1221 // sentinel, then we have in the slot either some other function or an 1221 // sentinel, then we have in the slot either some other function or an
1222 // AllocationSite. 1222 // AllocationSite.
1223 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex); 1223 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex);
1224 __ j(not_equal, &miss); 1224 __ j(not_equal, &miss);
1225 1225
1226 // Make sure the function is the Array() function 1226 // Make sure the function is the Array() function
1227 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); 1227 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11);
1228 __ cmpp(rdi, r11); 1228 __ cmpp(rdi, r11);
1229 __ j(not_equal, &megamorphic); 1229 __ j(not_equal, &megamorphic);
1230 __ jmp(&done_increment_count); 1230 __ jmp(&done);
1231 1231
1232 __ bind(&miss); 1232 __ bind(&miss);
1233 1233
1234 // A monomorphic miss (i.e, here the cache is not uninitialized) goes 1234 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
1235 // megamorphic. 1235 // megamorphic.
1236 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex); 1236 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex);
1237 __ j(equal, &initialize); 1237 __ j(equal, &initialize);
1238 // MegamorphicSentinel is an immortal immovable object (undefined) so no 1238 // MegamorphicSentinel is an immortal immovable object (undefined) so no
1239 // write-barrier is needed. 1239 // write-barrier is needed.
1240 __ bind(&megamorphic); 1240 __ bind(&megamorphic);
1241 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize), 1241 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
1242 TypeFeedbackVector::MegamorphicSentinel(isolate)); 1242 TypeFeedbackVector::MegamorphicSentinel(isolate));
1243 __ jmp(&done); 1243 __ jmp(&done);
1244 1244
1245 // An uninitialized cache is patched with the function or sentinel to 1245 // An uninitialized cache is patched with the function or sentinel to
1246 // indicate the ElementsKind if function is the Array constructor. 1246 // indicate the ElementsKind if function is the Array constructor.
1247 __ bind(&initialize); 1247 __ bind(&initialize);
1248 1248
1249 // Make sure the function is the Array() function 1249 // Make sure the function is the Array() function
1250 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); 1250 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11);
1251 __ cmpp(rdi, r11); 1251 __ cmpp(rdi, r11);
1252 __ j(not_equal, &not_array_function); 1252 __ j(not_equal, &not_array_function);
1253 1253
1254 CreateAllocationSiteStub create_stub(isolate); 1254 CreateAllocationSiteStub create_stub(isolate);
1255 CallStubInRecordCallTarget(masm, &create_stub); 1255 CallStubInRecordCallTarget(masm, &create_stub);
1256 __ jmp(&done_initialize_count); 1256 __ jmp(&done);
1257 1257
1258 __ bind(&not_array_function); 1258 __ bind(&not_array_function);
1259 CreateWeakCellStub weak_cell_stub(isolate); 1259 CreateWeakCellStub weak_cell_stub(isolate);
1260 CallStubInRecordCallTarget(masm, &weak_cell_stub); 1260 CallStubInRecordCallTarget(masm, &weak_cell_stub);
1261 1261
1262 __ bind(&done_initialize_count); 1262 __ bind(&done);
1263 // Initialize the call counter. 1263 // Increment the call count for all function calls.
1264 __ SmiToInteger32(rdx, rdx);
1265 __ Move(FieldOperand(rbx, rdx, times_pointer_size,
1266 FixedArray::kHeaderSize + kPointerSize),
1267 Smi::FromInt(1));
1268 __ jmp(&done);
1269
1270 __ bind(&done_increment_count);
1271
1272 // Increment the call count for monomorphic function calls.
1273 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size, 1264 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size,
1274 FixedArray::kHeaderSize + kPointerSize), 1265 FixedArray::kHeaderSize + kPointerSize),
1275 Smi::FromInt(1)); 1266 Smi::FromInt(1));
1276
1277 __ bind(&done);
1278 __ Integer32ToSmi(rdx, rdx);
1279 } 1267 }
1280 1268
1281 1269
1282 void CallConstructStub::Generate(MacroAssembler* masm) { 1270 void CallConstructStub::Generate(MacroAssembler* masm) {
1283 // rax : number of arguments 1271 // rax : number of arguments
1284 // rbx : feedback vector 1272 // rbx : feedback vector
1285 // rdx : slot in feedback vector (Smi) 1273 // rdx : slot in feedback vector (Smi)
1286 // rdi : constructor function 1274 // rdi : constructor function
1287 1275
1288 Label non_function; 1276 Label non_function;
1289 // Check that the constructor is not a smi. 1277 // Check that the constructor is not a smi.
1290 __ JumpIfSmi(rdi, &non_function); 1278 __ JumpIfSmi(rdi, &non_function);
1291 // Check that constructor is a JSFunction. 1279 // Check that constructor is a JSFunction.
1292 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11); 1280 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11);
1293 __ j(not_equal, &non_function); 1281 __ j(not_equal, &non_function);
1294 1282
1295 GenerateRecordCallTarget(masm); 1283 GenerateRecordCallTarget(masm);
1296 1284
1297 __ SmiToInteger32(rdx, rdx);
1298 Label feedback_register_initialized; 1285 Label feedback_register_initialized;
1299 // Put the AllocationSite from the feedback vector into rbx, or undefined. 1286 // Put the AllocationSite from the feedback vector into rbx, or undefined.
1300 __ movp(rbx, 1287 __ movp(rbx,
1301 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); 1288 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
1302 __ CompareRoot(FieldOperand(rbx, 0), Heap::kAllocationSiteMapRootIndex); 1289 __ CompareRoot(FieldOperand(rbx, 0), Heap::kAllocationSiteMapRootIndex);
1303 __ j(equal, &feedback_register_initialized, Label::kNear); 1290 __ j(equal, &feedback_register_initialized, Label::kNear);
1304 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); 1291 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
1305 __ bind(&feedback_register_initialized); 1292 __ bind(&feedback_register_initialized);
1306 1293
1307 __ AssertUndefinedOrAllocationSite(rbx); 1294 __ AssertUndefinedOrAllocationSite(rbx);
(...skipping 3866 matching lines...) Expand 10 before | Expand all | Expand 10 after
5174 kStackUnwindSpace, nullptr, return_value_operand, 5161 kStackUnwindSpace, nullptr, return_value_operand,
5175 NULL); 5162 NULL);
5176 } 5163 }
5177 5164
5178 #undef __ 5165 #undef __
5179 5166
5180 } // namespace internal 5167 } // namespace internal
5181 } // namespace v8 5168 } // namespace v8
5182 5169
5183 #endif // V8_TARGET_ARCH_X64 5170 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698