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

Side by Side Diff: src/mips/builtins-mips.cc

Issue 1227163011: Cleanup Generate_JSConstructStubHelper a bit. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comment typo. Created 5 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 | « src/ia32/builtins-ia32.cc ('k') | src/mips64/builtins-mips64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 5
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #if V8_TARGET_ARCH_MIPS 9 #if V8_TARGET_ARCH_MIPS
10 10
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 __ Branch(&ok, hs, sp, Operand(t0)); 309 __ Branch(&ok, hs, sp, Operand(t0));
310 310
311 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); 311 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode);
312 GenerateTailCallToReturnedCode(masm); 312 GenerateTailCallToReturnedCode(masm);
313 313
314 __ bind(&ok); 314 __ bind(&ok);
315 GenerateTailCallToSharedCode(masm); 315 GenerateTailCallToSharedCode(masm);
316 } 316 }
317 317
318 318
319 static void Generate_Runtime_NewObject(MacroAssembler* masm,
320 bool create_memento,
321 Register original_constructor,
322 Label* count_incremented,
323 Label* allocated) {
324 if (create_memento) {
325 // Get the cell or allocation site.
326 __ lw(a2, MemOperand(sp, 3 * kPointerSize));
327 __ push(a2);
328 }
329
330 __ push(a1); // argument for Runtime_NewObject
331 __ push(original_constructor); // original constructor
332 if (create_memento) {
333 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3);
334 } else {
335 __ CallRuntime(Runtime::kNewObject, 2);
336 }
337 __ mov(t4, v0);
338
339 // Runtime_NewObjectWithAllocationSite increments allocation count.
340 // Skip the increment.
341 if (create_memento) {
342 __ jmp(count_incremented);
343 } else {
344 __ jmp(allocated);
345 }
346 }
347
348
349 static void Generate_JSConstructStubHelper(MacroAssembler* masm, 319 static void Generate_JSConstructStubHelper(MacroAssembler* masm,
350 bool is_api_function, 320 bool is_api_function,
351 bool create_memento) { 321 bool create_memento) {
352 // ----------- S t a t e ------------- 322 // ----------- S t a t e -------------
353 // -- a0 : number of arguments 323 // -- a0 : number of arguments
354 // -- a1 : constructor function 324 // -- a1 : constructor function
355 // -- a2 : allocation site or undefined 325 // -- a2 : allocation site or undefined
356 // -- a3 : original constructor 326 // -- a3 : original constructor
357 // -- ra : return address 327 // -- ra : return address
358 // -- sp[...]: constructor arguments 328 // -- sp[...]: constructor arguments
359 // ----------------------------------- 329 // -----------------------------------
360 330
361 // Should never create mementos for api functions. 331 // Should never create mementos for api functions.
362 DCHECK(!is_api_function || !create_memento); 332 DCHECK(!is_api_function || !create_memento);
363 333
364 Isolate* isolate = masm->isolate(); 334 Isolate* isolate = masm->isolate();
365 335
366 // ----------- S t a t e -------------
367 // -- a0 : number of arguments
368 // -- a1 : constructor function
369 // -- ra : return address
370 // -- sp[...]: constructor arguments
371 // -----------------------------------
372
373 // Enter a construct frame. 336 // Enter a construct frame.
374 { 337 {
375 FrameScope scope(masm, StackFrame::CONSTRUCT); 338 FrameScope scope(masm, StackFrame::CONSTRUCT);
376 339
377 if (create_memento) { 340 if (create_memento) {
378 __ AssertUndefinedOrAllocationSite(a2, t0); 341 __ AssertUndefinedOrAllocationSite(a2, t0);
379 __ push(a2); 342 __ push(a2);
380 } 343 }
381 344
382 // Preserve the incoming parameters on the stack. 345 // Preserve the incoming parameters on the stack.
383 __ SmiTag(a0); 346 __ SmiTag(a0);
384 __ Push(a0, a1, a3); 347 __ Push(a0, a1, a3);
385 348
386 Label rt_call, allocated, normal_new, count_incremented;
387 __ Branch(&normal_new, eq, a1, Operand(a3));
388
389 // Original constructor and function are different.
390 Generate_Runtime_NewObject(masm, create_memento, a3, &count_incremented,
391 &allocated);
392 __ bind(&normal_new);
393
394 // Try to allocate the object without transitioning into C code. If any of 349 // Try to allocate the object without transitioning into C code. If any of
395 // the preconditions is not met, the code bails out to the runtime call. 350 // the preconditions is not met, the code bails out to the runtime call.
351 Label rt_call, allocated;
396 if (FLAG_inline_new) { 352 if (FLAG_inline_new) {
397 ExternalReference debug_step_in_fp = 353 ExternalReference debug_step_in_fp =
398 ExternalReference::debug_step_in_fp_address(isolate); 354 ExternalReference::debug_step_in_fp_address(isolate);
399 __ li(a2, Operand(debug_step_in_fp)); 355 __ li(a2, Operand(debug_step_in_fp));
400 __ lw(a2, MemOperand(a2)); 356 __ lw(a2, MemOperand(a2));
401 __ Branch(&rt_call, ne, a2, Operand(zero_reg)); 357 __ Branch(&rt_call, ne, a2, Operand(zero_reg));
402 358
359 // Fall back to runtime if the original constructor and function differ.
360 __ Branch(&rt_call, ne, a1, Operand(a3));
361
403 // Load the initial map and verify that it is in fact a map. 362 // Load the initial map and verify that it is in fact a map.
404 // a1: constructor function 363 // a1: constructor function
405 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); 364 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
406 __ JumpIfSmi(a2, &rt_call); 365 __ JumpIfSmi(a2, &rt_call);
407 __ GetObjectType(a2, a3, t4); 366 __ GetObjectType(a2, t5, t4);
408 __ Branch(&rt_call, ne, t4, Operand(MAP_TYPE)); 367 __ Branch(&rt_call, ne, t4, Operand(MAP_TYPE));
409 368
410 // Check that the constructor is not constructing a JSFunction (see 369 // Check that the constructor is not constructing a JSFunction (see
411 // comments in Runtime_NewObject in runtime.cc). In which case the 370 // comments in Runtime_NewObject in runtime.cc). In which case the
412 // initial map's instance type would be JS_FUNCTION_TYPE. 371 // initial map's instance type would be JS_FUNCTION_TYPE.
413 // a1: constructor function 372 // a1: constructor function
414 // a2: initial map 373 // a2: initial map
415 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset)); 374 __ lbu(t5, FieldMemOperand(a2, Map::kInstanceTypeOffset));
416 __ Branch(&rt_call, eq, a3, Operand(JS_FUNCTION_TYPE)); 375 __ Branch(&rt_call, eq, t5, Operand(JS_FUNCTION_TYPE));
417 376
418 if (!is_api_function) { 377 if (!is_api_function) {
419 Label allocate; 378 Label allocate;
420 MemOperand bit_field3 = FieldMemOperand(a2, Map::kBitField3Offset); 379 MemOperand bit_field3 = FieldMemOperand(a2, Map::kBitField3Offset);
421 // Check if slack tracking is enabled. 380 // Check if slack tracking is enabled.
422 __ lw(t0, bit_field3); 381 __ lw(t0, bit_field3);
423 __ DecodeField<Map::Counter>(t2, t0); 382 __ DecodeField<Map::Counter>(t2, t0);
424 __ Branch(&allocate, lt, t2, Operand(Map::kSlackTrackingCounterEnd)); 383 __ Branch(&allocate, lt, t2, Operand(Map::kSlackTrackingCounterEnd));
425 // Decrease generous allocation count. 384 // Decrease generous allocation count.
426 __ Subu(t0, t0, Operand(1 << Map::Counter::kShift)); 385 __ Subu(t0, t0, Operand(1 << Map::Counter::kShift));
427 __ Branch(USE_DELAY_SLOT, &allocate, ne, t2, 386 __ Branch(USE_DELAY_SLOT, &allocate, ne, t2,
428 Operand(Map::kSlackTrackingCounterEnd)); 387 Operand(Map::kSlackTrackingCounterEnd));
429 __ sw(t0, bit_field3); // In delay slot. 388 __ sw(t0, bit_field3); // In delay slot.
430 389
431 __ Push(a1, a2, a1); // a1 = Constructor. 390 __ Push(a1, a2, a1); // a1 = Constructor.
432 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); 391 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
433 392
434 __ Pop(a1, a2); 393 __ Pop(a1, a2);
435 __ li(t2, Operand(Map::kSlackTrackingCounterEnd - 1)); 394 __ li(t2, Operand(Map::kSlackTrackingCounterEnd - 1));
436 395
437 __ bind(&allocate); 396 __ bind(&allocate);
438 } 397 }
439 398
440 // Now allocate the JSObject on the heap. 399 // Now allocate the JSObject on the heap.
441 // a1: constructor function 400 // a1: constructor function
442 // a2: initial map 401 // a2: initial map
402 Label rt_call_reload_new_target;
443 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset)); 403 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset));
444 if (create_memento) { 404 if (create_memento) {
445 __ Addu(a3, a3, Operand(AllocationMemento::kSize / kPointerSize)); 405 __ Addu(a3, a3, Operand(AllocationMemento::kSize / kPointerSize));
446 } 406 }
447 407
448 __ Allocate(a3, t4, t5, t6, &rt_call, SIZE_IN_WORDS); 408 __ Allocate(a3, t4, t5, t6, &rt_call_reload_new_target, SIZE_IN_WORDS);
449 409
450 // Allocated the JSObject, now initialize the fields. Map is set to 410 // Allocated the JSObject, now initialize the fields. Map is set to
451 // initial map and properties and elements are set to empty fixed array. 411 // initial map and properties and elements are set to empty fixed array.
452 // a1: constructor function 412 // a1: constructor function
453 // a2: initial map 413 // a2: initial map
454 // a3: object size (including memento if create_memento) 414 // a3: object size (including memento if create_memento)
455 // t4: JSObject (not tagged) 415 // t4: JSObject (not tagged)
456 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex); 416 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
457 __ mov(t5, t4); 417 __ mov(t5, t4);
458 __ sw(a2, MemOperand(t5, JSObject::kMapOffset)); 418 __ sw(a2, MemOperand(t5, JSObject::kMapOffset));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 __ InitializeFieldsWithFiller(t5, a0, t7); 486 __ InitializeFieldsWithFiller(t5, a0, t7);
527 } 487 }
528 488
529 // Add the object tag to make the JSObject real, so that we can continue 489 // Add the object tag to make the JSObject real, so that we can continue
530 // and jump into the continuation code at any time from now on. 490 // and jump into the continuation code at any time from now on.
531 __ Addu(t4, t4, Operand(kHeapObjectTag)); 491 __ Addu(t4, t4, Operand(kHeapObjectTag));
532 492
533 // Continue with JSObject being successfully allocated. 493 // Continue with JSObject being successfully allocated.
534 // t4: JSObject 494 // t4: JSObject
535 __ jmp(&allocated); 495 __ jmp(&allocated);
496
497 // Reload the original constructor and fall-through.
498 __ bind(&rt_call_reload_new_target);
499 __ lw(a3, MemOperand(sp, 0 * kPointerSize));
536 } 500 }
537 501
538 // Allocate the new receiver object using the runtime call. 502 // Allocate the new receiver object using the runtime call.
539 // a1: constructor function 503 // a1: constructor function
504 // a3: original constructor
540 __ bind(&rt_call); 505 __ bind(&rt_call);
541 Generate_Runtime_NewObject(masm, create_memento, a1, &count_incremented, 506 if (create_memento) {
542 &allocated); 507 // Get the cell or allocation site.
508 __ lw(a2, MemOperand(sp, 3 * kPointerSize));
509 __ push(a2); // argument 1: allocation site
510 }
511
512 __ Push(a1, a3); // arguments 2-3 / 1-2
513 if (create_memento) {
514 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3);
515 } else {
516 __ CallRuntime(Runtime::kNewObject, 2);
517 }
518 __ mov(t4, v0);
519
520 // Runtime_NewObjectWithAllocationSite increments allocation count.
521 // Skip the increment.
522 Label count_incremented;
523 if (create_memento) {
524 __ jmp(&count_incremented);
525 }
543 526
544 // Receiver for constructor call allocated. 527 // Receiver for constructor call allocated.
545 // t4: JSObject 528 // t4: JSObject
546 __ bind(&allocated); 529 __ bind(&allocated);
547 530
548 if (create_memento) { 531 if (create_memento) {
549 __ lw(a2, MemOperand(sp, 3 * kPointerSize)); 532 __ lw(a2, MemOperand(sp, 3 * kPointerSize));
550 __ LoadRoot(t5, Heap::kUndefinedValueRootIndex); 533 __ LoadRoot(t5, Heap::kUndefinedValueRootIndex);
551 __ Branch(&count_incremented, eq, a2, Operand(t5)); 534 __ Branch(&count_incremented, eq, a2, Operand(t5));
552 // a2 is an AllocationSite. We are creating a memento from it, so we 535 // a2 is an AllocationSite. We are creating a memento from it, so we
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 } 1737 }
1755 } 1738 }
1756 1739
1757 1740
1758 #undef __ 1741 #undef __
1759 1742
1760 } // namespace internal 1743 } // namespace internal
1761 } // namespace v8 1744 } // namespace v8
1762 1745
1763 #endif // V8_TARGET_ARCH_MIPS 1746 #endif // V8_TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « src/ia32/builtins-ia32.cc ('k') | src/mips64/builtins-mips64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698