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

Side by Side Diff: runtime/vm/stub_code_ia32.cc

Issue 10912146: Finish implementing lazy deoptimization (ia32, x64). Ran tests with --deoptimize-alot. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/stub_code.h ('k') | runtime/vm/stub_code_x64.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 (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
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 // The code in this frame may not cause GC. kDeoptimizeCopyFrameRuntimeEntry
511 // and kDeoptimizeFillFrameRuntimeEntry are leaf runtime calls.
512 const intptr_t saved_eax_offset_from_ebp = -(kNumberOfCpuRegisters - EAX);
513 // Result in EAX is preserved as part of pushing all registers below.
514
507 // Push registers in their enumeration order: lowest register number at 515 // Push registers in their enumeration order: lowest register number at
508 // lowest address. 516 // lowest address.
509 for (intptr_t i = kNumberOfCpuRegisters - 1; i >= 0; i--) { 517 for (intptr_t i = kNumberOfCpuRegisters - 1; i >= 0; i--) {
510 __ pushl(static_cast<Register>(i)); 518 __ pushl(static_cast<Register>(i));
511 } 519 }
512 __ subl(ESP, Immediate(kNumberOfXmmRegisters * kDoubleSize)); 520 __ subl(ESP, Immediate(kNumberOfXmmRegisters * kDoubleSize));
513 intptr_t offset = 0; 521 intptr_t offset = 0;
514 for (intptr_t reg_idx = 0; reg_idx < kNumberOfXmmRegisters; ++reg_idx) { 522 for (intptr_t reg_idx = 0; reg_idx < kNumberOfXmmRegisters; ++reg_idx) {
515 XmmRegister xmm_reg = static_cast<XmmRegister>(reg_idx); 523 XmmRegister xmm_reg = static_cast<XmmRegister>(reg_idx);
516 __ movsd(Address(ESP, offset), xmm_reg); 524 __ movsd(Address(ESP, offset), xmm_reg);
517 offset += kDoubleSize; 525 offset += kDoubleSize;
518 } 526 }
519 527
520 __ movl(ECX, ESP); // Saved saved registers block. 528 __ movl(ECX, ESP); // Saved saved registers block.
521 __ ReserveAlignedFrameSpace(1 * kWordSize); 529 __ ReserveAlignedFrameSpace(1 * kWordSize);
522 __ SmiUntag(EAX); 530 __ SmiUntag(EAX);
523 __ movl(Address(ESP, 0), ECX); // Start of register block. 531 __ movl(Address(ESP, 0), ECX); // Start of register block.
524 __ CallRuntime(kDeoptimizeCopyFrameRuntimeEntry); 532 __ CallRuntime(kDeoptimizeCopyFrameRuntimeEntry);
525 // Result (EAX) is stack-size (FP - SP) in bytes, incl. the return address. 533 // Result (EAX) is stack-size (FP - SP) in bytes, incl. the return address.
534
535 if (preserve_eax) {
536 // Restore result into EBX temporarily.
537 __ movl(EBX, Address(EBP, saved_eax_offset_from_ebp * kWordSize));
538 }
539
526 __ LeaveFrame(); 540 __ LeaveFrame();
527 __ popl(EDX); // Preserve return address. 541 __ popl(EDX); // Preserve return address.
528 __ movl(ESP, EBP); 542 __ movl(ESP, EBP);
529 __ subl(ESP, EAX); 543 __ subl(ESP, EAX);
530 __ movl(Address(ESP, 0), EDX); 544 __ movl(Address(ESP, 0), EDX);
531 545
532 __ EnterFrame(0); 546 __ EnterFrame(0);
533 __ movl(ECX, ESP); // Get last FP address. 547 __ movl(ECX, ESP); // Get last FP address.
548 if (preserve_eax) {
549 __ pushl(EBX); // Preserve result.
550 }
534 __ ReserveAlignedFrameSpace(1 * kWordSize); 551 __ ReserveAlignedFrameSpace(1 * kWordSize);
535 __ movl(Address(ESP, 0), ECX); 552 __ movl(Address(ESP, 0), ECX);
536 __ CallRuntime(kDeoptimizeFillFrameRuntimeEntry); 553 __ CallRuntime(kDeoptimizeFillFrameRuntimeEntry);
554
555 if (preserve_eax) {
556 // Restore result into EAX.
557 __ movl(EAX, Address(EBP, -1 * kWordSize));
558 }
559 // Code above cannot cause GC.
537 __ LeaveFrame(); 560 __ LeaveFrame();
538 561
539 // Frame is fully rewritten at this point and it is safe to perform a GC. 562 // 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 563 // Materialize any objects that were deferred by FillFrame because they
541 // require allocation. 564 // require allocation.
542 __ EnterFrame(0); 565 __ EnterFrame(0);
566 if (preserve_eax) {
567 __ pushl(EAX); // Preserve result, it will be GC-d here.
568 }
543 __ CallRuntime(kDeoptimizeMaterializeDoublesRuntimeEntry); 569 __ CallRuntime(kDeoptimizeMaterializeDoublesRuntimeEntry);
570 if (preserve_eax) {
571 __ popl(EAX); // Restore result.
572 }
544 __ LeaveFrame(); 573 __ LeaveFrame();
545 __ ret(); 574 __ ret();
546 } 575 }
547 576
577 // TOS: return address + call-instruction-size (5 bytes).
578 // EAX: result, must be preserved
579 void StubCode::GenerateDeoptimizeLazyStub(Assembler* assembler) {
580 // Correct return address to point just after the call that is being
581 // deoptimized.
582 __ popl(EBX);
583 __ subl(EBX, Immediate(CallPattern::InstructionLength()));
584 __ pushl(EBX);
585 GenerateDeoptimizationSequence(assembler, true); // Preserve EAX.
586 }
587
588
589 void StubCode::GenerateDeoptimizeStub(Assembler* assembler) {
590 GenerateDeoptimizationSequence(assembler, false); // Don't preserve EAX.
591 }
592
548 593
549 // Called for inline allocation of arrays. 594 // Called for inline allocation of arrays.
550 // Input parameters: 595 // Input parameters:
551 // EDX : Array length as Smi. 596 // EDX : Array length as Smi.
552 // ECX : array element type (either NULL or an instantiated type). 597 // ECX : array element type (either NULL or an instantiated type).
553 // Uses EAX, EBX, ECX, EDI as temporary registers. 598 // Uses EAX, EBX, ECX, EDI as temporary registers.
554 // NOTE: EDX cannot be clobbered here as the caller relies on it being saved. 599 // NOTE: EDX cannot be clobbered here as the caller relies on it being saved.
555 // The newly allocated object is returned in EAX. 600 // The newly allocated object is returned in EAX.
556 void StubCode::GenerateAllocateArrayStub(Assembler* assembler) { 601 void StubCode::GenerateAllocateArrayStub(Assembler* assembler) {
557 Label slow_case; 602 Label slow_case;
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 __ movl(EAX, Address(ESP, 4 * kWordSize)); // Load error object. 1949 __ movl(EAX, Address(ESP, 4 * kWordSize)); // Load error object.
1905 __ movl(EBP, Address(ESP, 3 * kWordSize)); // Load target frame_pointer. 1950 __ movl(EBP, Address(ESP, 3 * kWordSize)); // Load target frame_pointer.
1906 __ movl(EBX, Address(ESP, 1 * kWordSize)); // Load target PC into EBX. 1951 __ movl(EBX, Address(ESP, 1 * kWordSize)); // Load target PC into EBX.
1907 __ movl(ESP, Address(ESP, 2 * kWordSize)); // Load target stack_pointer. 1952 __ movl(ESP, Address(ESP, 2 * kWordSize)); // Load target stack_pointer.
1908 __ jmp(EBX); // Jump to the exception handler code. 1953 __ jmp(EBX); // Jump to the exception handler code.
1909 } 1954 }
1910 1955
1911 } // namespace dart 1956 } // namespace dart
1912 1957
1913 #endif // defined TARGET_ARCH_IA32 1958 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/stub_code.h ('k') | runtime/vm/stub_code_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698