| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/deopt_instructions.h" | 5 #include "vm/deopt_instructions.h" |
| 6 | 6 |
| 7 #include "vm/assembler_macros.h" | 7 #include "vm/assembler_macros.h" |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 #include "vm/locations.h" | 9 #include "vm/locations.h" |
| 10 #include "vm/parser.h" | 10 #include "vm/parser.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 *from_addr, reinterpret_cast<RawDouble**>(to_addr)); | 115 *from_addr, reinterpret_cast<RawDouble**>(to_addr)); |
| 116 } | 116 } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 const intptr_t stack_slot_index_; // First argument is 0, always >= 0. | 119 const intptr_t stack_slot_index_; // First argument is 0, always >= 0. |
| 120 | 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(DeoptDoubleStackSlotInstr); | 121 DISALLOW_COPY_AND_ASSIGN(DeoptDoubleStackSlotInstr); |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 | 124 |
| 125 class DeoptInt64StackSlotInstr : public DeoptInstr { |
| 126 public: |
| 127 explicit DeoptInt64StackSlotInstr(intptr_t from_index) |
| 128 : stack_slot_index_(from_index) { |
| 129 ASSERT(stack_slot_index_ >= 0); |
| 130 } |
| 131 |
| 132 virtual intptr_t from_index() const { return stack_slot_index_; } |
| 133 virtual DeoptInstr::Kind kind() const { return kCopyInt64StackSlot; } |
| 134 |
| 135 virtual const char* ToCString() const { |
| 136 const char* format = "ms%"Pd""; |
| 137 intptr_t len = OS::SNPrint(NULL, 0, format, stack_slot_index_); |
| 138 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 139 OS::SNPrint(chars, len + 1, format, stack_slot_index_); |
| 140 return chars; |
| 141 } |
| 142 |
| 143 void Execute(DeoptimizationContext* deopt_context, intptr_t to_index) { |
| 144 intptr_t from_index = |
| 145 deopt_context->from_frame_size() - stack_slot_index_ - 1; |
| 146 int64_t* from_addr = reinterpret_cast<int64_t*>( |
| 147 deopt_context->GetFromFrameAddressAt(from_index)); |
| 148 intptr_t* to_addr = deopt_context->GetToFrameAddressAt(to_index); |
| 149 *reinterpret_cast<RawSmi**>(to_addr) = Smi::New(0); |
| 150 if (Smi::IsValid64(*from_addr)) { |
| 151 *to_addr = reinterpret_cast<intptr_t>( |
| 152 Smi::New(static_cast<intptr_t>(*from_addr))); |
| 153 } else { |
| 154 Isolate::Current()->DeferMintMaterialization( |
| 155 *from_addr, reinterpret_cast<RawMint**>(to_addr)); |
| 156 } |
| 157 } |
| 158 |
| 159 private: |
| 160 const intptr_t stack_slot_index_; // First argument is 0, always >= 0. |
| 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(DeoptInt64StackSlotInstr); |
| 163 }; |
| 164 |
| 165 |
| 125 // Deoptimization instruction creating return address using function and | 166 // Deoptimization instruction creating return address using function and |
| 126 // deopt-id stored at 'object_table_index'. Uses the deopt-after | 167 // deopt-id stored at 'object_table_index'. Uses the deopt-after |
| 127 // continuation point. | 168 // continuation point. |
| 128 class DeoptRetAddrAfterInstr : public DeoptInstr { | 169 class DeoptRetAddrAfterInstr : public DeoptInstr { |
| 129 public: | 170 public: |
| 130 explicit DeoptRetAddrAfterInstr(intptr_t object_table_index) | 171 explicit DeoptRetAddrAfterInstr(intptr_t object_table_index) |
| 131 : object_table_index_(object_table_index) { | 172 : object_table_index_(object_table_index) { |
| 132 ASSERT(object_table_index >= 0); | 173 ASSERT(object_table_index >= 0); |
| 133 } | 174 } |
| 134 | 175 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 value, reinterpret_cast<RawDouble**>(to_addr)); | 326 value, reinterpret_cast<RawDouble**>(to_addr)); |
| 286 } | 327 } |
| 287 | 328 |
| 288 private: | 329 private: |
| 289 const XmmRegister reg_; | 330 const XmmRegister reg_; |
| 290 | 331 |
| 291 DISALLOW_COPY_AND_ASSIGN(DeoptXmmRegisterInstr); | 332 DISALLOW_COPY_AND_ASSIGN(DeoptXmmRegisterInstr); |
| 292 }; | 333 }; |
| 293 | 334 |
| 294 | 335 |
| 336 class DeoptInt64XmmRegisterInstr: public DeoptInstr { |
| 337 public: |
| 338 explicit DeoptInt64XmmRegisterInstr(intptr_t reg_as_int) |
| 339 : reg_(static_cast<XmmRegister>(reg_as_int)) {} |
| 340 |
| 341 virtual intptr_t from_index() const { return static_cast<intptr_t>(reg_); } |
| 342 virtual DeoptInstr::Kind kind() const { return kCopyInt64XmmRegister; } |
| 343 |
| 344 virtual const char* ToCString() const { |
| 345 const char* format = "%s(m)"; |
| 346 intptr_t len = |
| 347 OS::SNPrint(NULL, 0, format, Assembler::XmmRegisterName(reg_)); |
| 348 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 349 OS::SNPrint(chars, len + 1, format, Assembler::XmmRegisterName(reg_)); |
| 350 return chars; |
| 351 } |
| 352 |
| 353 void Execute(DeoptimizationContext* deopt_context, intptr_t to_index) { |
| 354 int64_t value = deopt_context->XmmRegisterValueAsInt64(reg_); |
| 355 intptr_t* to_addr = deopt_context->GetToFrameAddressAt(to_index); |
| 356 *reinterpret_cast<RawSmi**>(to_addr) = Smi::New(0); |
| 357 if (Smi::IsValid64(value)) { |
| 358 *to_addr = reinterpret_cast<intptr_t>( |
| 359 Smi::New(static_cast<intptr_t>(value))); |
| 360 } else { |
| 361 Isolate::Current()->DeferMintMaterialization( |
| 362 value, reinterpret_cast<RawMint**>(to_addr)); |
| 363 } |
| 364 } |
| 365 |
| 366 private: |
| 367 const XmmRegister reg_; |
| 368 |
| 369 DISALLOW_COPY_AND_ASSIGN(DeoptInt64XmmRegisterInstr); |
| 370 }; |
| 371 |
| 372 |
| 295 // Deoptimization instruction creating a PC marker for the code of | 373 // Deoptimization instruction creating a PC marker for the code of |
| 296 // function at 'object_table_index'. | 374 // function at 'object_table_index'. |
| 297 class DeoptPcMarkerInstr : public DeoptInstr { | 375 class DeoptPcMarkerInstr : public DeoptInstr { |
| 298 public: | 376 public: |
| 299 explicit DeoptPcMarkerInstr(intptr_t object_table_index) | 377 explicit DeoptPcMarkerInstr(intptr_t object_table_index) |
| 300 : object_table_index_(object_table_index) { | 378 : object_table_index_(object_table_index) { |
| 301 ASSERT(object_table_index >= 0); | 379 ASSERT(object_table_index >= 0); |
| 302 } | 380 } |
| 303 | 381 |
| 304 virtual intptr_t from_index() const { return object_table_index_; } | 382 virtual intptr_t from_index() const { return object_table_index_; } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 private: | 454 private: |
| 377 DISALLOW_COPY_AND_ASSIGN(DeoptCallerPcInstr); | 455 DISALLOW_COPY_AND_ASSIGN(DeoptCallerPcInstr); |
| 378 }; | 456 }; |
| 379 | 457 |
| 380 | 458 |
| 381 DeoptInstr* DeoptInstr::Create(intptr_t kind_as_int, intptr_t from_index) { | 459 DeoptInstr* DeoptInstr::Create(intptr_t kind_as_int, intptr_t from_index) { |
| 382 Kind kind = static_cast<Kind>(kind_as_int); | 460 Kind kind = static_cast<Kind>(kind_as_int); |
| 383 switch (kind) { | 461 switch (kind) { |
| 384 case kCopyStackSlot: return new DeoptStackSlotInstr(from_index); | 462 case kCopyStackSlot: return new DeoptStackSlotInstr(from_index); |
| 385 case kCopyDoubleStackSlot: return new DeoptDoubleStackSlotInstr(from_index); | 463 case kCopyDoubleStackSlot: return new DeoptDoubleStackSlotInstr(from_index); |
| 464 case kCopyInt64StackSlot: return new DeoptInt64StackSlotInstr(from_index); |
| 386 case kSetRetAfterAddress: return new DeoptRetAddrAfterInstr(from_index); | 465 case kSetRetAfterAddress: return new DeoptRetAddrAfterInstr(from_index); |
| 387 case kSetRetBeforeAddress: return new DeoptRetAddrBeforeInstr(from_index); | 466 case kSetRetBeforeAddress: return new DeoptRetAddrBeforeInstr(from_index); |
| 388 case kCopyConstant: return new DeoptConstantInstr(from_index); | 467 case kCopyConstant: return new DeoptConstantInstr(from_index); |
| 389 case kCopyRegister: return new DeoptRegisterInstr(from_index); | 468 case kCopyRegister: return new DeoptRegisterInstr(from_index); |
| 390 case kCopyXmmRegister: return new DeoptXmmRegisterInstr(from_index); | 469 case kCopyXmmRegister: return new DeoptXmmRegisterInstr(from_index); |
| 470 case kCopyInt64XmmRegister: |
| 471 return new DeoptInt64XmmRegisterInstr(from_index); |
| 391 case kSetPcMarker: return new DeoptPcMarkerInstr(from_index); | 472 case kSetPcMarker: return new DeoptPcMarkerInstr(from_index); |
| 392 case kSetCallerFp: return new DeoptCallerFpInstr(); | 473 case kSetCallerFp: return new DeoptCallerFpInstr(); |
| 393 case kSetCallerPc: return new DeoptCallerPcInstr(); | 474 case kSetCallerPc: return new DeoptCallerPcInstr(); |
| 394 } | 475 } |
| 395 UNREACHABLE(); | 476 UNREACHABLE(); |
| 396 return NULL; | 477 return NULL; |
| 397 } | 478 } |
| 398 | 479 |
| 399 | 480 |
| 400 intptr_t DeoptInfoBuilder::FindOrAddObjectInTable(const Object& obj) const { | 481 intptr_t DeoptInfoBuilder::FindOrAddObjectInTable(const Object& obj) const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 void DeoptInfoBuilder::AddCopy(const Location& from_loc, | 525 void DeoptInfoBuilder::AddCopy(const Location& from_loc, |
| 445 const Value& from_value, | 526 const Value& from_value, |
| 446 const intptr_t to_index) { | 527 const intptr_t to_index) { |
| 447 DeoptInstr* deopt_instr = NULL; | 528 DeoptInstr* deopt_instr = NULL; |
| 448 if (from_loc.IsConstant()) { | 529 if (from_loc.IsConstant()) { |
| 449 intptr_t object_table_index = FindOrAddObjectInTable(from_loc.constant()); | 530 intptr_t object_table_index = FindOrAddObjectInTable(from_loc.constant()); |
| 450 deopt_instr = new DeoptConstantInstr(object_table_index); | 531 deopt_instr = new DeoptConstantInstr(object_table_index); |
| 451 } else if (from_loc.IsRegister()) { | 532 } else if (from_loc.IsRegister()) { |
| 452 deopt_instr = new DeoptRegisterInstr(from_loc.reg()); | 533 deopt_instr = new DeoptRegisterInstr(from_loc.reg()); |
| 453 } else if (from_loc.IsXmmRegister()) { | 534 } else if (from_loc.IsXmmRegister()) { |
| 454 deopt_instr = new DeoptXmmRegisterInstr(from_loc.xmm_reg()); | 535 if (from_loc.representation() == Location::kDouble) { |
| 536 deopt_instr = new DeoptXmmRegisterInstr(from_loc.xmm_reg()); |
| 537 } else { |
| 538 ASSERT(from_loc.representation() == Location::kMint); |
| 539 deopt_instr = new DeoptInt64XmmRegisterInstr(from_loc.xmm_reg()); |
| 540 } |
| 455 } else if (from_loc.IsStackSlot()) { | 541 } else if (from_loc.IsStackSlot()) { |
| 456 intptr_t from_index = (from_loc.stack_index() < 0) ? | 542 intptr_t from_index = (from_loc.stack_index() < 0) ? |
| 457 from_loc.stack_index() + num_args_ : | 543 from_loc.stack_index() + num_args_ : |
| 458 from_loc.stack_index() + num_args_ - | 544 from_loc.stack_index() + num_args_ - |
| 459 ParsedFunction::kFirstLocalSlotIndex + 1; | 545 ParsedFunction::kFirstLocalSlotIndex + 1; |
| 460 deopt_instr = new DeoptStackSlotInstr(from_index); | 546 deopt_instr = new DeoptStackSlotInstr(from_index); |
| 461 } else if (from_loc.IsDoubleStackSlot()) { | 547 } else if (from_loc.IsDoubleStackSlot()) { |
| 462 intptr_t from_index = (from_loc.stack_index() < 0) ? | 548 intptr_t from_index = (from_loc.stack_index() < 0) ? |
| 463 from_loc.stack_index() + num_args_ : | 549 from_loc.stack_index() + num_args_ : |
| 464 from_loc.stack_index() + num_args_ - | 550 from_loc.stack_index() + num_args_ - |
| 465 ParsedFunction::kFirstLocalSlotIndex + 1; | 551 ParsedFunction::kFirstLocalSlotIndex + 1; |
| 466 deopt_instr = new DeoptDoubleStackSlotInstr(from_index); | 552 if (from_loc.representation() == Location::kDouble) { |
| 553 deopt_instr = new DeoptDoubleStackSlotInstr(from_index); |
| 554 } else { |
| 555 ASSERT(from_loc.representation() == Location::kMint); |
| 556 deopt_instr = new DeoptInt64StackSlotInstr(from_index); |
| 557 } |
| 467 } else { | 558 } else { |
| 468 UNREACHABLE(); | 559 UNREACHABLE(); |
| 469 } | 560 } |
| 470 ASSERT(to_index == instructions_.length()); | 561 ASSERT(to_index == instructions_.length()); |
| 471 instructions_.Add(deopt_instr); | 562 instructions_.Add(deopt_instr); |
| 472 } | 563 } |
| 473 | 564 |
| 474 | 565 |
| 475 void DeoptInfoBuilder::AddCallerFp(intptr_t to_index) { | 566 void DeoptInfoBuilder::AddCallerFp(intptr_t to_index) { |
| 476 ASSERT(to_index == instructions_.length()); | 567 ASSERT(to_index == instructions_.length()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 Smi* offset, | 614 Smi* offset, |
| 524 DeoptInfo* info, | 615 DeoptInfo* info, |
| 525 Smi* reason) { | 616 Smi* reason) { |
| 526 intptr_t i = index * kEntrySize; | 617 intptr_t i = index * kEntrySize; |
| 527 *offset ^= table.At(i); | 618 *offset ^= table.At(i); |
| 528 *info ^= table.At(i + 1); | 619 *info ^= table.At(i + 1); |
| 529 *reason ^= table.At(i + 2); | 620 *reason ^= table.At(i + 2); |
| 530 } | 621 } |
| 531 | 622 |
| 532 } // namespace dart | 623 } // namespace dart |
| OLD | NEW |