Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: runtime/vm/object.cc

Issue 15743017: Adds a flag to the standalone vm to throw an exception on 53-bit integer overflow. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 6932 matching lines...) Expand 10 before | Expand all | Expand 10 after
6995 } \ 6997 } \
6996 if (!func.IsNull() && (func.SourceFingerprint() != fp)) { \ 6998 if (!func.IsNull() && (func.SourceFingerprint() != fp)) { \
6997 has_errors = true; \ 6999 has_errors = true; \
6998 OS::Print("Wrong fingerprint for '%s': expecting %d found %d\n", \ 7000 OS::Print("Wrong fingerprint for '%s': expecting %d found %d\n", \
6999 func.ToFullyQualifiedCString(), fp, func.SourceFingerprint()); \ 7001 func.ToFullyQualifiedCString(), fp, func.SourceFingerprint()); \
7000 collected_fp_diffs.Add(FpDiff(fp, func.SourceFingerprint())); \ 7002 collected_fp_diffs.Add(FpDiff(fp, func.SourceFingerprint())); \
7001 } \ 7003 } \
7002 7004
7003 lib = Library::CoreLibrary(); 7005 lib = Library::CoreLibrary();
7004 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); 7006 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
7007 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
7005 7008
7006 RECOGNIZED_LIST(CHECK_FINGERPRINTS); 7009 RECOGNIZED_LIST(CHECK_FINGERPRINTS);
7007 7010
7008 lib = Library::MathLibrary(); 7011 lib = Library::MathLibrary();
7009 MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); 7012 MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
7010 7013
7011 lib = Library::TypedDataLibrary(); 7014 lib = Library::TypedDataLibrary();
7012 TYPED_DATA_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS); 7015 TYPED_DATA_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS);
7013 7016
7014 #undef CHECK_FINGERPRINTS 7017 #undef CHECK_FINGERPRINTS
(...skipping 3405 matching lines...) Expand 10 before | Expand all | Expand 10 after
10420 ASSERT(!BigintOperations::FitsIntoInt64(big)); 10423 ASSERT(!BigintOperations::FitsIntoInt64(big));
10421 return big.raw(); 10424 return big.raw();
10422 } 10425 }
10423 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 10426 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
10424 return Smi::New(value); 10427 return Smi::New(value);
10425 } 10428 }
10426 return Mint::NewCanonical(value); 10429 return Mint::NewCanonical(value);
10427 } 10430 }
10428 10431
10429 10432
10433 // Throw FiftyThreeBitOverflow exception.
10434 static void ThrowFiftyThreeBitOverflow(const Integer& i) {
10435 const Array& exc_args = Array::Handle(Array::New(1));
10436 exc_args.SetAt(0, i);
10437 Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);
10438 }
10439
10440
10430 RawInteger* Integer::New(int64_t value, Heap::Space space) { 10441 RawInteger* Integer::New(int64_t value, Heap::Space space) {
10431 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 10442 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
10432 return Smi::New(value); 10443 return Smi::New(value);
10433 } 10444 }
10445 if (FLAG_throw_on_javascript_int_overflow && !Utils::IsInt(53, value)) {
10446 const Integer &i = Integer::Handle(Mint::New(value));
10447 ThrowFiftyThreeBitOverflow(i);
10448 }
10434 return Mint::New(value, space); 10449 return Mint::New(value, space);
10435 } 10450 }
10436 10451
10437 10452
10438 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { 10453 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) {
10439 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 10454 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
10455 if (FLAG_throw_on_javascript_int_overflow) {
10456 const Integer &i =
10457 Integer::Handle(BigintOperations::NewFromUint64(value));
10458 ThrowFiftyThreeBitOverflow(i);
10459 }
10440 return BigintOperations::NewFromUint64(value); 10460 return BigintOperations::NewFromUint64(value);
10441 } else { 10461 } else {
10442 return Integer::New(value); 10462 return Integer::New(value);
10443 } 10463 }
10444 } 10464 }
10445 10465
10446 10466
10447 double Integer::AsDoubleValue() const { 10467 double Integer::AsDoubleValue() const {
10448 UNIMPLEMENTED(); 10468 UNIMPLEMENTED();
10449 return 0.0; 10469 return 0.0;
10450 } 10470 }
10451 10471
10452 10472
10453 int64_t Integer::AsInt64Value() const { 10473 int64_t Integer::AsInt64Value() const {
10454 UNIMPLEMENTED(); 10474 UNIMPLEMENTED();
10455 return 0; 10475 return 0;
10456 } 10476 }
10457 10477
10458 10478
10459 int Integer::CompareWith(const Integer& other) const { 10479 int Integer::CompareWith(const Integer& other) const {
10460 UNIMPLEMENTED(); 10480 UNIMPLEMENTED();
10461 return 0; 10481 return 0;
10462 } 10482 }
10463 10483
10464 10484
10485 static void CheckFiftyThreeBitOverflow(const Integer &i) {
10486 if (i.IsSmi()) return;
10487 // Always overflow if the value doesn't fit into an int64_t.
10488 int64_t value = 1ULL << 63;
10489 if (i.IsMint()) {
10490 Mint& mint = Mint::Handle();
10491 mint ^= i.raw();
10492 value = mint.value();
10493 } else {
10494 ASSERT(i.IsBigint());
10495 Bigint& big_value = Bigint::Handle();
10496 big_value ^= i.raw();
10497 if (BigintOperations::FitsIntoInt64(big_value)) {
10498 value = BigintOperations::ToInt64(big_value);
10499 }
10500 }
10501 if (Utils::IsInt(53, value)) return;
10502 ThrowFiftyThreeBitOverflow(i);
10503 }
10504
10505
10465 RawInteger* Integer::AsValidInteger() const { 10506 RawInteger* Integer::AsValidInteger() const {
10507 if (FLAG_throw_on_javascript_int_overflow) {
10508 CheckFiftyThreeBitOverflow(*this);
10509 }
10466 if (IsSmi()) return raw(); 10510 if (IsSmi()) return raw();
10467 if (IsMint()) { 10511 if (IsMint()) {
10468 Mint& mint = Mint::Handle(); 10512 Mint& mint = Mint::Handle();
10469 mint ^= raw(); 10513 mint ^= raw();
10470 if (Smi::IsValid64(mint.value())) { 10514 if (Smi::IsValid64(mint.value())) {
10471 return Smi::New(mint.value()); 10515 return Smi::New(mint.value());
10472 } else { 10516 } else {
10473 return raw(); 10517 return raw();
10474 } 10518 }
10475 } 10519 }
(...skipping 2846 matching lines...) Expand 10 before | Expand all | Expand 10 after
13322 space); 13366 space);
13323 return reinterpret_cast<RawWeakProperty*>(raw); 13367 return reinterpret_cast<RawWeakProperty*>(raw);
13324 } 13368 }
13325 13369
13326 13370
13327 const char* WeakProperty::ToCString() const { 13371 const char* WeakProperty::ToCString() const {
13328 return "_WeakProperty"; 13372 return "_WeakProperty";
13329 } 13373 }
13330 13374
13331 } // namespace dart 13375 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698