yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_DEOPTIMIZER_H_ |
| 29 | #define V8_DEOPTIMIZER_H_ |
| 30 | |
| 31 | #include "v8.h" |
| 32 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 33 | #include "allocation.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "macro-assembler.h" |
| 35 | #include "zone-inl.h" |
| 36 | |
| 37 | |
| 38 | namespace v8 { |
| 39 | namespace internal { |
| 40 | |
| 41 | class FrameDescription; |
| 42 | class TranslationIterator; |
| 43 | class DeoptimizingCodeListNode; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 44 | class DeoptimizedFrameInfo; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 45 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 46 | class HeapNumberMaterializationDescriptor BASE_EMBEDDED { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 47 | public: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 48 | HeapNumberMaterializationDescriptor(Address slot_address, double val) |
| 49 | : slot_address_(slot_address), val_(val) { } |
| 50 | |
| 51 | Address slot_address() const { return slot_address_; } |
| 52 | double value() const { return val_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | |
| 54 | private: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 55 | Address slot_address_; |
| 56 | double val_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | |
| 60 | class OptimizedFunctionVisitor BASE_EMBEDDED { |
| 61 | public: |
| 62 | virtual ~OptimizedFunctionVisitor() {} |
| 63 | |
| 64 | // Function which is called before iteration of any optimized functions |
| 65 | // from given global context. |
| 66 | virtual void EnterContext(Context* context) = 0; |
| 67 | |
| 68 | virtual void VisitFunction(JSFunction* function) = 0; |
| 69 | |
| 70 | // Function which is called after iteration of all optimized functions |
| 71 | // from given global context. |
| 72 | virtual void LeaveContext(Context* context) = 0; |
| 73 | }; |
| 74 | |
| 75 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 76 | class Deoptimizer; |
| 77 | |
| 78 | |
| 79 | class DeoptimizerData { |
| 80 | public: |
| 81 | DeoptimizerData(); |
| 82 | ~DeoptimizerData(); |
| 83 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 84 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 85 | void Iterate(ObjectVisitor* v); |
| 86 | #endif |
| 87 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 88 | private: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 89 | MemoryChunk* eager_deoptimization_entry_code_; |
| 90 | MemoryChunk* lazy_deoptimization_entry_code_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | Deoptimizer* current_; |
| 92 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 93 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 94 | DeoptimizedFrameInfo* deoptimized_frame_info_; |
| 95 | #endif |
| 96 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 97 | // List of deoptimized code which still have references from active stack |
| 98 | // frames. These code objects are needed by the deoptimizer when deoptimizing |
| 99 | // a frame for which the code object for the function function has been |
| 100 | // changed from the code present when deoptimizing was done. |
| 101 | DeoptimizingCodeListNode* deoptimizing_code_list_; |
| 102 | |
| 103 | friend class Deoptimizer; |
| 104 | |
| 105 | DISALLOW_COPY_AND_ASSIGN(DeoptimizerData); |
| 106 | }; |
| 107 | |
| 108 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 109 | class Deoptimizer : public Malloced { |
| 110 | public: |
| 111 | enum BailoutType { |
| 112 | EAGER, |
| 113 | LAZY, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 114 | OSR, |
| 115 | // This last bailout type is not really a bailout, but used by the |
| 116 | // debugger to deoptimize stack frames to allow inspection. |
| 117 | DEBUGGER |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | int output_count() const { return output_count_; } |
| 121 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 122 | // Number of created JS frames. Not all created frames are necessarily JS. |
| 123 | int jsframe_count() const { return jsframe_count_; } |
| 124 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 125 | static Deoptimizer* New(JSFunction* function, |
| 126 | BailoutType type, |
| 127 | unsigned bailout_id, |
| 128 | Address from, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 129 | int fp_to_sp_delta, |
| 130 | Isolate* isolate); |
| 131 | static Deoptimizer* Grab(Isolate* isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 132 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 133 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 134 | // The returned object with information on the optimized frame needs to be |
| 135 | // freed before another one can be generated. |
| 136 | static DeoptimizedFrameInfo* DebuggerInspectableFrame(JavaScriptFrame* frame, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 137 | int jsframe_index, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 138 | Isolate* isolate); |
| 139 | static void DeleteDebuggerInspectableFrame(DeoptimizedFrameInfo* info, |
| 140 | Isolate* isolate); |
| 141 | #endif |
| 142 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 143 | // Makes sure that there is enough room in the relocation |
| 144 | // information of a code object to perform lazy deoptimization |
| 145 | // patching. If there is not enough room a new relocation |
| 146 | // information object is allocated and comments are added until it |
| 147 | // is big enough. |
| 148 | static void EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code); |
| 149 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 150 | // Deoptimize the function now. Its current optimized code will never be run |
| 151 | // again and any activations of the optimized code will get deoptimized when |
| 152 | // execution returns. |
| 153 | static void DeoptimizeFunction(JSFunction* function); |
| 154 | |
| 155 | // Deoptimize all functions in the heap. |
| 156 | static void DeoptimizeAll(); |
| 157 | |
| 158 | static void DeoptimizeGlobalObject(JSObject* object); |
| 159 | |
| 160 | static void VisitAllOptimizedFunctionsForContext( |
| 161 | Context* context, OptimizedFunctionVisitor* visitor); |
| 162 | |
| 163 | static void VisitAllOptimizedFunctionsForGlobalObject( |
| 164 | JSObject* object, OptimizedFunctionVisitor* visitor); |
| 165 | |
| 166 | static void VisitAllOptimizedFunctions(OptimizedFunctionVisitor* visitor); |
| 167 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 168 | // The size in bytes of the code required at a lazy deopt patch site. |
| 169 | static int patch_size(); |
| 170 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 171 | // Patch all stack guard checks in the unoptimized code to |
| 172 | // unconditionally call replacement_code. |
| 173 | static void PatchStackCheckCode(Code* unoptimized_code, |
| 174 | Code* check_code, |
| 175 | Code* replacement_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 176 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 177 | // Patch stack guard check at instruction before pc_after in |
| 178 | // the unoptimized code to unconditionally call replacement_code. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 179 | static void PatchStackCheckCodeAt(Code* unoptimized_code, |
| 180 | Address pc_after, |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 181 | Code* check_code, |
| 182 | Code* replacement_code); |
| 183 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 184 | // Change all patched stack guard checks in the unoptimized code |
| 185 | // back to a normal stack guard check. |
| 186 | static void RevertStackCheckCode(Code* unoptimized_code, |
| 187 | Code* check_code, |
| 188 | Code* replacement_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 189 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 190 | // Change all patched stack guard checks in the unoptimized code |
| 191 | // back to a normal stack guard check. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 192 | static void RevertStackCheckCodeAt(Code* unoptimized_code, |
| 193 | Address pc_after, |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 194 | Code* check_code, |
| 195 | Code* replacement_code); |
| 196 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 197 | ~Deoptimizer(); |
| 198 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 199 | void MaterializeHeapNumbers(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 200 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 201 | void MaterializeHeapNumbersForDebuggerInspectableFrame( |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 202 | Address parameters_top, |
| 203 | uint32_t parameters_size, |
| 204 | Address expressions_top, |
| 205 | uint32_t expressions_size, |
| 206 | DeoptimizedFrameInfo* info); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 207 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 208 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 209 | static void ComputeOutputFrames(Deoptimizer* deoptimizer); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 210 | |
| 211 | static Address GetDeoptimizationEntry(int id, BailoutType type); |
| 212 | static int GetDeoptimizationId(Address addr, BailoutType type); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 213 | static int GetOutputInfo(DeoptimizationOutputData* data, |
| 214 | unsigned node_id, |
| 215 | SharedFunctionInfo* shared); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 216 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 217 | // Code generation support. |
| 218 | static int input_offset() { return OFFSET_OF(Deoptimizer, input_); } |
| 219 | static int output_count_offset() { |
| 220 | return OFFSET_OF(Deoptimizer, output_count_); |
| 221 | } |
| 222 | static int output_offset() { return OFFSET_OF(Deoptimizer, output_); } |
| 223 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 224 | static int has_alignment_padding_offset() { |
| 225 | return OFFSET_OF(Deoptimizer, has_alignment_padding_); |
| 226 | } |
| 227 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 228 | static int GetDeoptimizedCodeCount(Isolate* isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 229 | |
| 230 | static const int kNotDeoptimizationEntry = -1; |
| 231 | |
| 232 | // Generators for the deoptimization entry code. |
| 233 | class EntryGenerator BASE_EMBEDDED { |
| 234 | public: |
| 235 | EntryGenerator(MacroAssembler* masm, BailoutType type) |
| 236 | : masm_(masm), type_(type) { } |
| 237 | virtual ~EntryGenerator() { } |
| 238 | |
| 239 | void Generate(); |
| 240 | |
| 241 | protected: |
| 242 | MacroAssembler* masm() const { return masm_; } |
| 243 | BailoutType type() const { return type_; } |
| 244 | |
| 245 | virtual void GeneratePrologue() { } |
| 246 | |
| 247 | private: |
| 248 | MacroAssembler* masm_; |
| 249 | Deoptimizer::BailoutType type_; |
| 250 | }; |
| 251 | |
| 252 | class TableEntryGenerator : public EntryGenerator { |
| 253 | public: |
| 254 | TableEntryGenerator(MacroAssembler* masm, BailoutType type, int count) |
| 255 | : EntryGenerator(masm, type), count_(count) { } |
| 256 | |
| 257 | protected: |
| 258 | virtual void GeneratePrologue(); |
| 259 | |
| 260 | private: |
| 261 | int count() const { return count_; } |
| 262 | |
| 263 | int count_; |
| 264 | }; |
| 265 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 266 | int ConvertJSFrameIndexToFrameIndex(int jsframe_index); |
| 267 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 268 | private: |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 269 | static const int kNumberOfEntries = 16384; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 270 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 271 | Deoptimizer(Isolate* isolate, |
| 272 | JSFunction* function, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 273 | BailoutType type, |
| 274 | unsigned bailout_id, |
| 275 | Address from, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 276 | int fp_to_sp_delta, |
| 277 | Code* optimized_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 278 | void DeleteFrameDescriptions(); |
| 279 | |
| 280 | void DoComputeOutputFrames(); |
| 281 | void DoComputeOsrOutputFrame(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 282 | void DoComputeJSFrame(TranslationIterator* iterator, int frame_index); |
| 283 | void DoComputeArgumentsAdaptorFrame(TranslationIterator* iterator, |
| 284 | int frame_index); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 285 | void DoComputeConstructStubFrame(TranslationIterator* iterator, |
| 286 | int frame_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 287 | void DoTranslateCommand(TranslationIterator* iterator, |
| 288 | int frame_index, |
| 289 | unsigned output_offset); |
| 290 | // Translate a command for OSR. Updates the input offset to be used for |
| 291 | // the next command. Returns false if translation of the command failed |
| 292 | // (e.g., a number conversion failed) and may or may not have updated the |
| 293 | // input offset. |
| 294 | bool DoOsrTranslateCommand(TranslationIterator* iterator, |
| 295 | int* input_offset); |
| 296 | |
| 297 | unsigned ComputeInputFrameSize() const; |
| 298 | unsigned ComputeFixedSize(JSFunction* function) const; |
| 299 | |
| 300 | unsigned ComputeIncomingArgumentSize(JSFunction* function) const; |
| 301 | unsigned ComputeOutgoingArgumentSize() const; |
| 302 | |
| 303 | Object* ComputeLiteral(int index) const; |
| 304 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 305 | void AddDoubleValue(intptr_t slot_address, double value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 306 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 307 | static MemoryChunk* CreateCode(BailoutType type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 308 | static void GenerateDeoptimizationEntries( |
| 309 | MacroAssembler* masm, int count, BailoutType type); |
| 310 | |
| 311 | // Weak handle callback for deoptimizing code objects. |
| 312 | static void HandleWeakDeoptimizedCode( |
| 313 | v8::Persistent<v8::Value> obj, void* data); |
| 314 | static Code* FindDeoptimizingCodeFromAddress(Address addr); |
| 315 | static void RemoveDeoptimizingCode(Code* code); |
| 316 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 317 | // Fill the input from from a JavaScript frame. This is used when |
| 318 | // the debugger needs to inspect an optimized frame. For normal |
| 319 | // deoptimizations the input frame is filled in generated code. |
| 320 | void FillInputFrame(Address tos, JavaScriptFrame* frame); |
| 321 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 322 | Isolate* isolate_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 323 | JSFunction* function_; |
| 324 | Code* optimized_code_; |
| 325 | unsigned bailout_id_; |
| 326 | BailoutType bailout_type_; |
| 327 | Address from_; |
| 328 | int fp_to_sp_delta_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 329 | int has_alignment_padding_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 330 | |
| 331 | // Input frame description. |
| 332 | FrameDescription* input_; |
| 333 | // Number of output frames. |
| 334 | int output_count_; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 335 | // Number of output js frames. |
| 336 | int jsframe_count_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 337 | // Array of output frame descriptions. |
| 338 | FrameDescription** output_; |
| 339 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 340 | List<HeapNumberMaterializationDescriptor> deferred_heap_numbers_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 341 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 342 | static const int table_entry_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 343 | |
| 344 | friend class FrameDescription; |
| 345 | friend class DeoptimizingCodeListNode; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 346 | friend class DeoptimizedFrameInfo; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | |
| 350 | class FrameDescription { |
| 351 | public: |
| 352 | FrameDescription(uint32_t frame_size, |
| 353 | JSFunction* function); |
| 354 | |
| 355 | void* operator new(size_t size, uint32_t frame_size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 356 | // Subtracts kPointerSize, as the member frame_content_ already supplies |
| 357 | // the first element of the area to store the frame. |
| 358 | return malloc(size + frame_size - kPointerSize); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 359 | } |
| 360 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 361 | void operator delete(void* pointer, uint32_t frame_size) { |
| 362 | free(pointer); |
| 363 | } |
| 364 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 365 | void operator delete(void* description) { |
| 366 | free(description); |
| 367 | } |
| 368 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 369 | uint32_t GetFrameSize() const { |
| 370 | ASSERT(static_cast<uint32_t>(frame_size_) == frame_size_); |
| 371 | return static_cast<uint32_t>(frame_size_); |
| 372 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 373 | |
| 374 | JSFunction* GetFunction() const { return function_; } |
| 375 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 376 | unsigned GetOffsetFromSlotIndex(int slot_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 377 | |
| 378 | intptr_t GetFrameSlot(unsigned offset) { |
| 379 | return *GetFrameSlotPointer(offset); |
| 380 | } |
| 381 | |
| 382 | double GetDoubleFrameSlot(unsigned offset) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 383 | intptr_t* ptr = GetFrameSlotPointer(offset); |
| 384 | #if V8_TARGET_ARCH_MIPS |
| 385 | // Prevent gcc from using load-double (mips ldc1) on (possibly) |
| 386 | // non-64-bit aligned double. Uses two lwc1 instructions. |
| 387 | union conversion { |
| 388 | double d; |
| 389 | uint32_t u[2]; |
| 390 | } c; |
| 391 | c.u[0] = *reinterpret_cast<uint32_t*>(ptr); |
| 392 | c.u[1] = *(reinterpret_cast<uint32_t*>(ptr) + 1); |
| 393 | return c.d; |
| 394 | #else |
| 395 | return *reinterpret_cast<double*>(ptr); |
| 396 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | void SetFrameSlot(unsigned offset, intptr_t value) { |
| 400 | *GetFrameSlotPointer(offset) = value; |
| 401 | } |
| 402 | |
| 403 | intptr_t GetRegister(unsigned n) const { |
| 404 | ASSERT(n < ARRAY_SIZE(registers_)); |
| 405 | return registers_[n]; |
| 406 | } |
| 407 | |
| 408 | double GetDoubleRegister(unsigned n) const { |
| 409 | ASSERT(n < ARRAY_SIZE(double_registers_)); |
| 410 | return double_registers_[n]; |
| 411 | } |
| 412 | |
| 413 | void SetRegister(unsigned n, intptr_t value) { |
| 414 | ASSERT(n < ARRAY_SIZE(registers_)); |
| 415 | registers_[n] = value; |
| 416 | } |
| 417 | |
| 418 | void SetDoubleRegister(unsigned n, double value) { |
| 419 | ASSERT(n < ARRAY_SIZE(double_registers_)); |
| 420 | double_registers_[n] = value; |
| 421 | } |
| 422 | |
| 423 | intptr_t GetTop() const { return top_; } |
| 424 | void SetTop(intptr_t top) { top_ = top; } |
| 425 | |
| 426 | intptr_t GetPc() const { return pc_; } |
| 427 | void SetPc(intptr_t pc) { pc_ = pc; } |
| 428 | |
| 429 | intptr_t GetFp() const { return fp_; } |
| 430 | void SetFp(intptr_t fp) { fp_ = fp; } |
| 431 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 432 | intptr_t GetContext() const { return context_; } |
| 433 | void SetContext(intptr_t context) { context_ = context; } |
| 434 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 435 | Smi* GetState() const { return state_; } |
| 436 | void SetState(Smi* state) { state_ = state; } |
| 437 | |
| 438 | void SetContinuation(intptr_t pc) { continuation_ = pc; } |
| 439 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 440 | StackFrame::Type GetFrameType() const { return type_; } |
| 441 | void SetFrameType(StackFrame::Type type) { type_ = type; } |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 442 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 443 | // Get the incoming arguments count. |
| 444 | int ComputeParametersCount(); |
| 445 | |
| 446 | // Get a parameter value for an unoptimized frame. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 447 | Object* GetParameter(int index); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 448 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 449 | // Get the expression stack height for a unoptimized frame. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 450 | unsigned GetExpressionCount(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 451 | |
| 452 | // Get the expression stack value for an unoptimized frame. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 453 | Object* GetExpression(int index); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 454 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 455 | static int registers_offset() { |
| 456 | return OFFSET_OF(FrameDescription, registers_); |
| 457 | } |
| 458 | |
| 459 | static int double_registers_offset() { |
| 460 | return OFFSET_OF(FrameDescription, double_registers_); |
| 461 | } |
| 462 | |
| 463 | static int frame_size_offset() { |
| 464 | return OFFSET_OF(FrameDescription, frame_size_); |
| 465 | } |
| 466 | |
| 467 | static int pc_offset() { |
| 468 | return OFFSET_OF(FrameDescription, pc_); |
| 469 | } |
| 470 | |
| 471 | static int state_offset() { |
| 472 | return OFFSET_OF(FrameDescription, state_); |
| 473 | } |
| 474 | |
| 475 | static int continuation_offset() { |
| 476 | return OFFSET_OF(FrameDescription, continuation_); |
| 477 | } |
| 478 | |
| 479 | static int frame_content_offset() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 480 | return OFFSET_OF(FrameDescription, frame_content_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | private: |
| 484 | static const uint32_t kZapUint32 = 0xbeeddead; |
| 485 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 486 | // Frame_size_ must hold a uint32_t value. It is only a uintptr_t to |
| 487 | // keep the variable-size array frame_content_ of type intptr_t at |
| 488 | // the end of the structure aligned. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 489 | uintptr_t frame_size_; // Number of bytes. |
| 490 | JSFunction* function_; |
| 491 | intptr_t registers_[Register::kNumRegisters]; |
| 492 | double double_registers_[DoubleRegister::kNumAllocatableRegisters]; |
| 493 | intptr_t top_; |
| 494 | intptr_t pc_; |
| 495 | intptr_t fp_; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 496 | intptr_t context_; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 497 | StackFrame::Type type_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 498 | Smi* state_; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 499 | #ifdef DEBUG |
| 500 | Code::Kind kind_; |
| 501 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 502 | |
| 503 | // Continuation is the PC where the execution continues after |
| 504 | // deoptimizing. |
| 505 | intptr_t continuation_; |
| 506 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 507 | // This must be at the end of the object as the object is allocated larger |
| 508 | // than it's definition indicate to extend this array. |
| 509 | intptr_t frame_content_[1]; |
| 510 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 511 | intptr_t* GetFrameSlotPointer(unsigned offset) { |
| 512 | ASSERT(offset < frame_size_); |
| 513 | return reinterpret_cast<intptr_t*>( |
| 514 | reinterpret_cast<Address>(this) + frame_content_offset() + offset); |
| 515 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 516 | |
| 517 | int ComputeFixedSize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | |
| 521 | class TranslationBuffer BASE_EMBEDDED { |
| 522 | public: |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 523 | explicit TranslationBuffer(Zone* zone) : contents_(256, zone) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 524 | |
| 525 | int CurrentIndex() const { return contents_.length(); } |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 526 | void Add(int32_t value, Zone* zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 527 | |
| 528 | Handle<ByteArray> CreateByteArray(); |
| 529 | |
| 530 | private: |
| 531 | ZoneList<uint8_t> contents_; |
| 532 | }; |
| 533 | |
| 534 | |
| 535 | class TranslationIterator BASE_EMBEDDED { |
| 536 | public: |
| 537 | TranslationIterator(ByteArray* buffer, int index) |
| 538 | : buffer_(buffer), index_(index) { |
| 539 | ASSERT(index >= 0 && index < buffer->length()); |
| 540 | } |
| 541 | |
| 542 | int32_t Next(); |
| 543 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 544 | bool HasNext() const { return index_ < buffer_->length(); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 545 | |
| 546 | void Skip(int n) { |
| 547 | for (int i = 0; i < n; i++) Next(); |
| 548 | } |
| 549 | |
| 550 | private: |
| 551 | ByteArray* buffer_; |
| 552 | int index_; |
| 553 | }; |
| 554 | |
| 555 | |
| 556 | class Translation BASE_EMBEDDED { |
| 557 | public: |
| 558 | enum Opcode { |
| 559 | BEGIN, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 560 | JS_FRAME, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 561 | CONSTRUCT_STUB_FRAME, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 562 | ARGUMENTS_ADAPTOR_FRAME, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 563 | REGISTER, |
| 564 | INT32_REGISTER, |
| 565 | DOUBLE_REGISTER, |
| 566 | STACK_SLOT, |
| 567 | INT32_STACK_SLOT, |
| 568 | DOUBLE_STACK_SLOT, |
| 569 | LITERAL, |
| 570 | ARGUMENTS_OBJECT, |
| 571 | |
| 572 | // A prefix indicating that the next command is a duplicate of the one |
| 573 | // that follows it. |
| 574 | DUPLICATE |
| 575 | }; |
| 576 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 577 | Translation(TranslationBuffer* buffer, int frame_count, int jsframe_count, |
| 578 | Zone* zone) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 579 | : buffer_(buffer), |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 580 | index_(buffer->CurrentIndex()), |
| 581 | zone_(zone) { |
| 582 | buffer_->Add(BEGIN, zone); |
| 583 | buffer_->Add(frame_count, zone); |
| 584 | buffer_->Add(jsframe_count, zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | int index() const { return index_; } |
| 588 | |
| 589 | // Commands. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 590 | void BeginJSFrame(int node_id, int literal_id, unsigned height); |
| 591 | void BeginArgumentsAdaptorFrame(int literal_id, unsigned height); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 592 | void BeginConstructStubFrame(int literal_id, unsigned height); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 593 | void StoreRegister(Register reg); |
| 594 | void StoreInt32Register(Register reg); |
| 595 | void StoreDoubleRegister(DoubleRegister reg); |
| 596 | void StoreStackSlot(int index); |
| 597 | void StoreInt32StackSlot(int index); |
| 598 | void StoreDoubleStackSlot(int index); |
| 599 | void StoreLiteral(int literal_id); |
| 600 | void StoreArgumentsObject(); |
| 601 | void MarkDuplicate(); |
| 602 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 603 | Zone* zone() const { return zone_; } |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 604 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 605 | static int NumberOfOperandsFor(Opcode opcode); |
| 606 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 607 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 608 | static const char* StringFor(Opcode opcode); |
| 609 | #endif |
| 610 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 611 | // A literal id which refers to the JSFunction itself. |
| 612 | static const int kSelfLiteralId = -239; |
| 613 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 614 | private: |
| 615 | TranslationBuffer* buffer_; |
| 616 | int index_; |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 617 | Zone* zone_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 618 | }; |
| 619 | |
| 620 | |
| 621 | // Linked list holding deoptimizing code objects. The deoptimizing code objects |
| 622 | // are kept as weak handles until they are no longer activated on the stack. |
| 623 | class DeoptimizingCodeListNode : public Malloced { |
| 624 | public: |
| 625 | explicit DeoptimizingCodeListNode(Code* code); |
| 626 | ~DeoptimizingCodeListNode(); |
| 627 | |
| 628 | DeoptimizingCodeListNode* next() const { return next_; } |
| 629 | void set_next(DeoptimizingCodeListNode* next) { next_ = next; } |
| 630 | Handle<Code> code() const { return code_; } |
| 631 | |
| 632 | private: |
| 633 | // Global (weak) handle to the deoptimizing code object. |
| 634 | Handle<Code> code_; |
| 635 | |
| 636 | // Next pointer for linked list. |
| 637 | DeoptimizingCodeListNode* next_; |
| 638 | }; |
| 639 | |
| 640 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 641 | class SlotRef BASE_EMBEDDED { |
| 642 | public: |
| 643 | enum SlotRepresentation { |
| 644 | UNKNOWN, |
| 645 | TAGGED, |
| 646 | INT32, |
| 647 | DOUBLE, |
| 648 | LITERAL |
| 649 | }; |
| 650 | |
| 651 | SlotRef() |
| 652 | : addr_(NULL), representation_(UNKNOWN) { } |
| 653 | |
| 654 | SlotRef(Address addr, SlotRepresentation representation) |
| 655 | : addr_(addr), representation_(representation) { } |
| 656 | |
| 657 | explicit SlotRef(Object* literal) |
| 658 | : literal_(literal), representation_(LITERAL) { } |
| 659 | |
| 660 | Handle<Object> GetValue() { |
| 661 | switch (representation_) { |
| 662 | case TAGGED: |
| 663 | return Handle<Object>(Memory::Object_at(addr_)); |
| 664 | |
| 665 | case INT32: { |
| 666 | int value = Memory::int32_at(addr_); |
| 667 | if (Smi::IsValid(value)) { |
| 668 | return Handle<Object>(Smi::FromInt(value)); |
| 669 | } else { |
| 670 | return Isolate::Current()->factory()->NewNumberFromInt(value); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | case DOUBLE: { |
| 675 | double value = Memory::double_at(addr_); |
| 676 | return Isolate::Current()->factory()->NewNumber(value); |
| 677 | } |
| 678 | |
| 679 | case LITERAL: |
| 680 | return literal_; |
| 681 | |
| 682 | default: |
| 683 | UNREACHABLE(); |
| 684 | return Handle<Object>::null(); |
| 685 | } |
| 686 | } |
| 687 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 688 | static Vector<SlotRef> ComputeSlotMappingForArguments( |
| 689 | JavaScriptFrame* frame, |
| 690 | int inlined_frame_index, |
| 691 | int formal_parameter_count); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 692 | |
| 693 | private: |
| 694 | Address addr_; |
| 695 | Handle<Object> literal_; |
| 696 | SlotRepresentation representation_; |
| 697 | |
| 698 | static Address SlotAddress(JavaScriptFrame* frame, int slot_index) { |
| 699 | if (slot_index >= 0) { |
| 700 | const int offset = JavaScriptFrameConstants::kLocal0Offset; |
| 701 | return frame->fp() + offset - (slot_index * kPointerSize); |
| 702 | } else { |
| 703 | const int offset = JavaScriptFrameConstants::kLastParameterOffset; |
| 704 | return frame->fp() + offset - ((slot_index + 1) * kPointerSize); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | static SlotRef ComputeSlotForNextArgument(TranslationIterator* iterator, |
| 709 | DeoptimizationInputData* data, |
| 710 | JavaScriptFrame* frame); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 711 | |
| 712 | static void ComputeSlotsForArguments( |
| 713 | Vector<SlotRef>* args_slots, |
| 714 | TranslationIterator* iterator, |
| 715 | DeoptimizationInputData* data, |
| 716 | JavaScriptFrame* frame); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 720 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 721 | // Class used to represent an unoptimized frame when the debugger |
| 722 | // needs to inspect a frame that is part of an optimized frame. The |
| 723 | // internally used FrameDescription objects are not GC safe so for use |
| 724 | // by the debugger frame information is copied to an object of this type. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 725 | // Represents parameters in unadapted form so their number might mismatch |
| 726 | // formal parameter count. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 727 | class DeoptimizedFrameInfo : public Malloced { |
| 728 | public: |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 729 | DeoptimizedFrameInfo(Deoptimizer* deoptimizer, |
| 730 | int frame_index, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 731 | bool has_arguments_adaptor, |
| 732 | bool has_construct_stub); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 733 | virtual ~DeoptimizedFrameInfo(); |
| 734 | |
| 735 | // GC support. |
| 736 | void Iterate(ObjectVisitor* v); |
| 737 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 738 | // Return the number of incoming arguments. |
| 739 | int parameters_count() { return parameters_count_; } |
| 740 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 741 | // Return the height of the expression stack. |
| 742 | int expression_count() { return expression_count_; } |
| 743 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 744 | // Get the frame function. |
| 745 | JSFunction* GetFunction() { |
| 746 | return function_; |
| 747 | } |
| 748 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 749 | // Check if this frame is preceded by construct stub frame. The bottom-most |
| 750 | // inlined frame might still be called by an uninlined construct stub. |
| 751 | bool HasConstructStub() { |
| 752 | return has_construct_stub_; |
| 753 | } |
| 754 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 755 | // Get an incoming argument. |
| 756 | Object* GetParameter(int index) { |
| 757 | ASSERT(0 <= index && index < parameters_count()); |
| 758 | return parameters_[index]; |
| 759 | } |
| 760 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 761 | // Get an expression from the expression stack. |
| 762 | Object* GetExpression(int index) { |
| 763 | ASSERT(0 <= index && index < expression_count()); |
| 764 | return expression_stack_[index]; |
| 765 | } |
| 766 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 767 | int GetSourcePosition() { |
| 768 | return source_position_; |
| 769 | } |
| 770 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 771 | private: |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 772 | // Set an incoming argument. |
| 773 | void SetParameter(int index, Object* obj) { |
| 774 | ASSERT(0 <= index && index < parameters_count()); |
| 775 | parameters_[index] = obj; |
| 776 | } |
| 777 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 778 | // Set an expression on the expression stack. |
| 779 | void SetExpression(int index, Object* obj) { |
| 780 | ASSERT(0 <= index && index < expression_count()); |
| 781 | expression_stack_[index] = obj; |
| 782 | } |
| 783 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 784 | JSFunction* function_; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 785 | bool has_construct_stub_; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 786 | int parameters_count_; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 787 | int expression_count_; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 788 | Object** parameters_; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 789 | Object** expression_stack_; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 790 | int source_position_; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 791 | |
| 792 | friend class Deoptimizer; |
| 793 | }; |
| 794 | #endif |
| 795 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 796 | } } // namespace v8::internal |
| 797 | |
| 798 | #endif // V8_DEOPTIMIZER_H_ |