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