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