mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1 | // Copyright 2013 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 | #include "v8.h" |
| 29 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 30 | #include "accessors.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 31 | #include "codegen.h" |
| 32 | #include "deoptimizer.h" |
| 33 | #include "disasm.h" |
| 34 | #include "full-codegen.h" |
| 35 | #include "global-handles.h" |
| 36 | #include "macro-assembler.h" |
| 37 | #include "prettyprinter.h" |
| 38 | |
| 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 43 | static MemoryChunk* AllocateCodeChunk(MemoryAllocator* allocator) { |
| 44 | return allocator->AllocateChunk(Deoptimizer::GetMaxDeoptTableSize(), |
| 45 | OS::CommitPageSize(), |
| 46 | EXECUTABLE, |
| 47 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 48 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 49 | |
| 50 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 51 | DeoptimizerData::DeoptimizerData(MemoryAllocator* allocator) |
| 52 | : allocator_(allocator), |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 53 | current_(NULL), |
| 54 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 55 | deoptimized_frame_info_(NULL), |
| 56 | #endif |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 57 | deoptimizing_code_list_(NULL) { |
| 58 | for (int i = 0; i < Deoptimizer::kBailoutTypesWithCodeEntry; ++i) { |
| 59 | deopt_entry_code_entries_[i] = -1; |
| 60 | deopt_entry_code_[i] = AllocateCodeChunk(allocator); |
| 61 | } |
| 62 | } |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 63 | |
| 64 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 65 | DeoptimizerData::~DeoptimizerData() { |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 66 | for (int i = 0; i < Deoptimizer::kBailoutTypesWithCodeEntry; ++i) { |
| 67 | allocator_->Free(deopt_entry_code_[i]); |
| 68 | deopt_entry_code_[i] = NULL; |
| 69 | } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 70 | |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 71 | DeoptimizingCodeListNode* current = deoptimizing_code_list_; |
| 72 | while (current != NULL) { |
| 73 | DeoptimizingCodeListNode* prev = current; |
| 74 | current = current->next(); |
| 75 | delete prev; |
| 76 | } |
| 77 | deoptimizing_code_list_ = NULL; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 78 | } |
| 79 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 80 | |
| 81 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 82 | void DeoptimizerData::Iterate(ObjectVisitor* v) { |
| 83 | if (deoptimized_frame_info_ != NULL) { |
| 84 | deoptimized_frame_info_->Iterate(v); |
| 85 | } |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 90 | Code* DeoptimizerData::FindDeoptimizingCode(Address addr) { |
| 91 | for (DeoptimizingCodeListNode* node = deoptimizing_code_list_; |
| 92 | node != NULL; |
| 93 | node = node->next()) { |
| 94 | if (node->code()->contains(addr)) return *node->code(); |
| 95 | } |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void DeoptimizerData::RemoveDeoptimizingCode(Code* code) { |
| 101 | for (DeoptimizingCodeListNode *prev = NULL, *cur = deoptimizing_code_list_; |
| 102 | cur != NULL; |
| 103 | prev = cur, cur = cur->next()) { |
| 104 | if (*cur->code() == code) { |
| 105 | if (prev == NULL) { |
| 106 | deoptimizing_code_list_ = cur->next(); |
| 107 | } else { |
| 108 | prev->set_next(cur->next()); |
| 109 | } |
| 110 | delete cur; |
| 111 | return; |
| 112 | } |
| 113 | } |
| 114 | // Deoptimizing code is removed through weak callback. Each object is expected |
| 115 | // to be removed once and only once. |
| 116 | UNREACHABLE(); |
| 117 | } |
| 118 | |
| 119 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 120 | // We rely on this function not causing a GC. It is called from generated code |
| 121 | // without having a real stack frame in place. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 122 | Deoptimizer* Deoptimizer::New(JSFunction* function, |
| 123 | BailoutType type, |
| 124 | unsigned bailout_id, |
| 125 | Address from, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 126 | int fp_to_sp_delta, |
| 127 | Isolate* isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | Deoptimizer* deoptimizer = new Deoptimizer(isolate, |
| 129 | function, |
| 130 | type, |
| 131 | bailout_id, |
| 132 | from, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 133 | fp_to_sp_delta, |
| 134 | NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 135 | ASSERT(isolate->deoptimizer_data()->current_ == NULL); |
| 136 | isolate->deoptimizer_data()->current_ = deoptimizer; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 137 | return deoptimizer; |
| 138 | } |
| 139 | |
| 140 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 141 | // No larger than 2K on all platforms |
| 142 | static const int kDeoptTableMaxEpilogueCodeSize = 2 * KB; |
| 143 | |
| 144 | |
| 145 | size_t Deoptimizer::GetMaxDeoptTableSize() { |
| 146 | int entries_size = |
| 147 | Deoptimizer::kMaxNumberOfEntries * Deoptimizer::table_entry_size_; |
| 148 | int commit_page_size = static_cast<int>(OS::CommitPageSize()); |
| 149 | int page_count = ((kDeoptTableMaxEpilogueCodeSize + entries_size - 1) / |
| 150 | commit_page_size) + 1; |
| 151 | return static_cast<size_t>(commit_page_size * page_count); |
| 152 | } |
| 153 | |
| 154 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 155 | Deoptimizer* Deoptimizer::Grab(Isolate* isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 156 | Deoptimizer* result = isolate->deoptimizer_data()->current_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 157 | ASSERT(result != NULL); |
| 158 | result->DeleteFrameDescriptions(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 159 | isolate->deoptimizer_data()->current_ = NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 160 | return result; |
| 161 | } |
| 162 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 163 | |
| 164 | int Deoptimizer::ConvertJSFrameIndexToFrameIndex(int jsframe_index) { |
| 165 | if (jsframe_index == 0) return 0; |
| 166 | |
| 167 | int frame_index = 0; |
| 168 | while (jsframe_index >= 0) { |
| 169 | FrameDescription* frame = output_[frame_index]; |
| 170 | if (frame->GetFrameType() == StackFrame::JAVA_SCRIPT) { |
| 171 | jsframe_index--; |
| 172 | } |
| 173 | frame_index++; |
| 174 | } |
| 175 | |
| 176 | return frame_index - 1; |
| 177 | } |
| 178 | |
| 179 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 180 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 181 | DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame( |
| 182 | JavaScriptFrame* frame, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 183 | int jsframe_index, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 184 | Isolate* isolate) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 185 | ASSERT(frame->is_optimized()); |
| 186 | ASSERT(isolate->deoptimizer_data()->deoptimized_frame_info_ == NULL); |
| 187 | |
| 188 | // Get the function and code from the frame. |
| 189 | JSFunction* function = JSFunction::cast(frame->function()); |
| 190 | Code* code = frame->LookupCode(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 191 | |
| 192 | // Locate the deoptimization point in the code. As we are at a call the |
| 193 | // return address must be at a place in the code with deoptimization support. |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 194 | SafepointEntry safepoint_entry = code->GetSafepointEntry(frame->pc()); |
| 195 | int deoptimization_index = safepoint_entry.deoptimization_index(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 196 | ASSERT(deoptimization_index != Safepoint::kNoDeoptimizationIndex); |
| 197 | |
| 198 | // Always use the actual stack slots when calculating the fp to sp |
| 199 | // delta adding two for the function and context. |
| 200 | unsigned stack_slots = code->stack_slots(); |
| 201 | unsigned fp_to_sp_delta = ((stack_slots + 2) * kPointerSize); |
| 202 | |
| 203 | Deoptimizer* deoptimizer = new Deoptimizer(isolate, |
| 204 | function, |
| 205 | Deoptimizer::DEBUGGER, |
| 206 | deoptimization_index, |
| 207 | frame->pc(), |
| 208 | fp_to_sp_delta, |
| 209 | code); |
| 210 | Address tos = frame->fp() - fp_to_sp_delta; |
| 211 | deoptimizer->FillInputFrame(tos, frame); |
| 212 | |
| 213 | // Calculate the output frames. |
| 214 | Deoptimizer::ComputeOutputFrames(deoptimizer); |
| 215 | |
| 216 | // Create the GC safe output frame information and register it for GC |
| 217 | // handling. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 218 | ASSERT_LT(jsframe_index, deoptimizer->jsframe_count()); |
| 219 | |
| 220 | // Convert JS frame index into frame index. |
| 221 | int frame_index = deoptimizer->ConvertJSFrameIndexToFrameIndex(jsframe_index); |
| 222 | |
| 223 | bool has_arguments_adaptor = |
| 224 | frame_index > 0 && |
| 225 | deoptimizer->output_[frame_index - 1]->GetFrameType() == |
| 226 | StackFrame::ARGUMENTS_ADAPTOR; |
| 227 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 228 | int construct_offset = has_arguments_adaptor ? 2 : 1; |
| 229 | bool has_construct_stub = |
| 230 | frame_index >= construct_offset && |
| 231 | deoptimizer->output_[frame_index - construct_offset]->GetFrameType() == |
| 232 | StackFrame::CONSTRUCT; |
| 233 | |
| 234 | DeoptimizedFrameInfo* info = new DeoptimizedFrameInfo(deoptimizer, |
| 235 | frame_index, |
| 236 | has_arguments_adaptor, |
| 237 | has_construct_stub); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 238 | isolate->deoptimizer_data()->deoptimized_frame_info_ = info; |
| 239 | |
| 240 | // Get the "simulated" top and size for the requested frame. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 241 | FrameDescription* parameters_frame = |
| 242 | deoptimizer->output_[ |
| 243 | has_arguments_adaptor ? (frame_index - 1) : frame_index]; |
| 244 | |
| 245 | uint32_t parameters_size = (info->parameters_count() + 1) * kPointerSize; |
| 246 | Address parameters_top = reinterpret_cast<Address>( |
| 247 | parameters_frame->GetTop() + (parameters_frame->GetFrameSize() - |
| 248 | parameters_size)); |
| 249 | |
| 250 | uint32_t expressions_size = info->expression_count() * kPointerSize; |
| 251 | Address expressions_top = reinterpret_cast<Address>( |
| 252 | deoptimizer->output_[frame_index]->GetTop()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 253 | |
| 254 | // Done with the GC-unsafe frame descriptions. This re-enables allocation. |
| 255 | deoptimizer->DeleteFrameDescriptions(); |
| 256 | |
| 257 | // Allocate a heap number for the doubles belonging to this frame. |
| 258 | deoptimizer->MaterializeHeapNumbersForDebuggerInspectableFrame( |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 259 | parameters_top, parameters_size, expressions_top, expressions_size, info); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 260 | |
| 261 | // Finished using the deoptimizer instance. |
| 262 | delete deoptimizer; |
| 263 | |
| 264 | return info; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | void Deoptimizer::DeleteDebuggerInspectableFrame(DeoptimizedFrameInfo* info, |
| 269 | Isolate* isolate) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 270 | ASSERT(isolate->deoptimizer_data()->deoptimized_frame_info_ == info); |
| 271 | delete info; |
| 272 | isolate->deoptimizer_data()->deoptimized_frame_info_ = NULL; |
| 273 | } |
| 274 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 275 | |
| 276 | void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm, |
| 277 | int count, |
| 278 | BailoutType type) { |
| 279 | TableEntryGenerator generator(masm, type, count); |
| 280 | generator.Generate(); |
| 281 | } |
| 282 | |
| 283 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 284 | void Deoptimizer::VisitAllOptimizedFunctionsForContext( |
| 285 | Context* context, OptimizedFunctionVisitor* visitor) { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 286 | Isolate* isolate = context->GetIsolate(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 287 | Zone zone(isolate); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 288 | DisallowHeapAllocation no_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 289 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 290 | ASSERT(context->IsNativeContext()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | |
| 292 | visitor->EnterContext(context); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 293 | |
| 294 | // Create a snapshot of the optimized functions list. This is needed because |
| 295 | // visitors might remove more than one link from the list at once. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 296 | ZoneList<JSFunction*> snapshot(1, &zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 297 | Object* element = context->OptimizedFunctionsListHead(); |
| 298 | while (!element->IsUndefined()) { |
| 299 | JSFunction* element_function = JSFunction::cast(element); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 300 | snapshot.Add(element_function, &zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 301 | element = element_function->next_function_link(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 302 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 303 | |
| 304 | // Run through the snapshot of optimized functions and visit them. |
| 305 | for (int i = 0; i < snapshot.length(); ++i) { |
| 306 | visitor->VisitFunction(snapshot.at(i)); |
| 307 | } |
| 308 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 309 | visitor->LeaveContext(context); |
| 310 | } |
| 311 | |
| 312 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 313 | void Deoptimizer::VisitAllOptimizedFunctions( |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 314 | Isolate* isolate, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 315 | OptimizedFunctionVisitor* visitor) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 316 | DisallowHeapAllocation no_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 317 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 318 | // Run through the list of all native contexts and deoptimize. |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 319 | Object* context = isolate->heap()->native_contexts_list(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 320 | while (!context->IsUndefined()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 321 | VisitAllOptimizedFunctionsForContext(Context::cast(context), visitor); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 322 | context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 327 | // Removes the functions selected by the given filter from the optimized |
| 328 | // function list of the given context and partitions the removed functions |
| 329 | // into one or more lists such that all functions in a list share the same |
| 330 | // code. The head of each list is written in the deoptimizing_functions field |
| 331 | // of the corresponding code object. |
| 332 | // The found code objects are returned in the given zone list. |
| 333 | static void PartitionOptimizedFunctions(Context* context, |
| 334 | OptimizedFunctionFilter* filter, |
| 335 | ZoneList<Code*>* partitions, |
| 336 | Zone* zone, |
| 337 | Object* undefined) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 338 | DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 339 | Object* current = context->get(Context::OPTIMIZED_FUNCTIONS_LIST); |
| 340 | Object* remainder_head = undefined; |
| 341 | Object* remainder_tail = undefined; |
| 342 | ASSERT_EQ(0, partitions->length()); |
| 343 | while (current != undefined) { |
| 344 | JSFunction* function = JSFunction::cast(current); |
| 345 | current = function->next_function_link(); |
| 346 | if (filter->TakeFunction(function)) { |
| 347 | Code* code = function->code(); |
| 348 | if (code->deoptimizing_functions() == undefined) { |
| 349 | partitions->Add(code, zone); |
| 350 | } else { |
| 351 | ASSERT(partitions->Contains(code)); |
| 352 | } |
| 353 | function->set_next_function_link(code->deoptimizing_functions()); |
| 354 | code->set_deoptimizing_functions(function); |
| 355 | } else { |
| 356 | if (remainder_head == undefined) { |
| 357 | remainder_head = function; |
| 358 | } else { |
| 359 | JSFunction::cast(remainder_tail)->set_next_function_link(function); |
| 360 | } |
| 361 | remainder_tail = function; |
| 362 | } |
| 363 | } |
| 364 | if (remainder_tail != undefined) { |
| 365 | JSFunction::cast(remainder_tail)->set_next_function_link(undefined); |
| 366 | } |
| 367 | context->set(Context::OPTIMIZED_FUNCTIONS_LIST, remainder_head); |
| 368 | } |
| 369 | |
| 370 | |
| 371 | class DeoptimizeAllFilter : public OptimizedFunctionFilter { |
| 372 | public: |
| 373 | virtual bool TakeFunction(JSFunction* function) { |
| 374 | return true; |
| 375 | } |
| 376 | }; |
| 377 | |
| 378 | |
| 379 | class DeoptimizeWithMatchingCodeFilter : public OptimizedFunctionFilter { |
| 380 | public: |
| 381 | explicit DeoptimizeWithMatchingCodeFilter(Code* code) : code_(code) {} |
| 382 | virtual bool TakeFunction(JSFunction* function) { |
| 383 | return function->code() == code_; |
| 384 | } |
| 385 | private: |
| 386 | Code* code_; |
| 387 | }; |
| 388 | |
| 389 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 390 | void Deoptimizer::DeoptimizeAll(Isolate* isolate) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 391 | DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 392 | |
| 393 | if (FLAG_trace_deopt) { |
| 394 | PrintF("[deoptimize all contexts]\n"); |
| 395 | } |
| 396 | |
| 397 | DeoptimizeAllFilter filter; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 398 | DeoptimizeAllFunctionsWith(isolate, &filter); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | |
| 402 | void Deoptimizer::DeoptimizeGlobalObject(JSObject* object) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 403 | DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 404 | DeoptimizeAllFilter filter; |
| 405 | if (object->IsJSGlobalProxy()) { |
| 406 | Object* proto = object->GetPrototype(); |
| 407 | ASSERT(proto->IsJSGlobalObject()); |
| 408 | DeoptimizeAllFunctionsForContext( |
| 409 | GlobalObject::cast(proto)->native_context(), &filter); |
| 410 | } else if (object->IsGlobalObject()) { |
| 411 | DeoptimizeAllFunctionsForContext( |
| 412 | GlobalObject::cast(object)->native_context(), &filter); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | |
| 417 | void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
| 418 | if (!function->IsOptimized()) return; |
| 419 | Code* code = function->code(); |
| 420 | Context* context = function->context()->native_context(); |
| 421 | Isolate* isolate = context->GetIsolate(); |
| 422 | Object* undefined = isolate->heap()->undefined_value(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 423 | Zone zone(isolate); |
| 424 | ZoneList<Code*> codes(1, &zone); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 425 | DeoptimizeWithMatchingCodeFilter filter(code); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 426 | PartitionOptimizedFunctions(context, &filter, &codes, &zone, undefined); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 427 | ASSERT_EQ(1, codes.length()); |
| 428 | DeoptimizeFunctionWithPreparedFunctionList( |
| 429 | JSFunction::cast(codes.at(0)->deoptimizing_functions())); |
| 430 | codes.at(0)->set_deoptimizing_functions(undefined); |
| 431 | } |
| 432 | |
| 433 | |
| 434 | void Deoptimizer::DeoptimizeAllFunctionsForContext( |
| 435 | Context* context, OptimizedFunctionFilter* filter) { |
| 436 | ASSERT(context->IsNativeContext()); |
| 437 | Isolate* isolate = context->GetIsolate(); |
| 438 | Object* undefined = isolate->heap()->undefined_value(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 439 | Zone zone(isolate); |
| 440 | ZoneList<Code*> codes(1, &zone); |
| 441 | PartitionOptimizedFunctions(context, filter, &codes, &zone, undefined); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 442 | for (int i = 0; i < codes.length(); ++i) { |
| 443 | DeoptimizeFunctionWithPreparedFunctionList( |
| 444 | JSFunction::cast(codes.at(i)->deoptimizing_functions())); |
| 445 | codes.at(i)->set_deoptimizing_functions(undefined); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 450 | void Deoptimizer::DeoptimizeAllFunctionsWith(Isolate* isolate, |
| 451 | OptimizedFunctionFilter* filter) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 452 | DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 453 | |
| 454 | // Run through the list of all native contexts and deoptimize. |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 455 | Object* context = isolate->heap()->native_contexts_list(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 456 | while (!context->IsUndefined()) { |
| 457 | DeoptimizeAllFunctionsForContext(Context::cast(context), filter); |
| 458 | context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 463 | void Deoptimizer::HandleWeakDeoptimizedCode(v8::Isolate* isolate, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 464 | v8::Persistent<v8::Value>* obj, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 465 | void* parameter) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 466 | DeoptimizingCodeListNode* node = |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 467 | reinterpret_cast<DeoptimizingCodeListNode*>(parameter); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 468 | DeoptimizerData* data = |
| 469 | reinterpret_cast<Isolate*>(isolate)->deoptimizer_data(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 470 | data->RemoveDeoptimizingCode(*node->code()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 471 | #ifdef DEBUG |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 472 | for (DeoptimizingCodeListNode* current = data->deoptimizing_code_list_; |
| 473 | current != NULL; |
| 474 | current = current->next()) { |
| 475 | ASSERT(current != node); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 476 | } |
| 477 | #endif |
| 478 | } |
| 479 | |
| 480 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 481 | void Deoptimizer::ComputeOutputFrames(Deoptimizer* deoptimizer) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 482 | deoptimizer->DoComputeOutputFrames(); |
| 483 | } |
| 484 | |
| 485 | |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 486 | bool Deoptimizer::TraceEnabledFor(BailoutType deopt_type, |
| 487 | StackFrame::Type frame_type) { |
| 488 | switch (deopt_type) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 489 | case EAGER: |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 490 | case SOFT: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 491 | case LAZY: |
| 492 | case DEBUGGER: |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 493 | return (frame_type == StackFrame::STUB) |
| 494 | ? FLAG_trace_stub_failures |
| 495 | : FLAG_trace_deopt; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 496 | case OSR: |
| 497 | return FLAG_trace_osr; |
| 498 | } |
| 499 | UNREACHABLE(); |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | const char* Deoptimizer::MessageFor(BailoutType type) { |
| 505 | switch (type) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 506 | case EAGER: return "eager"; |
| 507 | case SOFT: return "soft"; |
| 508 | case LAZY: return "lazy"; |
| 509 | case DEBUGGER: return "debugger"; |
| 510 | case OSR: return "OSR"; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 511 | } |
| 512 | UNREACHABLE(); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 513 | return NULL; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 517 | Deoptimizer::Deoptimizer(Isolate* isolate, |
| 518 | JSFunction* function, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 519 | BailoutType type, |
| 520 | unsigned bailout_id, |
| 521 | Address from, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 522 | int fp_to_sp_delta, |
| 523 | Code* optimized_code) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 524 | : isolate_(isolate), |
| 525 | function_(function), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 526 | bailout_id_(bailout_id), |
| 527 | bailout_type_(type), |
| 528 | from_(from), |
| 529 | fp_to_sp_delta_(fp_to_sp_delta), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 530 | has_alignment_padding_(0), |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 531 | input_(NULL), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 532 | output_count_(0), |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 533 | jsframe_count_(0), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 534 | output_(NULL), |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 535 | deferred_objects_tagged_values_(0), |
| 536 | deferred_objects_double_values_(0), |
| 537 | deferred_objects_(0), |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 538 | deferred_heap_numbers_(0), |
| 539 | trace_(false) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 540 | // For COMPILED_STUBs called from builtins, the function pointer is a SMI |
| 541 | // indicating an internal frame. |
| 542 | if (function->IsSmi()) { |
| 543 | function = NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 544 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 545 | if (function != NULL && function->IsOptimized()) { |
| 546 | function->shared()->increment_deopt_count(); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 547 | if (bailout_type_ == Deoptimizer::SOFT) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 548 | isolate->counters()->soft_deopts_executed()->Increment(); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 549 | // Soft deopts shouldn't count against the overall re-optimization count |
| 550 | // that can eventually lead to disabling optimization for a function. |
| 551 | int opt_count = function->shared()->opt_count(); |
| 552 | if (opt_count > 0) opt_count--; |
| 553 | function->shared()->set_opt_count(opt_count); |
| 554 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 555 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 556 | compiled_code_ = FindOptimizedCode(function, optimized_code); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 557 | StackFrame::Type frame_type = function == NULL |
| 558 | ? StackFrame::STUB |
| 559 | : StackFrame::JAVA_SCRIPT; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 560 | trace_ = TraceEnabledFor(type, frame_type); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 561 | #ifdef DEBUG |
| 562 | CHECK(AllowHeapAllocation::IsAllowed()); |
| 563 | disallow_heap_allocation_ = new DisallowHeapAllocation(); |
| 564 | #endif // DEBUG |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 565 | unsigned size = ComputeInputFrameSize(); |
| 566 | input_ = new(size) FrameDescription(size, function); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 567 | input_->SetFrameType(frame_type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 571 | Code* Deoptimizer::FindOptimizedCode(JSFunction* function, |
| 572 | Code* optimized_code) { |
| 573 | switch (bailout_type_) { |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 574 | case Deoptimizer::SOFT: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 575 | case Deoptimizer::EAGER: |
| 576 | ASSERT(from_ == NULL); |
| 577 | return function->code(); |
| 578 | case Deoptimizer::LAZY: { |
| 579 | Code* compiled_code = |
| 580 | isolate_->deoptimizer_data()->FindDeoptimizingCode(from_); |
| 581 | return (compiled_code == NULL) |
| 582 | ? static_cast<Code*>(isolate_->heap()->FindCodeObject(from_)) |
| 583 | : compiled_code; |
| 584 | } |
| 585 | case Deoptimizer::OSR: { |
| 586 | // The function has already been optimized and we're transitioning |
| 587 | // from the unoptimized shared version to the optimized one in the |
| 588 | // function. The return address (from_) points to unoptimized code. |
| 589 | Code* compiled_code = function->code(); |
| 590 | ASSERT(compiled_code->kind() == Code::OPTIMIZED_FUNCTION); |
| 591 | ASSERT(!compiled_code->contains(from_)); |
| 592 | return compiled_code; |
| 593 | } |
| 594 | case Deoptimizer::DEBUGGER: |
| 595 | ASSERT(optimized_code->contains(from_)); |
| 596 | return optimized_code; |
| 597 | } |
| 598 | UNREACHABLE(); |
| 599 | return NULL; |
| 600 | } |
| 601 | |
| 602 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 603 | void Deoptimizer::PrintFunctionName() { |
| 604 | if (function_->IsJSFunction()) { |
| 605 | function_->PrintName(); |
| 606 | } else { |
| 607 | PrintF("%s", Code::Kind2String(compiled_code_->kind())); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 612 | Deoptimizer::~Deoptimizer() { |
| 613 | ASSERT(input_ == NULL && output_ == NULL); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 614 | ASSERT(disallow_heap_allocation_ == NULL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
| 618 | void Deoptimizer::DeleteFrameDescriptions() { |
| 619 | delete input_; |
| 620 | for (int i = 0; i < output_count_; ++i) { |
| 621 | if (output_[i] != input_) delete output_[i]; |
| 622 | } |
| 623 | delete[] output_; |
| 624 | input_ = NULL; |
| 625 | output_ = NULL; |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 626 | #ifdef DEBUG |
| 627 | CHECK(!AllowHeapAllocation::IsAllowed()); |
| 628 | CHECK(disallow_heap_allocation_ != NULL); |
| 629 | delete disallow_heap_allocation_; |
| 630 | disallow_heap_allocation_ = NULL; |
| 631 | #endif // DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 635 | Address Deoptimizer::GetDeoptimizationEntry(Isolate* isolate, |
| 636 | int id, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 637 | BailoutType type, |
| 638 | GetEntryMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 639 | ASSERT(id >= 0); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 640 | if (id >= kMaxNumberOfEntries) return NULL; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 641 | if (mode == ENSURE_ENTRY_CODE) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 642 | EnsureCodeForDeoptimizationEntry(isolate, type, id); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 643 | } else { |
| 644 | ASSERT(mode == CALCULATE_ENTRY_ADDRESS); |
| 645 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 646 | DeoptimizerData* data = isolate->deoptimizer_data(); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 647 | ASSERT(type < kBailoutTypesWithCodeEntry); |
| 648 | MemoryChunk* base = data->deopt_entry_code_[type]; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 649 | return base->area_start() + (id * table_entry_size_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 653 | int Deoptimizer::GetDeoptimizationId(Isolate* isolate, |
| 654 | Address addr, |
| 655 | BailoutType type) { |
| 656 | DeoptimizerData* data = isolate->deoptimizer_data(); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 657 | MemoryChunk* base = data->deopt_entry_code_[type]; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 658 | Address start = base->area_start(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 659 | if (base == NULL || |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 660 | addr < start || |
| 661 | addr >= start + (kMaxNumberOfEntries * table_entry_size_)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 662 | return kNotDeoptimizationEntry; |
| 663 | } |
| 664 | ASSERT_EQ(0, |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 665 | static_cast<int>(addr - start) % table_entry_size_); |
| 666 | return static_cast<int>(addr - start) / table_entry_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 670 | int Deoptimizer::GetOutputInfo(DeoptimizationOutputData* data, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 671 | BailoutId id, |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 672 | SharedFunctionInfo* shared) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 673 | // TODO(kasperl): For now, we do a simple linear search for the PC |
| 674 | // offset associated with the given node id. This should probably be |
| 675 | // changed to a binary search. |
| 676 | int length = data->DeoptPoints(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 677 | for (int i = 0; i < length; i++) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 678 | if (data->AstId(i) == id) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 679 | return data->PcAndState(i)->value(); |
| 680 | } |
| 681 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 682 | PrintF("[couldn't find pc offset for node=%d]\n", id.ToInt()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 683 | PrintF("[method: %s]\n", *shared->DebugName()->ToCString()); |
| 684 | // Print the source code if available. |
| 685 | HeapStringAllocator string_allocator; |
| 686 | StringStream stream(&string_allocator); |
| 687 | shared->SourceCodePrint(&stream, -1); |
| 688 | PrintF("[source:\n%s\n]", *stream.ToCString()); |
| 689 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 690 | FATAL("unable to find pc offset during deoptimization"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 691 | return -1; |
| 692 | } |
| 693 | |
| 694 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 695 | int Deoptimizer::GetDeoptimizedCodeCount(Isolate* isolate) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 696 | int length = 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 697 | DeoptimizingCodeListNode* node = |
| 698 | isolate->deoptimizer_data()->deoptimizing_code_list_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 699 | while (node != NULL) { |
| 700 | length++; |
| 701 | node = node->next(); |
| 702 | } |
| 703 | return length; |
| 704 | } |
| 705 | |
| 706 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 707 | // We rely on this function not causing a GC. It is called from generated code |
| 708 | // without having a real stack frame in place. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 709 | void Deoptimizer::DoComputeOutputFrames() { |
| 710 | if (bailout_type_ == OSR) { |
| 711 | DoComputeOsrOutputFrame(); |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | // Print some helpful diagnostic information. |
| 716 | int64_t start = OS::Ticks(); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 717 | if (trace_) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 718 | PrintF("[deoptimizing (DEOPT %s): begin 0x%08" V8PRIxPTR " ", |
| 719 | MessageFor(bailout_type_), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 720 | reinterpret_cast<intptr_t>(function_)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 721 | PrintFunctionName(); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 722 | PrintF(" @%d, FP to SP delta: %d]\n", bailout_id_, fp_to_sp_delta_); |
| 723 | if (bailout_type_ == EAGER || bailout_type_ == SOFT) { |
| 724 | compiled_code_->PrintDeoptLocation(bailout_id_); |
| 725 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | // Determine basic deoptimization information. The optimized frame is |
| 729 | // described by the input data. |
| 730 | DeoptimizationInputData* input_data = |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 731 | DeoptimizationInputData::cast(compiled_code_->deoptimization_data()); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 732 | BailoutId node_id = input_data->AstId(bailout_id_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 733 | ByteArray* translations = input_data->TranslationByteArray(); |
| 734 | unsigned translation_index = |
| 735 | input_data->TranslationIndex(bailout_id_)->value(); |
| 736 | |
| 737 | // Do the input frame to output frame(s) translation. |
| 738 | TranslationIterator iterator(translations, translation_index); |
| 739 | Translation::Opcode opcode = |
| 740 | static_cast<Translation::Opcode>(iterator.Next()); |
| 741 | ASSERT(Translation::BEGIN == opcode); |
| 742 | USE(opcode); |
| 743 | // Read the number of output frames and allocate an array for their |
| 744 | // descriptions. |
| 745 | int count = iterator.Next(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 746 | iterator.Next(); // Drop JS frames count. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 747 | ASSERT(output_ == NULL); |
| 748 | output_ = new FrameDescription*[count]; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 749 | for (int i = 0; i < count; ++i) { |
| 750 | output_[i] = NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 751 | } |
| 752 | output_count_ = count; |
| 753 | |
| 754 | // Translate each output frame. |
| 755 | for (int i = 0; i < count; ++i) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 756 | // Read the ast node id, function, and frame height for this output frame. |
| 757 | Translation::Opcode opcode = |
| 758 | static_cast<Translation::Opcode>(iterator.Next()); |
| 759 | switch (opcode) { |
| 760 | case Translation::JS_FRAME: |
| 761 | DoComputeJSFrame(&iterator, i); |
| 762 | jsframe_count_++; |
| 763 | break; |
| 764 | case Translation::ARGUMENTS_ADAPTOR_FRAME: |
| 765 | DoComputeArgumentsAdaptorFrame(&iterator, i); |
| 766 | break; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 767 | case Translation::CONSTRUCT_STUB_FRAME: |
| 768 | DoComputeConstructStubFrame(&iterator, i); |
| 769 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 770 | case Translation::GETTER_STUB_FRAME: |
| 771 | DoComputeAccessorStubFrame(&iterator, i, false); |
| 772 | break; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 773 | case Translation::SETTER_STUB_FRAME: |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 774 | DoComputeAccessorStubFrame(&iterator, i, true); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 775 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 776 | case Translation::COMPILED_STUB_FRAME: |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 777 | DoComputeCompiledStubFrame(&iterator, i); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 778 | break; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 779 | case Translation::BEGIN: |
| 780 | case Translation::REGISTER: |
| 781 | case Translation::INT32_REGISTER: |
| 782 | case Translation::UINT32_REGISTER: |
| 783 | case Translation::DOUBLE_REGISTER: |
| 784 | case Translation::STACK_SLOT: |
| 785 | case Translation::INT32_STACK_SLOT: |
| 786 | case Translation::UINT32_STACK_SLOT: |
| 787 | case Translation::DOUBLE_STACK_SLOT: |
| 788 | case Translation::LITERAL: |
| 789 | case Translation::ARGUMENTS_OBJECT: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 790 | default: |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 791 | UNREACHABLE(); |
| 792 | break; |
| 793 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | // Print some helpful diagnostic information. |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 797 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 798 | double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
| 799 | int index = output_count_ - 1; // Index of the topmost frame. |
| 800 | JSFunction* function = output_[index]->GetFunction(); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 801 | PrintF("[deoptimizing (%s): end 0x%08" V8PRIxPTR " ", |
| 802 | MessageFor(bailout_type_), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 803 | reinterpret_cast<intptr_t>(function)); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 804 | PrintFunctionName(); |
| 805 | PrintF(" @%d => node=%d, pc=0x%08" V8PRIxPTR ", state=%s, alignment=%s," |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 806 | " took %0.3f ms]\n", |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 807 | bailout_id_, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 808 | node_id.ToInt(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 809 | output_[index]->GetPc(), |
| 810 | FullCodeGenerator::State2String( |
| 811 | static_cast<FullCodeGenerator::State>( |
| 812 | output_[index]->GetState()->value())), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 813 | has_alignment_padding_ ? "with padding" : "no padding", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 814 | ms); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 819 | void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, |
| 820 | int frame_index) { |
| 821 | BailoutId node_id = BailoutId(iterator->Next()); |
| 822 | JSFunction* function; |
| 823 | if (frame_index != 0) { |
| 824 | function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
| 825 | } else { |
| 826 | int closure_id = iterator->Next(); |
| 827 | USE(closure_id); |
| 828 | ASSERT_EQ(Translation::kSelfLiteralId, closure_id); |
| 829 | function = function_; |
| 830 | } |
| 831 | unsigned height = iterator->Next(); |
| 832 | unsigned height_in_bytes = height * kPointerSize; |
| 833 | if (trace_) { |
| 834 | PrintF(" translating "); |
| 835 | function->PrintName(); |
| 836 | PrintF(" => node=%d, height=%d\n", node_id.ToInt(), height_in_bytes); |
| 837 | } |
| 838 | |
| 839 | // The 'fixed' part of the frame consists of the incoming parameters and |
| 840 | // the part described by JavaScriptFrameConstants. |
| 841 | unsigned fixed_frame_size = ComputeFixedSize(function); |
| 842 | unsigned input_frame_size = input_->GetFrameSize(); |
| 843 | unsigned output_frame_size = height_in_bytes + fixed_frame_size; |
| 844 | |
| 845 | // Allocate and store the output frame description. |
| 846 | FrameDescription* output_frame = |
| 847 | new(output_frame_size) FrameDescription(output_frame_size, function); |
| 848 | output_frame->SetFrameType(StackFrame::JAVA_SCRIPT); |
| 849 | |
| 850 | bool is_bottommost = (0 == frame_index); |
| 851 | bool is_topmost = (output_count_ - 1 == frame_index); |
| 852 | ASSERT(frame_index >= 0 && frame_index < output_count_); |
| 853 | ASSERT(output_[frame_index] == NULL); |
| 854 | output_[frame_index] = output_frame; |
| 855 | |
| 856 | // The top address for the bottommost output frame can be computed from |
| 857 | // the input frame pointer and the output frame's height. For all |
| 858 | // subsequent output frames, it can be computed from the previous one's |
| 859 | // top address and the current frame's size. |
| 860 | Register fp_reg = JavaScriptFrame::fp_register(); |
| 861 | intptr_t top_address; |
| 862 | if (is_bottommost) { |
| 863 | // Determine whether the input frame contains alignment padding. |
| 864 | has_alignment_padding_ = HasAlignmentPadding(function) ? 1 : 0; |
| 865 | // 2 = context and function in the frame. |
| 866 | // If the optimized frame had alignment padding, adjust the frame pointer |
| 867 | // to point to the new position of the old frame pointer after padding |
| 868 | // is removed. Subtract 2 * kPointerSize for the context and function slots. |
| 869 | top_address = input_->GetRegister(fp_reg.code()) - (2 * kPointerSize) - |
| 870 | height_in_bytes + has_alignment_padding_ * kPointerSize; |
| 871 | } else { |
| 872 | top_address = output_[frame_index - 1]->GetTop() - output_frame_size; |
| 873 | } |
| 874 | output_frame->SetTop(top_address); |
| 875 | |
| 876 | // Compute the incoming parameter translation. |
| 877 | int parameter_count = function->shared()->formal_parameter_count() + 1; |
| 878 | unsigned output_offset = output_frame_size; |
| 879 | unsigned input_offset = input_frame_size; |
| 880 | for (int i = 0; i < parameter_count; ++i) { |
| 881 | output_offset -= kPointerSize; |
| 882 | DoTranslateCommand(iterator, frame_index, output_offset); |
| 883 | } |
| 884 | input_offset -= (parameter_count * kPointerSize); |
| 885 | |
| 886 | // There are no translation commands for the caller's pc and fp, the |
| 887 | // context, and the function. Synthesize their values and set them up |
| 888 | // explicitly. |
| 889 | // |
| 890 | // The caller's pc for the bottommost output frame is the same as in the |
| 891 | // input frame. For all subsequent output frames, it can be read from the |
| 892 | // previous one. This frame's pc can be computed from the non-optimized |
| 893 | // function code and AST id of the bailout. |
| 894 | output_offset -= kPointerSize; |
| 895 | input_offset -= kPointerSize; |
| 896 | intptr_t value; |
| 897 | if (is_bottommost) { |
| 898 | value = input_->GetFrameSlot(input_offset); |
| 899 | } else { |
| 900 | value = output_[frame_index - 1]->GetPc(); |
| 901 | } |
| 902 | output_frame->SetFrameSlot(output_offset, value); |
| 903 | if (trace_) { |
| 904 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 905 | V8PRIxPTR " ; caller's pc\n", |
| 906 | top_address + output_offset, output_offset, value); |
| 907 | } |
| 908 | |
| 909 | // The caller's frame pointer for the bottommost output frame is the same |
| 910 | // as in the input frame. For all subsequent output frames, it can be |
| 911 | // read from the previous one. Also compute and set this frame's frame |
| 912 | // pointer. |
| 913 | output_offset -= kPointerSize; |
| 914 | input_offset -= kPointerSize; |
| 915 | if (is_bottommost) { |
| 916 | value = input_->GetFrameSlot(input_offset); |
| 917 | } else { |
| 918 | value = output_[frame_index - 1]->GetFp(); |
| 919 | } |
| 920 | output_frame->SetFrameSlot(output_offset, value); |
| 921 | intptr_t fp_value = top_address + output_offset; |
| 922 | ASSERT(!is_bottommost || (input_->GetRegister(fp_reg.code()) + |
| 923 | has_alignment_padding_ * kPointerSize) == fp_value); |
| 924 | output_frame->SetFp(fp_value); |
| 925 | if (is_topmost) output_frame->SetRegister(fp_reg.code(), fp_value); |
| 926 | if (trace_) { |
| 927 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 928 | V8PRIxPTR " ; caller's fp\n", |
| 929 | fp_value, output_offset, value); |
| 930 | } |
| 931 | ASSERT(!is_bottommost || !has_alignment_padding_ || |
| 932 | (fp_value & kPointerSize) != 0); |
| 933 | |
| 934 | // For the bottommost output frame the context can be gotten from the input |
| 935 | // frame. For all subsequent output frames it can be gotten from the function |
| 936 | // so long as we don't inline functions that need local contexts. |
| 937 | Register context_reg = JavaScriptFrame::context_register(); |
| 938 | output_offset -= kPointerSize; |
| 939 | input_offset -= kPointerSize; |
| 940 | if (is_bottommost) { |
| 941 | value = input_->GetFrameSlot(input_offset); |
| 942 | } else { |
| 943 | value = reinterpret_cast<intptr_t>(function->context()); |
| 944 | } |
| 945 | output_frame->SetFrameSlot(output_offset, value); |
| 946 | output_frame->SetContext(value); |
| 947 | if (is_topmost) output_frame->SetRegister(context_reg.code(), value); |
| 948 | if (trace_) { |
| 949 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 950 | V8PRIxPTR "; context\n", |
| 951 | top_address + output_offset, output_offset, value); |
| 952 | } |
| 953 | |
| 954 | // The function was mentioned explicitly in the BEGIN_FRAME. |
| 955 | output_offset -= kPointerSize; |
| 956 | input_offset -= kPointerSize; |
| 957 | value = reinterpret_cast<intptr_t>(function); |
| 958 | // The function for the bottommost output frame should also agree with the |
| 959 | // input frame. |
| 960 | ASSERT(!is_bottommost || input_->GetFrameSlot(input_offset) == value); |
| 961 | output_frame->SetFrameSlot(output_offset, value); |
| 962 | if (trace_) { |
| 963 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 964 | V8PRIxPTR "; function\n", |
| 965 | top_address + output_offset, output_offset, value); |
| 966 | } |
| 967 | |
| 968 | // Translate the rest of the frame. |
| 969 | for (unsigned i = 0; i < height; ++i) { |
| 970 | output_offset -= kPointerSize; |
| 971 | DoTranslateCommand(iterator, frame_index, output_offset); |
| 972 | } |
| 973 | ASSERT(0 == output_offset); |
| 974 | |
| 975 | // Compute this frame's PC, state, and continuation. |
| 976 | Code* non_optimized_code = function->shared()->code(); |
| 977 | FixedArray* raw_data = non_optimized_code->deoptimization_data(); |
| 978 | DeoptimizationOutputData* data = DeoptimizationOutputData::cast(raw_data); |
| 979 | Address start = non_optimized_code->instruction_start(); |
| 980 | unsigned pc_and_state = GetOutputInfo(data, node_id, function->shared()); |
| 981 | unsigned pc_offset = FullCodeGenerator::PcField::decode(pc_and_state); |
| 982 | intptr_t pc_value = reinterpret_cast<intptr_t>(start + pc_offset); |
| 983 | output_frame->SetPc(pc_value); |
| 984 | |
| 985 | FullCodeGenerator::State state = |
| 986 | FullCodeGenerator::StateField::decode(pc_and_state); |
| 987 | output_frame->SetState(Smi::FromInt(state)); |
| 988 | |
| 989 | // Set the continuation for the topmost frame. |
| 990 | if (is_topmost && bailout_type_ != DEBUGGER) { |
| 991 | Builtins* builtins = isolate_->builtins(); |
| 992 | Code* continuation = builtins->builtin(Builtins::kNotifyDeoptimized); |
| 993 | if (bailout_type_ == LAZY) { |
| 994 | continuation = builtins->builtin(Builtins::kNotifyLazyDeoptimized); |
| 995 | } else if (bailout_type_ == SOFT) { |
| 996 | continuation = builtins->builtin(Builtins::kNotifySoftDeoptimized); |
| 997 | } else { |
| 998 | ASSERT(bailout_type_ == EAGER); |
| 999 | } |
| 1000 | output_frame->SetContinuation( |
| 1001 | reinterpret_cast<intptr_t>(continuation->entry())); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1006 | void Deoptimizer::DoComputeArgumentsAdaptorFrame(TranslationIterator* iterator, |
| 1007 | int frame_index) { |
| 1008 | JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
| 1009 | unsigned height = iterator->Next(); |
| 1010 | unsigned height_in_bytes = height * kPointerSize; |
| 1011 | if (trace_) { |
| 1012 | PrintF(" translating arguments adaptor => height=%d\n", height_in_bytes); |
| 1013 | } |
| 1014 | |
| 1015 | unsigned fixed_frame_size = ArgumentsAdaptorFrameConstants::kFrameSize; |
| 1016 | unsigned output_frame_size = height_in_bytes + fixed_frame_size; |
| 1017 | |
| 1018 | // Allocate and store the output frame description. |
| 1019 | FrameDescription* output_frame = |
| 1020 | new(output_frame_size) FrameDescription(output_frame_size, function); |
| 1021 | output_frame->SetFrameType(StackFrame::ARGUMENTS_ADAPTOR); |
| 1022 | |
| 1023 | // Arguments adaptor can not be topmost or bottommost. |
| 1024 | ASSERT(frame_index > 0 && frame_index < output_count_ - 1); |
| 1025 | ASSERT(output_[frame_index] == NULL); |
| 1026 | output_[frame_index] = output_frame; |
| 1027 | |
| 1028 | // The top address of the frame is computed from the previous |
| 1029 | // frame's top and this frame's size. |
| 1030 | intptr_t top_address; |
| 1031 | top_address = output_[frame_index - 1]->GetTop() - output_frame_size; |
| 1032 | output_frame->SetTop(top_address); |
| 1033 | |
| 1034 | // Compute the incoming parameter translation. |
| 1035 | int parameter_count = height; |
| 1036 | unsigned output_offset = output_frame_size; |
| 1037 | for (int i = 0; i < parameter_count; ++i) { |
| 1038 | output_offset -= kPointerSize; |
| 1039 | DoTranslateCommand(iterator, frame_index, output_offset); |
| 1040 | } |
| 1041 | |
| 1042 | // Read caller's PC from the previous frame. |
| 1043 | output_offset -= kPointerSize; |
| 1044 | intptr_t callers_pc = output_[frame_index - 1]->GetPc(); |
| 1045 | output_frame->SetFrameSlot(output_offset, callers_pc); |
| 1046 | if (trace_) { |
| 1047 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1048 | V8PRIxPTR " ; caller's pc\n", |
| 1049 | top_address + output_offset, output_offset, callers_pc); |
| 1050 | } |
| 1051 | |
| 1052 | // Read caller's FP from the previous frame, and set this frame's FP. |
| 1053 | output_offset -= kPointerSize; |
| 1054 | intptr_t value = output_[frame_index - 1]->GetFp(); |
| 1055 | output_frame->SetFrameSlot(output_offset, value); |
| 1056 | intptr_t fp_value = top_address + output_offset; |
| 1057 | output_frame->SetFp(fp_value); |
| 1058 | if (trace_) { |
| 1059 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1060 | V8PRIxPTR " ; caller's fp\n", |
| 1061 | fp_value, output_offset, value); |
| 1062 | } |
| 1063 | |
| 1064 | // A marker value is used in place of the context. |
| 1065 | output_offset -= kPointerSize; |
| 1066 | intptr_t context = reinterpret_cast<intptr_t>( |
| 1067 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 1068 | output_frame->SetFrameSlot(output_offset, context); |
| 1069 | if (trace_) { |
| 1070 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1071 | V8PRIxPTR " ; context (adaptor sentinel)\n", |
| 1072 | top_address + output_offset, output_offset, context); |
| 1073 | } |
| 1074 | |
| 1075 | // The function was mentioned explicitly in the ARGUMENTS_ADAPTOR_FRAME. |
| 1076 | output_offset -= kPointerSize; |
| 1077 | value = reinterpret_cast<intptr_t>(function); |
| 1078 | output_frame->SetFrameSlot(output_offset, value); |
| 1079 | if (trace_) { |
| 1080 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1081 | V8PRIxPTR " ; function\n", |
| 1082 | top_address + output_offset, output_offset, value); |
| 1083 | } |
| 1084 | |
| 1085 | // Number of incoming arguments. |
| 1086 | output_offset -= kPointerSize; |
| 1087 | value = reinterpret_cast<intptr_t>(Smi::FromInt(height - 1)); |
| 1088 | output_frame->SetFrameSlot(output_offset, value); |
| 1089 | if (trace_) { |
| 1090 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1091 | V8PRIxPTR " ; argc (%d)\n", |
| 1092 | top_address + output_offset, output_offset, value, height - 1); |
| 1093 | } |
| 1094 | |
| 1095 | ASSERT(0 == output_offset); |
| 1096 | |
| 1097 | Builtins* builtins = isolate_->builtins(); |
| 1098 | Code* adaptor_trampoline = |
| 1099 | builtins->builtin(Builtins::kArgumentsAdaptorTrampoline); |
| 1100 | intptr_t pc_value = reinterpret_cast<intptr_t>( |
| 1101 | adaptor_trampoline->instruction_start() + |
| 1102 | isolate_->heap()->arguments_adaptor_deopt_pc_offset()->value()); |
| 1103 | output_frame->SetPc(pc_value); |
| 1104 | } |
| 1105 | |
| 1106 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1107 | void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, |
| 1108 | int frame_index) { |
| 1109 | Builtins* builtins = isolate_->builtins(); |
| 1110 | Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric); |
| 1111 | JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
| 1112 | unsigned height = iterator->Next(); |
| 1113 | unsigned height_in_bytes = height * kPointerSize; |
| 1114 | if (trace_) { |
| 1115 | PrintF(" translating construct stub => height=%d\n", height_in_bytes); |
| 1116 | } |
| 1117 | |
| 1118 | unsigned fixed_frame_size = ConstructFrameConstants::kFrameSize; |
| 1119 | unsigned output_frame_size = height_in_bytes + fixed_frame_size; |
| 1120 | |
| 1121 | // Allocate and store the output frame description. |
| 1122 | FrameDescription* output_frame = |
| 1123 | new(output_frame_size) FrameDescription(output_frame_size, function); |
| 1124 | output_frame->SetFrameType(StackFrame::CONSTRUCT); |
| 1125 | |
| 1126 | // Construct stub can not be topmost or bottommost. |
| 1127 | ASSERT(frame_index > 0 && frame_index < output_count_ - 1); |
| 1128 | ASSERT(output_[frame_index] == NULL); |
| 1129 | output_[frame_index] = output_frame; |
| 1130 | |
| 1131 | // The top address of the frame is computed from the previous |
| 1132 | // frame's top and this frame's size. |
| 1133 | intptr_t top_address; |
| 1134 | top_address = output_[frame_index - 1]->GetTop() - output_frame_size; |
| 1135 | output_frame->SetTop(top_address); |
| 1136 | |
| 1137 | // Compute the incoming parameter translation. |
| 1138 | int parameter_count = height; |
| 1139 | unsigned output_offset = output_frame_size; |
| 1140 | for (int i = 0; i < parameter_count; ++i) { |
| 1141 | output_offset -= kPointerSize; |
| 1142 | DoTranslateCommand(iterator, frame_index, output_offset); |
| 1143 | } |
| 1144 | |
| 1145 | // Read caller's PC from the previous frame. |
| 1146 | output_offset -= kPointerSize; |
| 1147 | intptr_t callers_pc = output_[frame_index - 1]->GetPc(); |
| 1148 | output_frame->SetFrameSlot(output_offset, callers_pc); |
| 1149 | if (trace_) { |
| 1150 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1151 | V8PRIxPTR " ; caller's pc\n", |
| 1152 | top_address + output_offset, output_offset, callers_pc); |
| 1153 | } |
| 1154 | |
| 1155 | // Read caller's FP from the previous frame, and set this frame's FP. |
| 1156 | output_offset -= kPointerSize; |
| 1157 | intptr_t value = output_[frame_index - 1]->GetFp(); |
| 1158 | output_frame->SetFrameSlot(output_offset, value); |
| 1159 | intptr_t fp_value = top_address + output_offset; |
| 1160 | output_frame->SetFp(fp_value); |
| 1161 | if (trace_) { |
| 1162 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1163 | V8PRIxPTR " ; caller's fp\n", |
| 1164 | fp_value, output_offset, value); |
| 1165 | } |
| 1166 | |
| 1167 | // The context can be gotten from the previous frame. |
| 1168 | output_offset -= kPointerSize; |
| 1169 | value = output_[frame_index - 1]->GetContext(); |
| 1170 | output_frame->SetFrameSlot(output_offset, value); |
| 1171 | if (trace_) { |
| 1172 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1173 | V8PRIxPTR " ; context\n", |
| 1174 | top_address + output_offset, output_offset, value); |
| 1175 | } |
| 1176 | |
| 1177 | // A marker value is used in place of the function. |
| 1178 | output_offset -= kPointerSize; |
| 1179 | value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::CONSTRUCT)); |
| 1180 | output_frame->SetFrameSlot(output_offset, value); |
| 1181 | if (trace_) { |
| 1182 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1183 | V8PRIxPTR " ; function (construct sentinel)\n", |
| 1184 | top_address + output_offset, output_offset, value); |
| 1185 | } |
| 1186 | |
| 1187 | // The output frame reflects a JSConstructStubGeneric frame. |
| 1188 | output_offset -= kPointerSize; |
| 1189 | value = reinterpret_cast<intptr_t>(construct_stub); |
| 1190 | output_frame->SetFrameSlot(output_offset, value); |
| 1191 | if (trace_) { |
| 1192 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1193 | V8PRIxPTR " ; code object\n", |
| 1194 | top_address + output_offset, output_offset, value); |
| 1195 | } |
| 1196 | |
| 1197 | // Number of incoming arguments. |
| 1198 | output_offset -= kPointerSize; |
| 1199 | value = reinterpret_cast<intptr_t>(Smi::FromInt(height - 1)); |
| 1200 | output_frame->SetFrameSlot(output_offset, value); |
| 1201 | if (trace_) { |
| 1202 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1203 | V8PRIxPTR " ; argc (%d)\n", |
| 1204 | top_address + output_offset, output_offset, value, height - 1); |
| 1205 | } |
| 1206 | |
| 1207 | // Constructor function being invoked by the stub (only present on some |
| 1208 | // architectures, indicated by kConstructorOffset). |
| 1209 | if (ConstructFrameConstants::kConstructorOffset != kMinInt) { |
| 1210 | output_offset -= kPointerSize; |
| 1211 | value = reinterpret_cast<intptr_t>(function); |
| 1212 | output_frame->SetFrameSlot(output_offset, value); |
| 1213 | if (trace_) { |
| 1214 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1215 | V8PRIxPTR " ; constructor function\n", |
| 1216 | top_address + output_offset, output_offset, value); |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | // The newly allocated object was passed as receiver in the artificial |
| 1221 | // constructor stub environment created by HEnvironment::CopyForInlining(). |
| 1222 | output_offset -= kPointerSize; |
| 1223 | value = output_frame->GetFrameSlot(output_frame_size - kPointerSize); |
| 1224 | output_frame->SetFrameSlot(output_offset, value); |
| 1225 | if (trace_) { |
| 1226 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1227 | V8PRIxPTR " ; allocated receiver\n", |
| 1228 | top_address + output_offset, output_offset, value); |
| 1229 | } |
| 1230 | |
| 1231 | ASSERT(0 == output_offset); |
| 1232 | |
| 1233 | intptr_t pc = reinterpret_cast<intptr_t>( |
| 1234 | construct_stub->instruction_start() + |
| 1235 | isolate_->heap()->construct_stub_deopt_pc_offset()->value()); |
| 1236 | output_frame->SetPc(pc); |
| 1237 | } |
| 1238 | |
| 1239 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1240 | void Deoptimizer::DoComputeAccessorStubFrame(TranslationIterator* iterator, |
| 1241 | int frame_index, |
| 1242 | bool is_setter_stub_frame) { |
| 1243 | JSFunction* accessor = JSFunction::cast(ComputeLiteral(iterator->Next())); |
| 1244 | // The receiver (and the implicit return value, if any) are expected in |
| 1245 | // registers by the LoadIC/StoreIC, so they don't belong to the output stack |
| 1246 | // frame. This means that we have to use a height of 0. |
| 1247 | unsigned height = 0; |
| 1248 | unsigned height_in_bytes = height * kPointerSize; |
| 1249 | const char* kind = is_setter_stub_frame ? "setter" : "getter"; |
| 1250 | if (trace_) { |
| 1251 | PrintF(" translating %s stub => height=%u\n", kind, height_in_bytes); |
| 1252 | } |
| 1253 | |
| 1254 | // We need 1 stack entry for the return address + 4 stack entries from |
| 1255 | // StackFrame::INTERNAL (FP, context, frame type, code object, see |
| 1256 | // MacroAssembler::EnterFrame). For a setter stub frame we need one additional |
| 1257 | // entry for the implicit return value, see |
| 1258 | // StoreStubCompiler::CompileStoreViaSetter. |
| 1259 | unsigned fixed_frame_entries = 1 + 4 + (is_setter_stub_frame ? 1 : 0); |
| 1260 | unsigned fixed_frame_size = fixed_frame_entries * kPointerSize; |
| 1261 | unsigned output_frame_size = height_in_bytes + fixed_frame_size; |
| 1262 | |
| 1263 | // Allocate and store the output frame description. |
| 1264 | FrameDescription* output_frame = |
| 1265 | new(output_frame_size) FrameDescription(output_frame_size, accessor); |
| 1266 | output_frame->SetFrameType(StackFrame::INTERNAL); |
| 1267 | |
| 1268 | // A frame for an accessor stub can not be the topmost or bottommost one. |
| 1269 | ASSERT(frame_index > 0 && frame_index < output_count_ - 1); |
| 1270 | ASSERT(output_[frame_index] == NULL); |
| 1271 | output_[frame_index] = output_frame; |
| 1272 | |
| 1273 | // The top address of the frame is computed from the previous frame's top and |
| 1274 | // this frame's size. |
| 1275 | intptr_t top_address = output_[frame_index - 1]->GetTop() - output_frame_size; |
| 1276 | output_frame->SetTop(top_address); |
| 1277 | |
| 1278 | unsigned output_offset = output_frame_size; |
| 1279 | |
| 1280 | // Read caller's PC from the previous frame. |
| 1281 | output_offset -= kPointerSize; |
| 1282 | intptr_t callers_pc = output_[frame_index - 1]->GetPc(); |
| 1283 | output_frame->SetFrameSlot(output_offset, callers_pc); |
| 1284 | if (trace_) { |
| 1285 | PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR |
| 1286 | " ; caller's pc\n", |
| 1287 | top_address + output_offset, output_offset, callers_pc); |
| 1288 | } |
| 1289 | |
| 1290 | // Read caller's FP from the previous frame, and set this frame's FP. |
| 1291 | output_offset -= kPointerSize; |
| 1292 | intptr_t value = output_[frame_index - 1]->GetFp(); |
| 1293 | output_frame->SetFrameSlot(output_offset, value); |
| 1294 | intptr_t fp_value = top_address + output_offset; |
| 1295 | output_frame->SetFp(fp_value); |
| 1296 | if (trace_) { |
| 1297 | PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR |
| 1298 | " ; caller's fp\n", |
| 1299 | fp_value, output_offset, value); |
| 1300 | } |
| 1301 | |
| 1302 | // The context can be gotten from the previous frame. |
| 1303 | output_offset -= kPointerSize; |
| 1304 | value = output_[frame_index - 1]->GetContext(); |
| 1305 | output_frame->SetFrameSlot(output_offset, value); |
| 1306 | if (trace_) { |
| 1307 | PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR |
| 1308 | " ; context\n", |
| 1309 | top_address + output_offset, output_offset, value); |
| 1310 | } |
| 1311 | |
| 1312 | // A marker value is used in place of the function. |
| 1313 | output_offset -= kPointerSize; |
| 1314 | value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::INTERNAL)); |
| 1315 | output_frame->SetFrameSlot(output_offset, value); |
| 1316 | if (trace_) { |
| 1317 | PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR |
| 1318 | " ; function (%s sentinel)\n", |
| 1319 | top_address + output_offset, output_offset, value, kind); |
| 1320 | } |
| 1321 | |
| 1322 | // Get Code object from accessor stub. |
| 1323 | output_offset -= kPointerSize; |
| 1324 | Builtins::Name name = is_setter_stub_frame ? |
| 1325 | Builtins::kStoreIC_Setter_ForDeopt : |
| 1326 | Builtins::kLoadIC_Getter_ForDeopt; |
| 1327 | Code* accessor_stub = isolate_->builtins()->builtin(name); |
| 1328 | value = reinterpret_cast<intptr_t>(accessor_stub); |
| 1329 | output_frame->SetFrameSlot(output_offset, value); |
| 1330 | if (trace_) { |
| 1331 | PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR |
| 1332 | " ; code object\n", |
| 1333 | top_address + output_offset, output_offset, value); |
| 1334 | } |
| 1335 | |
| 1336 | // Skip receiver. |
| 1337 | Translation::Opcode opcode = |
| 1338 | static_cast<Translation::Opcode>(iterator->Next()); |
| 1339 | iterator->Skip(Translation::NumberOfOperandsFor(opcode)); |
| 1340 | |
| 1341 | if (is_setter_stub_frame) { |
| 1342 | // The implicit return value was part of the artificial setter stub |
| 1343 | // environment. |
| 1344 | output_offset -= kPointerSize; |
| 1345 | DoTranslateCommand(iterator, frame_index, output_offset); |
| 1346 | } |
| 1347 | |
| 1348 | ASSERT(0 == output_offset); |
| 1349 | |
| 1350 | Smi* offset = is_setter_stub_frame ? |
| 1351 | isolate_->heap()->setter_stub_deopt_pc_offset() : |
| 1352 | isolate_->heap()->getter_stub_deopt_pc_offset(); |
| 1353 | intptr_t pc = reinterpret_cast<intptr_t>( |
| 1354 | accessor_stub->instruction_start() + offset->value()); |
| 1355 | output_frame->SetPc(pc); |
| 1356 | } |
| 1357 | |
| 1358 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1359 | void Deoptimizer::DoComputeCompiledStubFrame(TranslationIterator* iterator, |
| 1360 | int frame_index) { |
| 1361 | // |
| 1362 | // FROM TO |
| 1363 | // | .... | | .... | |
| 1364 | // +-------------------------+ +-------------------------+ |
| 1365 | // | JSFunction continuation | | JSFunction continuation | |
| 1366 | // +-------------------------+ +-------------------------+ |
| 1367 | // | | saved frame (FP) | | saved frame (FP) | |
| 1368 | // | +=========================+<-fpreg +=========================+<-fpreg |
| 1369 | // | | JSFunction context | | JSFunction context | |
| 1370 | // v +-------------------------+ +-------------------------| |
| 1371 | // | COMPILED_STUB marker | | STUB_FAILURE marker | |
| 1372 | // +-------------------------+ +-------------------------+ |
| 1373 | // | | | caller args.arguments_ | |
| 1374 | // | ... | +-------------------------+ |
| 1375 | // | | | caller args.length_ | |
| 1376 | // |-------------------------|<-spreg +-------------------------+ |
| 1377 | // | caller args pointer | |
| 1378 | // +-------------------------+ |
| 1379 | // | caller stack param 1 | |
| 1380 | // parameters in registers +-------------------------+ |
| 1381 | // and spilled to stack | .... | |
| 1382 | // +-------------------------+ |
| 1383 | // | caller stack param n | |
| 1384 | // +-------------------------+<-spreg |
| 1385 | // reg = number of parameters |
| 1386 | // reg = failure handler address |
| 1387 | // reg = saved frame |
| 1388 | // reg = JSFunction context |
| 1389 | // |
| 1390 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1391 | ASSERT(compiled_code_->is_crankshafted() && |
| 1392 | compiled_code_->kind() != Code::OPTIMIZED_FUNCTION); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1393 | int major_key = compiled_code_->major_key(); |
| 1394 | CodeStubInterfaceDescriptor* descriptor = |
| 1395 | isolate_->code_stub_interface_descriptor(major_key); |
| 1396 | |
| 1397 | // The output frame must have room for all pushed register parameters |
| 1398 | // and the standard stack frame slots. Include space for an argument |
| 1399 | // object to the callee and optionally the space to pass the argument |
| 1400 | // object to the stub failure handler. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1401 | ASSERT(descriptor->register_param_count_ >= 0); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1402 | int height_in_bytes = kPointerSize * descriptor->register_param_count_ + |
| 1403 | sizeof(Arguments) + kPointerSize; |
| 1404 | int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; |
| 1405 | int input_frame_size = input_->GetFrameSize(); |
| 1406 | int output_frame_size = height_in_bytes + fixed_frame_size; |
| 1407 | if (trace_) { |
| 1408 | PrintF(" translating %s => StubFailureTrampolineStub, height=%d\n", |
| 1409 | CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), |
| 1410 | height_in_bytes); |
| 1411 | } |
| 1412 | |
| 1413 | // The stub failure trampoline is a single frame. |
| 1414 | FrameDescription* output_frame = |
| 1415 | new(output_frame_size) FrameDescription(output_frame_size, NULL); |
| 1416 | output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 1417 | ASSERT(frame_index == 0); |
| 1418 | output_[frame_index] = output_frame; |
| 1419 | |
| 1420 | // The top address for the output frame can be computed from the input |
| 1421 | // frame pointer and the output frame's height. Subtract space for the |
| 1422 | // context and function slots. |
| 1423 | Register fp_reg = StubFailureTrampolineFrame::fp_register(); |
| 1424 | intptr_t top_address = input_->GetRegister(fp_reg.code()) - |
| 1425 | (2 * kPointerSize) - height_in_bytes; |
| 1426 | output_frame->SetTop(top_address); |
| 1427 | |
| 1428 | // Read caller's PC (JSFunction continuation) from the input frame. |
| 1429 | unsigned input_frame_offset = input_frame_size - kPointerSize; |
| 1430 | unsigned output_frame_offset = output_frame_size - kPointerSize; |
| 1431 | intptr_t value = input_->GetFrameSlot(input_frame_offset); |
| 1432 | output_frame->SetFrameSlot(output_frame_offset, value); |
| 1433 | if (trace_) { |
| 1434 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1435 | V8PRIxPTR " ; caller's pc\n", |
| 1436 | top_address + output_frame_offset, output_frame_offset, value); |
| 1437 | } |
| 1438 | |
| 1439 | // Read caller's FP from the input frame, and set this frame's FP. |
| 1440 | input_frame_offset -= kPointerSize; |
| 1441 | value = input_->GetFrameSlot(input_frame_offset); |
| 1442 | output_frame_offset -= kPointerSize; |
| 1443 | output_frame->SetFrameSlot(output_frame_offset, value); |
| 1444 | intptr_t frame_ptr = input_->GetRegister(fp_reg.code()); |
| 1445 | output_frame->SetRegister(fp_reg.code(), frame_ptr); |
| 1446 | output_frame->SetFp(frame_ptr); |
| 1447 | if (trace_) { |
| 1448 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1449 | V8PRIxPTR " ; caller's fp\n", |
| 1450 | top_address + output_frame_offset, output_frame_offset, value); |
| 1451 | } |
| 1452 | |
| 1453 | // The context can be gotten from the input frame. |
| 1454 | Register context_reg = StubFailureTrampolineFrame::context_register(); |
| 1455 | input_frame_offset -= kPointerSize; |
| 1456 | value = input_->GetFrameSlot(input_frame_offset); |
| 1457 | output_frame->SetRegister(context_reg.code(), value); |
| 1458 | output_frame_offset -= kPointerSize; |
| 1459 | output_frame->SetFrameSlot(output_frame_offset, value); |
| 1460 | if (trace_) { |
| 1461 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1462 | V8PRIxPTR " ; context\n", |
| 1463 | top_address + output_frame_offset, output_frame_offset, value); |
| 1464 | } |
| 1465 | |
| 1466 | // A marker value is used in place of the function. |
| 1467 | output_frame_offset -= kPointerSize; |
| 1468 | value = reinterpret_cast<intptr_t>( |
| 1469 | Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); |
| 1470 | output_frame->SetFrameSlot(output_frame_offset, value); |
| 1471 | if (trace_) { |
| 1472 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1473 | V8PRIxPTR " ; function (stub failure sentinel)\n", |
| 1474 | top_address + output_frame_offset, output_frame_offset, value); |
| 1475 | } |
| 1476 | |
| 1477 | intptr_t caller_arg_count = 0; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1478 | bool arg_count_known = descriptor->stack_parameter_count_ == NULL; |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1479 | |
| 1480 | // Build the Arguments object for the caller's parameters and a pointer to it. |
| 1481 | output_frame_offset -= kPointerSize; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1482 | int args_arguments_offset = output_frame_offset; |
| 1483 | intptr_t the_hole = reinterpret_cast<intptr_t>( |
| 1484 | isolate_->heap()->the_hole_value()); |
| 1485 | if (arg_count_known) { |
| 1486 | value = frame_ptr + StandardFrameConstants::kCallerSPOffset + |
| 1487 | (caller_arg_count - 1) * kPointerSize; |
| 1488 | } else { |
| 1489 | value = the_hole; |
| 1490 | } |
| 1491 | |
| 1492 | output_frame->SetFrameSlot(args_arguments_offset, value); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1493 | if (trace_) { |
| 1494 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1495 | V8PRIxPTR " ; args.arguments %s\n", |
| 1496 | top_address + args_arguments_offset, args_arguments_offset, value, |
| 1497 | arg_count_known ? "" : "(the hole)"); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | output_frame_offset -= kPointerSize; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1501 | int length_frame_offset = output_frame_offset; |
| 1502 | value = arg_count_known ? caller_arg_count : the_hole; |
| 1503 | output_frame->SetFrameSlot(length_frame_offset, value); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1504 | if (trace_) { |
| 1505 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1506 | V8PRIxPTR " ; args.length %s\n", |
| 1507 | top_address + length_frame_offset, length_frame_offset, value, |
| 1508 | arg_count_known ? "" : "(the hole)"); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | output_frame_offset -= kPointerSize; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 1512 | value = frame_ptr + StandardFrameConstants::kCallerSPOffset - |
| 1513 | (output_frame_size - output_frame_offset) + kPointerSize; |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1514 | output_frame->SetFrameSlot(output_frame_offset, value); |
| 1515 | if (trace_) { |
| 1516 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1517 | V8PRIxPTR " ; args*\n", |
| 1518 | top_address + output_frame_offset, output_frame_offset, value); |
| 1519 | } |
| 1520 | |
| 1521 | // Copy the register parameters to the failure frame. |
| 1522 | for (int i = 0; i < descriptor->register_param_count_; ++i) { |
| 1523 | output_frame_offset -= kPointerSize; |
| 1524 | DoTranslateCommand(iterator, 0, output_frame_offset); |
| 1525 | } |
| 1526 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1527 | if (!arg_count_known) { |
| 1528 | DoTranslateCommand(iterator, 0, length_frame_offset, |
| 1529 | TRANSLATED_VALUE_IS_NATIVE); |
| 1530 | caller_arg_count = output_frame->GetFrameSlot(length_frame_offset); |
| 1531 | value = frame_ptr + StandardFrameConstants::kCallerSPOffset + |
| 1532 | (caller_arg_count - 1) * kPointerSize; |
| 1533 | output_frame->SetFrameSlot(args_arguments_offset, value); |
| 1534 | if (trace_) { |
| 1535 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1536 | V8PRIxPTR " ; args.arguments\n", |
| 1537 | top_address + args_arguments_offset, args_arguments_offset, value); |
| 1538 | } |
| 1539 | } |
| 1540 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1541 | ASSERT(0 == output_frame_offset); |
| 1542 | |
| 1543 | // Copy the double registers from the input into the output frame. |
| 1544 | CopyDoubleRegisters(output_frame); |
| 1545 | |
| 1546 | // Fill registers containing handler and number of parameters. |
| 1547 | SetPlatformCompiledStubRegisters(output_frame, descriptor); |
| 1548 | |
| 1549 | // Compute this frame's PC, state, and continuation. |
| 1550 | Code* trampoline = NULL; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1551 | StubFunctionMode function_mode = descriptor->function_mode_; |
| 1552 | StubFailureTrampolineStub(function_mode).FindCodeInCache(&trampoline, |
| 1553 | isolate_); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1554 | ASSERT(trampoline != NULL); |
| 1555 | output_frame->SetPc(reinterpret_cast<intptr_t>( |
| 1556 | trampoline->instruction_start())); |
| 1557 | output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); |
| 1558 | Code* notify_failure = |
| 1559 | isolate_->builtins()->builtin(Builtins::kNotifyStubFailure); |
| 1560 | output_frame->SetContinuation( |
| 1561 | reinterpret_cast<intptr_t>(notify_failure->entry())); |
| 1562 | } |
| 1563 | |
| 1564 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1565 | void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1566 | ASSERT_NE(DEBUGGER, bailout_type_); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1567 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1568 | // Handlify all tagged object values before triggering any allocation. |
| 1569 | List<Handle<Object> > values(deferred_objects_tagged_values_.length()); |
| 1570 | for (int i = 0; i < deferred_objects_tagged_values_.length(); ++i) { |
| 1571 | values.Add(Handle<Object>(deferred_objects_tagged_values_[i], isolate_)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | // Play it safe and clear all unhandlified values before we continue. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1575 | deferred_objects_tagged_values_.Clear(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1576 | |
| 1577 | // Materialize all heap numbers before looking at arguments because when the |
| 1578 | // output frames are used to materialize arguments objects later on they need |
| 1579 | // to already contain valid heap numbers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1580 | for (int i = 0; i < deferred_heap_numbers_.length(); i++) { |
| 1581 | HeapNumberMaterializationDescriptor d = deferred_heap_numbers_[i]; |
| 1582 | Handle<Object> num = isolate_->factory()->NewNumber(d.value()); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1583 | if (trace_) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1584 | PrintF("Materializing a new heap number %p [%e] in slot %p\n", |
| 1585 | reinterpret_cast<void*>(*num), |
| 1586 | d.value(), |
| 1587 | d.slot_address()); |
| 1588 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1589 | Memory::Object_at(d.slot_address()) = *num; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1590 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1591 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1592 | // Materialize all heap numbers required for arguments objects. |
| 1593 | for (int i = 0; i < values.length(); i++) { |
| 1594 | if (!values.at(i)->IsTheHole()) continue; |
| 1595 | double double_value = deferred_objects_double_values_[i]; |
| 1596 | Handle<Object> num = isolate_->factory()->NewNumber(double_value); |
| 1597 | if (trace_) { |
| 1598 | PrintF("Materializing a new heap number %p [%e] for arguments object\n", |
| 1599 | reinterpret_cast<void*>(*num), double_value); |
| 1600 | } |
| 1601 | values.Set(i, num); |
| 1602 | } |
| 1603 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1604 | // Materialize arguments objects one frame at a time. |
| 1605 | for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { |
| 1606 | if (frame_index != 0) it->Advance(); |
| 1607 | JavaScriptFrame* frame = it->frame(); |
| 1608 | Handle<JSFunction> function(JSFunction::cast(frame->function()), isolate_); |
| 1609 | Handle<JSObject> arguments; |
| 1610 | for (int i = frame->ComputeExpressionsCount() - 1; i >= 0; --i) { |
| 1611 | if (frame->GetExpression(i) == isolate_->heap()->arguments_marker()) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1612 | ObjectMaterializationDescriptor descriptor = |
| 1613 | deferred_objects_.RemoveLast(); |
| 1614 | const int length = descriptor.object_length(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1615 | if (arguments.is_null()) { |
| 1616 | if (frame->has_adapted_arguments()) { |
| 1617 | // Use the arguments adapter frame we just built to materialize the |
| 1618 | // arguments object. FunctionGetArguments can't throw an exception, |
| 1619 | // so cast away the doubt with an assert. |
| 1620 | arguments = Handle<JSObject>(JSObject::cast( |
| 1621 | Accessors::FunctionGetArguments(*function, |
| 1622 | NULL)->ToObjectUnchecked())); |
| 1623 | values.RewindBy(length); |
| 1624 | } else { |
| 1625 | // Construct an arguments object and copy the parameters to a newly |
| 1626 | // allocated arguments object backing store. |
| 1627 | arguments = |
| 1628 | isolate_->factory()->NewArgumentsObject(function, length); |
| 1629 | Handle<FixedArray> array = |
| 1630 | isolate_->factory()->NewFixedArray(length); |
| 1631 | ASSERT(array->length() == length); |
| 1632 | for (int i = length - 1; i >= 0 ; --i) { |
| 1633 | array->set(i, *values.RemoveLast()); |
| 1634 | } |
| 1635 | arguments->set_elements(*array); |
| 1636 | } |
| 1637 | } |
| 1638 | frame->SetExpression(i, *arguments); |
| 1639 | ASSERT_EQ(Memory::Object_at(descriptor.slot_address()), *arguments); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1640 | if (trace_) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1641 | PrintF("Materializing %sarguments object of length %d for %p: ", |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1642 | frame->has_adapted_arguments() ? "(adapted) " : "", |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1643 | arguments->elements()->length(), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1644 | reinterpret_cast<void*>(descriptor.slot_address())); |
| 1645 | arguments->ShortPrint(); |
| 1646 | PrintF("\n"); |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1654 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1655 | void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame( |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1656 | Address parameters_top, |
| 1657 | uint32_t parameters_size, |
| 1658 | Address expressions_top, |
| 1659 | uint32_t expressions_size, |
| 1660 | DeoptimizedFrameInfo* info) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1661 | ASSERT_EQ(DEBUGGER, bailout_type_); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1662 | Address parameters_bottom = parameters_top + parameters_size; |
| 1663 | Address expressions_bottom = expressions_top + expressions_size; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1664 | for (int i = 0; i < deferred_heap_numbers_.length(); i++) { |
| 1665 | HeapNumberMaterializationDescriptor d = deferred_heap_numbers_[i]; |
| 1666 | |
| 1667 | // Check of the heap number to materialize actually belong to the frame |
| 1668 | // being extracted. |
| 1669 | Address slot = d.slot_address(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1670 | if (parameters_top <= slot && slot < parameters_bottom) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1671 | Handle<Object> num = isolate_->factory()->NewNumber(d.value()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1672 | |
| 1673 | int index = (info->parameters_count() - 1) - |
| 1674 | static_cast<int>(slot - parameters_top) / kPointerSize; |
| 1675 | |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1676 | if (trace_) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1677 | PrintF("Materializing a new heap number %p [%e] in slot %p" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1678 | "for parameter slot #%d\n", |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1679 | reinterpret_cast<void*>(*num), |
| 1680 | d.value(), |
| 1681 | d.slot_address(), |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1682 | index); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1683 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1684 | |
| 1685 | info->SetParameter(index, *num); |
| 1686 | } else if (expressions_top <= slot && slot < expressions_bottom) { |
| 1687 | Handle<Object> num = isolate_->factory()->NewNumber(d.value()); |
| 1688 | |
| 1689 | int index = info->expression_count() - 1 - |
| 1690 | static_cast<int>(slot - expressions_top) / kPointerSize; |
| 1691 | |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1692 | if (trace_) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1693 | PrintF("Materializing a new heap number %p [%e] in slot %p" |
| 1694 | "for expression slot #%d\n", |
| 1695 | reinterpret_cast<void*>(*num), |
| 1696 | d.value(), |
| 1697 | d.slot_address(), |
| 1698 | index); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1699 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1700 | |
| 1701 | info->SetExpression(index, *num); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | #endif |
| 1706 | |
| 1707 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1708 | static const char* TraceValueType(bool is_smi, bool is_native = false) { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1709 | if (is_native) { |
| 1710 | return "native"; |
| 1711 | } else if (is_smi) { |
| 1712 | return "smi"; |
| 1713 | } |
| 1714 | |
| 1715 | return "heap number"; |
| 1716 | } |
| 1717 | |
| 1718 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1719 | void Deoptimizer::DoTranslateObject(TranslationIterator* iterator, |
| 1720 | int object_opcode, |
| 1721 | int field_index) { |
| 1722 | disasm::NameConverter converter; |
| 1723 | Address object_slot = deferred_objects_.last().slot_address(); |
| 1724 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1725 | Translation::Opcode opcode = |
| 1726 | static_cast<Translation::Opcode>(iterator->Next()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1727 | |
| 1728 | switch (opcode) { |
| 1729 | case Translation::BEGIN: |
| 1730 | case Translation::JS_FRAME: |
| 1731 | case Translation::ARGUMENTS_ADAPTOR_FRAME: |
| 1732 | case Translation::CONSTRUCT_STUB_FRAME: |
| 1733 | case Translation::GETTER_STUB_FRAME: |
| 1734 | case Translation::SETTER_STUB_FRAME: |
| 1735 | case Translation::COMPILED_STUB_FRAME: |
| 1736 | case Translation::ARGUMENTS_OBJECT: |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1737 | UNREACHABLE(); |
| 1738 | return; |
| 1739 | |
| 1740 | case Translation::REGISTER: { |
| 1741 | int input_reg = iterator->Next(); |
| 1742 | intptr_t input_value = input_->GetRegister(input_reg); |
| 1743 | if (trace_) { |
| 1744 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1745 | reinterpret_cast<intptr_t>(object_slot), |
| 1746 | field_index); |
| 1747 | PrintF("0x%08" V8PRIxPTR " ; %s ", input_value, |
| 1748 | converter.NameOfCPURegister(input_reg)); |
| 1749 | reinterpret_cast<Object*>(input_value)->ShortPrint(); |
| 1750 | PrintF("\n"); |
| 1751 | } |
| 1752 | AddObjectTaggedValue(input_value); |
| 1753 | return; |
| 1754 | } |
| 1755 | |
| 1756 | case Translation::INT32_REGISTER: { |
| 1757 | int input_reg = iterator->Next(); |
| 1758 | intptr_t value = input_->GetRegister(input_reg); |
| 1759 | bool is_smi = Smi::IsValid(value); |
| 1760 | if (trace_) { |
| 1761 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1762 | reinterpret_cast<intptr_t>(object_slot), |
| 1763 | field_index); |
| 1764 | PrintF("%" V8PRIdPTR " ; %s (%s)\n", value, |
| 1765 | converter.NameOfCPURegister(input_reg), |
| 1766 | TraceValueType(is_smi)); |
| 1767 | } |
| 1768 | if (is_smi) { |
| 1769 | intptr_t tagged_value = |
| 1770 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 1771 | AddObjectTaggedValue(tagged_value); |
| 1772 | } else { |
| 1773 | double double_value = static_cast<double>(static_cast<int32_t>(value)); |
| 1774 | AddObjectDoubleValue(double_value); |
| 1775 | } |
| 1776 | return; |
| 1777 | } |
| 1778 | |
| 1779 | case Translation::UINT32_REGISTER: { |
| 1780 | int input_reg = iterator->Next(); |
| 1781 | uintptr_t value = static_cast<uintptr_t>(input_->GetRegister(input_reg)); |
| 1782 | bool is_smi = (value <= static_cast<uintptr_t>(Smi::kMaxValue)); |
| 1783 | if (trace_) { |
| 1784 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1785 | reinterpret_cast<intptr_t>(object_slot), |
| 1786 | field_index); |
| 1787 | PrintF("%" V8PRIdPTR " ; uint %s (%s)\n", value, |
| 1788 | converter.NameOfCPURegister(input_reg), |
| 1789 | TraceValueType(is_smi)); |
| 1790 | } |
| 1791 | if (is_smi) { |
| 1792 | intptr_t tagged_value = |
| 1793 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 1794 | AddObjectTaggedValue(tagged_value); |
| 1795 | } else { |
| 1796 | double double_value = static_cast<double>(static_cast<uint32_t>(value)); |
| 1797 | AddObjectDoubleValue(double_value); |
| 1798 | } |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | case Translation::DOUBLE_REGISTER: { |
| 1803 | int input_reg = iterator->Next(); |
| 1804 | double value = input_->GetDoubleRegister(input_reg); |
| 1805 | if (trace_) { |
| 1806 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1807 | reinterpret_cast<intptr_t>(object_slot), |
| 1808 | field_index); |
| 1809 | PrintF("%e ; %s\n", value, |
| 1810 | DoubleRegister::AllocationIndexToString(input_reg)); |
| 1811 | } |
| 1812 | AddObjectDoubleValue(value); |
| 1813 | return; |
| 1814 | } |
| 1815 | |
| 1816 | case Translation::STACK_SLOT: { |
| 1817 | int input_slot_index = iterator->Next(); |
| 1818 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
| 1819 | intptr_t input_value = input_->GetFrameSlot(input_offset); |
| 1820 | if (trace_) { |
| 1821 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1822 | reinterpret_cast<intptr_t>(object_slot), |
| 1823 | field_index); |
| 1824 | PrintF("0x%08" V8PRIxPTR " ; [sp + %d] ", input_value, input_offset); |
| 1825 | reinterpret_cast<Object*>(input_value)->ShortPrint(); |
| 1826 | PrintF("\n"); |
| 1827 | } |
| 1828 | AddObjectTaggedValue(input_value); |
| 1829 | return; |
| 1830 | } |
| 1831 | |
| 1832 | case Translation::INT32_STACK_SLOT: { |
| 1833 | int input_slot_index = iterator->Next(); |
| 1834 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
| 1835 | intptr_t value = input_->GetFrameSlot(input_offset); |
| 1836 | bool is_smi = Smi::IsValid(value); |
| 1837 | if (trace_) { |
| 1838 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1839 | reinterpret_cast<intptr_t>(object_slot), |
| 1840 | field_index); |
| 1841 | PrintF("%" V8PRIdPTR " ; [sp + %d] (%s)\n", |
| 1842 | value, input_offset, TraceValueType(is_smi)); |
| 1843 | } |
| 1844 | if (is_smi) { |
| 1845 | intptr_t tagged_value = |
| 1846 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 1847 | AddObjectTaggedValue(tagged_value); |
| 1848 | } else { |
| 1849 | double double_value = static_cast<double>(static_cast<int32_t>(value)); |
| 1850 | AddObjectDoubleValue(double_value); |
| 1851 | } |
| 1852 | return; |
| 1853 | } |
| 1854 | |
| 1855 | case Translation::UINT32_STACK_SLOT: { |
| 1856 | int input_slot_index = iterator->Next(); |
| 1857 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
| 1858 | uintptr_t value = |
| 1859 | static_cast<uintptr_t>(input_->GetFrameSlot(input_offset)); |
| 1860 | bool is_smi = (value <= static_cast<uintptr_t>(Smi::kMaxValue)); |
| 1861 | if (trace_) { |
| 1862 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1863 | reinterpret_cast<intptr_t>(object_slot), |
| 1864 | field_index); |
| 1865 | PrintF("%" V8PRIdPTR " ; [sp + %d] (uint %s)\n", |
| 1866 | value, input_offset, TraceValueType(is_smi)); |
| 1867 | } |
| 1868 | if (is_smi) { |
| 1869 | intptr_t tagged_value = |
| 1870 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 1871 | AddObjectTaggedValue(tagged_value); |
| 1872 | } else { |
| 1873 | double double_value = static_cast<double>(static_cast<uint32_t>(value)); |
| 1874 | AddObjectDoubleValue(double_value); |
| 1875 | } |
| 1876 | return; |
| 1877 | } |
| 1878 | |
| 1879 | case Translation::DOUBLE_STACK_SLOT: { |
| 1880 | int input_slot_index = iterator->Next(); |
| 1881 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
| 1882 | double value = input_->GetDoubleFrameSlot(input_offset); |
| 1883 | if (trace_) { |
| 1884 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1885 | reinterpret_cast<intptr_t>(object_slot), |
| 1886 | field_index); |
| 1887 | PrintF("%e ; [sp + %d]\n", value, input_offset); |
| 1888 | } |
| 1889 | AddObjectDoubleValue(value); |
| 1890 | return; |
| 1891 | } |
| 1892 | |
| 1893 | case Translation::LITERAL: { |
| 1894 | Object* literal = ComputeLiteral(iterator->Next()); |
| 1895 | if (trace_) { |
| 1896 | PrintF(" object @0x%08" V8PRIxPTR ": [field #%d] <- ", |
| 1897 | reinterpret_cast<intptr_t>(object_slot), |
| 1898 | field_index); |
| 1899 | literal->ShortPrint(); |
| 1900 | PrintF(" ; literal\n"); |
| 1901 | } |
| 1902 | intptr_t value = reinterpret_cast<intptr_t>(literal); |
| 1903 | AddObjectTaggedValue(value); |
| 1904 | return; |
| 1905 | } |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1910 | void Deoptimizer::DoTranslateCommand(TranslationIterator* iterator, |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1911 | int frame_index, |
| 1912 | unsigned output_offset, |
| 1913 | DeoptimizerTranslatedValueType value_type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1914 | disasm::NameConverter converter; |
| 1915 | // A GC-safe temporary placeholder that we can put in the output frame. |
| 1916 | const intptr_t kPlaceholder = reinterpret_cast<intptr_t>(Smi::FromInt(0)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1917 | bool is_native = value_type == TRANSLATED_VALUE_IS_NATIVE; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1918 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1919 | Translation::Opcode opcode = |
| 1920 | static_cast<Translation::Opcode>(iterator->Next()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1921 | |
| 1922 | switch (opcode) { |
| 1923 | case Translation::BEGIN: |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1924 | case Translation::JS_FRAME: |
| 1925 | case Translation::ARGUMENTS_ADAPTOR_FRAME: |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1926 | case Translation::CONSTRUCT_STUB_FRAME: |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1927 | case Translation::GETTER_STUB_FRAME: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1928 | case Translation::SETTER_STUB_FRAME: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1929 | case Translation::COMPILED_STUB_FRAME: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1930 | UNREACHABLE(); |
| 1931 | return; |
| 1932 | |
| 1933 | case Translation::REGISTER: { |
| 1934 | int input_reg = iterator->Next(); |
| 1935 | intptr_t input_value = input_->GetRegister(input_reg); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1936 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1937 | PrintF( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1938 | " 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" V8PRIxPTR " ; %s ", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1939 | output_[frame_index]->GetTop() + output_offset, |
| 1940 | output_offset, |
| 1941 | input_value, |
| 1942 | converter.NameOfCPURegister(input_reg)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1943 | reinterpret_cast<Object*>(input_value)->ShortPrint(); |
| 1944 | PrintF("\n"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | } |
| 1946 | output_[frame_index]->SetFrameSlot(output_offset, input_value); |
| 1947 | return; |
| 1948 | } |
| 1949 | |
| 1950 | case Translation::INT32_REGISTER: { |
| 1951 | int input_reg = iterator->Next(); |
| 1952 | intptr_t value = input_->GetRegister(input_reg); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1953 | bool is_smi = (value_type == TRANSLATED_VALUE_IS_TAGGED) && |
| 1954 | Smi::IsValid(value); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1955 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1956 | PrintF( |
| 1957 | " 0x%08" V8PRIxPTR ": [top + %d] <- %" V8PRIdPTR " ; %s (%s)\n", |
| 1958 | output_[frame_index]->GetTop() + output_offset, |
| 1959 | output_offset, |
| 1960 | value, |
| 1961 | converter.NameOfCPURegister(input_reg), |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1962 | TraceValueType(is_smi, is_native)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1963 | } |
| 1964 | if (is_smi) { |
| 1965 | intptr_t tagged_value = |
| 1966 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 1967 | output_[frame_index]->SetFrameSlot(output_offset, tagged_value); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1968 | } else if (value_type == TRANSLATED_VALUE_IS_NATIVE) { |
| 1969 | output_[frame_index]->SetFrameSlot(output_offset, value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1970 | } else { |
| 1971 | // We save the untagged value on the side and store a GC-safe |
| 1972 | // temporary placeholder in the frame. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1973 | ASSERT(value_type == TRANSLATED_VALUE_IS_TAGGED); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1974 | AddDoubleValue(output_[frame_index]->GetTop() + output_offset, |
| 1975 | static_cast<double>(static_cast<int32_t>(value))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1976 | output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder); |
| 1977 | } |
| 1978 | return; |
| 1979 | } |
| 1980 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1981 | case Translation::UINT32_REGISTER: { |
| 1982 | int input_reg = iterator->Next(); |
| 1983 | uintptr_t value = static_cast<uintptr_t>(input_->GetRegister(input_reg)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1984 | bool is_smi = (value_type == TRANSLATED_VALUE_IS_TAGGED) && |
| 1985 | (value <= static_cast<uintptr_t>(Smi::kMaxValue)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1986 | if (trace_) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1987 | PrintF( |
| 1988 | " 0x%08" V8PRIxPTR ": [top + %d] <- %" V8PRIuPTR |
| 1989 | " ; uint %s (%s)\n", |
| 1990 | output_[frame_index]->GetTop() + output_offset, |
| 1991 | output_offset, |
| 1992 | value, |
| 1993 | converter.NameOfCPURegister(input_reg), |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1994 | TraceValueType(is_smi, is_native)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1995 | } |
| 1996 | if (is_smi) { |
| 1997 | intptr_t tagged_value = |
| 1998 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 1999 | output_[frame_index]->SetFrameSlot(output_offset, tagged_value); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2000 | } else if (value_type == TRANSLATED_VALUE_IS_NATIVE) { |
| 2001 | output_[frame_index]->SetFrameSlot(output_offset, value); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2002 | } else { |
| 2003 | // We save the untagged value on the side and store a GC-safe |
| 2004 | // temporary placeholder in the frame. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2005 | ASSERT(value_type == TRANSLATED_VALUE_IS_TAGGED); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2006 | AddDoubleValue(output_[frame_index]->GetTop() + output_offset, |
| 2007 | static_cast<double>(static_cast<uint32_t>(value))); |
| 2008 | output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder); |
| 2009 | } |
| 2010 | return; |
| 2011 | } |
| 2012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2013 | case Translation::DOUBLE_REGISTER: { |
| 2014 | int input_reg = iterator->Next(); |
| 2015 | double value = input_->GetDoubleRegister(input_reg); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2016 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2017 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- %e ; %s\n", |
| 2018 | output_[frame_index]->GetTop() + output_offset, |
| 2019 | output_offset, |
| 2020 | value, |
| 2021 | DoubleRegister::AllocationIndexToString(input_reg)); |
| 2022 | } |
| 2023 | // We save the untagged value on the side and store a GC-safe |
| 2024 | // temporary placeholder in the frame. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2025 | AddDoubleValue(output_[frame_index]->GetTop() + output_offset, value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2026 | output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder); |
| 2027 | return; |
| 2028 | } |
| 2029 | |
| 2030 | case Translation::STACK_SLOT: { |
| 2031 | int input_slot_index = iterator->Next(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2032 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2033 | intptr_t input_value = input_->GetFrameSlot(input_offset); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2034 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2035 | PrintF(" 0x%08" V8PRIxPTR ": ", |
| 2036 | output_[frame_index]->GetTop() + output_offset); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2037 | PrintF("[top + %d] <- 0x%08" V8PRIxPTR " ; [sp + %d] ", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2038 | output_offset, |
| 2039 | input_value, |
| 2040 | input_offset); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2041 | reinterpret_cast<Object*>(input_value)->ShortPrint(); |
| 2042 | PrintF("\n"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2043 | } |
| 2044 | output_[frame_index]->SetFrameSlot(output_offset, input_value); |
| 2045 | return; |
| 2046 | } |
| 2047 | |
| 2048 | case Translation::INT32_STACK_SLOT: { |
| 2049 | int input_slot_index = iterator->Next(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2050 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2051 | intptr_t value = input_->GetFrameSlot(input_offset); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2052 | bool is_smi = (value_type == TRANSLATED_VALUE_IS_TAGGED) && |
| 2053 | Smi::IsValid(value); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2054 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2055 | PrintF(" 0x%08" V8PRIxPTR ": ", |
| 2056 | output_[frame_index]->GetTop() + output_offset); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2057 | PrintF("[top + %d] <- %" V8PRIdPTR " ; [sp + %d] (%s)\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2058 | output_offset, |
| 2059 | value, |
| 2060 | input_offset, |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2061 | TraceValueType(is_smi, is_native)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2062 | } |
| 2063 | if (is_smi) { |
| 2064 | intptr_t tagged_value = |
| 2065 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 2066 | output_[frame_index]->SetFrameSlot(output_offset, tagged_value); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2067 | } else if (value_type == TRANSLATED_VALUE_IS_NATIVE) { |
| 2068 | output_[frame_index]->SetFrameSlot(output_offset, value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2069 | } else { |
| 2070 | // We save the untagged value on the side and store a GC-safe |
| 2071 | // temporary placeholder in the frame. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2072 | ASSERT(value_type == TRANSLATED_VALUE_IS_TAGGED); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2073 | AddDoubleValue(output_[frame_index]->GetTop() + output_offset, |
| 2074 | static_cast<double>(static_cast<int32_t>(value))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2075 | output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder); |
| 2076 | } |
| 2077 | return; |
| 2078 | } |
| 2079 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2080 | case Translation::UINT32_STACK_SLOT: { |
| 2081 | int input_slot_index = iterator->Next(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2082 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2083 | uintptr_t value = |
| 2084 | static_cast<uintptr_t>(input_->GetFrameSlot(input_offset)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2085 | bool is_smi = (value_type == TRANSLATED_VALUE_IS_TAGGED) && |
| 2086 | (value <= static_cast<uintptr_t>(Smi::kMaxValue)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2087 | if (trace_) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2088 | PrintF(" 0x%08" V8PRIxPTR ": ", |
| 2089 | output_[frame_index]->GetTop() + output_offset); |
| 2090 | PrintF("[top + %d] <- %" V8PRIuPTR " ; [sp + %d] (uint32 %s)\n", |
| 2091 | output_offset, |
| 2092 | value, |
| 2093 | input_offset, |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2094 | TraceValueType(is_smi, is_native)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2095 | } |
| 2096 | if (is_smi) { |
| 2097 | intptr_t tagged_value = |
| 2098 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(value))); |
| 2099 | output_[frame_index]->SetFrameSlot(output_offset, tagged_value); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2100 | } else if (value_type == TRANSLATED_VALUE_IS_NATIVE) { |
| 2101 | output_[frame_index]->SetFrameSlot(output_offset, value); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2102 | } else { |
| 2103 | // We save the untagged value on the side and store a GC-safe |
| 2104 | // temporary placeholder in the frame. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2105 | ASSERT(value_type == TRANSLATED_VALUE_IS_TAGGED); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2106 | AddDoubleValue(output_[frame_index]->GetTop() + output_offset, |
| 2107 | static_cast<double>(static_cast<uint32_t>(value))); |
| 2108 | output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder); |
| 2109 | } |
| 2110 | return; |
| 2111 | } |
| 2112 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2113 | case Translation::DOUBLE_STACK_SLOT: { |
| 2114 | int input_slot_index = iterator->Next(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2115 | unsigned input_offset = input_->GetOffsetFromSlotIndex(input_slot_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2116 | double value = input_->GetDoubleFrameSlot(input_offset); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2117 | if (trace_) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2118 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- %e ; [sp + %d]\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2119 | output_[frame_index]->GetTop() + output_offset, |
| 2120 | output_offset, |
| 2121 | value, |
| 2122 | input_offset); |
| 2123 | } |
| 2124 | // We save the untagged value on the side and store a GC-safe |
| 2125 | // temporary placeholder in the frame. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2126 | AddDoubleValue(output_[frame_index]->GetTop() + output_offset, value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2127 | output_[frame_index]->SetFrameSlot(output_offset, kPlaceholder); |
| 2128 | return; |
| 2129 | } |
| 2130 | |
| 2131 | case Translation::LITERAL: { |
| 2132 | Object* literal = ComputeLiteral(iterator->Next()); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2133 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2134 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- ", |
| 2135 | output_[frame_index]->GetTop() + output_offset, |
| 2136 | output_offset); |
| 2137 | literal->ShortPrint(); |
| 2138 | PrintF(" ; literal\n"); |
| 2139 | } |
| 2140 | intptr_t value = reinterpret_cast<intptr_t>(literal); |
| 2141 | output_[frame_index]->SetFrameSlot(output_offset, value); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
| 2145 | case Translation::ARGUMENTS_OBJECT: { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2146 | int length = iterator->Next(); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2147 | if (trace_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2148 | PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- ", |
| 2149 | output_[frame_index]->GetTop() + output_offset, |
| 2150 | output_offset); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2151 | isolate_->heap()->arguments_marker()->ShortPrint(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2152 | PrintF(" ; arguments object (length = %d)\n", length); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2154 | // Use the arguments marker value as a sentinel and fill in the arguments |
| 2155 | // object after the deoptimized frame is built. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2156 | intptr_t value = reinterpret_cast<intptr_t>( |
| 2157 | isolate_->heap()->arguments_marker()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2158 | AddObjectStart(output_[frame_index]->GetTop() + output_offset, length); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2159 | output_[frame_index]->SetFrameSlot(output_offset, value); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2160 | // We save the argument values on the side and materialize the actual |
| 2161 | // arguments object after the deoptimized frame is built. |
| 2162 | for (int i = 0; i < length; i++) { |
| 2163 | DoTranslateObject(iterator, Translation::ARGUMENTS_OBJECT, i); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2164 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2165 | return; |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | |
| 2171 | bool Deoptimizer::DoOsrTranslateCommand(TranslationIterator* iterator, |
| 2172 | int* input_offset) { |
| 2173 | disasm::NameConverter converter; |
| 2174 | FrameDescription* output = output_[0]; |
| 2175 | |
| 2176 | // The input values are all part of the unoptimized frame so they |
| 2177 | // are all tagged pointers. |
| 2178 | uintptr_t input_value = input_->GetFrameSlot(*input_offset); |
| 2179 | Object* input_object = reinterpret_cast<Object*>(input_value); |
| 2180 | |
| 2181 | Translation::Opcode opcode = |
| 2182 | static_cast<Translation::Opcode>(iterator->Next()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2183 | |
| 2184 | switch (opcode) { |
| 2185 | case Translation::BEGIN: |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2186 | case Translation::JS_FRAME: |
| 2187 | case Translation::ARGUMENTS_ADAPTOR_FRAME: |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2188 | case Translation::CONSTRUCT_STUB_FRAME: |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2189 | case Translation::GETTER_STUB_FRAME: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2190 | case Translation::SETTER_STUB_FRAME: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2191 | case Translation::COMPILED_STUB_FRAME: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2192 | UNREACHABLE(); // Malformed input. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 2193 | return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2194 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 2195 | case Translation::REGISTER: { |
| 2196 | int output_reg = iterator->Next(); |
| 2197 | if (FLAG_trace_osr) { |
| 2198 | PrintF(" %s <- 0x%08" V8PRIxPTR " ; [sp + %d]\n", |
| 2199 | converter.NameOfCPURegister(output_reg), |
| 2200 | input_value, |
| 2201 | *input_offset); |
| 2202 | } |
| 2203 | output->SetRegister(output_reg, input_value); |
| 2204 | break; |
| 2205 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2206 | |
| 2207 | case Translation::INT32_REGISTER: { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2208 | int32_t int32_value = 0; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2209 | if (!input_object->ToInt32(&int32_value)) return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2210 | |
| 2211 | int output_reg = iterator->Next(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2212 | if (FLAG_trace_osr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2213 | PrintF(" %s <- %d (int32) ; [sp + %d]\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2214 | converter.NameOfCPURegister(output_reg), |
| 2215 | int32_value, |
| 2216 | *input_offset); |
| 2217 | } |
| 2218 | output->SetRegister(output_reg, int32_value); |
| 2219 | break; |
| 2220 | } |
| 2221 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2222 | case Translation::UINT32_REGISTER: { |
| 2223 | uint32_t uint32_value = 0; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2224 | if (!input_object->ToUint32(&uint32_value)) return false; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2225 | |
| 2226 | int output_reg = iterator->Next(); |
| 2227 | if (FLAG_trace_osr) { |
| 2228 | PrintF(" %s <- %u (uint32) ; [sp + %d]\n", |
| 2229 | converter.NameOfCPURegister(output_reg), |
| 2230 | uint32_value, |
| 2231 | *input_offset); |
| 2232 | } |
| 2233 | output->SetRegister(output_reg, static_cast<int32_t>(uint32_value)); |
| 2234 | } |
| 2235 | |
| 2236 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2237 | case Translation::DOUBLE_REGISTER: { |
| 2238 | // Abort OSR if we don't have a number. |
| 2239 | if (!input_object->IsNumber()) return false; |
| 2240 | |
| 2241 | int output_reg = iterator->Next(); |
| 2242 | double double_value = input_object->Number(); |
| 2243 | if (FLAG_trace_osr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2244 | PrintF(" %s <- %g (double) ; [sp + %d]\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2245 | DoubleRegister::AllocationIndexToString(output_reg), |
| 2246 | double_value, |
| 2247 | *input_offset); |
| 2248 | } |
| 2249 | output->SetDoubleRegister(output_reg, double_value); |
| 2250 | break; |
| 2251 | } |
| 2252 | |
| 2253 | case Translation::STACK_SLOT: { |
| 2254 | int output_index = iterator->Next(); |
| 2255 | unsigned output_offset = |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2256 | output->GetOffsetFromSlotIndex(output_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2257 | if (FLAG_trace_osr) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2258 | PrintF(" [sp + %d] <- 0x%08" V8PRIxPTR " ; [sp + %d] ", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | output_offset, |
| 2260 | input_value, |
| 2261 | *input_offset); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2262 | reinterpret_cast<Object*>(input_value)->ShortPrint(); |
| 2263 | PrintF("\n"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2264 | } |
| 2265 | output->SetFrameSlot(output_offset, input_value); |
| 2266 | break; |
| 2267 | } |
| 2268 | |
| 2269 | case Translation::INT32_STACK_SLOT: { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2270 | int32_t int32_value = 0; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2271 | if (!input_object->ToInt32(&int32_value)) return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2272 | |
| 2273 | int output_index = iterator->Next(); |
| 2274 | unsigned output_offset = |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2275 | output->GetOffsetFromSlotIndex(output_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2276 | if (FLAG_trace_osr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2277 | PrintF(" [sp + %d] <- %d (int32) ; [sp + %d]\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2278 | output_offset, |
| 2279 | int32_value, |
| 2280 | *input_offset); |
| 2281 | } |
| 2282 | output->SetFrameSlot(output_offset, int32_value); |
| 2283 | break; |
| 2284 | } |
| 2285 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2286 | case Translation::UINT32_STACK_SLOT: { |
| 2287 | uint32_t uint32_value = 0; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2288 | if (!input_object->ToUint32(&uint32_value)) return false; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2289 | |
| 2290 | int output_index = iterator->Next(); |
| 2291 | unsigned output_offset = |
| 2292 | output->GetOffsetFromSlotIndex(output_index); |
| 2293 | if (FLAG_trace_osr) { |
| 2294 | PrintF(" [sp + %d] <- %u (uint32) ; [sp + %d]\n", |
| 2295 | output_offset, |
| 2296 | uint32_value, |
| 2297 | *input_offset); |
| 2298 | } |
| 2299 | output->SetFrameSlot(output_offset, static_cast<int32_t>(uint32_value)); |
| 2300 | break; |
| 2301 | } |
| 2302 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2303 | case Translation::DOUBLE_STACK_SLOT: { |
| 2304 | static const int kLowerOffset = 0 * kPointerSize; |
| 2305 | static const int kUpperOffset = 1 * kPointerSize; |
| 2306 | |
| 2307 | // Abort OSR if we don't have a number. |
| 2308 | if (!input_object->IsNumber()) return false; |
| 2309 | |
| 2310 | int output_index = iterator->Next(); |
| 2311 | unsigned output_offset = |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2312 | output->GetOffsetFromSlotIndex(output_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2313 | double double_value = input_object->Number(); |
| 2314 | uint64_t int_value = BitCast<uint64_t, double>(double_value); |
| 2315 | int32_t lower = static_cast<int32_t>(int_value); |
| 2316 | int32_t upper = static_cast<int32_t>(int_value >> kBitsPerInt); |
| 2317 | if (FLAG_trace_osr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2318 | PrintF(" [sp + %d] <- 0x%08x (upper bits of %g) ; [sp + %d]\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2319 | output_offset + kUpperOffset, |
| 2320 | upper, |
| 2321 | double_value, |
| 2322 | *input_offset); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2323 | PrintF(" [sp + %d] <- 0x%08x (lower bits of %g) ; [sp + %d]\n", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2324 | output_offset + kLowerOffset, |
| 2325 | lower, |
| 2326 | double_value, |
| 2327 | *input_offset); |
| 2328 | } |
| 2329 | output->SetFrameSlot(output_offset + kLowerOffset, lower); |
| 2330 | output->SetFrameSlot(output_offset + kUpperOffset, upper); |
| 2331 | break; |
| 2332 | } |
| 2333 | |
| 2334 | case Translation::LITERAL: { |
| 2335 | // Just ignore non-materialized literals. |
| 2336 | iterator->Next(); |
| 2337 | break; |
| 2338 | } |
| 2339 | |
| 2340 | case Translation::ARGUMENTS_OBJECT: { |
| 2341 | // Optimized code assumes that the argument object has not been |
| 2342 | // materialized and so bypasses it when doing arguments access. |
| 2343 | // We should have bailed out before starting the frame |
| 2344 | // translation. |
| 2345 | UNREACHABLE(); |
| 2346 | return false; |
| 2347 | } |
| 2348 | } |
| 2349 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 2350 | *input_offset -= kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2351 | return true; |
| 2352 | } |
| 2353 | |
| 2354 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2355 | void Deoptimizer::PatchInterruptCode(Code* unoptimized_code, |
| 2356 | Code* interrupt_code, |
| 2357 | Code* replacement_code) { |
| 2358 | // Iterate over the back edge table and patch every interrupt |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2359 | // call to an unconditional call to the replacement code. |
| 2360 | ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2361 | int loop_nesting_level = unoptimized_code->allow_osr_at_loop_nesting_level(); |
| 2362 | Address back_edge_cursor = unoptimized_code->instruction_start() + |
| 2363 | unoptimized_code->back_edge_table_offset(); |
| 2364 | uint32_t table_length = Memory::uint32_at(back_edge_cursor); |
| 2365 | back_edge_cursor += kIntSize; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2366 | for (uint32_t i = 0; i < table_length; ++i) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2367 | uint8_t loop_depth = Memory::uint8_at(back_edge_cursor + 2 * kIntSize); |
| 2368 | if (loop_depth == loop_nesting_level) { |
| 2369 | // Loop back edge has the loop depth that we want to patch. |
| 2370 | uint32_t pc_offset = Memory::uint32_at(back_edge_cursor + kIntSize); |
| 2371 | Address pc_after = unoptimized_code->instruction_start() + pc_offset; |
| 2372 | PatchInterruptCodeAt(unoptimized_code, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2373 | pc_after, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2374 | interrupt_code, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2375 | replacement_code); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2376 | } |
| 2377 | back_edge_cursor += FullCodeGenerator::kBackEdgeEntrySize; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2378 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2379 | unoptimized_code->set_back_edges_patched_for_osr(true); |
| 2380 | #ifdef DEBUG |
| 2381 | Deoptimizer::VerifyInterruptCode( |
| 2382 | unoptimized_code, interrupt_code, replacement_code, loop_nesting_level); |
| 2383 | #endif // DEBUG |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2387 | void Deoptimizer::RevertInterruptCode(Code* unoptimized_code, |
| 2388 | Code* interrupt_code, |
| 2389 | Code* replacement_code) { |
| 2390 | // Iterate over the back edge table and revert the patched interrupt calls. |
| 2391 | ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
| 2392 | ASSERT(unoptimized_code->back_edges_patched_for_osr()); |
| 2393 | int loop_nesting_level = unoptimized_code->allow_osr_at_loop_nesting_level(); |
| 2394 | Address back_edge_cursor = unoptimized_code->instruction_start() + |
| 2395 | unoptimized_code->back_edge_table_offset(); |
| 2396 | uint32_t table_length = Memory::uint32_at(back_edge_cursor); |
| 2397 | back_edge_cursor += kIntSize; |
| 2398 | for (uint32_t i = 0; i < table_length; ++i) { |
| 2399 | uint8_t loop_depth = Memory::uint8_at(back_edge_cursor + 2 * kIntSize); |
| 2400 | if (loop_depth <= loop_nesting_level) { |
| 2401 | uint32_t pc_offset = Memory::uint32_at(back_edge_cursor + kIntSize); |
| 2402 | Address pc_after = unoptimized_code->instruction_start() + pc_offset; |
| 2403 | RevertInterruptCodeAt(unoptimized_code, |
| 2404 | pc_after, |
| 2405 | interrupt_code, |
| 2406 | replacement_code); |
| 2407 | } |
| 2408 | back_edge_cursor += FullCodeGenerator::kBackEdgeEntrySize; |
| 2409 | } |
| 2410 | unoptimized_code->set_back_edges_patched_for_osr(false); |
jkummerow@chromium.org | fee992b | 2013-06-19 18:17:45 +0000 | [diff] [blame] | 2411 | unoptimized_code->set_allow_osr_at_loop_nesting_level(0); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2412 | #ifdef DEBUG |
| 2413 | // Assert that none of the back edges are patched anymore. |
| 2414 | Deoptimizer::VerifyInterruptCode( |
| 2415 | unoptimized_code, interrupt_code, replacement_code, -1); |
| 2416 | #endif // DEBUG |
| 2417 | } |
| 2418 | |
| 2419 | |
| 2420 | #ifdef DEBUG |
| 2421 | void Deoptimizer::VerifyInterruptCode(Code* unoptimized_code, |
| 2422 | Code* interrupt_code, |
| 2423 | Code* replacement_code, |
| 2424 | int loop_nesting_level) { |
| 2425 | CHECK(unoptimized_code->kind() == Code::FUNCTION); |
| 2426 | Address back_edge_cursor = unoptimized_code->instruction_start() + |
| 2427 | unoptimized_code->back_edge_table_offset(); |
| 2428 | uint32_t table_length = Memory::uint32_at(back_edge_cursor); |
| 2429 | back_edge_cursor += kIntSize; |
| 2430 | for (uint32_t i = 0; i < table_length; ++i) { |
| 2431 | uint8_t loop_depth = Memory::uint8_at(back_edge_cursor + 2 * kIntSize); |
| 2432 | CHECK_LE(loop_depth, Code::kMaxLoopNestingMarker); |
| 2433 | // Assert that all back edges for shallower loops (and only those) |
| 2434 | // have already been patched. |
| 2435 | uint32_t pc_offset = Memory::uint32_at(back_edge_cursor + kIntSize); |
| 2436 | Address pc_after = unoptimized_code->instruction_start() + pc_offset; |
| 2437 | CHECK_EQ((loop_depth <= loop_nesting_level), |
| 2438 | InterruptCodeIsPatched(unoptimized_code, |
| 2439 | pc_after, |
| 2440 | interrupt_code, |
| 2441 | replacement_code)); |
| 2442 | back_edge_cursor += FullCodeGenerator::kBackEdgeEntrySize; |
| 2443 | } |
| 2444 | } |
| 2445 | #endif // DEBUG |
| 2446 | |
| 2447 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2448 | unsigned Deoptimizer::ComputeInputFrameSize() const { |
| 2449 | unsigned fixed_size = ComputeFixedSize(function_); |
| 2450 | // The fp-to-sp delta already takes the context and the function |
| 2451 | // into account so we have to avoid double counting them (-2). |
| 2452 | unsigned result = fixed_size + fp_to_sp_delta_ - (2 * kPointerSize); |
| 2453 | #ifdef DEBUG |
| 2454 | if (bailout_type_ == OSR) { |
| 2455 | // TODO(kasperl): It would be nice if we could verify that the |
| 2456 | // size matches with the stack height we can compute based on the |
| 2457 | // environment at the OSR entry. The code for that his built into |
| 2458 | // the DoComputeOsrOutputFrame function for now. |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2459 | } else if (compiled_code_->kind() == Code::OPTIMIZED_FUNCTION) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2460 | unsigned stack_slots = compiled_code_->stack_slots(); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2461 | unsigned outgoing_size = ComputeOutgoingArgumentSize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2462 | ASSERT(result == fixed_size + (stack_slots * kPointerSize) + outgoing_size); |
| 2463 | } |
| 2464 | #endif |
| 2465 | return result; |
| 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | unsigned Deoptimizer::ComputeFixedSize(JSFunction* function) const { |
| 2470 | // The fixed part of the frame consists of the return address, frame |
| 2471 | // pointer, function, context, and all the incoming arguments. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2472 | return ComputeIncomingArgumentSize(function) + |
| 2473 | StandardFrameConstants::kFixedFrameSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | |
| 2477 | unsigned Deoptimizer::ComputeIncomingArgumentSize(JSFunction* function) const { |
| 2478 | // The incoming arguments is the values for formal parameters and |
| 2479 | // the receiver. Every slot contains a pointer. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2480 | if (function->IsSmi()) { |
| 2481 | ASSERT(Smi::cast(function) == Smi::FromInt(StackFrame::STUB)); |
| 2482 | return 0; |
| 2483 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2484 | unsigned arguments = function->shared()->formal_parameter_count() + 1; |
| 2485 | return arguments * kPointerSize; |
| 2486 | } |
| 2487 | |
| 2488 | |
| 2489 | unsigned Deoptimizer::ComputeOutgoingArgumentSize() const { |
| 2490 | DeoptimizationInputData* data = DeoptimizationInputData::cast( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2491 | compiled_code_->deoptimization_data()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2492 | unsigned height = data->ArgumentsStackHeight(bailout_id_)->value(); |
| 2493 | return height * kPointerSize; |
| 2494 | } |
| 2495 | |
| 2496 | |
| 2497 | Object* Deoptimizer::ComputeLiteral(int index) const { |
| 2498 | DeoptimizationInputData* data = DeoptimizationInputData::cast( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2499 | compiled_code_->deoptimization_data()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2500 | FixedArray* literals = data->LiteralArray(); |
| 2501 | return literals->get(index); |
| 2502 | } |
| 2503 | |
| 2504 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2505 | void Deoptimizer::AddObjectStart(intptr_t slot_address, int length) { |
| 2506 | ObjectMaterializationDescriptor object_desc( |
| 2507 | reinterpret_cast<Address>(slot_address), length); |
| 2508 | deferred_objects_.Add(object_desc); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2512 | void Deoptimizer::AddObjectTaggedValue(intptr_t value) { |
| 2513 | deferred_objects_tagged_values_.Add(reinterpret_cast<Object*>(value)); |
| 2514 | deferred_objects_double_values_.Add(isolate()->heap()->nan_value()->value()); |
| 2515 | } |
| 2516 | |
| 2517 | |
| 2518 | void Deoptimizer::AddObjectDoubleValue(double value) { |
| 2519 | deferred_objects_tagged_values_.Add(isolate()->heap()->the_hole_value()); |
| 2520 | deferred_objects_double_values_.Add(value); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | void Deoptimizer::AddDoubleValue(intptr_t slot_address, double value) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2525 | HeapNumberMaterializationDescriptor value_desc( |
| 2526 | reinterpret_cast<Address>(slot_address), value); |
| 2527 | deferred_heap_numbers_.Add(value_desc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2531 | void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate, |
| 2532 | BailoutType type, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2533 | int max_entry_id) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2534 | // We cannot run this if the serializer is enabled because this will |
| 2535 | // cause us to emit relocation information for the external |
| 2536 | // references. This is fine because the deoptimizer's code section |
| 2537 | // isn't meant to be serialized at all. |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 2538 | ASSERT(type == EAGER || type == SOFT || type == LAZY); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2539 | DeoptimizerData* data = isolate->deoptimizer_data(); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 2540 | int entry_count = data->deopt_entry_code_entries_[type]; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2541 | if (max_entry_id < entry_count) return; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2542 | entry_count = Max(entry_count, Deoptimizer::kMinNumberOfEntries); |
| 2543 | while (max_entry_id >= entry_count) entry_count *= 2; |
| 2544 | ASSERT(entry_count <= Deoptimizer::kMaxNumberOfEntries); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2545 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2546 | MacroAssembler masm(isolate, NULL, 16 * KB); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2547 | masm.set_emit_debug_code(false); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2548 | GenerateDeoptimizationEntries(&masm, entry_count, type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2549 | CodeDesc desc; |
| 2550 | masm.GetCode(&desc); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 2551 | ASSERT(!RelocInfo::RequiresRelocation(desc)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2552 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 2553 | MemoryChunk* chunk = data->deopt_entry_code_[type]; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 2554 | ASSERT(static_cast<int>(Deoptimizer::GetMaxDeoptTableSize()) >= |
| 2555 | desc.instr_size); |
| 2556 | chunk->CommitArea(desc.instr_size); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2557 | CopyBytes(chunk->area_start(), desc.buffer, |
| 2558 | static_cast<size_t>(desc.instr_size)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 2559 | CPU::FlushICache(chunk->area_start(), desc.instr_size); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2560 | |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 2561 | data->deopt_entry_code_entries_[type] = entry_count; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2565 | void Deoptimizer::ReplaceCodeForRelatedFunctions(JSFunction* function, |
| 2566 | Code* code) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2567 | SharedFunctionInfo* shared = function->shared(); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 2568 | Object* undefined = function->GetHeap()->undefined_value(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2569 | Object* current = function; |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2570 | |
| 2571 | while (current != undefined) { |
| 2572 | JSFunction* func = JSFunction::cast(current); |
| 2573 | current = func->next_function_link(); |
| 2574 | func->set_code(shared->code()); |
| 2575 | func->set_next_function_link(undefined); |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2580 | FrameDescription::FrameDescription(uint32_t frame_size, |
| 2581 | JSFunction* function) |
| 2582 | : frame_size_(frame_size), |
| 2583 | function_(function), |
| 2584 | top_(kZapUint32), |
| 2585 | pc_(kZapUint32), |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2586 | fp_(kZapUint32), |
| 2587 | context_(kZapUint32) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2588 | // Zap all the registers. |
| 2589 | for (int r = 0; r < Register::kNumRegisters; r++) { |
| 2590 | SetRegister(r, kZapUint32); |
| 2591 | } |
| 2592 | |
| 2593 | // Zap all the slots. |
| 2594 | for (unsigned o = 0; o < frame_size; o += kPointerSize) { |
| 2595 | SetFrameSlot(o, kZapUint32); |
| 2596 | } |
| 2597 | } |
| 2598 | |
| 2599 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2600 | int FrameDescription::ComputeFixedSize() { |
| 2601 | return StandardFrameConstants::kFixedFrameSize + |
| 2602 | (ComputeParametersCount() + 1) * kPointerSize; |
| 2603 | } |
| 2604 | |
| 2605 | |
| 2606 | unsigned FrameDescription::GetOffsetFromSlotIndex(int slot_index) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2607 | if (slot_index >= 0) { |
| 2608 | // Local or spill slots. Skip the fixed part of the frame |
| 2609 | // including all arguments. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2610 | unsigned base = GetFrameSize() - ComputeFixedSize(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2611 | return base - ((slot_index + 1) * kPointerSize); |
| 2612 | } else { |
| 2613 | // Incoming parameter. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2614 | int arg_size = (ComputeParametersCount() + 1) * kPointerSize; |
| 2615 | unsigned base = GetFrameSize() - arg_size; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2616 | return base - ((slot_index + 1) * kPointerSize); |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2621 | int FrameDescription::ComputeParametersCount() { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2622 | switch (type_) { |
| 2623 | case StackFrame::JAVA_SCRIPT: |
| 2624 | return function_->shared()->formal_parameter_count(); |
| 2625 | case StackFrame::ARGUMENTS_ADAPTOR: { |
| 2626 | // Last slot contains number of incomming arguments as a smi. |
| 2627 | // Can't use GetExpression(0) because it would cause infinite recursion. |
| 2628 | return reinterpret_cast<Smi*>(*GetFrameSlotPointer(0))->value(); |
| 2629 | } |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 2630 | case StackFrame::STUB: |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2631 | return -1; // Minus receiver. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2632 | default: |
| 2633 | UNREACHABLE(); |
| 2634 | return 0; |
| 2635 | } |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2639 | Object* FrameDescription::GetParameter(int index) { |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2640 | ASSERT(index >= 0); |
| 2641 | ASSERT(index < ComputeParametersCount()); |
| 2642 | // The slot indexes for incoming arguments are negative. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2643 | unsigned offset = GetOffsetFromSlotIndex(index - ComputeParametersCount()); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2644 | return reinterpret_cast<Object*>(*GetFrameSlotPointer(offset)); |
| 2645 | } |
| 2646 | |
| 2647 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2648 | unsigned FrameDescription::GetExpressionCount() { |
| 2649 | ASSERT_EQ(StackFrame::JAVA_SCRIPT, type_); |
| 2650 | unsigned size = GetFrameSize() - ComputeFixedSize(); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2651 | return size / kPointerSize; |
| 2652 | } |
| 2653 | |
| 2654 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2655 | Object* FrameDescription::GetExpression(int index) { |
| 2656 | ASSERT_EQ(StackFrame::JAVA_SCRIPT, type_); |
| 2657 | unsigned offset = GetOffsetFromSlotIndex(index); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2658 | return reinterpret_cast<Object*>(*GetFrameSlotPointer(offset)); |
| 2659 | } |
| 2660 | |
| 2661 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2662 | void TranslationBuffer::Add(int32_t value, Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2663 | // Encode the sign bit in the least significant bit. |
| 2664 | bool is_negative = (value < 0); |
| 2665 | uint32_t bits = ((is_negative ? -value : value) << 1) | |
| 2666 | static_cast<int32_t>(is_negative); |
| 2667 | // Encode the individual bytes using the least significant bit of |
| 2668 | // each byte to indicate whether or not more bytes follow. |
| 2669 | do { |
| 2670 | uint32_t next = bits >> 7; |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2671 | contents_.Add(((bits << 1) & 0xFF) | (next != 0), zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2672 | bits = next; |
| 2673 | } while (bits != 0); |
| 2674 | } |
| 2675 | |
| 2676 | |
| 2677 | int32_t TranslationIterator::Next() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2678 | // Run through the bytes until we reach one with a least significant |
| 2679 | // bit of zero (marks the end). |
| 2680 | uint32_t bits = 0; |
| 2681 | for (int i = 0; true; i += 7) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2682 | ASSERT(HasNext()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2683 | uint8_t next = buffer_->get(index_++); |
| 2684 | bits |= (next >> 1) << i; |
| 2685 | if ((next & 1) == 0) break; |
| 2686 | } |
| 2687 | // The bits encode the sign in the least significant bit. |
| 2688 | bool is_negative = (bits & 1) == 1; |
| 2689 | int32_t result = bits >> 1; |
| 2690 | return is_negative ? -result : result; |
| 2691 | } |
| 2692 | |
| 2693 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 2694 | Handle<ByteArray> TranslationBuffer::CreateByteArray(Factory* factory) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2695 | int length = contents_.length(); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 2696 | Handle<ByteArray> result = factory->NewByteArray(length, TENURED); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2697 | OS::MemCopy( |
| 2698 | result->GetDataStartAddress(), contents_.ToVector().start(), length); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2699 | return result; |
| 2700 | } |
| 2701 | |
| 2702 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2703 | void Translation::BeginConstructStubFrame(int literal_id, unsigned height) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2704 | buffer_->Add(CONSTRUCT_STUB_FRAME, zone()); |
| 2705 | buffer_->Add(literal_id, zone()); |
| 2706 | buffer_->Add(height, zone()); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2710 | void Translation::BeginGetterStubFrame(int literal_id) { |
| 2711 | buffer_->Add(GETTER_STUB_FRAME, zone()); |
| 2712 | buffer_->Add(literal_id, zone()); |
| 2713 | } |
| 2714 | |
| 2715 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2716 | void Translation::BeginSetterStubFrame(int literal_id) { |
| 2717 | buffer_->Add(SETTER_STUB_FRAME, zone()); |
| 2718 | buffer_->Add(literal_id, zone()); |
| 2719 | } |
| 2720 | |
| 2721 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2722 | void Translation::BeginArgumentsAdaptorFrame(int literal_id, unsigned height) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2723 | buffer_->Add(ARGUMENTS_ADAPTOR_FRAME, zone()); |
| 2724 | buffer_->Add(literal_id, zone()); |
| 2725 | buffer_->Add(height, zone()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2729 | void Translation::BeginJSFrame(BailoutId node_id, |
| 2730 | int literal_id, |
| 2731 | unsigned height) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2732 | buffer_->Add(JS_FRAME, zone()); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2733 | buffer_->Add(node_id.ToInt(), zone()); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2734 | buffer_->Add(literal_id, zone()); |
| 2735 | buffer_->Add(height, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2739 | void Translation::BeginCompiledStubFrame() { |
| 2740 | buffer_->Add(COMPILED_STUB_FRAME, zone()); |
| 2741 | } |
| 2742 | |
| 2743 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2744 | void Translation::BeginArgumentsObject(int args_length) { |
| 2745 | buffer_->Add(ARGUMENTS_OBJECT, zone()); |
| 2746 | buffer_->Add(args_length, zone()); |
| 2747 | } |
| 2748 | |
| 2749 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2750 | void Translation::StoreRegister(Register reg) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2751 | buffer_->Add(REGISTER, zone()); |
| 2752 | buffer_->Add(reg.code(), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | |
| 2756 | void Translation::StoreInt32Register(Register reg) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2757 | buffer_->Add(INT32_REGISTER, zone()); |
| 2758 | buffer_->Add(reg.code(), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2762 | void Translation::StoreUint32Register(Register reg) { |
| 2763 | buffer_->Add(UINT32_REGISTER, zone()); |
| 2764 | buffer_->Add(reg.code(), zone()); |
| 2765 | } |
| 2766 | |
| 2767 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2768 | void Translation::StoreDoubleRegister(DoubleRegister reg) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2769 | buffer_->Add(DOUBLE_REGISTER, zone()); |
| 2770 | buffer_->Add(DoubleRegister::ToAllocationIndex(reg), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | |
| 2774 | void Translation::StoreStackSlot(int index) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2775 | buffer_->Add(STACK_SLOT, zone()); |
| 2776 | buffer_->Add(index, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | |
| 2780 | void Translation::StoreInt32StackSlot(int index) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2781 | buffer_->Add(INT32_STACK_SLOT, zone()); |
| 2782 | buffer_->Add(index, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2786 | void Translation::StoreUint32StackSlot(int index) { |
| 2787 | buffer_->Add(UINT32_STACK_SLOT, zone()); |
| 2788 | buffer_->Add(index, zone()); |
| 2789 | } |
| 2790 | |
| 2791 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2792 | void Translation::StoreDoubleStackSlot(int index) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2793 | buffer_->Add(DOUBLE_STACK_SLOT, zone()); |
| 2794 | buffer_->Add(index, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | |
| 2798 | void Translation::StoreLiteral(int literal_id) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2799 | buffer_->Add(LITERAL, zone()); |
| 2800 | buffer_->Add(literal_id, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 2804 | void Translation::StoreArgumentsObject(bool args_known, |
| 2805 | int args_index, |
| 2806 | int args_length) { |
| 2807 | buffer_->Add(ARGUMENTS_OBJECT, zone()); |
| 2808 | buffer_->Add(args_known, zone()); |
| 2809 | buffer_->Add(args_index, zone()); |
| 2810 | buffer_->Add(args_length, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | |
| 2814 | int Translation::NumberOfOperandsFor(Opcode opcode) { |
| 2815 | switch (opcode) { |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2816 | case GETTER_STUB_FRAME: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2817 | case SETTER_STUB_FRAME: |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2818 | case ARGUMENTS_OBJECT: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2819 | case REGISTER: |
| 2820 | case INT32_REGISTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2821 | case UINT32_REGISTER: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2822 | case DOUBLE_REGISTER: |
| 2823 | case STACK_SLOT: |
| 2824 | case INT32_STACK_SLOT: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2825 | case UINT32_STACK_SLOT: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2826 | case DOUBLE_STACK_SLOT: |
| 2827 | case LITERAL: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2828 | case COMPILED_STUB_FRAME: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2829 | return 1; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2830 | case BEGIN: |
| 2831 | case ARGUMENTS_ADAPTOR_FRAME: |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2832 | case CONSTRUCT_STUB_FRAME: |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2833 | return 2; |
| 2834 | case JS_FRAME: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2835 | return 3; |
| 2836 | } |
| 2837 | UNREACHABLE(); |
| 2838 | return -1; |
| 2839 | } |
| 2840 | |
| 2841 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2842 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2843 | |
| 2844 | const char* Translation::StringFor(Opcode opcode) { |
| 2845 | switch (opcode) { |
| 2846 | case BEGIN: |
| 2847 | return "BEGIN"; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2848 | case JS_FRAME: |
| 2849 | return "JS_FRAME"; |
| 2850 | case ARGUMENTS_ADAPTOR_FRAME: |
| 2851 | return "ARGUMENTS_ADAPTOR_FRAME"; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2852 | case CONSTRUCT_STUB_FRAME: |
| 2853 | return "CONSTRUCT_STUB_FRAME"; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2854 | case GETTER_STUB_FRAME: |
| 2855 | return "GETTER_STUB_FRAME"; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2856 | case SETTER_STUB_FRAME: |
| 2857 | return "SETTER_STUB_FRAME"; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2858 | case COMPILED_STUB_FRAME: |
| 2859 | return "COMPILED_STUB_FRAME"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2860 | case REGISTER: |
| 2861 | return "REGISTER"; |
| 2862 | case INT32_REGISTER: |
| 2863 | return "INT32_REGISTER"; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2864 | case UINT32_REGISTER: |
| 2865 | return "UINT32_REGISTER"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2866 | case DOUBLE_REGISTER: |
| 2867 | return "DOUBLE_REGISTER"; |
| 2868 | case STACK_SLOT: |
| 2869 | return "STACK_SLOT"; |
| 2870 | case INT32_STACK_SLOT: |
| 2871 | return "INT32_STACK_SLOT"; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2872 | case UINT32_STACK_SLOT: |
| 2873 | return "UINT32_STACK_SLOT"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2874 | case DOUBLE_STACK_SLOT: |
| 2875 | return "DOUBLE_STACK_SLOT"; |
| 2876 | case LITERAL: |
| 2877 | return "LITERAL"; |
| 2878 | case ARGUMENTS_OBJECT: |
| 2879 | return "ARGUMENTS_OBJECT"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2880 | } |
| 2881 | UNREACHABLE(); |
| 2882 | return ""; |
| 2883 | } |
| 2884 | |
| 2885 | #endif |
| 2886 | |
| 2887 | |
| 2888 | DeoptimizingCodeListNode::DeoptimizingCodeListNode(Code* code): next_(NULL) { |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 2889 | GlobalHandles* global_handles = code->GetIsolate()->global_handles(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2890 | // Globalize the code object and make it weak. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2891 | code_ = Handle<Code>::cast(global_handles->Create(code)); |
| 2892 | global_handles->MakeWeak(reinterpret_cast<Object**>(code_.location()), |
| 2893 | this, |
| 2894 | Deoptimizer::HandleWeakDeoptimizedCode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | |
| 2898 | DeoptimizingCodeListNode::~DeoptimizingCodeListNode() { |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 2899 | GlobalHandles* global_handles = code_->GetIsolate()->global_handles(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2900 | global_handles->Destroy(reinterpret_cast<Object**>(code_.location())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2904 | // We can't intermix stack decoding and allocations because |
| 2905 | // deoptimization infrastracture is not GC safe. |
| 2906 | // Thus we build a temporary structure in malloced space. |
| 2907 | SlotRef SlotRef::ComputeSlotForNextArgument(TranslationIterator* iterator, |
| 2908 | DeoptimizationInputData* data, |
| 2909 | JavaScriptFrame* frame) { |
| 2910 | Translation::Opcode opcode = |
| 2911 | static_cast<Translation::Opcode>(iterator->Next()); |
| 2912 | |
| 2913 | switch (opcode) { |
| 2914 | case Translation::BEGIN: |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2915 | case Translation::JS_FRAME: |
| 2916 | case Translation::ARGUMENTS_ADAPTOR_FRAME: |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2917 | case Translation::CONSTRUCT_STUB_FRAME: |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2918 | case Translation::GETTER_STUB_FRAME: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2919 | case Translation::SETTER_STUB_FRAME: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2920 | // Peeled off before getting here. |
| 2921 | break; |
| 2922 | |
| 2923 | case Translation::ARGUMENTS_OBJECT: |
| 2924 | // This can be only emitted for local slots not for argument slots. |
| 2925 | break; |
| 2926 | |
| 2927 | case Translation::REGISTER: |
| 2928 | case Translation::INT32_REGISTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2929 | case Translation::UINT32_REGISTER: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2930 | case Translation::DOUBLE_REGISTER: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2931 | // We are at safepoint which corresponds to call. All registers are |
| 2932 | // saved by caller so there would be no live registers at this |
| 2933 | // point. Thus these translation commands should not be used. |
| 2934 | break; |
| 2935 | |
| 2936 | case Translation::STACK_SLOT: { |
| 2937 | int slot_index = iterator->Next(); |
| 2938 | Address slot_addr = SlotAddress(frame, slot_index); |
| 2939 | return SlotRef(slot_addr, SlotRef::TAGGED); |
| 2940 | } |
| 2941 | |
| 2942 | case Translation::INT32_STACK_SLOT: { |
| 2943 | int slot_index = iterator->Next(); |
| 2944 | Address slot_addr = SlotAddress(frame, slot_index); |
| 2945 | return SlotRef(slot_addr, SlotRef::INT32); |
| 2946 | } |
| 2947 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2948 | case Translation::UINT32_STACK_SLOT: { |
| 2949 | int slot_index = iterator->Next(); |
| 2950 | Address slot_addr = SlotAddress(frame, slot_index); |
| 2951 | return SlotRef(slot_addr, SlotRef::UINT32); |
| 2952 | } |
| 2953 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2954 | case Translation::DOUBLE_STACK_SLOT: { |
| 2955 | int slot_index = iterator->Next(); |
| 2956 | Address slot_addr = SlotAddress(frame, slot_index); |
| 2957 | return SlotRef(slot_addr, SlotRef::DOUBLE); |
| 2958 | } |
| 2959 | |
| 2960 | case Translation::LITERAL: { |
| 2961 | int literal_index = iterator->Next(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2962 | return SlotRef(data->GetIsolate(), |
| 2963 | data->LiteralArray()->get(literal_index)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2964 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2965 | |
| 2966 | case Translation::COMPILED_STUB_FRAME: |
| 2967 | UNREACHABLE(); |
| 2968 | break; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | UNREACHABLE(); |
| 2972 | return SlotRef(); |
| 2973 | } |
| 2974 | |
| 2975 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2976 | void SlotRef::ComputeSlotsForArguments(Vector<SlotRef>* args_slots, |
| 2977 | TranslationIterator* it, |
| 2978 | DeoptimizationInputData* data, |
| 2979 | JavaScriptFrame* frame) { |
| 2980 | // Process the translation commands for the arguments. |
| 2981 | |
| 2982 | // Skip the translation command for the receiver. |
| 2983 | it->Skip(Translation::NumberOfOperandsFor( |
| 2984 | static_cast<Translation::Opcode>(it->Next()))); |
| 2985 | |
| 2986 | // Compute slots for arguments. |
| 2987 | for (int i = 0; i < args_slots->length(); ++i) { |
| 2988 | (*args_slots)[i] = ComputeSlotForNextArgument(it, data, frame); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | |
| 2993 | Vector<SlotRef> SlotRef::ComputeSlotMappingForArguments( |
| 2994 | JavaScriptFrame* frame, |
| 2995 | int inlined_jsframe_index, |
| 2996 | int formal_parameter_count) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 2997 | DisallowHeapAllocation no_gc; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2998 | int deopt_index = Safepoint::kNoDeoptimizationIndex; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2999 | DeoptimizationInputData* data = |
| 3000 | static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); |
| 3001 | TranslationIterator it(data->TranslationByteArray(), |
| 3002 | data->TranslationIndex(deopt_index)->value()); |
| 3003 | Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 3004 | ASSERT(opcode == Translation::BEGIN); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3005 | it.Next(); // Drop frame count. |
| 3006 | int jsframe_count = it.Next(); |
| 3007 | USE(jsframe_count); |
| 3008 | ASSERT(jsframe_count > inlined_jsframe_index); |
| 3009 | int jsframes_to_skip = inlined_jsframe_index; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3010 | while (true) { |
| 3011 | opcode = static_cast<Translation::Opcode>(it.Next()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3012 | if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) { |
| 3013 | if (jsframes_to_skip == 0) { |
| 3014 | ASSERT(Translation::NumberOfOperandsFor(opcode) == 2); |
| 3015 | |
| 3016 | it.Skip(1); // literal id |
| 3017 | int height = it.Next(); |
| 3018 | |
| 3019 | // We reached the arguments adaptor frame corresponding to the |
| 3020 | // inlined function in question. Number of arguments is height - 1. |
| 3021 | Vector<SlotRef> args_slots = |
| 3022 | Vector<SlotRef>::New(height - 1); // Minus receiver. |
| 3023 | ComputeSlotsForArguments(&args_slots, &it, data, frame); |
| 3024 | return args_slots; |
| 3025 | } |
| 3026 | } else if (opcode == Translation::JS_FRAME) { |
| 3027 | if (jsframes_to_skip == 0) { |
| 3028 | // Skip over operands to advance to the next opcode. |
| 3029 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 3030 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3031 | // We reached the frame corresponding to the inlined function |
| 3032 | // in question. Process the translation commands for the |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3033 | // arguments. Number of arguments is equal to the number of |
| 3034 | // format parameter count. |
| 3035 | Vector<SlotRef> args_slots = |
| 3036 | Vector<SlotRef>::New(formal_parameter_count); |
| 3037 | ComputeSlotsForArguments(&args_slots, &it, data, frame); |
| 3038 | return args_slots; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3039 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3040 | jsframes_to_skip--; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3041 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3042 | |
| 3043 | // Skip over operands to advance to the next opcode. |
| 3044 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | UNREACHABLE(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3048 | return Vector<SlotRef>(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3049 | } |
| 3050 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3051 | #ifdef ENABLE_DEBUGGER_SUPPORT |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3052 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3053 | DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer, |
| 3054 | int frame_index, |
| 3055 | bool has_arguments_adaptor, |
| 3056 | bool has_construct_stub) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3057 | FrameDescription* output_frame = deoptimizer->output_[frame_index]; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 3058 | function_ = output_frame->GetFunction(); |
| 3059 | has_construct_stub_ = has_construct_stub; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3060 | expression_count_ = output_frame->GetExpressionCount(); |
| 3061 | expression_stack_ = new Object*[expression_count_]; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3062 | // Get the source position using the unoptimized code. |
| 3063 | Address pc = reinterpret_cast<Address>(output_frame->GetPc()); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 3064 | Code* code = Code::cast(deoptimizer->isolate()->heap()->FindCodeObject(pc)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3065 | source_position_ = code->SourcePosition(pc); |
| 3066 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3067 | for (int i = 0; i < expression_count_; i++) { |
| 3068 | SetExpression(i, output_frame->GetExpression(i)); |
| 3069 | } |
| 3070 | |
| 3071 | if (has_arguments_adaptor) { |
| 3072 | output_frame = deoptimizer->output_[frame_index - 1]; |
| 3073 | ASSERT(output_frame->GetFrameType() == StackFrame::ARGUMENTS_ADAPTOR); |
| 3074 | } |
| 3075 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3076 | parameters_count_ = output_frame->ComputeParametersCount(); |
| 3077 | parameters_ = new Object*[parameters_count_]; |
| 3078 | for (int i = 0; i < parameters_count_; i++) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3079 | SetParameter(i, output_frame->GetParameter(i)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | |
| 3084 | DeoptimizedFrameInfo::~DeoptimizedFrameInfo() { |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3085 | delete[] expression_stack_; |
| 3086 | delete[] parameters_; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3087 | } |
| 3088 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3089 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3090 | void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3091 | v->VisitPointer(BitCast<Object**>(&function_)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3092 | v->VisitPointers(parameters_, parameters_ + parameters_count_); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3093 | v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); |
| 3094 | } |
| 3095 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3096 | #endif // ENABLE_DEBUGGER_SUPPORT |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3097 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3098 | } } // namespace v8::internal |