| OLD | NEW |
| 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 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_ARM | 7 #if V8_TARGET_ARCH_ARM |
| 8 | 8 |
| 9 #include "codegen.h" | 9 #include "codegen.h" |
| 10 #include "debug.h" | 10 #include "debug.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 CallRuntimePassFunction(masm, Runtime::kHiddenTryInstallOptimizedCode); | 306 CallRuntimePassFunction(masm, Runtime::kHiddenTryInstallOptimizedCode); |
| 307 GenerateTailCallToReturnedCode(masm); | 307 GenerateTailCallToReturnedCode(masm); |
| 308 | 308 |
| 309 __ bind(&ok); | 309 __ bind(&ok); |
| 310 GenerateTailCallToSharedCode(masm); | 310 GenerateTailCallToSharedCode(masm); |
| 311 } | 311 } |
| 312 | 312 |
| 313 | 313 |
| 314 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 314 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 315 bool is_api_function, | 315 bool is_api_function, |
| 316 bool count_constructions, |
| 316 bool create_memento) { | 317 bool create_memento) { |
| 317 // ----------- S t a t e ------------- | 318 // ----------- S t a t e ------------- |
| 318 // -- r0 : number of arguments | 319 // -- r0 : number of arguments |
| 319 // -- r1 : constructor function | 320 // -- r1 : constructor function |
| 320 // -- r2 : allocation site or undefined | 321 // -- r2 : allocation site or undefined |
| 321 // -- lr : return address | 322 // -- lr : return address |
| 322 // -- sp[...]: constructor arguments | 323 // -- sp[...]: constructor arguments |
| 323 // ----------------------------------- | 324 // ----------------------------------- |
| 324 | 325 |
| 326 // Should never count constructions for api objects. |
| 327 ASSERT(!is_api_function || !count_constructions); |
| 328 |
| 325 // Should never create mementos for api functions. | 329 // Should never create mementos for api functions. |
| 326 ASSERT(!is_api_function || !create_memento); | 330 ASSERT(!is_api_function || !create_memento); |
| 327 | 331 |
| 332 // Should never create mementos before slack tracking is finished. |
| 333 ASSERT(!count_constructions || !create_memento); |
| 334 |
| 328 Isolate* isolate = masm->isolate(); | 335 Isolate* isolate = masm->isolate(); |
| 329 | 336 |
| 330 // Enter a construct frame. | 337 // Enter a construct frame. |
| 331 { | 338 { |
| 332 FrameAndConstantPoolScope scope(masm, StackFrame::CONSTRUCT); | 339 FrameAndConstantPoolScope scope(masm, StackFrame::CONSTRUCT); |
| 333 | 340 |
| 334 if (create_memento) { | 341 if (create_memento) { |
| 335 __ AssertUndefinedOrAllocationSite(r2, r3); | 342 __ AssertUndefinedOrAllocationSite(r2, r3); |
| 336 __ push(r2); | 343 __ push(r2); |
| 337 } | 344 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 361 __ b(ne, &rt_call); | 368 __ b(ne, &rt_call); |
| 362 | 369 |
| 363 // Check that the constructor is not constructing a JSFunction (see | 370 // Check that the constructor is not constructing a JSFunction (see |
| 364 // comments in Runtime_NewObject in runtime.cc). In which case the | 371 // comments in Runtime_NewObject in runtime.cc). In which case the |
| 365 // initial map's instance type would be JS_FUNCTION_TYPE. | 372 // initial map's instance type would be JS_FUNCTION_TYPE. |
| 366 // r1: constructor function | 373 // r1: constructor function |
| 367 // r2: initial map | 374 // r2: initial map |
| 368 __ CompareInstanceType(r2, r3, JS_FUNCTION_TYPE); | 375 __ CompareInstanceType(r2, r3, JS_FUNCTION_TYPE); |
| 369 __ b(eq, &rt_call); | 376 __ b(eq, &rt_call); |
| 370 | 377 |
| 371 if (!is_api_function) { | 378 if (count_constructions) { |
| 372 Label allocate; | 379 Label allocate; |
| 373 MemOperand bit_field3 = FieldMemOperand(r2, Map::kBitField3Offset); | |
| 374 // Check if slack tracking is enabled. | |
| 375 __ ldr(r4, bit_field3); | |
| 376 __ DecodeField<Map::ConstructionCount>(r3, r4); | |
| 377 __ cmp(r3, Operand(JSFunction::kNoSlackTracking)); | |
| 378 __ b(eq, &allocate); | |
| 379 // Decrease generous allocation count. | 380 // Decrease generous allocation count. |
| 380 __ sub(r4, r4, Operand(1 << Map::ConstructionCount::kShift)); | 381 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 381 __ str(r4, bit_field3); | 382 MemOperand constructor_count = |
| 382 __ cmp(r3, Operand(JSFunction::kFinishSlackTracking)); | 383 FieldMemOperand(r3, SharedFunctionInfo::kConstructionCountOffset); |
| 384 __ ldrb(r4, constructor_count); |
| 385 __ sub(r4, r4, Operand(1), SetCC); |
| 386 __ strb(r4, constructor_count); |
| 383 __ b(ne, &allocate); | 387 __ b(ne, &allocate); |
| 384 | 388 |
| 385 __ push(r1); | 389 __ push(r1); |
| 386 | 390 |
| 387 __ Push(r2, r1); // r1 = constructor | 391 __ Push(r2, r1); // r1 = constructor |
| 392 // The call will replace the stub, so the countdown is only done once. |
| 388 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); | 393 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); |
| 389 | 394 |
| 390 __ pop(r2); | 395 __ pop(r2); |
| 391 __ pop(r1); | 396 __ pop(r1); |
| 392 | 397 |
| 393 __ bind(&allocate); | 398 __ bind(&allocate); |
| 394 } | 399 } |
| 395 | 400 |
| 396 // Now allocate the JSObject on the heap. | 401 // Now allocate the JSObject on the heap. |
| 397 // r1: constructor function | 402 // r1: constructor function |
| (...skipping 20 matching lines...) Expand all Loading... |
| 418 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); | 423 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); |
| 419 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | 424 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 420 | 425 |
| 421 // Fill all the in-object properties with the appropriate filler. | 426 // Fill all the in-object properties with the appropriate filler. |
| 422 // r1: constructor function | 427 // r1: constructor function |
| 423 // r2: initial map | 428 // r2: initial map |
| 424 // r3: object size (in words, including memento if create_memento) | 429 // r3: object size (in words, including memento if create_memento) |
| 425 // r4: JSObject (not tagged) | 430 // r4: JSObject (not tagged) |
| 426 // r5: First in-object property of JSObject (not tagged) | 431 // r5: First in-object property of JSObject (not tagged) |
| 427 ASSERT_EQ(3 * kPointerSize, JSObject::kHeaderSize); | 432 ASSERT_EQ(3 * kPointerSize, JSObject::kHeaderSize); |
| 428 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex); | |
| 429 | 433 |
| 430 if (!is_api_function) { | 434 if (count_constructions) { |
| 431 Label no_inobject_slack_tracking; | 435 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex); |
| 432 | |
| 433 // Check if slack tracking is enabled. | |
| 434 __ ldr(ip, FieldMemOperand(r2, Map::kBitField3Offset)); | |
| 435 __ DecodeField<Map::ConstructionCount>(ip); | |
| 436 __ cmp(ip, Operand(JSFunction::kNoSlackTracking)); | |
| 437 __ b(eq, &no_inobject_slack_tracking); | |
| 438 | |
| 439 // Allocate object with a slack. | |
| 440 __ ldr(r0, FieldMemOperand(r2, Map::kInstanceSizesOffset)); | 436 __ ldr(r0, FieldMemOperand(r2, Map::kInstanceSizesOffset)); |
| 441 __ Ubfx(r0, r0, Map::kPreAllocatedPropertyFieldsByte * kBitsPerByte, | 437 __ Ubfx(r0, r0, Map::kPreAllocatedPropertyFieldsByte * kBitsPerByte, |
| 442 kBitsPerByte); | 438 kBitsPerByte); |
| 443 __ add(r0, r5, Operand(r0, LSL, kPointerSizeLog2)); | 439 __ add(r0, r5, Operand(r0, LSL, kPointerSizeLog2)); |
| 444 // r0: offset of first field after pre-allocated fields | 440 // r0: offset of first field after pre-allocated fields |
| 445 if (FLAG_debug_code) { | 441 if (FLAG_debug_code) { |
| 446 __ add(ip, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. | 442 __ add(ip, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. |
| 447 __ cmp(r0, ip); | 443 __ cmp(r0, ip); |
| 448 __ Assert(le, kUnexpectedNumberOfPreAllocatedPropertyFields); | 444 __ Assert(le, kUnexpectedNumberOfPreAllocatedPropertyFields); |
| 449 } | 445 } |
| 450 __ InitializeFieldsWithFiller(r5, r0, r6); | 446 __ InitializeFieldsWithFiller(r5, r0, r6); |
| 451 // To allow for truncation. | 447 // To allow for truncation. |
| 452 __ LoadRoot(r6, Heap::kOnePointerFillerMapRootIndex); | 448 __ LoadRoot(r6, Heap::kOnePointerFillerMapRootIndex); |
| 453 // Fill the remaining fields with one pointer filler map. | 449 __ add(r0, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. |
| 454 | 450 __ InitializeFieldsWithFiller(r5, r0, r6); |
| 455 __ bind(&no_inobject_slack_tracking); | 451 } else if (create_memento) { |
| 456 } | 452 __ sub(r6, r3, Operand(AllocationMemento::kSize / kPointerSize)); |
| 457 | 453 __ add(r0, r4, Operand(r6, LSL, kPointerSizeLog2)); // End of object. |
| 458 if (create_memento) { | 454 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex); |
| 459 __ sub(ip, r3, Operand(AllocationMemento::kSize / kPointerSize)); | |
| 460 __ add(r0, r4, Operand(ip, LSL, kPointerSizeLog2)); // End of object. | |
| 461 __ InitializeFieldsWithFiller(r5, r0, r6); | 455 __ InitializeFieldsWithFiller(r5, r0, r6); |
| 462 | 456 |
| 463 // Fill in memento fields. | 457 // Fill in memento fields. |
| 464 // r5: points to the allocated but uninitialized memento. | 458 // r5: points to the allocated but uninitialized memento. |
| 465 __ LoadRoot(r6, Heap::kAllocationMementoMapRootIndex); | 459 __ LoadRoot(r6, Heap::kAllocationMementoMapRootIndex); |
| 466 ASSERT_EQ(0 * kPointerSize, AllocationMemento::kMapOffset); | 460 ASSERT_EQ(0 * kPointerSize, AllocationMemento::kMapOffset); |
| 467 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | 461 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 468 // Load the AllocationSite | 462 // Load the AllocationSite |
| 469 __ ldr(r6, MemOperand(sp, 2 * kPointerSize)); | 463 __ ldr(r6, MemOperand(sp, 2 * kPointerSize)); |
| 470 ASSERT_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); | 464 ASSERT_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); |
| 471 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | 465 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); |
| 472 } else { | 466 } else { |
| 467 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex); |
| 473 __ add(r0, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. | 468 __ add(r0, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. |
| 474 __ InitializeFieldsWithFiller(r5, r0, r6); | 469 __ InitializeFieldsWithFiller(r5, r0, r6); |
| 475 } | 470 } |
| 476 | 471 |
| 477 // Add the object tag to make the JSObject real, so that we can continue | 472 // Add the object tag to make the JSObject real, so that we can continue |
| 478 // and jump into the continuation code at any time from now on. Any | 473 // and jump into the continuation code at any time from now on. Any |
| 479 // failures need to undo the allocation, so that the heap is in a | 474 // failures need to undo the allocation, so that the heap is in a |
| 480 // consistent state and verifiable. | 475 // consistent state and verifiable. |
| 481 __ add(r4, r4, Operand(kHeapObjectTag)); | 476 __ add(r4, r4, Operand(kHeapObjectTag)); |
| 482 | 477 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); | 648 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 654 Handle<Code> code = | 649 Handle<Code> code = |
| 655 masm->isolate()->builtins()->HandleApiCallConstruct(); | 650 masm->isolate()->builtins()->HandleApiCallConstruct(); |
| 656 __ Call(code, RelocInfo::CODE_TARGET); | 651 __ Call(code, RelocInfo::CODE_TARGET); |
| 657 } else { | 652 } else { |
| 658 ParameterCount actual(r0); | 653 ParameterCount actual(r0); |
| 659 __ InvokeFunction(r1, actual, CALL_FUNCTION, NullCallWrapper()); | 654 __ InvokeFunction(r1, actual, CALL_FUNCTION, NullCallWrapper()); |
| 660 } | 655 } |
| 661 | 656 |
| 662 // Store offset of return address for deoptimizer. | 657 // Store offset of return address for deoptimizer. |
| 663 if (!is_api_function) { | 658 if (!is_api_function && !count_constructions) { |
| 664 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); | 659 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
| 665 } | 660 } |
| 666 | 661 |
| 667 // Restore context from the frame. | 662 // Restore context from the frame. |
| 668 // r0: result | 663 // r0: result |
| 669 // sp[0]: receiver | 664 // sp[0]: receiver |
| 670 // sp[1]: constructor function | 665 // sp[1]: constructor function |
| 671 // sp[2]: number of arguments (smi-tagged) | 666 // sp[2]: number of arguments (smi-tagged) |
| 672 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); | 667 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 673 | 668 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 // Leave construct frame. | 700 // Leave construct frame. |
| 706 } | 701 } |
| 707 | 702 |
| 708 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); | 703 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); |
| 709 __ add(sp, sp, Operand(kPointerSize)); | 704 __ add(sp, sp, Operand(kPointerSize)); |
| 710 __ IncrementCounter(isolate->counters()->constructed_objects(), 1, r1, r2); | 705 __ IncrementCounter(isolate->counters()->constructed_objects(), 1, r1, r2); |
| 711 __ Jump(lr); | 706 __ Jump(lr); |
| 712 } | 707 } |
| 713 | 708 |
| 714 | 709 |
| 710 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { |
| 711 Generate_JSConstructStubHelper(masm, false, true, false); |
| 712 } |
| 713 |
| 714 |
| 715 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 715 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
| 716 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); | 716 Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new); |
| 717 } | 717 } |
| 718 | 718 |
| 719 | 719 |
| 720 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 720 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
| 721 Generate_JSConstructStubHelper(masm, true, false); | 721 Generate_JSConstructStubHelper(masm, true, false, false); |
| 722 } | 722 } |
| 723 | 723 |
| 724 | 724 |
| 725 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 725 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
| 726 bool is_construct) { | 726 bool is_construct) { |
| 727 // Called from Generate_JS_Entry | 727 // Called from Generate_JS_Entry |
| 728 // r0: code entry | 728 // r0: code entry |
| 729 // r1: function | 729 // r1: function |
| 730 // r2: receiver | 730 // r2: receiver |
| 731 // r3: argc | 731 // r3: argc |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 __ bkpt(0); | 1551 __ bkpt(0); |
| 1552 } | 1552 } |
| 1553 } | 1553 } |
| 1554 | 1554 |
| 1555 | 1555 |
| 1556 #undef __ | 1556 #undef __ |
| 1557 | 1557 |
| 1558 } } // namespace v8::internal | 1558 } } // namespace v8::internal |
| 1559 | 1559 |
| 1560 #endif // V8_TARGET_ARCH_ARM | 1560 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |