| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 414 |
| 415 // --------------------------------------------------------------------------- | 415 // --------------------------------------------------------------------------- |
| 416 // Runtime calls | 416 // Runtime calls |
| 417 | 417 |
| 418 // Call a code stub. Generate the code if necessary. | 418 // Call a code stub. Generate the code if necessary. |
| 419 void CallStub(CodeStub* stub); | 419 void CallStub(CodeStub* stub); |
| 420 | 420 |
| 421 // Call a code stub and return the code object called. Try to generate | 421 // Call a code stub and return the code object called. Try to generate |
| 422 // the code if necessary. Do not perform a GC but instead return a retry | 422 // the code if necessary. Do not perform a GC but instead return a retry |
| 423 // after GC failure. | 423 // after GC failure. |
| 424 Object* TryCallStub(CodeStub* stub); | 424 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub); |
| 425 | 425 |
| 426 // Tail call a code stub (jump). Generate the code if necessary. | 426 // Tail call a code stub (jump). Generate the code if necessary. |
| 427 void TailCallStub(CodeStub* stub); | 427 void TailCallStub(CodeStub* stub); |
| 428 | 428 |
| 429 // Tail call a code stub (jump) and return the code object called. Try to | 429 // Tail call a code stub (jump) and return the code object called. Try to |
| 430 // generate the code if necessary. Do not perform a GC but instead return | 430 // generate the code if necessary. Do not perform a GC but instead return |
| 431 // a retry after GC failure. | 431 // a retry after GC failure. |
| 432 Object* TryTailCallStub(CodeStub* stub); | 432 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub); |
| 433 | 433 |
| 434 // Return from a code stub after popping its arguments. | 434 // Return from a code stub after popping its arguments. |
| 435 void StubReturn(int argc); | 435 void StubReturn(int argc); |
| 436 | 436 |
| 437 // Call a runtime routine. | 437 // Call a runtime routine. |
| 438 void CallRuntime(Runtime::Function* f, int num_arguments); | 438 void CallRuntime(Runtime::Function* f, int num_arguments); |
| 439 | 439 |
| 440 // Call a runtime function, returning the CodeStub object called. | 440 // Call a runtime function, returning the CodeStub object called. |
| 441 // Try to generate the stub code if necessary. Do not perform a GC | 441 // Try to generate the stub code if necessary. Do not perform a GC |
| 442 // but instead return a retry after GC failure. | 442 // but instead return a retry after GC failure. |
| 443 Object* TryCallRuntime(Runtime::Function* f, int num_arguments); | 443 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::Function* f, |
| 444 int num_arguments); |
| 444 | 445 |
| 445 // Convenience function: Same as above, but takes the fid instead. | 446 // Convenience function: Same as above, but takes the fid instead. |
| 446 void CallRuntime(Runtime::FunctionId id, int num_arguments); | 447 void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 447 | 448 |
| 448 // Convenience function: Same as above, but takes the fid instead. | 449 // Convenience function: Same as above, but takes the fid instead. |
| 449 Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments); | 450 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id, |
| 451 int num_arguments); |
| 450 | 452 |
| 451 // Convenience function: call an external reference. | 453 // Convenience function: call an external reference. |
| 452 void CallExternalReference(ExternalReference ref, int num_arguments); | 454 void CallExternalReference(ExternalReference ref, int num_arguments); |
| 453 | 455 |
| 454 // Tail call of a runtime routine (jump). | 456 // Tail call of a runtime routine (jump). |
| 455 // Like JumpToExternalReference, but also takes care of passing the number | 457 // Like JumpToExternalReference, but also takes care of passing the number |
| 456 // of parameters. | 458 // of parameters. |
| 457 void TailCallExternalReference(const ExternalReference& ext, | 459 void TailCallExternalReference(const ExternalReference& ext, |
| 458 int num_arguments, | 460 int num_arguments, |
| 459 int result_size); | 461 int result_size); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 473 void PrepareCallCFunction(int num_arguments, Register scratch); | 475 void PrepareCallCFunction(int num_arguments, Register scratch); |
| 474 | 476 |
| 475 // Calls a C function and cleans up the space for arguments allocated | 477 // Calls a C function and cleans up the space for arguments allocated |
| 476 // by PrepareCallCFunction. The called function is not allowed to trigger a | 478 // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 477 // garbage collection, since that might move the code and invalidate the | 479 // garbage collection, since that might move the code and invalidate the |
| 478 // return address (unless this is somehow accounted for by the called | 480 // return address (unless this is somehow accounted for by the called |
| 479 // function). | 481 // function). |
| 480 void CallCFunction(ExternalReference function, int num_arguments); | 482 void CallCFunction(ExternalReference function, int num_arguments); |
| 481 void CallCFunction(Register function, int num_arguments); | 483 void CallCFunction(Register function, int num_arguments); |
| 482 | 484 |
| 483 void PushHandleScope(Register scratch); | 485 // Prepares stack to put arguments (aligns and so on). Reserves |
| 486 // space for return value if needed (assumes the return value is a handle). |
| 487 // Uses callee-saved esi to restore stack state after call. Arguments must be |
| 488 // stored in ApiParameterOperand(0), ApiParameterOperand(1) etc. |
| 489 void PrepareCallApiFunction(int stack_space, int argc); |
| 484 | 490 |
| 485 // Pops a handle scope using the specified scratch register and | 491 // Tail call an API function (jump). Allocates HandleScope, extracts |
| 486 // ensuring that saved register is left unchanged. | 492 // returned value from handle and propagates exceptions. |
| 487 void PopHandleScope(Register saved, Register scratch); | 493 // Clobbers ebx, esi, edi and caller-save registers. |
| 488 | 494 void CallApiFunctionAndReturn(ApiFunction* function, int argc); |
| 489 // As PopHandleScope, but does not perform a GC. Instead, returns a | |
| 490 // retry after GC failure object if GC is necessary. | |
| 491 Object* TryPopHandleScope(Register saved, Register scratch); | |
| 492 | 495 |
| 493 // Jump to a runtime routine. | 496 // Jump to a runtime routine. |
| 494 void JumpToExternalReference(const ExternalReference& ext); | 497 void JumpToExternalReference(const ExternalReference& ext); |
| 495 | 498 |
| 496 | 499 |
| 497 // --------------------------------------------------------------------------- | 500 // --------------------------------------------------------------------------- |
| 498 // Utilities | 501 // Utilities |
| 499 | 502 |
| 500 void Ret(); | 503 void Ret(); |
| 501 | 504 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 // Allocation support helpers. | 592 // Allocation support helpers. |
| 590 void LoadAllocationTopHelper(Register result, | 593 void LoadAllocationTopHelper(Register result, |
| 591 Register result_end, | 594 Register result_end, |
| 592 Register scratch, | 595 Register scratch, |
| 593 AllocationFlags flags); | 596 AllocationFlags flags); |
| 594 void UpdateAllocationTopHelper(Register result_end, Register scratch); | 597 void UpdateAllocationTopHelper(Register result_end, Register scratch); |
| 595 | 598 |
| 596 // Helper for PopHandleScope. Allowed to perform a GC and returns | 599 // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 597 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and | 600 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 598 // possibly returns a failure object indicating an allocation failure. | 601 // possibly returns a failure object indicating an allocation failure. |
| 599 Object* PopHandleScopeHelper(Register saved, | 602 MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved, |
| 600 Register scratch, | 603 Register scratch, |
| 601 bool gc_allowed); | 604 bool gc_allowed); |
| 602 }; | 605 }; |
| 603 | 606 |
| 604 | 607 |
| 605 // The code patcher is used to patch (typically) small parts of code e.g. for | 608 // The code patcher is used to patch (typically) small parts of code e.g. for |
| 606 // debugging and other types of instrumentation. When using the code patcher | 609 // debugging and other types of instrumentation. When using the code patcher |
| 607 // the exact number of bytes specified must be emitted. Is not legal to emit | 610 // the exact number of bytes specified must be emitted. Is not legal to emit |
| 608 // relocation information. If any of these constraints are violated it causes | 611 // relocation information. If any of these constraints are violated it causes |
| 609 // an assertion. | 612 // an assertion. |
| 610 class CodePatcher { | 613 class CodePatcher { |
| 611 public: | 614 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 632 | 635 |
| 633 | 636 |
| 634 // Generate an Operand for loading an indexed field from an object. | 637 // Generate an Operand for loading an indexed field from an object. |
| 635 static inline Operand FieldOperand(Register object, | 638 static inline Operand FieldOperand(Register object, |
| 636 Register index, | 639 Register index, |
| 637 ScaleFactor scale, | 640 ScaleFactor scale, |
| 638 int offset) { | 641 int offset) { |
| 639 return Operand(object, index, scale, offset - kHeapObjectTag); | 642 return Operand(object, index, scale, offset - kHeapObjectTag); |
| 640 } | 643 } |
| 641 | 644 |
| 645 // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 646 Operand ApiParameterOperand(int index); |
| 647 |
| 642 | 648 |
| 643 #ifdef GENERATED_CODE_COVERAGE | 649 #ifdef GENERATED_CODE_COVERAGE |
| 644 extern void LogGeneratedCodeCoverage(const char* file_line); | 650 extern void LogGeneratedCodeCoverage(const char* file_line); |
| 645 #define CODE_COVERAGE_STRINGIFY(x) #x | 651 #define CODE_COVERAGE_STRINGIFY(x) #x |
| 646 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) | 652 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 647 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) | 653 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 648 #define ACCESS_MASM(masm) { \ | 654 #define ACCESS_MASM(masm) { \ |
| 649 byte* ia32_coverage_function = \ | 655 byte* ia32_coverage_function = \ |
| 650 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ | 656 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 651 masm->pushfd(); \ | 657 masm->pushfd(); \ |
| 652 masm->pushad(); \ | 658 masm->pushad(); \ |
| 653 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ | 659 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 654 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ | 660 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 655 masm->pop(eax); \ | 661 masm->pop(eax); \ |
| 656 masm->popad(); \ | 662 masm->popad(); \ |
| 657 masm->popfd(); \ | 663 masm->popfd(); \ |
| 658 } \ | 664 } \ |
| 659 masm-> | 665 masm-> |
| 660 #else | 666 #else |
| 661 #define ACCESS_MASM(masm) masm-> | 667 #define ACCESS_MASM(masm) masm-> |
| 662 #endif | 668 #endif |
| 663 | 669 |
| 664 | 670 |
| 665 } } // namespace v8::internal | 671 } } // namespace v8::internal |
| 666 | 672 |
| 667 #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ | 673 #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| OLD | NEW |