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 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 // ------------------------------------------------------------------------- | 35 // ------------------------------------------------------------------------- |
| 36 // Virtual frame elements | 36 // Virtual frame elements |
| 37 // | 37 // |
| 38 // The internal elements of the virtual frames. Elements are (currently) of | 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 | 39 // only one kind, in-memory. Their actual location is given by their |
| 40 // position in the virtual frame. | 40 // position in the virtual frame. |
| 41 | 41 |
| 42 class Element BASE_EMBEDDED { | 42 class FrameElement BASE_EMBEDDED { |
| 43 public: | 43 public: |
| 44 Element() {} | 44 enum Type { MEMORY = 0, CONSTANT = 2}; |
| 45 | 45 |
| 46 bool matches(const Element& other) { return true; } | 46 FrameElement() : type_(MEMORY) {} |
| 47 | |
| 48 explicit FrameElement(Handle<Object> value) : type_(CONSTANT | 0x1) { | |
| 49 data_.handle_ = value.location(); | |
| 50 } | |
| 51 | |
| 52 Type type() const { return static_cast<Type>(type_ & ~0x1); } | |
|
William Hesse
2008/11/18 16:37:34
Name the dirty flag mask. Unless you are also sto
Kevin Millikin (Chromium)
2008/11/18 19:12:06
OK.
| |
| 53 | |
| 54 bool is_dirty() const { return type_ & 0x1; } | |
| 55 | |
| 56 void set_dirty() { | |
| 57 ASSERT(type_ != MEMORY); | |
| 58 type_ = type_ | 0x1; | |
| 59 } | |
| 60 | |
| 61 void clear_dirty() { | |
| 62 ASSERT(type_ != MEMORY); | |
| 63 type_ = type_ & 0x1; | |
| 64 } | |
| 65 | |
| 66 Handle<Object> handle() const { return Handle<Object>(data_.handle_); } | |
|
William Hesse
2008/11/18 16:37:34
Put asserts here to assert it is a type that has h
Kevin Millikin (Chromium)
2008/11/18 19:12:06
OK.
| |
| 67 | |
| 68 private: | |
| 69 // The element's type and a dirty bit in the low-order bit. The dirty bit | |
| 70 // can be cleared for non-memory elements to indicate that the element | |
| 71 // agrees with the value in memory in the actual frame. | |
| 72 int type_; | |
| 73 | |
| 74 union { | |
| 75 Object** handle_; | |
| 76 } data_; | |
|
William Hesse
2008/11/18 16:37:34
ASSERT( sizeof data_ == sizeof what? )
| |
| 47 }; | 77 }; |
| 48 | 78 |
| 49 | 79 |
| 50 // ------------------------------------------------------------------------- | 80 // ------------------------------------------------------------------------- |
| 51 // Virtual frames | 81 // Virtual frames |
| 52 // | 82 // |
| 53 // The virtual frame is an abstraction of the physical stack frame. It | 83 // The virtual frame is an abstraction of the physical stack frame. It |
| 54 // encapsulates the parameters, frame-allocated locals, and the expression | 84 // encapsulates the parameters, frame-allocated locals, and the expression |
| 55 // stack. It supports push/pop operations on the expression stack, as well | 85 // stack. It supports push/pop operations on the expression stack, as well |
| 56 // as random access to the expression stack elements, locals, and | 86 // as random access to the expression stack elements, locals, and |
| 57 // parameters. | 87 // parameters. |
| 58 | 88 |
| 59 class VirtualFrame : public Malloced { | 89 class VirtualFrame : public Malloced { |
| 60 public: | 90 public: |
| 61 // Construct a virtual frame with the given code generator used to | 91 // Construct an initial virtual frame on entry to a JS function. |
| 62 // generate code. | |
| 63 explicit VirtualFrame(CodeGenerator* cgen); | 92 explicit VirtualFrame(CodeGenerator* cgen); |
| 64 | 93 |
| 65 // Construct a virtual frame that is a clone of an existing one, initially | 94 // Construct a virtual frame as a clone of an existing one. |
| 66 // with an identical state. | |
| 67 explicit VirtualFrame(VirtualFrame* original); | 95 explicit VirtualFrame(VirtualFrame* original); |
| 68 | 96 |
| 69 // The height of the virtual expression stack. | 97 // The height of the virtual expression stack. |
| 70 int height() const { | 98 int height() const { |
| 71 return elements_.length() - expression_base_index(); | 99 return elements_.length() - expression_base_index(); |
| 72 } | 100 } |
| 73 | 101 |
| 74 // Add extra in-memory elements to the top of the frame without generating | 102 // Add extra in-memory elements to the top of the frame to match an actual |
| 75 // code. | 103 // frame (eg, the frame after an exception handler is pushed). No code is |
| 104 // emitted. | |
| 76 void Adjust(int count); | 105 void Adjust(int count); |
| 77 | 106 |
| 78 // Forget frame elements without generating code. | 107 // Forget elements from the top of the frame to match an actual frame (eg, |
| 108 // the frame after a runtime call). No code is emitted. | |
| 79 void Forget(int count); | 109 void Forget(int count); |
| 80 | 110 |
| 111 // Spill all values from the frame to memory. | |
| 112 void SpillAll(); | |
| 113 | |
| 114 // Ensure that this frame is in a state where an arbitrary frame of the | |
| 115 // right size could be merged to it. May emit code. | |
| 116 void EnsureMergable(); | |
| 117 | |
| 81 // Make this virtual frame have a state identical to an expected virtual | 118 // Make this virtual frame have a state identical to an expected virtual |
| 82 // frame. As a side effect, code may be emitted to make this frame match | 119 // frame. As a side effect, code may be emitted to make this frame match |
| 83 // the expected one. | 120 // the expected one. |
| 84 void MergeTo(VirtualFrame* expected); | 121 void MergeTo(VirtualFrame* expected); |
| 85 | 122 |
| 86 // Emit code for the physical JS entry and exit frame sequences. After | 123 // Emit code for the physical JS entry and exit frame sequences. After |
| 87 // calling Enter, the virtual frame is ready for use; and after calling | 124 // calling Enter, the virtual frame is ready for use; and after calling |
| 88 // Exit it should not be used. Note that Enter does not allocate space in | 125 // Exit it should not be used. Note that Enter does not allocate space in |
| 89 // the physical frame for storing frame-allocated locals. | 126 // the physical frame for storing frame-allocated locals. |
| 90 void Enter(); | 127 void Enter(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 int frame_arg_count); | 188 int frame_arg_count); |
| 152 | 189 |
| 153 // Drop a number of elements from the top of the expression stack. May | 190 // Drop a number of elements from the top of the expression stack. May |
| 154 // emit code to affect the physical frame. Does not clobber any registers | 191 // emit code to affect the physical frame. Does not clobber any registers |
| 155 // excepting possibly the stack pointer. | 192 // excepting possibly the stack pointer. |
| 156 void Drop(int count); | 193 void Drop(int count); |
| 157 | 194 |
| 158 // Drop one element. | 195 // Drop one element. |
| 159 void Drop(); | 196 void Drop(); |
| 160 | 197 |
| 161 // Pop and save an element from the top of the expression stack. May emit | 198 // Pop and save an element from the top of the expression stack and emit a |
| 162 // code. | 199 // corresponding pop instruction. |
| 163 void Pop(Register reg); | 200 void EmitPop(Register reg); |
| 164 void Pop(Operand operand); | 201 void EmitPop(Operand operand); |
| 165 | 202 |
| 166 // Push an element on top of the expression stack and emit a corresponding | 203 // Push an element on top of the expression stack and emit a corresponding |
| 167 // push instruction. | 204 // push instruction. |
| 168 void EmitPush(Register reg); | 205 void EmitPush(Register reg); |
| 169 void EmitPush(Operand operand); | 206 void EmitPush(Operand operand); |
| 170 void EmitPush(Immediate immediate); | 207 void EmitPush(Immediate immediate); |
| 171 | 208 |
| 172 private: | 209 private: |
| 210 // An illegal index into the virtual frame. | |
| 211 static const int kIllegalIndex = -1; | |
| 212 | |
| 173 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; | 213 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
| 174 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; | 214 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; |
| 175 static const int kContextOffset = StandardFrameConstants::kContextOffset; | 215 static const int kContextOffset = StandardFrameConstants::kContextOffset; |
| 176 | 216 |
| 177 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; | 217 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; |
| 178 | 218 |
| 179 MacroAssembler* masm_; | 219 MacroAssembler* masm_; |
| 180 | 220 |
| 181 List<Element> elements_; | 221 List<FrameElement> elements_; |
| 182 | 222 |
| 183 int parameter_count_; | 223 int parameter_count_; |
| 184 int local_count_; | 224 int local_count_; |
| 185 | 225 |
| 226 // The index of the element that is at the processor's stack pointer | |
| 227 // (the esp register). | |
| 228 int stack_pointer_; | |
| 229 | |
| 230 // The index of the element that is at the processor's frame pointer | |
| 231 // (the ebp register). | |
| 186 int frame_pointer_; | 232 int frame_pointer_; |
| 187 | 233 |
| 188 // The index of the first parameter. The receiver lies below the first | 234 // The index of the first parameter. The receiver lies below the first |
| 189 // parameter. | 235 // parameter. |
| 190 int param0_index() const { return 1; } | 236 int param0_index() const { return 1; } |
| 191 | 237 |
| 192 // The index of the first local. Between the parameters and the locals | 238 // The index of the first local. Between the parameters and the locals |
| 193 // lie the return address, the saved frame pointer, the context, and the | 239 // lie the return address, the saved frame pointer, the context, and the |
| 194 // function. | 240 // function. |
| 195 int local0_index() const { return param0_index() + parameter_count_ + 4; } | 241 int local0_index() const { return param0_index() + parameter_count_ + 4; } |
| 196 | 242 |
| 197 // The index of the base of the expression stack. | 243 // The index of the base of the expression stack. |
| 198 int expression_base_index() const { return local0_index() + local_count_; } | 244 int expression_base_index() const { return local0_index() + local_count_; } |
| 245 | |
| 246 // Convert a frame index into a frame pointer relative offset into the | |
| 247 // actual stack. | |
| 248 int fp_relative(int index) const { | |
| 249 return (frame_pointer_ - index) * kPointerSize; | |
| 250 } | |
| 251 | |
| 252 // Spill the topmost elements of the frame to memory (eg, they are the | |
| 253 // arguments to a call) and all registers. | |
| 254 void PrepareCall(int count); | |
|
William Hesse
2008/11/18 16:37:34
PrepareForCall?
Kevin Millikin (Chromium)
2008/11/18 19:12:06
OK.
| |
| 199 }; | 255 }; |
| 200 | 256 |
| 201 | 257 |
| 202 } } // namespace v8::internal | 258 } } // namespace v8::internal |
| 203 | 259 |
| 204 #endif // V8_VIRTUAL_FRAME_IA32_H_ | 260 #endif // V8_VIRTUAL_FRAME_IA32_H_ |
| OLD | NEW |