Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 15 matching lines...) Expand all Loading... | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_VIRTUAL_FRAME_IA32_H_ | 28 #ifndef V8_VIRTUAL_FRAME_IA32_H_ |
| 29 #define V8_VIRTUAL_FRAME_IA32_H_ | 29 #define V8_VIRTUAL_FRAME_IA32_H_ |
| 30 | 30 |
| 31 #include "macro-assembler.h" | 31 #include "macro-assembler.h" |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 // ------------------------------------------------------------------------- | 35 // ------------------------------------------------------------------------- |
| 36 // Virtual frame elements | |
| 37 // | |
| 38 // The internal elements of the virtual frames. Elements are (currently) of | |
| 39 // only one kind, in-memory. Their actual location is given by their | |
| 40 // position in the virtual frame. | |
| 41 | |
| 42 class Element BASE_EMBEDDED { | |
| 43 public: | |
| 44 Element() {} | |
| 45 | |
| 46 bool matches(const Element& other) { return true; } | |
| 47 }; | |
| 48 | |
| 49 | |
| 50 // ------------------------------------------------------------------------- | |
| 36 // Virtual frames | 51 // Virtual frames |
| 37 // | 52 // |
| 38 // The virtual frame is an abstraction of the physical stack frame. It | 53 // The virtual frame is an abstraction of the physical stack frame. It |
| 39 // encapsulates the parameters, frame-allocated locals, and the expression | 54 // encapsulates the parameters, frame-allocated locals, and the expression |
| 40 // stack. It supports push/pop operations on the expression stack, as well | 55 // stack. It supports push/pop operations on the expression stack, as well |
| 41 // as random access to the expression stack elements, locals, and | 56 // as random access to the expression stack elements, locals, and |
| 42 // parameters. | 57 // parameters. |
| 43 | 58 |
| 44 class VirtualFrame : public Malloced { | 59 class VirtualFrame : public Malloced { |
| 45 public: | 60 public: |
| 46 // Construct a virtual frame with the given code generator used to | 61 // Construct a virtual frame with the given code generator used to |
| 47 // generate code. | 62 // generate code. |
| 48 explicit VirtualFrame(CodeGenerator* cgen); | 63 explicit VirtualFrame(CodeGenerator* cgen); |
| 49 | 64 |
| 50 // Construct a virtual frame that is a clone of an existing one, initially | 65 // Construct a virtual frame that is a clone of an existing one, initially |
| 51 // with an identical state. | 66 // with an identical state. |
| 52 explicit VirtualFrame(VirtualFrame* original); | 67 explicit VirtualFrame(VirtualFrame* original); |
| 53 | 68 |
| 54 // The height of the virtual expression stack. Always non-negative. | 69 // The height of the virtual expression stack. Always non-negative. |
| 55 int height() const { return height_; } | 70 int height() const { |
| 71 return virtual_stack_pointer_ - expression_base_index() + 1; | |
| 72 } | |
| 56 | 73 |
| 57 // Forget elements from the top of the expression stack. This is | 74 // Add extra in-memory elements to the top of the frame without generating |
| 58 // used when the stack pointer is manually lowered to pop values | 75 // code. |
| 59 // left by statements (eg, for...in, try...finally) that have been | 76 void Adjust(int count); |
|
Erik Corry
2008/11/11 10:47:05
The name Adjust seems mighty generic. Perhaps Adj
Kevin Millikin (Chromium)
2008/11/11 11:37:31
Perhaps. Eventually its use will be minimized: ex
| |
| 60 // escaped from. | 77 |
| 78 // Forget frame elements without generating code. | |
| 61 void Forget(int count); | 79 void Forget(int count); |
|
Erik Corry
2008/11/11 10:47:05
ForgetElements?
Kevin Millikin (Chromium)
2008/11/11 11:37:31
Maybe. It will also be minimized, so I'll hold of
| |
| 62 | 80 |
| 63 // Make this virtual frame have a state identical to an expected virtual | 81 // Make this virtual frame have a state identical to an expected virtual |
| 64 // frame. As a side effect, code may be emitted to make this frame match | 82 // frame. As a side effect, code may be emitted to make this frame match |
| 65 // the expected one. | 83 // the expected one. |
| 66 void MergeTo(VirtualFrame* expected); | 84 void MergeTo(VirtualFrame* expected); |
| 67 | 85 |
| 68 // Emit code for the physical JS entry and exit frame sequences. After | 86 // Emit code for the physical JS entry and exit frame sequences. After |
| 69 // calling Enter, the virtual frame is ready for use; and after calling | 87 // calling Enter, the virtual frame is ready for use; and after calling |
| 70 // Exit it should not be used. Note that Enter does not allocate space in | 88 // Exit it should not be used. Note that Enter does not allocate space in |
| 71 // the physical frame for storing frame-allocated locals. | 89 // the physical frame for storing frame-allocated locals. |
| 72 void Enter(); | 90 void Enter(); |
| 73 void Exit(); | 91 void Exit(); |
| 74 | 92 |
| 75 // Allocate and initialize the frame-allocated locals. The number of | 93 // Allocate and initialize the frame-allocated locals. The number of |
| 76 // locals is known from the frame's code generator's state (specifically | 94 // locals is known from the frame's code generator's state (specifically |
| 77 // its scope). As a side effect, code may be emitted. | 95 // its scope). As a side effect, code may be emitted. |
| 78 void AllocateLocals(); | 96 void AllocateLocals(int count); |
| 79 | 97 |
| 80 // The current top of the expression stack as an assembly operand. | 98 // The current top of the expression stack as an assembly operand. |
| 81 Operand Top() const { return Operand(esp, 0); } | 99 Operand Top() const { return Operand(esp, 0); } |
| 82 | 100 |
| 83 // An element of the expression stack as an assembly operand. | 101 // An element of the expression stack as an assembly operand. |
| 84 Operand Element(int index) const { | 102 Operand ElementAt(int index) const { |
| 85 return Operand(esp, index * kPointerSize); | 103 return Operand(esp, index * kPointerSize); |
| 86 } | 104 } |
| 87 | 105 |
| 88 // A frame-allocated local as an assembly operand. | 106 // A frame-allocated local as an assembly operand. |
| 89 Operand Local(int index) const { | 107 Operand Local(int index) const { |
| 90 ASSERT(0 <= index && index < frame_local_count_); | 108 ASSERT(0 <= index && index < local_count_); |
|
Erik Corry
2008/11/11 10:47:05
2 different asserts is nicer here if one is trigge
Kevin Millikin (Chromium)
2008/11/11 11:37:31
Agreed. Changed.
| |
| 91 return Operand(ebp, kLocal0Offset - index * kPointerSize); | 109 return Operand(ebp, kLocal0Offset - index * kPointerSize); |
| 92 } | 110 } |
| 93 | 111 |
| 94 // The function frame slot. | 112 // The function frame slot. |
| 95 Operand Function() const { return Operand(ebp, kFunctionOffset); } | 113 Operand Function() const { return Operand(ebp, kFunctionOffset); } |
| 96 | 114 |
| 97 // The context frame slot. | 115 // The context frame slot. |
| 98 Operand Context() const { return Operand(ebp, kContextOffset); } | 116 Operand Context() const { return Operand(ebp, kContextOffset); } |
| 99 | 117 |
| 100 // A parameter as an assembly operand. | 118 // A parameter as an assembly operand. |
| 101 Operand Parameter(int index) const { | 119 Operand Parameter(int index) const { |
| 102 ASSERT(-1 <= index && index < parameter_count_); | 120 ASSERT(-1 <= index && index < parameter_count_); |
| 103 return Operand(ebp, (1 + parameter_count_ - index) * kPointerSize); | 121 return Operand(ebp, (1 + parameter_count_ - index) * kPointerSize); |
| 104 } | 122 } |
| 105 | 123 |
| 106 // The receiver frame slot. | 124 // The receiver frame slot. |
| 107 Operand Receiver() const { return Parameter(-1); } | 125 Operand Receiver() const { return Parameter(-1); } |
| 108 | 126 |
| 109 // Push a try-catch or try-finally handler on top of the virtual frame. | 127 // Push a try-catch or try-finally handler on top of the virtual frame. |
| 110 inline void PushTryHandler(HandlerType type); | 128 void PushTryHandler(HandlerType type); |
| 111 | 129 |
| 112 // Call a code stub, given the number of arguments it expects on (and | 130 // Call a code stub, given the number of arguments it expects on (and |
| 113 // removes from) the top of the physical frame. | 131 // removes from) the top of the physical frame. |
| 114 inline void CallStub(CodeStub* stub, int frame_arg_count); | 132 void CallStub(CodeStub* stub, int frame_arg_count); |
| 115 | 133 |
| 116 // Call the runtime, given the number of arguments expected on (and | 134 // Call the runtime, given the number of arguments expected on (and |
| 117 // removed from) the top of the physical frame. | 135 // removed from) the top of the physical frame. |
| 118 inline void CallRuntime(Runtime::Function* f, int frame_arg_count); | 136 void CallRuntime(Runtime::Function* f, int frame_arg_count); |
| 119 inline void CallRuntime(Runtime::FunctionId id, int frame_arg_count); | 137 void CallRuntime(Runtime::FunctionId id, int frame_arg_count); |
| 120 | 138 |
| 121 // Invoke a builtin, given the number of arguments it expects on (and | 139 // Invoke a builtin, given the number of arguments it expects on (and |
| 122 // removes from) the top of the physical frame. | 140 // removes from) the top of the physical frame. |
| 123 inline void InvokeBuiltin(Builtins::JavaScript id, | 141 void InvokeBuiltin(Builtins::JavaScript id, |
| 124 InvokeFlag flag, | 142 InvokeFlag flag, |
| 125 int frame_arg_count); | 143 int frame_arg_count); |
| 126 | 144 |
| 127 // Call into a JS code object, given the number of arguments it expects on | 145 // Call into a JS code object, given the number of arguments it expects on |
| 128 // (and removes from) the top of the physical frame. | 146 // (and removes from) the top of the physical frame. |
| 129 inline void CallCode(Handle<Code> ic, | 147 void CallCode(Handle<Code> ic, RelocInfo::Mode rmode, int frame_arg_count); |
| 130 RelocInfo::Mode rmode, | |
| 131 int frame_arg_count); | |
| 132 | 148 |
| 133 // Drop a number of elements from the top of the expression stack. May | 149 // Drop a number of elements from the top of the expression stack. May |
| 134 // emit code to effect the physical frame. | 150 // emit code to effect the physical frame. Does not clobber any registers |
|
Erik Corry
2008/11/11 10:47:05
effect -> affect
Kevin Millikin (Chromium)
2008/11/11 11:37:31
Embarassing.
| |
| 135 inline void Drop(int count); | 151 // excepting possibly the stack pointer. |
| 152 void Drop(int count); | |
| 136 | 153 |
| 137 // Pop and discard an element from the top of the expression stack. | 154 // Drop one element. |
| 138 // Specifically does not clobber any registers excepting possibly the | 155 void Drop(); |
| 139 // stack pointer. | |
| 140 inline void Pop(); | |
| 141 | 156 |
| 142 // Pop and save an element from the top of the expression stack. May emit | 157 // Pop and save an element from the top of the expression stack. May emit |
| 143 // code. | 158 // code. |
| 144 inline void Pop(Register reg); | 159 void Pop(Register reg); |
| 145 inline void Pop(Operand operand); | 160 void Pop(Operand operand); |
| 146 | 161 |
| 147 // Push an element on top of the expression stack. May emit code. | 162 // Push an element on top of the expression stack. May emit code. |
| 148 inline void Push(Register reg); | 163 void Push(Register reg); |
| 149 inline void Push(Operand operand); | 164 void Push(Operand operand); |
| 150 inline void Push(Immediate immediate); | 165 void Push(Immediate immediate); |
| 151 | 166 |
| 152 private: | 167 private: |
| 153 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; | 168 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
| 154 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; | 169 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; |
| 155 static const int kContextOffset = StandardFrameConstants::kContextOffset; | 170 static const int kContextOffset = StandardFrameConstants::kContextOffset; |
| 156 | 171 |
| 157 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; | 172 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; |
| 158 | 173 |
| 159 MacroAssembler* masm_; | 174 MacroAssembler* masm_; |
| 160 | 175 |
| 161 // The number of frame-allocated locals and parameters respectively. | 176 List<Element> elements_; |
| 177 | |
| 178 // The virtual stack pointer is the index of the top element of the stack. | |
| 179 int virtual_stack_pointer_; | |
| 180 | |
| 181 int virtual_frame_pointer_; | |
| 182 | |
| 162 int parameter_count_; | 183 int parameter_count_; |
| 163 int frame_local_count_; | 184 int local_count_; |
| 164 | 185 |
| 165 // The height of the expression stack. | 186 // The index of the first parameter. The receiver lies below the first |
| 166 int height_; | 187 // parameter. |
| 188 int param0_index() const { return 1; } | |
| 189 | |
| 190 // The index of the first local. Between the parameters and the locals | |
| 191 // lie the return address, the saved frame pointer, the context, and the | |
| 192 // function. | |
| 193 int local0_index() const { return param0_index() + parameter_count_ + 4; } | |
| 194 | |
| 195 // The index of the base of the expression stack. | |
| 196 int expression_base_index() const { return local0_index() + local_count_; } | |
| 197 | |
| 198 void AddElement(const Element& element) { | |
| 199 virtual_stack_pointer_++; | |
| 200 elements_.Add(element); | |
| 201 } | |
| 202 | |
| 203 Element RemoveElement() { | |
| 204 virtual_stack_pointer_--; | |
| 205 return elements_.RemoveLast(); | |
| 206 } | |
| 167 | 207 |
| 168 // The JumpTarget class explicitly sets the height_ field of the expected | 208 // The JumpTarget class explicitly sets the height_ field of the expected |
| 169 // frame at the actual return target. | 209 // frame at the actual return target. |
| 170 friend class JumpTarget; | 210 friend class JumpTarget; |
| 171 }; | 211 }; |
| 172 | 212 |
| 173 | 213 |
| 174 } } // namespace v8::internal | 214 } } // namespace v8::internal |
| 175 | 215 |
| 176 #endif // V8_VIRTUAL_FRAME_IA32_H_ | 216 #endif // V8_VIRTUAL_FRAME_IA32_H_ |
| OLD | NEW |