/js/src/methodjit/InlineFrameAssembler.h

http://github.com/zpao/v8monkey · C Header · 161 lines · 79 code · 24 blank · 58 comment · 6 complexity · 1648acb1d5ea3117fed0d1bf00157685 MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set ts=4 sw=4 et tw=99:
  3. *
  4. * ***** BEGIN LICENSE BLOCK *****
  5. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
  18. * May 28, 2008.
  19. *
  20. * The Initial Developer of the Original Code is
  21. * Brendan Eich <brendan@mozilla.org>
  22. *
  23. * Contributor(s):
  24. * David Anderson <danderson@mozilla.com>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #if !defined jsjaeger_inl_frame_asm_h__ && defined JS_METHODJIT && defined JS_MONOIC
  40. #define jsjaeger_inl_frame_asm_h__
  41. #include "assembler/assembler/MacroAssembler.h"
  42. #include "assembler/assembler/CodeLocation.h"
  43. #include "methodjit/MethodJIT.h"
  44. #include "CodeGenIncludes.h"
  45. namespace js {
  46. namespace mjit {
  47. struct AdjustedFrame {
  48. AdjustedFrame(uint32_t baseOffset)
  49. : baseOffset(baseOffset)
  50. { }
  51. uint32_t baseOffset;
  52. JSC::MacroAssembler::Address addrOf(uint32_t offset) {
  53. return JSC::MacroAssembler::Address(JSFrameReg, baseOffset + offset);
  54. }
  55. };
  56. /*
  57. * This is used for emitting code to inline callee-side frame creation and
  58. * should jit code equivalent to StackFrame::initCallFrameCallerHalf.
  59. *
  60. * Once finished, JSFrameReg is advanced to be the new fp.
  61. */
  62. class InlineFrameAssembler {
  63. typedef JSC::MacroAssembler::RegisterID RegisterID;
  64. typedef JSC::MacroAssembler::Address Address;
  65. typedef JSC::MacroAssembler::Imm32 Imm32;
  66. typedef JSC::MacroAssembler::ImmPtr ImmPtr;
  67. typedef JSC::MacroAssembler::DataLabelPtr DataLabelPtr;
  68. Assembler &masm;
  69. FrameSize frameSize; // size of the caller's frame
  70. RegisterID funObjReg; // register containing the function object (callee)
  71. uint32_t flags; // frame flags
  72. public:
  73. /*
  74. * Register state, so consumers of this class can restrict which registers
  75. * can and can't be clobbered.
  76. */
  77. Registers tempRegs;
  78. InlineFrameAssembler(Assembler &masm, ic::CallICInfo &ic, uint32_t flags)
  79. : masm(masm), flags(flags), tempRegs(Registers::AvailRegs)
  80. {
  81. frameSize = ic.frameSize;
  82. funObjReg = ic.funObjReg;
  83. tempRegs.takeReg(funObjReg);
  84. }
  85. InlineFrameAssembler(Assembler &masm, Compiler::CallGenInfo &gen, uint32_t flags)
  86. : masm(masm), flags(flags), tempRegs(Registers::AvailRegs)
  87. {
  88. frameSize = gen.frameSize;
  89. funObjReg = gen.funObjReg;
  90. tempRegs.takeReg(funObjReg);
  91. }
  92. DataLabelPtr assemble(void *ncode, jsbytecode *pc)
  93. {
  94. JS_ASSERT((flags & ~StackFrame::CONSTRUCTING) == 0);
  95. /* Generate StackFrame::initCallFrameCallerHalf. */
  96. /* Get the actual flags to write. */
  97. JS_ASSERT(!(flags & ~StackFrame::CONSTRUCTING));
  98. uint32_t flags = this->flags | StackFrame::FUNCTION;
  99. if (frameSize.lowered(pc))
  100. flags |= StackFrame::LOWERED_CALL_APPLY;
  101. DataLabelPtr ncodePatch;
  102. if (frameSize.isStatic()) {
  103. uint32_t frameDepth = frameSize.staticLocalSlots();
  104. AdjustedFrame newfp(sizeof(StackFrame) + frameDepth * sizeof(Value));
  105. Address flagsAddr = newfp.addrOf(StackFrame::offsetOfFlags());
  106. masm.store32(Imm32(flags), flagsAddr);
  107. Address prevAddr = newfp.addrOf(StackFrame::offsetOfPrev());
  108. masm.storePtr(JSFrameReg, prevAddr);
  109. Address ncodeAddr = newfp.addrOf(StackFrame::offsetOfNcode());
  110. ncodePatch = masm.storePtrWithPatch(ImmPtr(ncode), ncodeAddr);
  111. masm.addPtr(Imm32(sizeof(StackFrame) + frameDepth * sizeof(Value)), JSFrameReg);
  112. } else {
  113. /*
  114. * If the frame size is dynamic, then the fast path generated by
  115. * generateFullCallStub must be used. Thus, this code is executed
  116. * after stubs::SplatApplyArgs has been called. SplatApplyArgs
  117. * stores the dynamic stack pointer (i.e., regs.sp after pushing a
  118. * dynamic number of arguments) to VMFrame.regs, so we just load it
  119. * here to get the new frame pointer.
  120. */
  121. RegisterID newfp = tempRegs.takeAnyReg().reg();
  122. masm.loadPtr(FrameAddress(VMFrame::offsetOfRegsSp()), newfp);
  123. Address flagsAddr(newfp, StackFrame::offsetOfFlags());
  124. masm.store32(Imm32(flags), flagsAddr);
  125. Address prevAddr(newfp, StackFrame::offsetOfPrev());
  126. masm.storePtr(JSFrameReg, prevAddr);
  127. Address ncodeAddr(newfp, StackFrame::offsetOfNcode());
  128. ncodePatch = masm.storePtrWithPatch(ImmPtr(ncode), ncodeAddr);
  129. masm.move(newfp, JSFrameReg);
  130. tempRegs.putReg(newfp);
  131. }
  132. return ncodePatch;
  133. }
  134. };
  135. } /* namespace mjit */
  136. } /* namespace js */
  137. #endif /* jsjaeger_inl_frame_asm_h__ */