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

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, 7 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 58
57 static const char* kGetterPrefix = "get:"; 59 static const char* kGetterPrefix = "get:";
58 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); 60 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix);
59 static const char* kSetterPrefix = "set:"; 61 static const char* kSetterPrefix = "set:";
60 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); 62 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix);
61 63
62 cpp_vtable Object::handle_vtable_ = 0; 64 cpp_vtable Object::handle_vtable_ = 0;
(...skipping 10368 matching lines...) Expand 10 before | Expand all | Expand 10 after
10431 ASSERT(!BigintOperations::FitsIntoInt64(big)); 10433 ASSERT(!BigintOperations::FitsIntoInt64(big));
10432 return big.raw(); 10434 return big.raw();
10433 } 10435 }
10434 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 10436 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
10435 return Smi::New(value); 10437 return Smi::New(value);
10436 } 10438 }
10437 return Mint::NewCanonical(value); 10439 return Mint::NewCanonical(value);
10438 } 10440 }
10439 10441
10440 10442
10443 // Throw FiftyThreeBitOverflow exception.
10444 static void ThrowFiftyThreeBitOverflow() {
10445 const Array& exc_args = Array::Handle(Array::New(0));
10446 Exceptions::ThrowByType(Exceptions::kFiftyThreeBitOverflowError, exc_args);
10447 return;
srdjan 2013/05/28 10:57:14 remove return.
zra 2013/05/28 17:06:39 Done.
10448 }
10449
10450
10441 RawInteger* Integer::New(int64_t value, Heap::Space space) { 10451 RawInteger* Integer::New(int64_t value, Heap::Space space) {
10442 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 10452 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
10443 return Smi::New(value); 10453 return Smi::New(value);
10444 } 10454 }
10455 if (FLAG_throw_on_javascript_int_overflow && !Utils::IsInt(53, value)) {
10456 ThrowFiftyThreeBitOverflow();
10457 }
10445 return Mint::New(value, space); 10458 return Mint::New(value, space);
10446 } 10459 }
10447 10460
10448 10461
10449 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { 10462 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) {
10450 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 10463 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
10464 if (FLAG_throw_on_javascript_int_overflow) {
10465 ThrowFiftyThreeBitOverflow();
10466 }
10451 return BigintOperations::NewFromUint64(value); 10467 return BigintOperations::NewFromUint64(value);
10452 } else { 10468 } else {
10453 return Integer::New(value); 10469 return Integer::New(value);
10454 } 10470 }
10455 } 10471 }
10456 10472
10457 10473
10458 double Integer::AsDoubleValue() const { 10474 double Integer::AsDoubleValue() const {
10459 UNIMPLEMENTED(); 10475 UNIMPLEMENTED();
10460 return 0.0; 10476 return 0.0;
10461 } 10477 }
10462 10478
10463 10479
10464 int64_t Integer::AsInt64Value() const { 10480 int64_t Integer::AsInt64Value() const {
10465 UNIMPLEMENTED(); 10481 UNIMPLEMENTED();
10466 return 0; 10482 return 0;
10467 } 10483 }
10468 10484
10469 10485
10470 int Integer::CompareWith(const Integer& other) const { 10486 int Integer::CompareWith(const Integer& other) const {
10471 UNIMPLEMENTED(); 10487 UNIMPLEMENTED();
10472 return 0; 10488 return 0;
10473 } 10489 }
10474 10490
10475 10491
10492 static void CheckFiftyThreeBitOverflow(const Integer &i) {
srdjan 2013/05/28 10:57:14 Optional: The code would be simpler if you have Th
zra 2013/05/28 17:06:39 I gave this a shot. Please let me know if it looks
10493 if (i.IsSmi()) return;
10494 if (i.IsMint()) {
10495 Mint& mint = Mint::Handle();
10496 mint ^= i.raw();
10497 if (!Utils::IsInt(53, mint.value())) {
10498 ThrowFiftyThreeBitOverflow();
10499 }
10500 return;
10501 }
10502 ASSERT(i.IsBigint());
10503 Bigint& big_value = Bigint::Handle();
10504 big_value ^= i.raw();
10505 if (BigintOperations::FitsIntoInt64(big_value)) {
10506 if (!Utils::IsInt(53, BigintOperations::ToInt64(big_value))) {
10507 ThrowFiftyThreeBitOverflow();
10508 }
10509 } else {
10510 ThrowFiftyThreeBitOverflow();
10511 }
10512 }
10513
10514
10476 RawInteger* Integer::AsValidInteger() const { 10515 RawInteger* Integer::AsValidInteger() const {
10516 if (FLAG_throw_on_javascript_int_overflow) {
10517 CheckFiftyThreeBitOverflow(*this);
10518 }
10477 if (IsSmi()) return raw(); 10519 if (IsSmi()) return raw();
10478 if (IsMint()) { 10520 if (IsMint()) {
10479 Mint& mint = Mint::Handle(); 10521 Mint& mint = Mint::Handle();
10480 mint ^= raw(); 10522 mint ^= raw();
10481 if (Smi::IsValid64(mint.value())) { 10523 if (Smi::IsValid64(mint.value())) {
10482 return Smi::New(mint.value()); 10524 return Smi::New(mint.value());
10483 } else { 10525 } else {
10484 return raw(); 10526 return raw();
10485 } 10527 }
10486 } 10528 }
(...skipping 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after
13336 } 13378 }
13337 return result.raw(); 13379 return result.raw();
13338 } 13380 }
13339 13381
13340 13382
13341 const char* WeakProperty::ToCString() const { 13383 const char* WeakProperty::ToCString() const {
13342 return "_WeakProperty"; 13384 return "_WeakProperty";
13343 } 13385 }
13344 13386
13345 } // namespace dart 13387 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier.cc ('k') | runtime/vm/symbols.h » ('j') | sdk/lib/core/errors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698