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

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

Issue 14962008: Fix issue 5275: The VM must always generate the most compact form of an integer (Smi, Mint or Bigin… (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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 3913 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 static RawInteger* New(int64_t value, Heap::Space space = Heap::kNew); 3924 static RawInteger* New(int64_t value, Heap::Space space = Heap::kNew);
3925 3925
3926 virtual double AsDoubleValue() const; 3926 virtual double AsDoubleValue() const;
3927 virtual int64_t AsInt64Value() const; 3927 virtual int64_t AsInt64Value() const;
3928 3928
3929 // Returns 0, -1 or 1. 3929 // Returns 0, -1 or 1.
3930 virtual int CompareWith(const Integer& other) const; 3930 virtual int CompareWith(const Integer& other) const;
3931 3931
3932 // Return the most compact presentation of an integer. 3932 // Return the most compact presentation of an integer.
3933 RawInteger* AsValidInteger() const; 3933 RawInteger* AsValidInteger() const;
3934 // Return an integer in the form of a RawBigint.
3935 RawBigint* AsBigint() const;
3936 3934
3937 RawInteger* ArithmeticOp(Token::Kind operation, const Integer& other) const; 3935 RawInteger* ArithmeticOp(Token::Kind operation, const Integer& other) const;
3938 RawInteger* BitOp(Token::Kind operation, const Integer& other) const; 3936 RawInteger* BitOp(Token::Kind operation, const Integer& other) const;
3939 3937
3938 private:
3939 // Return an integer in the form of a RawBigint.
3940 RawBigint* AsBigint() const;
3941
3940 OBJECT_IMPLEMENTATION(Integer, Number); 3942 OBJECT_IMPLEMENTATION(Integer, Number);
3941 friend class Class; 3943 friend class Class;
3942 }; 3944 };
3943 3945
3944 3946
3945 class Smi : public Integer { 3947 class Smi : public Integer {
3946 public: 3948 public:
3947 static const intptr_t kBits = kSmiBits; 3949 static const intptr_t kBits = kSmiBits;
3948 static const intptr_t kMaxValue = kSmiMax; 3950 static const intptr_t kMaxValue = kSmiMax;
3949 static const intptr_t kMinValue = kSmiMin; 3951 static const intptr_t kMinValue = kSmiMin;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4039 return value() < 0; 4041 return value() < 0;
4040 } 4042 }
4041 4043
4042 virtual bool Equals(const Instance& other) const; 4044 virtual bool Equals(const Instance& other) const;
4043 4045
4044 virtual double AsDoubleValue() const; 4046 virtual double AsDoubleValue() const;
4045 virtual int64_t AsInt64Value() const; 4047 virtual int64_t AsInt64Value() const;
4046 4048
4047 virtual int CompareWith(const Integer& other) const; 4049 virtual int CompareWith(const Integer& other) const;
4048 4050
4049 static RawMint* New(int64_t value, Heap::Space space = Heap::kNew);
4050 static RawMint* NewCanonical(int64_t value);
4051
4052 static intptr_t InstanceSize() { 4051 static intptr_t InstanceSize() {
4053 return RoundedAllocationSize(sizeof(RawMint)); 4052 return RoundedAllocationSize(sizeof(RawMint));
4054 } 4053 }
4055 4054
4055 protected:
4056 // Only Integer::NewXXX is allowed to call Mint::NewXXX directly.
4057 friend class Integer;
4058
4059 static RawMint* New(int64_t value, Heap::Space space = Heap::kNew);
4060
4061 static RawMint* NewCanonical(int64_t value);
4062
4056 private: 4063 private:
4057 void set_value(int64_t value) const; 4064 void set_value(int64_t value) const;
4058 4065
4059 FINAL_HEAP_OBJECT_IMPLEMENTATION(Mint, Integer); 4066 FINAL_HEAP_OBJECT_IMPLEMENTATION(Mint, Integer);
4060 friend class Class; 4067 friend class Class;
4061 }; 4068 };
4062 4069
4063 4070
4064 class Bigint : public Integer { 4071 class Bigint : public Integer {
4065 private: 4072 private:
(...skipping 15 matching lines...) Expand all
4081 static const intptr_t kBytesPerElement = kChunkSize; 4088 static const intptr_t kBytesPerElement = kChunkSize;
4082 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; 4089 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
4083 4090
4084 static intptr_t InstanceSize() { return 0; } 4091 static intptr_t InstanceSize() { return 0; }
4085 4092
4086 static intptr_t InstanceSize(intptr_t len) { 4093 static intptr_t InstanceSize(intptr_t len) {
4087 ASSERT(0 <= len && len <= kMaxElements); 4094 ASSERT(0 <= len && len <= kMaxElements);
4088 return RoundedAllocationSize(sizeof(RawBigint) + (len * kBytesPerElement)); 4095 return RoundedAllocationSize(sizeof(RawBigint) + (len * kBytesPerElement));
4089 } 4096 }
4090 4097
4098 RawBigint* ArithmeticOp(Token::Kind operation, const Bigint& other) const;
4099
4100 protected:
4101 // Only Integer::NewXXX is allowed to call Bigint::NewXXX directly.
4102 friend class Integer;
4103
4091 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew); 4104 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew);
4092 4105
4093 // Returns a canonical Bigint object allocated in the old gen space. 4106 // Returns a canonical Bigint object allocated in the old gen space.
4094 static RawBigint* NewCanonical(const String& str); 4107 static RawBigint* NewCanonical(const String& str);
4095 4108
4096 RawBigint* ArithmeticOp(Token::Kind operation, const Bigint& other) const;
4097
4098 private: 4109 private:
4099 Chunk GetChunkAt(intptr_t i) const { 4110 Chunk GetChunkAt(intptr_t i) const {
4100 return *ChunkAddr(i); 4111 return *ChunkAddr(i);
4101 } 4112 }
4102 4113
4103 void SetChunkAt(intptr_t i, Chunk newValue) const { 4114 void SetChunkAt(intptr_t i, Chunk newValue) const {
4104 *ChunkAddr(i) = newValue; 4115 *ChunkAddr(i) = newValue;
4105 } 4116 }
4106 4117
4107 // Returns the number of chunks in use. 4118 // Returns the number of chunks in use.
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
5753 5764
5754 5765
5755 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 5766 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
5756 intptr_t index) { 5767 intptr_t index) {
5757 return array.At((index * kEntryLength) + kTargetFunctionIndex); 5768 return array.At((index * kEntryLength) + kTargetFunctionIndex);
5758 } 5769 }
5759 5770
5760 } // namespace dart 5771 } // namespace dart
5761 5772
5762 #endif // VM_OBJECT_H_ 5773 #endif // VM_OBJECT_H_
OLDNEW
« runtime/lib/typed_data.cc ('K') | « runtime/vm/isolate.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698