Chromium Code Reviews| 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 DeoptMintStackSlotInstr : public DeoptInstr { | |
|
srdjan
2012/09/28 16:50:26
Should this be Deopt64bitStackSlotInstr instead si
Florian Schneider
2012/10/02 11:10:31
Done.
| |
| 126 public: | |
| 127 explicit DeoptMintStackSlotInstr(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 kCopyMintStackSlot; } | |
| 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(DeoptMintStackSlotInstr); | |
| 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 DeoptMintXmmRegisterInstr: public DeoptInstr { | |
| 337 public: | |
| 338 explicit DeoptMintXmmRegisterInstr(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 kCopyMintXmmRegister; } | |
| 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->XmmRegisterValueAsMint(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(DeoptMintXmmRegisterInstr); | |
| 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 kCopyMintStackSlot: return new DeoptMintStackSlotInstr(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 kCopyMintXmmRegister: return new DeoptMintXmmRegisterInstr(from_index); | |
| 391 case kSetPcMarker: return new DeoptPcMarkerInstr(from_index); | 471 case kSetPcMarker: return new DeoptPcMarkerInstr(from_index); |
| 392 case kSetCallerFp: return new DeoptCallerFpInstr(); | 472 case kSetCallerFp: return new DeoptCallerFpInstr(); |
| 393 case kSetCallerPc: return new DeoptCallerPcInstr(); | 473 case kSetCallerPc: return new DeoptCallerPcInstr(); |
| 394 } | 474 } |
| 395 UNREACHABLE(); | 475 UNREACHABLE(); |
| 396 return NULL; | 476 return NULL; |
| 397 } | 477 } |
| 398 | 478 |
| 399 | 479 |
| 400 intptr_t DeoptInfoBuilder::FindOrAddObjectInTable(const Object& obj) const { | 480 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, | 524 void DeoptInfoBuilder::AddCopy(const Location& from_loc, |
| 445 const Value& from_value, | 525 const Value& from_value, |
| 446 const intptr_t to_index) { | 526 const intptr_t to_index) { |
| 447 DeoptInstr* deopt_instr = NULL; | 527 DeoptInstr* deopt_instr = NULL; |
| 448 if (from_loc.IsConstant()) { | 528 if (from_loc.IsConstant()) { |
| 449 intptr_t object_table_index = FindOrAddObjectInTable(from_loc.constant()); | 529 intptr_t object_table_index = FindOrAddObjectInTable(from_loc.constant()); |
| 450 deopt_instr = new DeoptConstantInstr(object_table_index); | 530 deopt_instr = new DeoptConstantInstr(object_table_index); |
| 451 } else if (from_loc.IsRegister()) { | 531 } else if (from_loc.IsRegister()) { |
| 452 deopt_instr = new DeoptRegisterInstr(from_loc.reg()); | 532 deopt_instr = new DeoptRegisterInstr(from_loc.reg()); |
| 453 } else if (from_loc.IsXmmRegister()) { | 533 } else if (from_loc.IsXmmRegister()) { |
| 454 deopt_instr = new DeoptXmmRegisterInstr(from_loc.xmm_reg()); | 534 if (from_loc.representation() == Location::kDouble) { |
| 535 deopt_instr = new DeoptXmmRegisterInstr(from_loc.xmm_reg()); | |
| 536 } else { | |
| 537 ASSERT(from_loc.representation() == Location::kMint); | |
| 538 deopt_instr = new DeoptMintXmmRegisterInstr(from_loc.xmm_reg()); | |
| 539 } | |
| 455 } else if (from_loc.IsStackSlot()) { | 540 } else if (from_loc.IsStackSlot()) { |
| 456 intptr_t from_index = (from_loc.stack_index() < 0) ? | 541 intptr_t from_index = (from_loc.stack_index() < 0) ? |
| 457 from_loc.stack_index() + num_args_ : | 542 from_loc.stack_index() + num_args_ : |
| 458 from_loc.stack_index() + num_args_ - | 543 from_loc.stack_index() + num_args_ - |
| 459 ParsedFunction::kFirstLocalSlotIndex + 1; | 544 ParsedFunction::kFirstLocalSlotIndex + 1; |
| 460 deopt_instr = new DeoptStackSlotInstr(from_index); | 545 deopt_instr = new DeoptStackSlotInstr(from_index); |
| 461 } else if (from_loc.IsDoubleStackSlot()) { | 546 } else if (from_loc.IsDoubleStackSlot()) { |
| 462 intptr_t from_index = (from_loc.stack_index() < 0) ? | 547 intptr_t from_index = (from_loc.stack_index() < 0) ? |
| 463 from_loc.stack_index() + num_args_ : | 548 from_loc.stack_index() + num_args_ : |
| 464 from_loc.stack_index() + num_args_ - | 549 from_loc.stack_index() + num_args_ - |
| 465 ParsedFunction::kFirstLocalSlotIndex + 1; | 550 ParsedFunction::kFirstLocalSlotIndex + 1; |
| 466 deopt_instr = new DeoptDoubleStackSlotInstr(from_index); | 551 if (from_loc.representation() == Location::kDouble) { |
| 552 deopt_instr = new DeoptDoubleStackSlotInstr(from_index); | |
| 553 } else { | |
| 554 ASSERT(from_loc.representation() == Location::kMint); | |
| 555 deopt_instr = new DeoptMintStackSlotInstr(from_index); | |
| 556 } | |
| 467 } else { | 557 } else { |
| 468 UNREACHABLE(); | 558 UNREACHABLE(); |
| 469 } | 559 } |
| 470 ASSERT(to_index == instructions_.length()); | 560 ASSERT(to_index == instructions_.length()); |
| 471 instructions_.Add(deopt_instr); | 561 instructions_.Add(deopt_instr); |
| 472 } | 562 } |
| 473 | 563 |
| 474 | 564 |
| 475 void DeoptInfoBuilder::AddCallerFp(intptr_t to_index) { | 565 void DeoptInfoBuilder::AddCallerFp(intptr_t to_index) { |
| 476 ASSERT(to_index == instructions_.length()); | 566 ASSERT(to_index == instructions_.length()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 488 const intptr_t len = instructions_.length(); | 578 const intptr_t len = instructions_.length(); |
| 489 const DeoptInfo& deopt_info = DeoptInfo::Handle(DeoptInfo::New(len)); | 579 const DeoptInfo& deopt_info = DeoptInfo::Handle(DeoptInfo::New(len)); |
| 490 for (intptr_t i = 0; i < len; i++) { | 580 for (intptr_t i = 0; i < len; i++) { |
| 491 DeoptInstr* instr = instructions_[i]; | 581 DeoptInstr* instr = instructions_[i]; |
| 492 deopt_info.SetAt(i, instr->kind(), instr->from_index()); | 582 deopt_info.SetAt(i, instr->kind(), instr->from_index()); |
| 493 } | 583 } |
| 494 return deopt_info.raw(); | 584 return deopt_info.raw(); |
| 495 } | 585 } |
| 496 | 586 |
| 497 } // namespace dart | 587 } // namespace dart |
| OLD | NEW |