| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 6382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6393 return *(EntryAddr(index, kDeoptIdEntry)); | 6393 return *(EntryAddr(index, kDeoptIdEntry)); |
| 6394 } | 6394 } |
| 6395 | 6395 |
| 6396 | 6396 |
| 6397 void PcDescriptors::SetDeoptId(intptr_t index, intptr_t value) const { | 6397 void PcDescriptors::SetDeoptId(intptr_t index, intptr_t value) const { |
| 6398 *(EntryAddr(index, kDeoptIdEntry)) = value; | 6398 *(EntryAddr(index, kDeoptIdEntry)) = value; |
| 6399 } | 6399 } |
| 6400 | 6400 |
| 6401 | 6401 |
| 6402 intptr_t PcDescriptors::TokenPos(intptr_t index) const { | 6402 intptr_t PcDescriptors::TokenPos(intptr_t index) const { |
| 6403 ASSERT(DescriptorKind(index) != kDeoptIndex); | |
| 6404 return *(EntryAddr(index, kTokenPosEntry)); | 6403 return *(EntryAddr(index, kTokenPosEntry)); |
| 6405 } | 6404 } |
| 6406 | 6405 |
| 6407 | 6406 |
| 6408 void PcDescriptors::SetTokenPos(intptr_t index, intptr_t value) const { | 6407 void PcDescriptors::SetTokenPos(intptr_t index, intptr_t value) const { |
| 6409 *(EntryAddr(index, kTokenPosEntry)) = value; | 6408 *(EntryAddr(index, kTokenPosEntry)) = value; |
| 6410 } | 6409 } |
| 6411 | 6410 |
| 6412 | 6411 |
| 6413 intptr_t PcDescriptors::TryIndex(intptr_t index) const { | 6412 intptr_t PcDescriptors::TryIndex(intptr_t index) const { |
| 6414 ASSERT(DescriptorKind(index) != kDeoptIndex); | |
| 6415 return *(EntryAddr(index, kTryIndexEntry)); | 6413 return *(EntryAddr(index, kTryIndexEntry)); |
| 6416 } | 6414 } |
| 6417 | 6415 |
| 6418 | 6416 |
| 6419 void PcDescriptors::SetTryIndex(intptr_t index, intptr_t value) const { | 6417 void PcDescriptors::SetTryIndex(intptr_t index, intptr_t value) const { |
| 6420 *(EntryAddr(index, kTryIndexEntry)) = value; | 6418 *(EntryAddr(index, kTryIndexEntry)) = value; |
| 6421 } | 6419 } |
| 6422 | 6420 |
| 6423 | 6421 |
| 6424 intptr_t PcDescriptors::DeoptIndex(intptr_t index) const { | |
| 6425 ASSERT(DescriptorKind(index) == kDeoptIndex); | |
| 6426 return *(EntryAddr(index, kDeoptIndexEntry)); | |
| 6427 } | |
| 6428 | |
| 6429 | |
| 6430 intptr_t PcDescriptors::DeoptReason(intptr_t index) const { | |
| 6431 ASSERT(DescriptorKind(index) == kDeoptIndex); | |
| 6432 return *(EntryAddr(index, kDeoptReasonEntry)); | |
| 6433 } | |
| 6434 | |
| 6435 | |
| 6436 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors) { | 6422 RawPcDescriptors* PcDescriptors::New(intptr_t num_descriptors) { |
| 6437 ASSERT(Object::pc_descriptors_class() != Class::null()); | 6423 ASSERT(Object::pc_descriptors_class() != Class::null()); |
| 6438 if (num_descriptors < 0 || num_descriptors > kMaxElements) { | 6424 if (num_descriptors < 0 || num_descriptors > kMaxElements) { |
| 6439 // This should be caught before we reach here. | 6425 // This should be caught before we reach here. |
| 6440 FATAL1("Fatal error in PcDescriptors::New: " | 6426 FATAL1("Fatal error in PcDescriptors::New: " |
| 6441 "invalid num_descriptors %"Pd"\n", num_descriptors); | 6427 "invalid num_descriptors %"Pd"\n", num_descriptors); |
| 6442 } | 6428 } |
| 6443 PcDescriptors& result = PcDescriptors::Handle(); | 6429 PcDescriptors& result = PcDescriptors::Handle(); |
| 6444 { | 6430 { |
| 6445 uword size = PcDescriptors::InstanceSize(num_descriptors); | 6431 uword size = PcDescriptors::InstanceSize(num_descriptors); |
| 6446 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 6432 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, |
| 6447 size, | 6433 size, |
| 6448 Heap::kOld); | 6434 Heap::kOld); |
| 6449 NoGCScope no_gc; | 6435 NoGCScope no_gc; |
| 6450 result ^= raw; | 6436 result ^= raw; |
| 6451 result.SetLength(num_descriptors); | 6437 result.SetLength(num_descriptors); |
| 6452 } | 6438 } |
| 6453 return result.raw(); | 6439 return result.raw(); |
| 6454 } | 6440 } |
| 6455 | 6441 |
| 6456 | 6442 |
| 6457 const char* PcDescriptors::KindAsStr(intptr_t index) const { | 6443 const char* PcDescriptors::KindAsStr(intptr_t index) const { |
| 6458 switch (DescriptorKind(index)) { | 6444 switch (DescriptorKind(index)) { |
| 6459 case PcDescriptors::kDeoptBefore: return "deopt-before "; | 6445 case PcDescriptors::kDeoptBefore: return "deopt-before "; |
| 6460 case PcDescriptors::kDeoptAfter: return "deopt-after "; | 6446 case PcDescriptors::kDeoptAfter: return "deopt-after "; |
| 6461 case PcDescriptors::kDeoptIndex: return "deopt-ix "; | |
| 6462 case PcDescriptors::kPatchCode: return "patch "; | 6447 case PcDescriptors::kPatchCode: return "patch "; |
| 6463 case PcDescriptors::kLazyDeoptJump: return "lazy-deopt "; | 6448 case PcDescriptors::kLazyDeoptJump: return "lazy-deopt "; |
| 6464 case PcDescriptors::kIcCall: return "ic-call "; | 6449 case PcDescriptors::kIcCall: return "ic-call "; |
| 6465 case PcDescriptors::kFuncCall: return "fn-call "; | 6450 case PcDescriptors::kFuncCall: return "fn-call "; |
| 6466 case PcDescriptors::kReturn: return "return "; | 6451 case PcDescriptors::kReturn: return "return "; |
| 6467 case PcDescriptors::kOther: return "other "; | 6452 case PcDescriptors::kOther: return "other "; |
| 6468 } | 6453 } |
| 6469 UNREACHABLE(); | 6454 UNREACHABLE(); |
| 6470 return ""; | 6455 return ""; |
| 6471 } | 6456 } |
| 6472 | 6457 |
| 6473 | 6458 |
| 6474 void PcDescriptors::PrintHeaderString() { | 6459 void PcDescriptors::PrintHeaderString() { |
| 6475 // 4 bits per hex digit + 2 for "0x". | 6460 // 4 bits per hex digit + 2 for "0x". |
| 6476 const int addr_width = (kBitsPerWord / 4) + 2; | 6461 const int addr_width = (kBitsPerWord / 4) + 2; |
| 6477 // "*" in a printf format specifier tells it to read the field width from | 6462 // "*" in a printf format specifier tells it to read the field width from |
| 6478 // the printf argument list. | 6463 // the printf argument list. |
| 6479 OS::Print("%-*s\tkind \tdeopt-id\ttok-ix\ttry/deopt-ix\n", | 6464 OS::Print("%-*s\tkind \tdeopt-id\ttok-ix\ttry-ix\n", |
| 6480 addr_width, "pc"); | 6465 addr_width, "pc"); |
| 6481 } | 6466 } |
| 6482 | 6467 |
| 6483 | 6468 |
| 6484 const char* PcDescriptors::ToCString() const { | 6469 const char* PcDescriptors::ToCString() const { |
| 6485 if (Length() == 0) { | 6470 if (Length() == 0) { |
| 6486 return "No pc descriptors\n"; | 6471 return "No pc descriptors\n"; |
| 6487 } | 6472 } |
| 6488 // 4 bits per hex digit. | 6473 // 4 bits per hex digit. |
| 6489 const int addr_width = kBitsPerWord / 4; | 6474 const int addr_width = kBitsPerWord / 4; |
| 6490 // "*" in a printf format specifier tells it to read the field width from | 6475 // "*" in a printf format specifier tells it to read the field width from |
| 6491 // the printf argument list. | 6476 // the printf argument list. |
| 6492 const char* kFormat = | 6477 const char* kFormat = |
| 6493 "%#-*"Px"\t%s\t%"Pd"\t%"Pd"\t%"Pd"\n"; | 6478 "%#-*"Px"\t%s\t%"Pd"\t%"Pd"\t%"Pd"\n"; |
| 6494 // First compute the buffer size required. | 6479 // First compute the buffer size required. |
| 6495 intptr_t len = 1; // Trailing '\0'. | 6480 intptr_t len = 1; // Trailing '\0'. |
| 6496 for (intptr_t i = 0; i < Length(); i++) { | 6481 for (intptr_t i = 0; i < Length(); i++) { |
| 6497 intptr_t token_pos_or_deopt_reason = DescriptorKind(i) == kDeoptIndex ? | |
| 6498 DeoptReason(i) : TokenPos(i); | |
| 6499 intptr_t multi_purpose_index = DescriptorKind(i) == kDeoptIndex ? | |
| 6500 DeoptIndex(i) : TryIndex(i); | |
| 6501 len += OS::SNPrint(NULL, 0, kFormat, addr_width, | 6482 len += OS::SNPrint(NULL, 0, kFormat, addr_width, |
| 6502 PC(i), | 6483 PC(i), |
| 6503 KindAsStr(i), | 6484 KindAsStr(i), |
| 6504 DeoptId(i), | 6485 DeoptId(i), |
| 6505 token_pos_or_deopt_reason, | 6486 TokenPos(i), |
| 6506 multi_purpose_index); | 6487 TryIndex(i)); |
| 6507 } | 6488 } |
| 6508 // Allocate the buffer. | 6489 // Allocate the buffer. |
| 6509 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); | 6490 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 6510 // Layout the fields in the buffer. | 6491 // Layout the fields in the buffer. |
| 6511 intptr_t index = 0; | 6492 intptr_t index = 0; |
| 6512 for (intptr_t i = 0; i < Length(); i++) { | 6493 for (intptr_t i = 0; i < Length(); i++) { |
| 6513 intptr_t token_pos_or_deopt_reason = DescriptorKind(i) == kDeoptIndex ? | |
| 6514 DeoptReason(i) : TokenPos(i); | |
| 6515 intptr_t multi_purpose_index = DescriptorKind(i) == kDeoptIndex ? | |
| 6516 DeoptIndex(i) : TryIndex(i); | |
| 6517 index += OS::SNPrint((buffer + index), (len - index), kFormat, addr_width, | 6494 index += OS::SNPrint((buffer + index), (len - index), kFormat, addr_width, |
| 6518 PC(i), | 6495 PC(i), |
| 6519 KindAsStr(i), | 6496 KindAsStr(i), |
| 6520 DeoptId(i), | 6497 DeoptId(i), |
| 6521 token_pos_or_deopt_reason, | 6498 TokenPos(i), |
| 6522 multi_purpose_index); | 6499 TryIndex(i)); |
| 6523 } | 6500 } |
| 6524 return buffer; | 6501 return buffer; |
| 6525 } | 6502 } |
| 6526 | 6503 |
| 6527 | 6504 |
| 6528 // Verify assumptions (in debug mode only). | 6505 // Verify assumptions (in debug mode only). |
| 6529 // - No two deopt descriptors have the same deoptimization id. | 6506 // - No two deopt descriptors have the same deoptimization id. |
| 6530 // - No two ic-call descriptors have the same deoptimization id (type feedback). | 6507 // - No two ic-call descriptors have the same deoptimization id (type feedback). |
| 6531 // A function without unique ids is marked as non-optimizable (e.g., because of | 6508 // A function without unique ids is marked as non-optimizable (e.g., because of |
| 6532 // finally blocks). | 6509 // finally blocks). |
| (...skipping 5622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12155 } | 12132 } |
| 12156 return result.raw(); | 12133 return result.raw(); |
| 12157 } | 12134 } |
| 12158 | 12135 |
| 12159 | 12136 |
| 12160 const char* WeakProperty::ToCString() const { | 12137 const char* WeakProperty::ToCString() const { |
| 12161 return "_WeakProperty"; | 12138 return "_WeakProperty"; |
| 12162 } | 12139 } |
| 12163 | 12140 |
| 12164 } // namespace dart | 12141 } // namespace dart |
| OLD | NEW |