OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/assembler_macros.h" | 9 #include "vm/assembler_macros.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
11 #include "vm/flow_graph_compiler.h" | 11 #include "vm/flow_graph_compiler.h" |
12 #include "vm/instructions.h" | |
12 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
13 #include "vm/pages.h" | 14 #include "vm/pages.h" |
14 #include "vm/resolver.h" | 15 #include "vm/resolver.h" |
15 #include "vm/scavenger.h" | 16 #include "vm/scavenger.h" |
16 #include "vm/stub_code.h" | 17 #include "vm/stub_code.h" |
17 | 18 |
18 | 19 |
19 #define __ assembler-> | 20 #define __ assembler-> |
20 | 21 |
21 namespace dart { | 22 namespace dart { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 __ ret(); | 475 __ ret(); |
475 } | 476 } |
476 | 477 |
477 | 478 |
478 DECLARE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame, | 479 DECLARE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame, |
479 intptr_t deopt_reason, | 480 intptr_t deopt_reason, |
480 uword saved_registers_address); | 481 uword saved_registers_address); |
481 | 482 |
482 DECLARE_LEAF_RUNTIME_ENTRY(void, DeoptimizeFillFrame, uword last_fp); | 483 DECLARE_LEAF_RUNTIME_ENTRY(void, DeoptimizeFillFrame, uword last_fp); |
483 | 484 |
485 | |
486 // Used by eager and lazy deoptimization. Preserve result in EAX if necessary. | |
484 // This stub translates optimized frame into unoptimized frame. The optimized | 487 // This stub translates optimized frame into unoptimized frame. The optimized |
485 // frame can contain values in registers and on stack, the unoptimized | 488 // frame can contain values in registers and on stack, the unoptimized |
486 // frame contains all values on stack. | 489 // frame contains all values on stack. |
487 // Deoptimization occurs in following steps: | 490 // Deoptimization occurs in following steps: |
488 // - Push all registers that can contain values. | 491 // - Push all registers that can contain values. |
489 // - Call C routine to copy the stack and saved registers into temporary buffer. | 492 // - Call C routine to copy the stack and saved registers into temporary buffer. |
490 // - Adjust caller's frame to correct unoptimized frame size. | 493 // - Adjust caller's frame to correct unoptimized frame size. |
491 // - Fill the unoptimized frame. | 494 // - Fill the unoptimized frame. |
492 // - Materialize objects that require allocation (e.g. Double instances). | 495 // - Materialize objects that require allocation (e.g. Double instances). |
493 // GC can occur only after frame is fully rewritten. | 496 // GC can occur only after frame is fully rewritten. |
494 // Stack: | 497 // Stack: |
495 // +------------------+ | 498 // +------------------+ |
496 // | 0 as PC marker | <- TOS | 499 // | Saved FP | <- TOS |
497 // +------------------+ | |
498 // | Saved FP | | |
499 // +------------------+ | 500 // +------------------+ |
500 // | return-address | (deoptimization point) | 501 // | return-address | (deoptimization point) |
501 // +------------------+ | 502 // +------------------+ |
502 // | optimized frame | | 503 // | optimized frame | |
503 // | ... | | 504 // | ... | |
504 // | 505 // |
505 void StubCode::GenerateDeoptimizeStub(Assembler* assembler) { | 506 // Parts of the code cannot GC, part of the code can GC. |
507 static void GenerateDeoptimizationSequence(Assembler* assembler, | |
508 bool preserve_eax) { | |
506 __ EnterFrame(0); | 509 __ EnterFrame(0); |
510 const intptr_t saved_eax_offset_from_ebp = -(kNumberOfCpuRegisters - EAX); | |
511 // Result in EAX is preserved as part of pushing all registers below. | |
512 | |
507 // Push registers in their enumeration order: lowest register number at | 513 // Push registers in their enumeration order: lowest register number at |
508 // lowest address. | 514 // lowest address. |
509 for (intptr_t i = kNumberOfCpuRegisters - 1; i >= 0; i--) { | 515 for (intptr_t i = kNumberOfCpuRegisters - 1; i >= 0; i--) { |
510 __ pushl(static_cast<Register>(i)); | 516 __ pushl(static_cast<Register>(i)); |
511 } | 517 } |
512 __ subl(ESP, Immediate(kNumberOfXmmRegisters * kDoubleSize)); | 518 __ subl(ESP, Immediate(kNumberOfXmmRegisters * kDoubleSize)); |
513 intptr_t offset = 0; | 519 intptr_t offset = 0; |
514 for (intptr_t reg_idx = 0; reg_idx < kNumberOfXmmRegisters; ++reg_idx) { | 520 for (intptr_t reg_idx = 0; reg_idx < kNumberOfXmmRegisters; ++reg_idx) { |
515 XmmRegister xmm_reg = static_cast<XmmRegister>(reg_idx); | 521 XmmRegister xmm_reg = static_cast<XmmRegister>(reg_idx); |
516 __ movsd(Address(ESP, offset), xmm_reg); | 522 __ movsd(Address(ESP, offset), xmm_reg); |
517 offset += kDoubleSize; | 523 offset += kDoubleSize; |
518 } | 524 } |
519 | 525 |
520 __ movl(ECX, ESP); // Saved saved registers block. | 526 __ movl(ECX, ESP); // Saved saved registers block. |
521 __ ReserveAlignedFrameSpace(1 * kWordSize); | 527 __ ReserveAlignedFrameSpace(1 * kWordSize); |
522 __ SmiUntag(EAX); | 528 __ SmiUntag(EAX); |
523 __ movl(Address(ESP, 0), ECX); // Start of register block. | 529 __ movl(Address(ESP, 0), ECX); // Start of register block. |
524 __ CallRuntime(kDeoptimizeCopyFrameRuntimeEntry); | 530 __ CallRuntime(kDeoptimizeCopyFrameRuntimeEntry); |
525 // Result (EAX) is stack-size (FP - SP) in bytes, incl. the return address. | 531 // Result (EAX) is stack-size (FP - SP) in bytes, incl. the return address. |
532 | |
533 if (preserve_eax) { | |
534 // Restore result into EBX temporarily. | |
535 __ movl(EBX, Address(EBP, saved_eax_offset_from_ebp * kWordSize)); | |
536 } | |
537 | |
526 __ LeaveFrame(); | 538 __ LeaveFrame(); |
527 __ popl(EDX); // Preserve return address. | 539 __ popl(EDX); // Preserve return address. |
528 __ movl(ESP, EBP); | 540 __ movl(ESP, EBP); |
529 __ subl(ESP, EAX); | 541 __ subl(ESP, EAX); |
530 __ movl(Address(ESP, 0), EDX); | 542 __ movl(Address(ESP, 0), EDX); |
531 | 543 |
532 __ EnterFrame(0); | 544 __ EnterFrame(0); |
533 __ movl(ECX, ESP); // Get last FP address. | 545 __ movl(ECX, ESP); // Get last FP address. |
546 if (preserve_eax) { | |
547 __ pushl(EBX); // Preserve result. | |
548 } | |
534 __ ReserveAlignedFrameSpace(1 * kWordSize); | 549 __ ReserveAlignedFrameSpace(1 * kWordSize); |
535 __ movl(Address(ESP, 0), ECX); | 550 __ movl(Address(ESP, 0), ECX); |
536 __ CallRuntime(kDeoptimizeFillFrameRuntimeEntry); | 551 __ CallRuntime(kDeoptimizeFillFrameRuntimeEntry); |
552 | |
553 if (preserve_eax) { | |
554 // Restore result into EAX. | |
555 __ movl(EAX, Address(EBP, -1 * kWordSize)); | |
556 } | |
537 __ LeaveFrame(); | 557 __ LeaveFrame(); |
siva
2012/09/07 23:16:17
Could you add a comment here or above stating that
srdjan
2012/09/12 06:15:26
Done.
| |
538 | 558 |
539 // Frame is fully rewritten at this point and it is safe to perform a GC. | 559 // Frame is fully rewritten at this point and it is safe to perform a GC. |
540 // Materialize any objects that were deferred by FillFrame because they | 560 // Materialize any objects that were deferred by FillFrame because they |
541 // require allocation. | 561 // require allocation. |
542 __ EnterFrame(0); | 562 __ EnterFrame(0); |
563 if (preserve_eax) { | |
564 __ pushl(EAX); // Preserve result, it will be GC-d here. | |
565 } | |
543 __ CallRuntime(kDeoptimizeMaterializeDoublesRuntimeEntry); | 566 __ CallRuntime(kDeoptimizeMaterializeDoublesRuntimeEntry); |
567 if (preserve_eax) { | |
568 __ popl(EAX); // Restore result. | |
569 } | |
544 __ LeaveFrame(); | 570 __ LeaveFrame(); |
545 __ ret(); | 571 __ ret(); |
546 } | 572 } |
547 | 573 |
574 // TOS: return address + call-instruction-size (5 bytes). | |
575 // EAX: result, must be preserved | |
576 void StubCode::GenerateDeoptimizeLazyStub(Assembler* assembler) { | |
577 // Correct return address to point just after the call that is being | |
578 // deoptimized. | |
579 __ popl(EBX); | |
580 __ subl(EBX, Immediate(CallPattern::InstructionLength())); | |
581 __ pushl(EBX); | |
582 GenerateDeoptimizationSequence(assembler, true); // Preserve EAX. | |
583 } | |
584 | |
585 | |
586 void StubCode::GenerateDeoptimizeStub(Assembler* assembler) { | |
587 GenerateDeoptimizationSequence(assembler, false); // Don't preserve EAX. | |
588 } | |
589 | |
548 | 590 |
549 // Called for inline allocation of arrays. | 591 // Called for inline allocation of arrays. |
550 // Input parameters: | 592 // Input parameters: |
551 // EDX : Array length as Smi. | 593 // EDX : Array length as Smi. |
552 // ECX : array element type (either NULL or an instantiated type). | 594 // ECX : array element type (either NULL or an instantiated type). |
553 // Uses EAX, EBX, ECX, EDI as temporary registers. | 595 // Uses EAX, EBX, ECX, EDI as temporary registers. |
554 // NOTE: EDX cannot be clobbered here as the caller relies on it being saved. | 596 // NOTE: EDX cannot be clobbered here as the caller relies on it being saved. |
555 // The newly allocated object is returned in EAX. | 597 // The newly allocated object is returned in EAX. |
556 void StubCode::GenerateAllocateArrayStub(Assembler* assembler) { | 598 void StubCode::GenerateAllocateArrayStub(Assembler* assembler) { |
557 Label slow_case; | 599 Label slow_case; |
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1904 __ movl(EAX, Address(ESP, 4 * kWordSize)); // Load error object. | 1946 __ movl(EAX, Address(ESP, 4 * kWordSize)); // Load error object. |
1905 __ movl(EBP, Address(ESP, 3 * kWordSize)); // Load target frame_pointer. | 1947 __ movl(EBP, Address(ESP, 3 * kWordSize)); // Load target frame_pointer. |
1906 __ movl(EBX, Address(ESP, 1 * kWordSize)); // Load target PC into EBX. | 1948 __ movl(EBX, Address(ESP, 1 * kWordSize)); // Load target PC into EBX. |
1907 __ movl(ESP, Address(ESP, 2 * kWordSize)); // Load target stack_pointer. | 1949 __ movl(ESP, Address(ESP, 2 * kWordSize)); // Load target stack_pointer. |
1908 __ jmp(EBX); // Jump to the exception handler code. | 1950 __ jmp(EBX); // Jump to the exception handler code. |
1909 } | 1951 } |
1910 | 1952 |
1911 } // namespace dart | 1953 } // namespace dart |
1912 | 1954 |
1913 #endif // defined TARGET_ARCH_IA32 | 1955 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |