| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 DEFINE_FLAG(bool, show_internal_names, false, | 44 DEFINE_FLAG(bool, show_internal_names, false, |
| 45 "Show names of internal classes (e.g. \"OneByteString\") in error messages " | 45 "Show names of internal classes (e.g. \"OneByteString\") in error messages " |
| 46 "instead of showing the corresponding interface names (e.g. \"String\")"); | 46 "instead of showing the corresponding interface names (e.g. \"String\")"); |
| 47 DEFINE_FLAG(bool, trace_disabling_optimized_code, false, | 47 DEFINE_FLAG(bool, trace_disabling_optimized_code, false, |
| 48 "Trace disabling optimized code."); | 48 "Trace disabling optimized code."); |
| 49 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, | 49 DEFINE_FLAG(int, huge_method_cutoff_in_tokens, 20000, |
| 50 "Huge method cutoff in tokens: Disables optimizations for huge methods."); | 50 "Huge method cutoff in tokens: Disables optimizations for huge methods."); |
| 51 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, | 51 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, |
| 52 "Huge method cutoff in unoptimized code size (in bytes)."); | 52 "Huge method cutoff in unoptimized code size (in bytes)."); |
| 53 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false, |
| 54 "Throw an exception when integer arithmetic exceeds 53 bits."); |
| 53 DECLARE_FLAG(bool, trace_compiler); | 55 DECLARE_FLAG(bool, trace_compiler); |
| 54 DECLARE_FLAG(bool, eliminate_type_checks); | 56 DECLARE_FLAG(bool, eliminate_type_checks); |
| 55 DECLARE_FLAG(bool, enable_type_checks); | 57 DECLARE_FLAG(bool, enable_type_checks); |
| 56 DECLARE_FLAG(int, deoptimization_counter_threshold); | 58 DECLARE_FLAG(int, deoptimization_counter_threshold); |
| 57 | 59 |
| 58 static const char* kGetterPrefix = "get:"; | 60 static const char* kGetterPrefix = "get:"; |
| 59 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); | 61 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); |
| 60 static const char* kSetterPrefix = "set:"; | 62 static const char* kSetterPrefix = "set:"; |
| 61 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); | 63 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); |
| 62 | 64 |
| (...skipping 6935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6998 } \ | 7000 } \ |
| 6999 if (!func.IsNull() && (func.SourceFingerprint() != fp)) { \ | 7001 if (!func.IsNull() && (func.SourceFingerprint() != fp)) { \ |
| 7000 has_errors = true; \ | 7002 has_errors = true; \ |
| 7001 OS::Print("Wrong fingerprint for '%s': expecting %d found %d\n", \ | 7003 OS::Print("Wrong fingerprint for '%s': expecting %d found %d\n", \ |
| 7002 func.ToFullyQualifiedCString(), fp, func.SourceFingerprint()); \ | 7004 func.ToFullyQualifiedCString(), fp, func.SourceFingerprint()); \ |
| 7003 collected_fp_diffs.Add(FpDiff(fp, func.SourceFingerprint())); \ | 7005 collected_fp_diffs.Add(FpDiff(fp, func.SourceFingerprint())); \ |
| 7004 } \ | 7006 } \ |
| 7005 | 7007 |
| 7006 lib = Library::CoreLibrary(); | 7008 lib = Library::CoreLibrary(); |
| 7007 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 7009 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 7010 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 7008 | 7011 |
| 7009 RECOGNIZED_LIST(CHECK_FINGERPRINTS); | 7012 RECOGNIZED_LIST(CHECK_FINGERPRINTS); |
| 7010 | 7013 |
| 7011 lib = Library::MathLibrary(); | 7014 lib = Library::MathLibrary(); |
| 7012 MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 7015 MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 7013 | 7016 |
| 7014 lib = Library::TypedDataLibrary(); | 7017 lib = Library::TypedDataLibrary(); |
| 7015 TYPED_DATA_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); | 7018 TYPED_DATA_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); |
| 7016 | 7019 |
| 7017 #undef CHECK_FINGERPRINTS | 7020 #undef CHECK_FINGERPRINTS |
| (...skipping 3415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10433 ASSERT(!BigintOperations::FitsIntoInt64(big)); | 10436 ASSERT(!BigintOperations::FitsIntoInt64(big)); |
| 10434 return big.raw(); | 10437 return big.raw(); |
| 10435 } | 10438 } |
| 10436 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 10439 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
| 10437 return Smi::New(value); | 10440 return Smi::New(value); |
| 10438 } | 10441 } |
| 10439 return Mint::NewCanonical(value); | 10442 return Mint::NewCanonical(value); |
| 10440 } | 10443 } |
| 10441 | 10444 |
| 10442 | 10445 |
| 10446 // Throw FiftyThreeBitOverflow exception. |
| 10447 static void ThrowFiftyThreeBitOverflow(const Integer& i) { |
| 10448 const Array& exc_args = Array::Handle(Array::New(1)); |
| 10449 exc_args.SetAt(0, i); |
| 10450 Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args); |
| 10451 } |
| 10452 |
| 10453 |
| 10443 RawInteger* Integer::New(int64_t value, Heap::Space space) { | 10454 RawInteger* Integer::New(int64_t value, Heap::Space space) { |
| 10444 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 10455 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
| 10445 return Smi::New(value); | 10456 return Smi::New(value); |
| 10446 } | 10457 } |
| 10458 if (FLAG_throw_on_javascript_int_overflow && !Utils::IsInt(53, value)) { |
| 10459 const Integer &i = Integer::Handle(Mint::New(value)); |
| 10460 ThrowFiftyThreeBitOverflow(i); |
| 10461 } |
| 10447 return Mint::New(value, space); | 10462 return Mint::New(value, space); |
| 10448 } | 10463 } |
| 10449 | 10464 |
| 10450 | 10465 |
| 10451 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { | 10466 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { |
| 10452 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { | 10467 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { |
| 10468 if (FLAG_throw_on_javascript_int_overflow) { |
| 10469 const Integer &i = |
| 10470 Integer::Handle(BigintOperations::NewFromUint64(value)); |
| 10471 ThrowFiftyThreeBitOverflow(i); |
| 10472 } |
| 10453 return BigintOperations::NewFromUint64(value); | 10473 return BigintOperations::NewFromUint64(value); |
| 10454 } else { | 10474 } else { |
| 10455 return Integer::New(value); | 10475 return Integer::New(value); |
| 10456 } | 10476 } |
| 10457 } | 10477 } |
| 10458 | 10478 |
| 10459 | 10479 |
| 10460 double Integer::AsDoubleValue() const { | 10480 double Integer::AsDoubleValue() const { |
| 10461 UNIMPLEMENTED(); | 10481 UNIMPLEMENTED(); |
| 10462 return 0.0; | 10482 return 0.0; |
| 10463 } | 10483 } |
| 10464 | 10484 |
| 10465 | 10485 |
| 10466 int64_t Integer::AsInt64Value() const { | 10486 int64_t Integer::AsInt64Value() const { |
| 10467 UNIMPLEMENTED(); | 10487 UNIMPLEMENTED(); |
| 10468 return 0; | 10488 return 0; |
| 10469 } | 10489 } |
| 10470 | 10490 |
| 10471 | 10491 |
| 10472 int Integer::CompareWith(const Integer& other) const { | 10492 int Integer::CompareWith(const Integer& other) const { |
| 10473 UNIMPLEMENTED(); | 10493 UNIMPLEMENTED(); |
| 10474 return 0; | 10494 return 0; |
| 10475 } | 10495 } |
| 10476 | 10496 |
| 10477 | 10497 |
| 10498 static void CheckFiftyThreeBitOverflow(const Integer &i) { |
| 10499 if (i.IsSmi()) return; |
| 10500 // Always overflow if the value doesn't fit into an int64_t. |
| 10501 int64_t value = 1ULL << 63; |
| 10502 if (i.IsMint()) { |
| 10503 Mint& mint = Mint::Handle(); |
| 10504 mint ^= i.raw(); |
| 10505 value = mint.value(); |
| 10506 } else { |
| 10507 ASSERT(i.IsBigint()); |
| 10508 Bigint& big_value = Bigint::Handle(); |
| 10509 big_value ^= i.raw(); |
| 10510 if (BigintOperations::FitsIntoInt64(big_value)) { |
| 10511 value = BigintOperations::ToInt64(big_value); |
| 10512 } |
| 10513 } |
| 10514 if (Utils::IsInt(53, value)) return; |
| 10515 ThrowFiftyThreeBitOverflow(i); |
| 10516 } |
| 10517 |
| 10518 |
| 10478 RawInteger* Integer::AsValidInteger() const { | 10519 RawInteger* Integer::AsValidInteger() const { |
| 10520 if (FLAG_throw_on_javascript_int_overflow) { |
| 10521 CheckFiftyThreeBitOverflow(*this); |
| 10522 } |
| 10479 if (IsSmi()) return raw(); | 10523 if (IsSmi()) return raw(); |
| 10480 if (IsMint()) { | 10524 if (IsMint()) { |
| 10481 Mint& mint = Mint::Handle(); | 10525 Mint& mint = Mint::Handle(); |
| 10482 mint ^= raw(); | 10526 mint ^= raw(); |
| 10483 if (Smi::IsValid64(mint.value())) { | 10527 if (Smi::IsValid64(mint.value())) { |
| 10484 return Smi::New(mint.value()); | 10528 return Smi::New(mint.value()); |
| 10485 } else { | 10529 } else { |
| 10486 return raw(); | 10530 return raw(); |
| 10487 } | 10531 } |
| 10488 } | 10532 } |
| (...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13329 space); | 13373 space); |
| 13330 return reinterpret_cast<RawWeakProperty*>(raw); | 13374 return reinterpret_cast<RawWeakProperty*>(raw); |
| 13331 } | 13375 } |
| 13332 | 13376 |
| 13333 | 13377 |
| 13334 const char* WeakProperty::ToCString() const { | 13378 const char* WeakProperty::ToCString() const { |
| 13335 return "_WeakProperty"; | 13379 return "_WeakProperty"; |
| 13336 } | 13380 } |
| 13337 | 13381 |
| 13338 } // namespace dart | 13382 } // namespace dart |
| OLD | NEW |